iw: add VHT80 support for 802.11s
[openwrt/svn-archive/archive.git] / package / network / utils / iw / patches / 303-mesh_add_VHT80.patch
1 From: Sven Eckelmann <sven@open-mesh.com>
2 Date: Tue, 24 Nov 2015 17:55:22 +0100
3 Subject: iw: add VHT80 support for 802.11s
4
5 Support next to the non-HT/HT channel widths like HT20 or NOHT also VHT80
6 channels during the mesh join
7
8 iw dev mesh0 mesh join "meshnet" freq 5180 80MHz
9
10 Signed-off-by: Sven Eckelmann <sven@open-mesh.com>
11 ---
12 ibss.c | 33 ---------------------------------
13 iw.h | 9 +++++++++
14 mesh.c | 16 ++++++++--------
15 util.c | 26 ++++++++++++++++++++++++++
16 4 files changed, 43 insertions(+), 41 deletions(-)
17
18 diff --git a/ibss.c b/ibss.c
19 index 23bda70..ac06fc5 100644
20 --- a/ibss.c
21 +++ b/ibss.c
22 @@ -16,39 +16,6 @@
23
24 SECTION(ibss);
25
26 -struct chanmode {
27 - const char *name;
28 - unsigned int width;
29 - int freq1_diff;
30 - int chantype; /* for older kernel */
31 -};
32 -
33 -static int get_cf1(const struct chanmode *chanmode, unsigned long freq)
34 -{
35 - int cf1 = freq, j;
36 - int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
37 -
38 - switch (chanmode->width) {
39 - case NL80211_CHAN_WIDTH_80:
40 - /* setup center_freq1 */
41 - for (j = 0; j < ARRAY_SIZE(vht80); j++) {
42 - if (freq >= vht80[j] && freq < vht80[j] + 80)
43 - break;
44 - }
45 -
46 - if (j == ARRAY_SIZE(vht80))
47 - break;
48 -
49 - cf1 = vht80[j] + 30;
50 - break;
51 - default:
52 - cf1 = freq + chanmode->freq1_diff;
53 - break;
54 - }
55 -
56 - return cf1;
57 -}
58 -
59 static int join_ibss(struct nl80211_state *state,
60 struct nl_msg *msg,
61 int argc, char **argv,
62 diff --git a/iw.h b/iw.h
63 index cef9da8..8e1a37a 100644
64 --- a/iw.h
65 +++ b/iw.h
66 @@ -59,6 +59,13 @@ struct cmd {
67 const struct cmd *parent;
68 };
69
70 +struct chanmode {
71 + const char *name;
72 + unsigned int width;
73 + int freq1_diff;
74 + int chantype; /* for older kernel */
75 +};
76 +
77 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
78 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
79
80 @@ -174,6 +181,8 @@ void print_ies(unsigned char *ie, int ielen, bool unknown,
81 void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen);
82 void iw_hexdump(const char *prefix, const __u8 *data, size_t len);
83
84 +int get_cf1(const struct chanmode *chanmode, unsigned long freq);
85 +
86 #define SCHED_SCAN_OPTIONS "interval <in_msecs> [delay <in_secs>] " \
87 "[freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] [randomise[=<addr>/<mask>]]"
88 int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv);
89 diff --git a/mesh.c b/mesh.c
90 index 0090530..930d58f 100644
91 --- a/mesh.c
92 +++ b/mesh.c
93 @@ -439,12 +439,8 @@ static int join_mesh(struct nl80211_state *state,
94 int bintval, dtim_period, i, n_rates = 0;
95 char *end, *value = NULL, *sptr = NULL;
96 unsigned long freq = 0;
97 - static const struct {
98 - const char *name;
99 - unsigned int width;
100 - int freq1_diff;
101 - int chantype; /* for older kernel */
102 - } *chanmode_selected = NULL, chanmode[] = {
103 + const struct chanmode *chanmode_selected = NULL;
104 + static const struct chanmode chanmode[] = {
105 { .name = "HT20",
106 .width = NL80211_CHAN_WIDTH_20,
107 .freq1_diff = 0,
108 @@ -461,6 +457,10 @@ static int join_mesh(struct nl80211_state *state,
109 .width = NL80211_CHAN_WIDTH_20_NOHT,
110 .freq1_diff = 0,
111 .chantype = NL80211_CHAN_NO_HT },
112 + { .name = "80MHz",
113 + .width = NL80211_CHAN_WIDTH_80,
114 + .freq1_diff = 0,
115 + .chantype = -1 },
116 };
117
118 if (argc < 1)
119 @@ -497,7 +497,7 @@ static int join_mesh(struct nl80211_state *state,
120 NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
121 chanmode_selected->width);
122 NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1,
123 - freq + chanmode_selected->freq1_diff);
124 + get_cf1(chanmode_selected, freq));
125 if (chanmode_selected->chantype != -1)
126 NLA_PUT_U32(msg,
127 NL80211_ATTR_WIPHY_CHANNEL_TYPE,
128 @@ -599,7 +599,7 @@ static int join_mesh(struct nl80211_state *state,
129 nla_put_failure:
130 return -ENOBUFS;
131 }
132 -COMMAND(mesh, join, "<mesh ID> [[freq <freq in MHz> <HT20|HT40+|HT40-|NOHT>]"
133 +COMMAND(mesh, join, "<mesh ID> [[freq <freq in MHz> <HT20|HT40+|HT40-|NOHT|80MHz>]"
134 " [basic-rates <rate in Mbps,rate2,...>]], [mcast-rate <rate in Mbps>]"
135 " [beacon-interval <time in TUs>] [dtim-period <value>]"
136 " [vendor_sync on|off] [<param>=<value>]*",
137 diff --git a/util.c b/util.c
138 index 4efc4c8..d75ffe0 100644
139 --- a/util.c
140 +++ b/util.c
141 @@ -728,3 +728,29 @@ void iw_hexdump(const char *prefix, const __u8 *buf, size_t size)
142 }
143 printf("\n\n");
144 }
145 +
146 +int get_cf1(const struct chanmode *chanmode, unsigned long freq)
147 +{
148 + int cf1 = freq, j;
149 + int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
150 +
151 + switch (chanmode->width) {
152 + case NL80211_CHAN_WIDTH_80:
153 + /* setup center_freq1 */
154 + for (j = 0; j < ARRAY_SIZE(vht80); j++) {
155 + if (freq >= vht80[j] && freq < vht80[j] + 80)
156 + break;
157 + }
158 +
159 + if (j == ARRAY_SIZE(vht80))
160 + break;
161 +
162 + cf1 = vht80[j] + 30;
163 + break;
164 + default:
165 + cf1 = freq + chanmode->freq1_diff;
166 + break;
167 + }
168 +
169 + return cf1;
170 +}