Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 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> |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 64 | #include "p80211types.h" |
| 65 | #include "p80211hdr.h" |
| 66 | #include "p80211mgmt.h" |
| 67 | #include "p80211conv.h" |
| 68 | #include "p80211msg.h" |
| 69 | #include "p80211netdev.h" |
| 70 | #include "p80211ioctl.h" |
| 71 | #include "p80211metadef.h" |
| 72 | #include "p80211metastruct.h" |
| 73 | #include "p80211req.h" |
| 74 | |
Edgardo Hames | 3d04943 | 2010-08-02 17:17:17 -0300 | [diff] [blame] | 75 | static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg); |
Devendra Naga | bdced87 | 2012-09-09 18:40:57 +0530 | [diff] [blame] | 76 | static void p80211req_mibset_mibget(wlandevice_t *wlandev, |
Edgardo Hames | b6bb56e | 2010-08-02 16:20:39 -0300 | [diff] [blame] | 77 | struct p80211msg_dot11req_mibget *mib_msg, |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 78 | int isget); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 79 | |
| 80 | /*---------------------------------------------------------------- |
| 81 | * p80211req_dorequest |
| 82 | * |
Masanari Iida | 1a6dfce | 2014-12-01 00:29:00 +0900 | [diff] [blame] | 83 | * Handles an MLME request/confirm message. |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 84 | * |
| 85 | * Arguments: |
| 86 | * wlandev WLAN device struct |
| 87 | * msgbuf Buffer containing a request message |
| 88 | * |
| 89 | * Returns: |
| 90 | * 0 on success, an errno otherwise |
| 91 | * |
| 92 | * Call context: |
| 93 | * Potentially blocks the caller, so it's a good idea to |
| 94 | * not call this function from an interrupt context. |
| 95 | ----------------------------------------------------------------*/ |
Svenne Krap | 5dd8acc | 2010-02-14 18:59:00 +0100 | [diff] [blame] | 96 | int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 97 | { |
Edgardo Hames | 3d04943 | 2010-08-02 17:17:17 -0300 | [diff] [blame] | 98 | struct p80211msg *msg = (struct p80211msg *) msgbuf; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 99 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 100 | /* Check to make sure the MSD is running */ |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 101 | if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT && |
| 102 | msg->msgcode == DIDmsg_lnxreq_ifstate) || |
| 103 | wlandev->msdstate == WLAN_MSD_RUNNING || |
| 104 | wlandev->msdstate == WLAN_MSD_FWLOAD)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 105 | return -ENODEV; |
| 106 | } |
| 107 | |
| 108 | /* Check Permissions */ |
Patrick Rooney | 67a7b37 | 2010-03-10 08:46:30 +0000 | [diff] [blame] | 109 | if (!capable(CAP_NET_ADMIN) && |
| 110 | (msg->msgcode != DIDmsg_dot11req_mibget)) { |
Vitaly Osipov | 02d9b1e | 2014-05-18 16:59:36 +1000 | [diff] [blame] | 111 | netdev_err(wlandev->netdev, |
| 112 | "%s: only dot11req_mibget allowed for non-root.\n", |
| 113 | wlandev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 114 | return -EPERM; |
| 115 | } |
| 116 | |
| 117 | /* Check for busy status */ |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 118 | if (test_and_set_bit(1, &(wlandev->request_pending))) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 119 | return -EBUSY; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 120 | |
| 121 | /* Allow p80211 to look at msg and handle if desired. */ |
| 122 | /* So far, all p80211 msgs are immediate, no waitq/timer necessary */ |
| 123 | /* This may change. */ |
| 124 | p80211req_handlemsg(wlandev, msg); |
| 125 | |
| 126 | /* Pass it down to wlandev via wlandev->mlmerequest */ |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 127 | if (wlandev->mlmerequest != NULL) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 128 | wlandev->mlmerequest(wlandev, msg); |
| 129 | |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 130 | clear_bit(1, &(wlandev->request_pending)); |
Peter Senna Tschudin | 4764ca9 | 2014-05-26 16:08:50 +0200 | [diff] [blame] | 131 | return 0; /* if result==0, msg->status still may contain an err */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /*---------------------------------------------------------------- |
| 135 | * p80211req_handlemsg |
| 136 | * |
| 137 | * p80211 message handler. Primarily looks for messages that |
| 138 | * belong to p80211 and then dispatches the appropriate response. |
| 139 | * TODO: we don't do anything yet. Once the linuxMIB is better |
| 140 | * defined we'll need a get/set handler. |
| 141 | * |
| 142 | * Arguments: |
| 143 | * wlandev WLAN device struct |
| 144 | * msg message structure |
| 145 | * |
| 146 | * Returns: |
| 147 | * nothing (any results are set in the status field of the msg) |
| 148 | * |
| 149 | * Call context: |
| 150 | * Process thread |
| 151 | ----------------------------------------------------------------*/ |
Edgardo Hames | 3d04943 | 2010-08-02 17:17:17 -0300 | [diff] [blame] | 152 | static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 153 | { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 154 | switch (msg->msgcode) { |
| 155 | |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 156 | case DIDmsg_lnxreq_hostwep:{ |
Devendra Naga | 009629e | 2012-09-09 18:40:56 +0530 | [diff] [blame] | 157 | struct p80211msg_lnxreq_hostwep *req = |
| 158 | (struct p80211msg_lnxreq_hostwep *) msg; |
| 159 | wlandev->hostwep &= |
| 160 | ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT); |
| 161 | if (req->decrypt.data == P80211ENUM_truth_true) |
| 162 | wlandev->hostwep |= HOSTWEP_DECRYPT; |
| 163 | if (req->encrypt.data == P80211ENUM_truth_true) |
| 164 | wlandev->hostwep |= HOSTWEP_ENCRYPT; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 165 | |
Devendra Naga | 009629e | 2012-09-09 18:40:56 +0530 | [diff] [blame] | 166 | break; |
| 167 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 168 | case DIDmsg_dot11req_mibget: |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 169 | case DIDmsg_dot11req_mibset:{ |
Devendra Naga | 009629e | 2012-09-09 18:40:56 +0530 | [diff] [blame] | 170 | int isget = (msg->msgcode == DIDmsg_dot11req_mibget); |
| 171 | struct p80211msg_dot11req_mibget *mib_msg = |
| 172 | (struct p80211msg_dot11req_mibget *) msg; |
| 173 | p80211req_mibset_mibget(wlandev, mib_msg, isget); |
| 174 | break; |
| 175 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 176 | } /* switch msg->msgcode */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Devendra Naga | bdced87 | 2012-09-09 18:40:57 +0530 | [diff] [blame] | 179 | static void p80211req_mibset_mibget(wlandevice_t *wlandev, |
Edgardo Hames | b6bb56e | 2010-08-02 16:20:39 -0300 | [diff] [blame] | 180 | struct p80211msg_dot11req_mibget *mib_msg, |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 181 | int isget) |
| 182 | { |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 183 | p80211itemd_t *mibitem = (p80211itemd_t *) mib_msg->mibattribute.data; |
| 184 | p80211pstrd_t *pstr = (p80211pstrd_t *) mibitem->data; |
Solomon Peachy | aaad430 | 2008-10-29 10:42:53 -0400 | [diff] [blame] | 185 | u8 *key = mibitem->data + sizeof(p80211pstrd_t); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 186 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 187 | switch (mibitem->did) { |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 188 | case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 189 | if (!isget) |
| 190 | wep_change_key(wlandev, 0, key, pstr->len); |
| 191 | break; |
| 192 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 193 | case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 194 | if (!isget) |
| 195 | wep_change_key(wlandev, 1, key, pstr->len); |
| 196 | break; |
| 197 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 198 | case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 199 | if (!isget) |
| 200 | wep_change_key(wlandev, 2, key, pstr->len); |
| 201 | break; |
| 202 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 203 | case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 204 | if (!isget) |
| 205 | wep_change_key(wlandev, 3, key, pstr->len); |
| 206 | break; |
| 207 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 208 | case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 209 | u32 *data = (u32 *) mibitem->data; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 210 | |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 211 | if (isget) { |
| 212 | *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK; |
| 213 | } else { |
| 214 | wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK); |
| 215 | wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK); |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 216 | } |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 217 | break; |
| 218 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 219 | case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 220 | u32 *data = (u32 *) mibitem->data; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 221 | |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 222 | if (isget) { |
| 223 | if (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) |
| 224 | *data = P80211ENUM_truth_true; |
| 225 | else |
| 226 | *data = P80211ENUM_truth_false; |
| 227 | } else { |
| 228 | wlandev->hostwep &= ~(HOSTWEP_PRIVACYINVOKED); |
| 229 | if (*data == P80211ENUM_truth_true) |
| 230 | wlandev->hostwep |= HOSTWEP_PRIVACYINVOKED; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 231 | } |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 232 | break; |
| 233 | } |
Moritz Muehlenhoff | b1de967 | 2009-02-08 02:20:46 +0100 | [diff] [blame] | 234 | case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{ |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 235 | u32 *data = (u32 *) mibitem->data; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 236 | |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 237 | if (isget) { |
| 238 | if (wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) |
| 239 | *data = P80211ENUM_truth_true; |
| 240 | else |
| 241 | *data = P80211ENUM_truth_false; |
| 242 | } else { |
| 243 | wlandev->hostwep &= ~(HOSTWEP_EXCLUDEUNENCRYPTED); |
| 244 | if (*data == P80211ENUM_truth_true) |
| 245 | wlandev->hostwep |= HOSTWEP_EXCLUDEUNENCRYPTED; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 246 | } |
Devendra Naga | 7694538 | 2012-09-09 18:40:58 +0530 | [diff] [blame] | 247 | break; |
| 248 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 249 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 250 | } |