iw: add VHT80 support for IBSS
[openwrt.git] / package / network / utils / iw / patches / 301-ibss_add_VHT80.patch
1 From: "Janusz.Dziedzic@tieto.com" <Janusz.Dziedzic@tieto.com>
2 Date: Thu, 10 Sep 2015 12:04:13 +0200
3 Subject: ibss: add VHT80 support for IBSS
4
5 Add VHT80 support for IBSS.
6
7 eg. iw wlan0 ibss join 5180 80MHZ
8     iw wlan0 ibbs join 5220 80MHZ
9
10 Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
11 [fix formatting]
12 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
13 ---
14  ibss.c | 49 +++++++++++++++++++++++++++++++++++++++++--------
15  1 file changed, 41 insertions(+), 8 deletions(-)
16
17 diff --git a/ibss.c b/ibss.c
18 index 7a0b707..a99a262 100644
19 --- a/ibss.c
20 +++ b/ibss.c
21 @@ -16,6 +16,39 @@
22  
23  SECTION(ibss);
24  
25 +struct chanmode {
26 +       const char *name;
27 +       unsigned int width;
28 +       int freq1_diff;
29 +       int chantype; /* for older kernel */
30 +};
31 +
32 +static int get_cf1(const struct chanmode *chanmode, unsigned long freq)
33 +{
34 +       int cf1 = freq, j;
35 +       int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
36 +
37 +       switch (chanmode->width) {
38 +       case NL80211_CHAN_WIDTH_80:
39 +               /* setup center_freq1 */
40 +               for (j = 0; j < ARRAY_SIZE(vht80); j++) {
41 +                       if (freq >= vht80[j] && freq < vht80[j] + 80)
42 +                               break;
43 +               }
44 +
45 +               if (j == ARRAY_SIZE(vht80))
46 +                       break;
47 +
48 +               cf1 = vht80[j] + 30;
49 +               break;
50 +       default:
51 +               cf1 = freq + chanmode->freq1_diff;
52 +               break;
53 +       }
54 +
55 +       return cf1;
56 +}
57 +
58  static int join_ibss(struct nl80211_state *state,
59                      struct nl_msg *msg,
60                      int argc, char **argv,
61 @@ -30,12 +63,8 @@ static int join_ibss(struct nl80211_state *state,
62         int bintval;
63         int i;
64         unsigned long freq;
65 -       static const struct {
66 -               const char *name;
67 -               unsigned int width;
68 -               int freq1_diff;
69 -               int chantype; /* for older kernel */
70 -       } *chanmode_selected = NULL, chanmode[] = {
71 +       const struct chanmode *chanmode_selected = NULL;
72 +       static const struct chanmode chanmode[] = {
73                 { .name = "HT20",
74                   .width = NL80211_CHAN_WIDTH_20,
75                   .freq1_diff = 0,
76 @@ -60,6 +89,10 @@ static int join_ibss(struct nl80211_state *state,
77                   .width = NL80211_CHAN_WIDTH_10,
78                   .freq1_diff = 0,
79                   .chantype = -1 },
80 +               { .name = "80MHZ",
81 +                 .width = NL80211_CHAN_WIDTH_80,
82 +                 .freq1_diff = 0,
83 +                 .chantype = -1 },
84         };
85  
86         if (argc < 2)
87 @@ -90,7 +123,7 @@ static int join_ibss(struct nl80211_state *state,
88                         NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
89                                     chanmode_selected->width);
90                         NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1,
91 -                                   freq + chanmode_selected->freq1_diff);
92 +                                   get_cf1(chanmode_selected, freq));
93                         if (chanmode_selected->chantype != -1)
94                                 NLA_PUT_U32(msg,
95                                             NL80211_ATTR_WIPHY_CHANNEL_TYPE,
96 @@ -192,7 +225,7 @@ COMMAND(ibss, leave, NULL,
97         NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
98         "Leave the current IBSS cell.");
99  COMMAND(ibss, join,
100 -       "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT|5MHZ|10MHZ] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
101 +       "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT|5MHZ|10MHZ|80MHZ] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
102         " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
103         "[key d:0:abcde]",
104         NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,