| 1 | From 4bb69d15477e0f2b00e166845341dc933de47c58 Mon Sep 17 00:00:00 2001 |
| 2 | From: Antonio Quartulli <ordex@autistici.org> |
| 3 | Date: Sun, 3 Jun 2012 18:22:56 +0200 |
| 4 | Subject: [PATCHv2 601/602] wpa_supplicant: add new config params to be used |
| 5 | with the ibss join command |
| 6 | |
| 7 | Signed-hostap: Antonio Quartulli <ordex@autistici.org> |
| 8 | --- |
| 9 | src/drivers/driver.h | 6 +++ |
| 10 | wpa_supplicant/config.c | 96 +++++++++++++++++++++++++++++++++++++++ |
| 11 | wpa_supplicant/config_ssid.h | 6 +++ |
| 12 | wpa_supplicant/wpa_supplicant.c | 23 +++++++--- |
| 13 | 4 files changed, 124 insertions(+), 7 deletions(-) |
| 14 | |
| 15 | --- a/src/drivers/driver.h |
| 16 | +++ b/src/drivers/driver.h |
| 17 | @@ -19,6 +19,7 @@ |
| 18 | |
| 19 | #define WPA_SUPPLICANT_DRIVER_VERSION 4 |
| 20 | |
| 21 | +#include "drivers/nl80211_copy.h" |
| 22 | #include "common/defs.h" |
| 23 | |
| 24 | #define HOSTAPD_CHAN_DISABLED 0x00000001 |
| 25 | @@ -351,6 +352,11 @@ struct wpa_driver_associate_params { |
| 26 | */ |
| 27 | int freq; |
| 28 | |
| 29 | + int beacon_interval; |
| 30 | + int fixed_freq; |
| 31 | + unsigned char rates[NL80211_MAX_SUPP_RATES]; |
| 32 | + int mcast_rate; |
| 33 | + |
| 34 | /** |
| 35 | * bg_scan_period - Background scan period in seconds, 0 to disable |
| 36 | * background scan, or -1 to indicate no change to default driver |
| 37 | --- a/wpa_supplicant/config.c |
| 38 | +++ b/wpa_supplicant/config.c |
| 39 | @@ -14,6 +14,7 @@ |
| 40 | #include "rsn_supp/wpa.h" |
| 41 | #include "eap_peer/eap.h" |
| 42 | #include "p2p/p2p.h" |
| 43 | +#include "drivers/nl80211_copy.h" |
| 44 | #include "config.h" |
| 45 | |
| 46 | |
| 47 | @@ -1463,6 +1464,97 @@ static char * wpa_config_write_p2p_clien |
| 48 | |
| 49 | #endif /* CONFIG_P2P */ |
| 50 | |
| 51 | +static int wpa_config_parse_mcast_rate(const struct parse_data *data, |
| 52 | + struct wpa_ssid *ssid, int line, |
| 53 | + const char *value) |
| 54 | +{ |
| 55 | + ssid->mcast_rate = (int)(strtod(value, NULL) * 10); |
| 56 | + |
| 57 | + return 0; |
| 58 | +} |
| 59 | + |
| 60 | +#ifndef NO_CONFIG_WRITE |
| 61 | +static char * wpa_config_write_mcast_rate(const struct parse_data *data, |
| 62 | + struct wpa_ssid *ssid) |
| 63 | +{ |
| 64 | + char *value; |
| 65 | + int res; |
| 66 | + |
| 67 | + if (!ssid->mcast_rate == 0) |
| 68 | + return NULL; |
| 69 | + |
| 70 | + value = os_malloc(6); /* longest: 300.0 */ |
| 71 | + if (value == NULL) |
| 72 | + return NULL; |
| 73 | + res = os_snprintf(value, 5, "%.1f", (double)ssid->mcast_rate / 10); |
| 74 | + if (res < 0) { |
| 75 | + os_free(value); |
| 76 | + return NULL; |
| 77 | + } |
| 78 | + return value; |
| 79 | +} |
| 80 | +#endif /* NO_CONFIG_WRITE */ |
| 81 | + |
| 82 | +static int wpa_config_parse_rates(const struct parse_data *data, |
| 83 | + struct wpa_ssid *ssid, int line, |
| 84 | + const char *value) |
| 85 | +{ |
| 86 | + int i; |
| 87 | + char *pos, *r, *sptr, *end; |
| 88 | + double rate; |
| 89 | + |
| 90 | + pos = (char *)value; |
| 91 | + r = strtok_r(pos, ",", &sptr); |
| 92 | + i = 0; |
| 93 | + while (pos && i < NL80211_MAX_SUPP_RATES) { |
| 94 | + rate = 0.0; |
| 95 | + if (r) |
| 96 | + rate = strtod(r, &end); |
| 97 | + ssid->rates[i] = rate * 2; |
| 98 | + if (*end != '\0' || rate * 2 != ssid->rates[i]) |
| 99 | + return 1; |
| 100 | + |
| 101 | + i++; |
| 102 | + r = strtok_r(NULL, ",", &sptr); |
| 103 | + } |
| 104 | + |
| 105 | + return 0; |
| 106 | +} |
| 107 | + |
| 108 | +#ifndef NO_CONFIG_WRITE |
| 109 | +static char * wpa_config_write_rates(const struct parse_data *data, |
| 110 | + struct wpa_ssid *ssid) |
| 111 | +{ |
| 112 | + char *value, *pos; |
| 113 | + int res, i; |
| 114 | + |
| 115 | + if (ssid->rates[0] <= 0) |
| 116 | + return NULL; |
| 117 | + |
| 118 | + value = os_malloc(6 * NL80211_MAX_SUPP_RATES + 1); |
| 119 | + if (value == NULL) |
| 120 | + return NULL; |
| 121 | + pos = value; |
| 122 | + for (i = 0; i < NL80211_MAX_SUPP_RATES - 1; i++) { |
| 123 | + res = os_snprintf(pos, 6, "%.1f,", (double)ssid->rates[i] / 2); |
| 124 | + if (res < 0) { |
| 125 | + os_free(value); |
| 126 | + return NULL; |
| 127 | + } |
| 128 | + pos += res; |
| 129 | + } |
| 130 | + res = os_snprintf(pos, 6, "%.1f", |
| 131 | + (double)ssid->rates[NL80211_MAX_SUPP_RATES - 1] / 2); |
| 132 | + if (res < 0) { |
| 133 | + os_free(value); |
| 134 | + return NULL; |
| 135 | + } |
| 136 | + |
| 137 | + value[6 * NL80211_MAX_SUPP_RATES] = '\0'; |
| 138 | + return value; |
| 139 | +} |
| 140 | +#endif /* NO_CONFIG_WRITE */ |
| 141 | + |
| 142 | /* Helper macros for network block parser */ |
| 143 | |
| 144 | #ifdef OFFSET |
| 145 | @@ -1638,6 +1730,10 @@ static const struct parse_data ssid_fiel |
| 146 | #endif /* CONFIG_HT_OVERRIDES */ |
| 147 | { INT(ap_max_inactivity) }, |
| 148 | { INT(dtim_period) }, |
| 149 | + { INT_RANGE(fixed_freq, 0, 1) }, |
| 150 | + { INT_RANGE(beacon_interval, 0, 1000) }, |
| 151 | + { FUNC(rates) }, |
| 152 | + { FUNC(mcast_rate) }, |
| 153 | }; |
| 154 | |
| 155 | #undef OFFSET |
| 156 | --- a/wpa_supplicant/config_ssid.h |
| 157 | +++ b/wpa_supplicant/config_ssid.h |
| 158 | @@ -11,6 +11,7 @@ |
| 159 | |
| 160 | #include "common/defs.h" |
| 161 | #include "eap_peer/eap_config.h" |
| 162 | +#include "drivers/nl80211_copy.h" |
| 163 | |
| 164 | #define MAX_SSID_LEN 32 |
| 165 | |
| 166 | @@ -529,6 +530,11 @@ struct wpa_ssid { |
| 167 | * disabled_until - Network block disabled until this time if non-zero |
| 168 | */ |
| 169 | struct os_time disabled_until; |
| 170 | + |
| 171 | + int fixed_freq; |
| 172 | + int beacon_interval; |
| 173 | + unsigned char rates[NL80211_MAX_SUPP_RATES]; |
| 174 | + double mcast_rate; |
| 175 | }; |
| 176 | |
| 177 | #endif /* CONFIG_SSID_H */ |
| 178 | --- a/wpa_supplicant/wpa_supplicant.c |
| 179 | +++ b/wpa_supplicant/wpa_supplicant.c |
| 180 | @@ -1561,15 +1561,24 @@ void wpa_supplicant_associate(struct wpa |
| 181 | params.ssid_len = ssid->ssid_len; |
| 182 | } |
| 183 | |
| 184 | - if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set && |
| 185 | - wpa_s->conf->ap_scan == 2) { |
| 186 | - params.bssid = ssid->bssid; |
| 187 | - params.fixed_bssid = 1; |
| 188 | + if (ssid->mode == WPAS_MODE_IBSS) { |
| 189 | + if (ssid->bssid_set && wpa_s->conf->ap_scan == 2) { |
| 190 | + params.bssid = ssid->bssid; |
| 191 | + params.fixed_bssid = 1; |
| 192 | + } |
| 193 | + if (ssid->frequency > 0 && params.freq == 0) |
| 194 | + /* Initial channel for IBSS */ |
| 195 | + params.freq = ssid->frequency; |
| 196 | + params.fixed_freq = ssid->fixed_freq; |
| 197 | + params.beacon_interval = ssid->beacon_interval; |
| 198 | + i = 0; |
| 199 | + while (i < NL80211_MAX_SUPP_RATES) { |
| 200 | + params.rates[i] = ssid->rates[i]; |
| 201 | + i++; |
| 202 | + } |
| 203 | + params.mcast_rate = ssid->mcast_rate; |
| 204 | } |
| 205 | |
| 206 | - if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 && |
| 207 | - params.freq == 0) |
| 208 | - params.freq = ssid->frequency; /* Initial channel for IBSS */ |
| 209 | params.wpa_ie = wpa_ie; |
| 210 | params.wpa_ie_len = wpa_ie_len; |
| 211 | params.pairwise_suite = cipher_pairwise; |
| 212 | |