7e1a7a072fa923e5078a2f72254da4c4a334e535
[openwrt.git] / package / hostapd / patches / 604-wpa_s-support-htmode-param.patch
1 From b9329c5dfeed7d5c55d2117d8dfe326fc40c8fb1 Mon Sep 17 00:00:00 2001
2 From: Antonio Quartulli <ordex@autistici.org>
3 Date: Tue, 3 Jul 2012 00:36:24 +0200
4 Subject: [PATCH] wpa_s: support htmode param
5
6 possible values are HT20, HT40-, HT40+ and NOHT
7
8 Signed-off-by: Antonio Quartulli <ordex@autistici.org>
9 ---
10  src/drivers/driver.h            |    2 ++
11  src/drivers/driver_nl80211.c    |   16 ++++++++++
12  wpa_supplicant/config.c         |   66 +++++++++++++++++++++++++++++++++++++++
13  wpa_supplicant/config_ssid.h    |    2 ++
14  wpa_supplicant/wpa_supplicant.c |    2 ++
15  5 files changed, 88 insertions(+)
16
17 diff --git a/src/drivers/driver.h b/src/drivers/driver.h
18 index dda2fbc..28bd181 100644
19 --- a/src/drivers/driver.h
20 +++ b/src/drivers/driver.h
21 @@ -337,6 +337,8 @@ struct wpa_driver_associate_params {
22         int fixed_freq;
23         unsigned char rates[NL80211_MAX_SUPP_RATES];
24         int mcast_rate;
25 +       int ht_set;
26 +       unsigned int htmode;
27  
28         /**
29          * bg_scan_period - Background scan period in seconds, 0 to disable
30 diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
31 index 9783c96..d1257a7 100644
32 --- a/src/drivers/driver_nl80211.c
33 +++ b/src/drivers/driver_nl80211.c
34 @@ -6493,6 +6493,22 @@ retry:
35                 NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, params->mcast_rate);
36         }
37  
38 +       if (params->ht_set) {
39 +               switch(params->htmode) {
40 +                       case NL80211_CHAN_HT20:
41 +                               wpa_printf(MSG_DEBUG, "  * ht=HT20");
42 +                               break;
43 +                       case NL80211_CHAN_HT40PLUS:
44 +                               wpa_printf(MSG_DEBUG, "  * ht=HT40+");
45 +                               break;
46 +                       case NL80211_CHAN_HT40MINUS:
47 +                               wpa_printf(MSG_DEBUG, "  * ht=HT40-");
48 +                               break;
49 +               }
50 +               NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
51 +                           params->htmode);
52 +       }
53 +
54         ret = nl80211_set_conn_keys(params, msg);
55         if (ret)
56                 goto nla_put_failure;
57 diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
58 index 3d6c0e6..d96b2ea 100644
59 --- a/wpa_supplicant/config.c
60 +++ b/wpa_supplicant/config.c
61 @@ -1468,6 +1468,71 @@ static char * wpa_config_write_mcast_rate(const struct parse_data *data,
62  }
63  #endif /* NO_CONFIG_WRITE */
64  
65 +static int wpa_config_parse_htmode(const struct parse_data *data,
66 +                                  struct wpa_ssid *ssid, int line,
67 +                                  const char *value)
68 +{
69 +       int i;
70 +       static const struct {
71 +               const char *name;
72 +               unsigned int val;
73 +       } htmap[] = {
74 +               { .name = "HT20", .val = NL80211_CHAN_HT20, },
75 +               { .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, },
76 +               { .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, },
77 +               { .name = "NOHT", .val = NL80211_CHAN_NO_HT, },
78 +       };
79 +       ssid->ht_set = 0;;
80 +       for (i = 0; i < 4; i++) {
81 +               if (strcasecmp(htmap[i].name, value) == 0) {
82 +                       ssid->htmode = htmap[i].val;
83 +                       ssid->ht_set = 1;
84 +                       break;
85 +               }
86 +       }
87 +
88 +       return 0;
89 +}
90 +
91 +#ifndef NO_CONFIG_WRITE
92 +static char * wpa_config_write_htmode(const struct parse_data *data,
93 +                                     struct wpa_ssid *ssid)
94 +{
95 +       char *value;
96 +       int res;
97 +
98 +       value = os_malloc(6); /* longest: HT40+ */
99 +       if (value == NULL)
100 +               return NULL;
101 +
102 +       switch(ssid->htmode) {
103 +               case NL80211_CHAN_HT20:
104 +                       res = os_snprintf(value, 4, "HT20");
105 +                       break;
106 +               case NL80211_CHAN_HT40PLUS:
107 +                       res = os_snprintf(value, 5, "HT40+");
108 +                       break;
109 +               case NL80211_CHAN_HT40MINUS:
110 +                       res = os_snprintf(value, 5, "HT40-");
111 +                       break;
112 +               case NL80211_CHAN_NO_HT:
113 +                       res = os_snprintf(value, 4, "NOHT");
114 +                       break;
115 +               default:
116 +                       os_free(value);
117 +                       return NULL;
118 +       }
119 +
120 +       if (res < 0) {
121 +               os_free(value);
122 +               return NULL;
123 +       }
124 +
125 +       return value;
126 +}
127 +#endif /* NO_CONFIG_WRITE */
128 +
129 +
130  static int wpa_config_parse_rates(const struct parse_data *data,
131                                   struct wpa_ssid *ssid, int line,
132                                   const char *value)
133 @@ -1706,6 +1771,7 @@ static const struct parse_data ssid_fields[] = {
134         { INT_RANGE(beacon_interval, 0, 1000) },
135         { FUNC(rates) },
136         { FUNC(mcast_rate) },
137 +       { FUNC(htmode) },
138  };
139  
140  #undef OFFSET
141 diff --git a/wpa_supplicant/config_ssid.h b/wpa_supplicant/config_ssid.h
142 index 8d152a4..7143277 100644
143 --- a/wpa_supplicant/config_ssid.h
144 +++ b/wpa_supplicant/config_ssid.h
145 @@ -505,6 +505,8 @@ struct wpa_ssid {
146         int beacon_interval;
147         unsigned char rates[NL80211_MAX_SUPP_RATES];
148         double mcast_rate;
149 +       int ht_set;
150 +       unsigned int htmode;
151  };
152  
153  #endif /* CONFIG_SSID_H */
154 diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
155 index 59efa16..fc8762f 100644
156 --- a/wpa_supplicant/wpa_supplicant.c
157 +++ b/wpa_supplicant/wpa_supplicant.c
158 @@ -1379,6 +1379,8 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
159                         i++;
160                 }
161                 params.mcast_rate = ssid->mcast_rate;
162 +               params.ht_set = ssid->ht_set;
163 +               params.htmode = ssid->htmode;
164         }
165  
166         params.wpa_ie = wpa_ie;
167 -- 
168 1.7.9.4
169