aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/assoc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/libertas/assoc.c')
-rw-r--r--drivers/net/wireless/libertas/assoc.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index 81f86ef26990..dd8732611ba9 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -34,7 +34,8 @@ static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) =
34 * 34 *
35 * @param priv A pointer to struct lbs_private structure 35 * @param priv A pointer to struct lbs_private structure
36 * @param rates the buffer which keeps input and output 36 * @param rates the buffer which keeps input and output
37 * @param rates_size the size of rate1 buffer; new size of buffer on return 37 * @param rates_size the size of rates buffer; new size of buffer on return,
38 * which will be less than or equal to original rates_size
38 * 39 *
39 * @return 0 on success, or -1 on error 40 * @return 0 on success, or -1 on error
40 */ 41 */
@@ -42,48 +43,42 @@ static int get_common_rates(struct lbs_private *priv,
42 u8 *rates, 43 u8 *rates,
43 u16 *rates_size) 44 u16 *rates_size)
44{ 45{
45 u8 *card_rates = lbs_bg_rates; 46 int i, j;
46 size_t num_card_rates = sizeof(lbs_bg_rates); 47 u8 intersection[MAX_RATES];
47 int ret = 0, i, j; 48 u16 intersection_size;
48 u8 *tmp; 49 u16 num_rates = 0;
49 size_t tmp_size = 0; 50
50 51 intersection_size = min_t(u16, *rates_size, ARRAY_SIZE(intersection));
51 tmp = kzalloc((ARRAY_SIZE(lbs_bg_rates) - 1) * (*rates_size - 1), 52
52 GFP_KERNEL); 53 /* Allow each rate from 'rates' that is supported by the hardware */
53 if (!tmp) 54 for (i = 0; i < ARRAY_SIZE(lbs_bg_rates) && lbs_bg_rates[i]; i++) {
54 return -1; 55 for (j = 0; j < intersection_size && rates[j]; j++) {
55 56 if (rates[j] == lbs_bg_rates[i])
56 /* For each rate in card_rates that exists in rate1, copy to tmp */ 57 intersection[num_rates++] = rates[j];
57 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
58 for (j = 0; rates[j] && (j < *rates_size); j++) {
59 if (rates[j] == card_rates[i])
60 tmp[tmp_size++] = card_rates[i];
61 } 58 }
62 } 59 }
63 60
64 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); 61 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
65 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); 62 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", lbs_bg_rates,
66 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); 63 ARRAY_SIZE(lbs_bg_rates));
64 lbs_deb_hex(LBS_DEB_JOIN, "common rates", intersection, num_rates);
67 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); 65 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate);
68 66
69 if (!priv->enablehwauto) { 67 if (!priv->enablehwauto) {
70 for (i = 0; i < tmp_size; i++) { 68 for (i = 0; i < num_rates; i++) {
71 if (tmp[i] == priv->cur_rate) 69 if (intersection[i] == priv->cur_rate)
72 goto done; 70 goto done;
73 } 71 }
74 lbs_pr_alert("Previously set fixed data rate %#x isn't " 72 lbs_pr_alert("Previously set fixed data rate %#x isn't "
75 "compatible with the network.\n", priv->cur_rate); 73 "compatible with the network.\n", priv->cur_rate);
76 ret = -1; 74 return -1;
77 goto done;
78 } 75 }
79 ret = 0;
80 76
81done: 77done:
82 memset(rates, 0, *rates_size); 78 memset(rates, 0, *rates_size);
83 *rates_size = min_t(int, tmp_size, *rates_size); 79 *rates_size = num_rates;
84 memcpy(rates, tmp, *rates_size); 80 memcpy(rates, intersection, num_rates);
85 kfree(tmp); 81 return 0;
86 return ret;
87} 82}
88 83
89 84
@@ -325,8 +320,8 @@ static int lbs_associate(struct lbs_private *priv,
325 320
326 rates = (struct mrvl_ie_rates_param_set *) pos; 321 rates = (struct mrvl_ie_rates_param_set *) pos;
327 rates->header.type = cpu_to_le16(TLV_TYPE_RATES); 322 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
328 memcpy(&rates->rates, &bss->rates, MAX_RATES); 323 tmplen = min_t(u16, ARRAY_SIZE(bss->rates), MAX_RATES);
329 tmplen = MAX_RATES; 324 memcpy(&rates->rates, &bss->rates, tmplen);
330 if (get_common_rates(priv, rates->rates, &tmplen)) { 325 if (get_common_rates(priv, rates->rates, &tmplen)) {
331 ret = -1; 326 ret = -1;
332 goto done; 327 goto done;
@@ -600,7 +595,7 @@ static int lbs_adhoc_join(struct lbs_private *priv,
600 595
601 /* Copy Data rates from the rates recorded in scan response */ 596 /* Copy Data rates from the rates recorded in scan response */
602 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates)); 597 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates));
603 ratesize = min_t(u16, sizeof(cmd.bss.rates), MAX_RATES); 598 ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), ARRAY_SIZE (bss->rates));
604 memcpy(cmd.bss.rates, bss->rates, ratesize); 599 memcpy(cmd.bss.rates, bss->rates, ratesize);
605 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) { 600 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) {
606 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n"); 601 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");