Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /* Copyright (C) 2006, Red Hat, Inc. */ |
| 2 | |
| 3 | #include <linux/bitops.h> |
| 4 | #include <net/ieee80211.h> |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 5 | #include <linux/etherdevice.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 6 | |
| 7 | #include "assoc.h" |
| 8 | #include "join.h" |
| 9 | #include "decl.h" |
| 10 | #include "hostcmd.h" |
| 11 | #include "host.h" |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 12 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | |
| 14 | |
| 15 | static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 16 | static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 17 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 18 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 19 | static int assoc_helper_essid(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 20 | struct assoc_request * assoc_req) |
| 21 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 22 | int ret = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 23 | struct bss_descriptor * bss; |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 24 | int channel = -1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 25 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 26 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 27 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 28 | /* FIXME: take channel into account when picking SSIDs if a channel |
| 29 | * is set. |
| 30 | */ |
| 31 | |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 32 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 33 | channel = assoc_req->channel; |
| 34 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 35 | lbs_deb_assoc("SSID '%s' requested\n", |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 36 | escape_essid(assoc_req->ssid, assoc_req->ssid_len)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 37 | if (assoc_req->mode == IW_MODE_INFRA) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 38 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
Holger Schurig | 6e22a85 | 2007-08-02 13:05:32 -0400 | [diff] [blame] | 39 | assoc_req->ssid_len, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 40 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 41 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 42 | assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 43 | if (bss != NULL) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 44 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 45 | ret = lbs_associate(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 46 | } else { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 47 | lbs_deb_assoc("SSID not found; cannot associate\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 48 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 49 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 50 | /* Scan for the network, do not save previous results. Stale |
| 51 | * scan data will cause us to join a non-existant adhoc network |
| 52 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 53 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 54 | assoc_req->ssid_len, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 55 | |
| 56 | /* Search for the requested SSID in the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 57 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 58 | assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 59 | if (bss != NULL) { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 60 | lbs_deb_assoc("SSID found, will join\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 61 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 62 | lbs_join_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 63 | } else { |
| 64 | /* else send START command */ |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 65 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 66 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 67 | IW_ESSID_MAX_SIZE); |
| 68 | assoc_req->bss.ssid_len = assoc_req->ssid_len; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 69 | lbs_start_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 70 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 71 | } |
| 72 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 73 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 78 | static int assoc_helper_bssid(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 79 | struct assoc_request * assoc_req) |
| 80 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 81 | int ret = 0; |
| 82 | struct bss_descriptor * bss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 83 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 84 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 85 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s", |
| 86 | print_mac(mac, assoc_req->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 87 | |
| 88 | /* Search for index position in list for requested MAC */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 89 | bss = lbs_find_bssid_in_list(priv, assoc_req->bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 90 | assoc_req->mode); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 91 | if (bss == NULL) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 92 | lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, " |
| 93 | "cannot associate.\n", print_mac(mac, assoc_req->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 94 | goto out; |
| 95 | } |
| 96 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 97 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 98 | if (assoc_req->mode == IW_MODE_INFRA) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 99 | ret = lbs_associate(priv, assoc_req); |
| 100 | lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 101 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 102 | lbs_join_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 103 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 104 | |
| 105 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 106 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 111 | static int assoc_helper_associate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 112 | struct assoc_request * assoc_req) |
| 113 | { |
| 114 | int ret = 0, done = 0; |
| 115 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 116 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 117 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 118 | /* If we're given and 'any' BSSID, try associating based on SSID */ |
| 119 | |
| 120 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 121 | if (compare_ether_addr(bssid_any, assoc_req->bssid) |
| 122 | && compare_ether_addr(bssid_off, assoc_req->bssid)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 123 | ret = assoc_helper_bssid(priv, assoc_req); |
| 124 | done = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 129 | ret = assoc_helper_essid(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 130 | } |
| 131 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 132 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 137 | static int assoc_helper_mode(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 138 | struct assoc_request * assoc_req) |
| 139 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 140 | int ret = 0; |
| 141 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 142 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 144 | if (assoc_req->mode == priv->mode) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 145 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 146 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 147 | if (assoc_req->mode == IW_MODE_INFRA) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 148 | if (priv->psstate != PS_STATE_FULL_POWER) |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 149 | lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 150 | priv->psmode = LBS802_11POWERMODECAM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 151 | } |
| 152 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 153 | priv->mode = assoc_req->mode; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 154 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 155 | CMD_802_11_SNMP_MIB, |
| 156 | 0, CMD_OPTION_WAITFORRSP, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 157 | OID_802_11_INFRASTRUCTURE_MODE, |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 158 | /* Shoot me now */ (void *) (size_t) assoc_req->mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 159 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 160 | done: |
| 161 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 166 | int lbs_update_channel(struct lbs_private *priv) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 167 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 168 | int ret; |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 169 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 170 | /* the channel in f/w could be out of sync, get the current channel */ |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 171 | lbs_deb_enter(LBS_DEB_ASSOC); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 172 | |
| 173 | ret = lbs_get_channel(priv); |
| 174 | if (ret > 0) |
| 175 | priv->curbssparams.channel = (u8) ret; |
| 176 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 177 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 178 | return ret; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 179 | } |
| 180 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 181 | void lbs_sync_channel(struct work_struct *work) |
Luis Carlos Cobo Rus | b8bedef | 2007-05-30 12:14:34 -0400 | [diff] [blame] | 182 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 183 | struct lbs_private *priv = container_of(work, struct lbs_private, |
| 184 | sync_channel); |
Luis Carlos Cobo Rus | b8bedef | 2007-05-30 12:14:34 -0400 | [diff] [blame] | 185 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 186 | lbs_deb_enter(LBS_DEB_ASSOC); |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 187 | if (lbs_update_channel(priv)) |
Luis Carlos Cobo Rus | b8bedef | 2007-05-30 12:14:34 -0400 | [diff] [blame] | 188 | lbs_pr_info("Channel synchronization failed."); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 189 | lbs_deb_leave(LBS_DEB_ASSOC); |
Luis Carlos Cobo Rus | b8bedef | 2007-05-30 12:14:34 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 192 | static int assoc_helper_channel(struct lbs_private *priv, |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 193 | struct assoc_request * assoc_req) |
| 194 | { |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 195 | int ret = 0; |
| 196 | |
| 197 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 198 | |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 199 | ret = lbs_update_channel(priv); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 200 | if (ret < 0) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 201 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 202 | } |
| 203 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 204 | if (assoc_req->channel == priv->curbssparams.channel) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 205 | goto done; |
| 206 | |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 207 | if (priv->mesh_dev) { |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame^] | 208 | /* Change mesh channel first; 21.p21 firmware won't let |
| 209 | you change channel otherwise (even though it'll return |
| 210 | an error to this */ |
| 211 | lbs_mesh_config(priv, 0, assoc_req->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 212 | } |
| 213 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 214 | lbs_deb_assoc("ASSOC: channel: %d -> %d\n", |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame^] | 215 | priv->curbssparams.channel, assoc_req->channel); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 216 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 217 | ret = lbs_set_channel(priv, assoc_req->channel); |
| 218 | if (ret < 0) |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 219 | lbs_deb_assoc("ASSOC: channel: error setting channel.\n"); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 220 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 221 | /* FIXME: shouldn't need to grab the channel _again_ after setting |
| 222 | * it since the firmware is supposed to return the new channel, but |
| 223 | * whatever... */ |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 224 | ret = lbs_update_channel(priv); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 225 | if (ret < 0) |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 226 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 227 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 228 | if (assoc_req->channel != priv->curbssparams.channel) { |
David Woodhouse | 88ae291 | 2007-12-11 19:57:05 -0500 | [diff] [blame] | 229 | lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n", |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 230 | assoc_req->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 231 | goto restore_mesh; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if ( assoc_req->secinfo.wep_enabled |
| 235 | && (assoc_req->wep_keys[0].len |
| 236 | || assoc_req->wep_keys[1].len |
| 237 | || assoc_req->wep_keys[2].len |
| 238 | || assoc_req->wep_keys[3].len)) { |
| 239 | /* Make sure WEP keys are re-sent to firmware */ |
| 240 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 241 | } |
| 242 | |
| 243 | /* Must restart/rejoin adhoc networks after channel change */ |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 244 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 245 | |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 246 | restore_mesh: |
| 247 | if (priv->mesh_dev) |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame^] | 248 | lbs_mesh_config(priv, 1, priv->curbssparams.channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 249 | |
| 250 | done: |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 251 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 252 | return ret; |
| 253 | } |
| 254 | |
| 255 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 256 | static int assoc_helper_wep_keys(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 257 | struct assoc_request * assoc_req) |
| 258 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 259 | int i; |
| 260 | int ret = 0; |
| 261 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 262 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 263 | |
| 264 | /* Set or remove WEP keys */ |
| 265 | if ( assoc_req->wep_keys[0].len |
| 266 | || assoc_req->wep_keys[1].len |
| 267 | || assoc_req->wep_keys[2].len |
| 268 | || assoc_req->wep_keys[3].len) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 269 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 270 | CMD_802_11_SET_WEP, |
| 271 | CMD_ACT_ADD, |
| 272 | CMD_OPTION_WAITFORRSP, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 273 | 0, assoc_req); |
| 274 | } else { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 275 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 276 | CMD_802_11_SET_WEP, |
| 277 | CMD_ACT_REMOVE, |
| 278 | CMD_OPTION_WAITFORRSP, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 279 | 0, NULL); |
| 280 | } |
| 281 | |
| 282 | if (ret) |
| 283 | goto out; |
| 284 | |
| 285 | /* enable/disable the MAC's WEP packet filter */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 286 | if (assoc_req->secinfo.wep_enabled) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 287 | priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 288 | else |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 289 | priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 290 | ret = lbs_set_mac_packet_filter(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 291 | if (ret) |
| 292 | goto out; |
| 293 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 294 | mutex_lock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 295 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 296 | /* Copy WEP keys into priv wep key fields */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 297 | for (i = 0; i < 4; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 298 | memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i], |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 299 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 300 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 301 | priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 302 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 303 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 304 | |
| 305 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 306 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 | return ret; |
| 308 | } |
| 309 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 310 | static int assoc_helper_secinfo(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 311 | struct assoc_request * assoc_req) |
| 312 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 313 | int ret = 0; |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 314 | u32 do_wpa; |
| 315 | u32 rsn = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 316 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 317 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 318 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 319 | memcpy(&priv->secinfo, &assoc_req->secinfo, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 320 | sizeof(struct lbs_802_11_security)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 321 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 322 | ret = lbs_set_mac_packet_filter(priv); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 323 | if (ret) |
| 324 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 325 | |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 326 | /* If RSN is already enabled, don't try to enable it again, since |
| 327 | * ENABLE_RSN resets internal state machines and will clobber the |
| 328 | * 4-way WPA handshake. |
| 329 | */ |
| 330 | |
| 331 | /* Get RSN enabled/disabled */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 332 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 333 | CMD_802_11_ENABLE_RSN, |
| 334 | CMD_ACT_GET, |
| 335 | CMD_OPTION_WAITFORRSP, |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 336 | 0, &rsn); |
| 337 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 338 | lbs_deb_assoc("Failed to get RSN status: %d\n", ret); |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 339 | goto out; |
| 340 | } |
| 341 | |
| 342 | /* Don't re-enable RSN if it's already enabled */ |
| 343 | do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled); |
| 344 | if (do_wpa == rsn) |
| 345 | goto out; |
| 346 | |
| 347 | /* Set RSN enabled/disabled */ |
| 348 | rsn = do_wpa; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 349 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 350 | CMD_802_11_ENABLE_RSN, |
| 351 | CMD_ACT_SET, |
| 352 | CMD_OPTION_WAITFORRSP, |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 353 | 0, &rsn); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 354 | |
| 355 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 356 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 357 | return ret; |
| 358 | } |
| 359 | |
| 360 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 361 | static int assoc_helper_wpa_keys(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 362 | struct assoc_request * assoc_req) |
| 363 | { |
| 364 | int ret = 0; |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 365 | unsigned int flags = assoc_req->flags; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 366 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 367 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 368 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 369 | /* Work around older firmware bug where WPA unicast and multicast |
| 370 | * keys must be set independently. Seen in SDIO parts with firmware |
| 371 | * version 5.0.11p0. |
| 372 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 373 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 374 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 375 | clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 376 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 377 | CMD_802_11_KEY_MATERIAL, |
| 378 | CMD_ACT_SET, |
| 379 | CMD_OPTION_WAITFORRSP, |
| 380 | 0, assoc_req); |
| 381 | assoc_req->flags = flags; |
| 382 | } |
| 383 | |
| 384 | if (ret) |
| 385 | goto out; |
| 386 | |
| 387 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 388 | clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 389 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 390 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 391 | CMD_802_11_KEY_MATERIAL, |
| 392 | CMD_ACT_SET, |
| 393 | CMD_OPTION_WAITFORRSP, |
| 394 | 0, assoc_req); |
| 395 | assoc_req->flags = flags; |
| 396 | } |
| 397 | |
| 398 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 399 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 400 | return ret; |
| 401 | } |
| 402 | |
| 403 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 404 | static int assoc_helper_wpa_ie(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 405 | struct assoc_request * assoc_req) |
| 406 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 407 | int ret = 0; |
| 408 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 409 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 410 | |
| 411 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 412 | memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
| 413 | priv->wpa_ie_len = assoc_req->wpa_ie_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 414 | } else { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 415 | memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN); |
| 416 | priv->wpa_ie_len = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 417 | } |
| 418 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 419 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 424 | static int should_deauth_infrastructure(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 425 | struct assoc_request * assoc_req) |
| 426 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 427 | int ret = 0; |
| 428 | |
| 429 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 430 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 431 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 432 | return 0; |
| 433 | |
| 434 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 435 | lbs_deb_assoc("Deauthenticating due to new SSID\n"); |
| 436 | ret = 1; |
| 437 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 441 | if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 442 | lbs_deb_assoc("Deauthenticating due to new security\n"); |
| 443 | ret = 1; |
| 444 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
| 448 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 449 | lbs_deb_assoc("Deauthenticating due to new BSSID\n"); |
| 450 | ret = 1; |
| 451 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 452 | } |
| 453 | |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 454 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 455 | lbs_deb_assoc("Deauthenticating due to channel switch\n"); |
| 456 | ret = 1; |
| 457 | goto out; |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 460 | /* FIXME: deal with 'auto' mode somehow */ |
| 461 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 462 | if (assoc_req->mode != IW_MODE_INFRA) { |
| 463 | lbs_deb_assoc("Deauthenticating due to leaving " |
| 464 | "infra mode\n"); |
| 465 | ret = 1; |
| 466 | goto out; |
| 467 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 468 | } |
| 469 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 470 | out: |
| 471 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 476 | static int should_stop_adhoc(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 477 | struct assoc_request * assoc_req) |
| 478 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 479 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 480 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 481 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | return 0; |
| 483 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 484 | if (lbs_ssid_cmp(priv->curbssparams.ssid, |
| 485 | priv->curbssparams.ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 486 | assoc_req->ssid, assoc_req->ssid_len) != 0) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 487 | return 1; |
| 488 | |
| 489 | /* FIXME: deal with 'auto' mode somehow */ |
| 490 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 491 | if (assoc_req->mode != IW_MODE_ADHOC) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 492 | return 1; |
| 493 | } |
| 494 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 495 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 496 | if (assoc_req->channel != priv->curbssparams.channel) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 497 | return 1; |
| 498 | } |
| 499 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 500 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 505 | void lbs_association_worker(struct work_struct *work) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 506 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 507 | struct lbs_private *priv = container_of(work, struct lbs_private, |
| 508 | assoc_work.work); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 509 | struct assoc_request * assoc_req = NULL; |
| 510 | int ret = 0; |
| 511 | int find_any_ssid = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 512 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 513 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 514 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 515 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 516 | mutex_lock(&priv->lock); |
| 517 | assoc_req = priv->pending_assoc_req; |
| 518 | priv->pending_assoc_req = NULL; |
| 519 | priv->in_progress_assoc_req = assoc_req; |
| 520 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 521 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 522 | if (!assoc_req) |
| 523 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 524 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 525 | lbs_deb_assoc( |
| 526 | "Association Request:\n" |
| 527 | " flags: 0x%08lx\n" |
| 528 | " SSID: '%s'\n" |
| 529 | " chann: %d\n" |
| 530 | " band: %d\n" |
| 531 | " mode: %d\n" |
| 532 | " BSSID: %s\n" |
| 533 | " secinfo: %s%s%s\n" |
| 534 | " auth_mode: %d\n", |
| 535 | assoc_req->flags, |
| 536 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), |
| 537 | assoc_req->channel, assoc_req->band, assoc_req->mode, |
| 538 | print_mac(mac, assoc_req->bssid), |
| 539 | assoc_req->secinfo.WPAenabled ? " WPA" : "", |
| 540 | assoc_req->secinfo.WPA2enabled ? " WPA2" : "", |
| 541 | assoc_req->secinfo.wep_enabled ? " WEP" : "", |
| 542 | assoc_req->secinfo.auth_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 543 | |
| 544 | /* If 'any' SSID was specified, find an SSID to associate with */ |
| 545 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 546 | && !assoc_req->ssid_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 547 | find_any_ssid = 1; |
| 548 | |
| 549 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ |
| 550 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 551 | if (compare_ether_addr(assoc_req->bssid, bssid_any) |
| 552 | && compare_ether_addr(assoc_req->bssid, bssid_off)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 553 | find_any_ssid = 0; |
| 554 | } |
| 555 | |
| 556 | if (find_any_ssid) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 557 | u8 new_mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 558 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 559 | ret = lbs_find_best_network_ssid(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 560 | &assoc_req->ssid_len, assoc_req->mode, &new_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 561 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 562 | lbs_deb_assoc("Could not find best network\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 563 | ret = -ENETUNREACH; |
| 564 | goto out; |
| 565 | } |
| 566 | |
| 567 | /* Ensure we switch to the mode of the AP */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 568 | if (assoc_req->mode == IW_MODE_AUTO) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 569 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 570 | assoc_req->mode = new_mode; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Check if the attributes being changing require deauthentication |
| 576 | * from the currently associated infrastructure access point. |
| 577 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 578 | if (priv->mode == IW_MODE_INFRA) { |
| 579 | if (should_deauth_infrastructure(priv, assoc_req)) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 580 | ret = lbs_send_deauthentication(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 581 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 582 | lbs_deb_assoc("Deauthentication due to new " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 583 | "configuration request failed: %d\n", |
| 584 | ret); |
| 585 | } |
| 586 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 587 | } else if (priv->mode == IW_MODE_ADHOC) { |
| 588 | if (should_stop_adhoc(priv, assoc_req)) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 589 | ret = lbs_stop_adhoc_network(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 590 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 591 | lbs_deb_assoc("Teardown of AdHoc network due to " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 592 | "new configuration request failed: %d\n", |
| 593 | ret); |
| 594 | } |
| 595 | |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /* Send the various configuration bits to the firmware */ |
| 600 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
| 601 | ret = assoc_helper_mode(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 602 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 603 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 604 | } |
| 605 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 606 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 607 | ret = assoc_helper_channel(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 608 | if (ret) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 609 | goto out; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 610 | } |
| 611 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 612 | if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) |
| 613 | || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { |
| 614 | ret = assoc_helper_wep_keys(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 615 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 616 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 620 | ret = assoc_helper_secinfo(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 621 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 622 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 626 | ret = assoc_helper_wpa_ie(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 627 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 628 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) |
| 632 | || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 633 | ret = assoc_helper_wpa_keys(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 634 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 635 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /* SSID/BSSID should be the _last_ config option set, because they |
| 639 | * trigger the association attempt. |
| 640 | */ |
| 641 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) |
| 642 | || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 643 | int success = 1; |
| 644 | |
| 645 | ret = assoc_helper_associate(priv, assoc_req); |
| 646 | if (ret) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 647 | lbs_deb_assoc("ASSOC: association unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 648 | ret); |
| 649 | success = 0; |
| 650 | } |
| 651 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 652 | if (priv->connect_status != LBS_CONNECTED) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 653 | lbs_deb_assoc("ASSOC: association unsuccessful, " |
| 654 | "not connected\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 655 | success = 0; |
| 656 | } |
| 657 | |
| 658 | if (success) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 659 | lbs_deb_assoc("ASSOC: associated to '%s', %s\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 660 | escape_essid(priv->curbssparams.ssid, |
| 661 | priv->curbssparams.ssid_len), |
| 662 | print_mac(mac, priv->curbssparams.bssid)); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 663 | lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 664 | CMD_802_11_RSSI, |
| 665 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 666 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 667 | lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 668 | CMD_802_11_GET_LOG, |
| 669 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 670 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | ret = -1; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | out: |
| 676 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 677 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 678 | ret); |
| 679 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 680 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 681 | mutex_lock(&priv->lock); |
| 682 | priv->in_progress_assoc_req = NULL; |
| 683 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 684 | kfree(assoc_req); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 685 | |
| 686 | done: |
| 687 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
| 691 | /* |
| 692 | * Caller MUST hold any necessary locks |
| 693 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 694 | struct assoc_request *lbs_get_association_request(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 695 | { |
| 696 | struct assoc_request * assoc_req; |
| 697 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 698 | lbs_deb_enter(LBS_DEB_ASSOC); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 699 | if (!priv->pending_assoc_req) { |
| 700 | priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request), |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 701 | GFP_KERNEL); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 702 | if (!priv->pending_assoc_req) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 703 | lbs_pr_info("Not enough memory to allocate association" |
| 704 | " request!\n"); |
| 705 | return NULL; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /* Copy current configuration attributes to the association request, |
| 710 | * but don't overwrite any that are already set. |
| 711 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 712 | assoc_req = priv->pending_assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 713 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 714 | memcpy(&assoc_req->ssid, &priv->curbssparams.ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 715 | IW_ESSID_MAX_SIZE); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 716 | assoc_req->ssid_len = priv->curbssparams.ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 720 | assoc_req->channel = priv->curbssparams.channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 721 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 722 | if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 723 | assoc_req->band = priv->curbssparams.band; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 724 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 725 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 726 | assoc_req->mode = priv->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 727 | |
| 728 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 729 | memcpy(&assoc_req->bssid, priv->curbssparams.bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 730 | ETH_ALEN); |
| 731 | } |
| 732 | |
| 733 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { |
| 734 | int i; |
| 735 | for (i = 0; i < 4; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 736 | memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i], |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 737 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 742 | assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 743 | |
| 744 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 745 | memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 746 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 750 | memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 751 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 755 | memcpy(&assoc_req->secinfo, &priv->secinfo, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 756 | sizeof(struct lbs_802_11_security)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 760 | memcpy(&assoc_req->wpa_ie, &priv->wpa_ie, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 761 | MAX_WPA_IE_LEN); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 762 | assoc_req->wpa_ie_len = priv->wpa_ie_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 763 | } |
| 764 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 765 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 766 | return assoc_req; |
| 767 | } |