mac80211: backport latest patches except for NVRAM support
[openwrt.git] / package / kernel / mac80211 / patches / 315-brcmfmac-make-use-of-cfg80211_check_combinations.patch
1 From: Arend van Spriel <arend@broadcom.com>
2 Date: Thu, 20 Aug 2015 22:06:05 +0200
3 Subject: [PATCH] brcmfmac: make use of cfg80211_check_combinations()
4
5 Use cfg80211_check_combinations() so we can bail out early when an
6 interface add or change results in an invalid combination.
7
8 Reviewed-by: Hante Meuleman <meuleman@broadcom.com>
9 Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
10 Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
11 Signed-off-by: Arend van Spriel <arend@broadcom.com>
12 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
13 ---
14
15 --- a/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
16 +++ b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
17 @@ -469,6 +469,36 @@ brcmf_find_wpsie(const u8 *parse, u32 le
18         return NULL;
19  }
20  
21 +static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
22 +                                    struct brcmf_cfg80211_vif *vif,
23 +                                    enum nl80211_iftype new_type)
24 +{
25 +       int iftype_num[NUM_NL80211_IFTYPES];
26 +       struct brcmf_cfg80211_vif *pos;
27 +
28 +       memset(&iftype_num[0], 0, sizeof(iftype_num));
29 +       list_for_each_entry(pos, &cfg->vif_list, list)
30 +               if (pos == vif)
31 +                       iftype_num[new_type]++;
32 +               else
33 +                       iftype_num[pos->wdev.iftype]++;
34 +
35 +       return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
36 +}
37 +
38 +static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
39 +                                 enum nl80211_iftype new_type)
40 +{
41 +       int iftype_num[NUM_NL80211_IFTYPES];
42 +       struct brcmf_cfg80211_vif *pos;
43 +
44 +       memset(&iftype_num[0], 0, sizeof(iftype_num));
45 +       list_for_each_entry(pos, &cfg->vif_list, list)
46 +               iftype_num[pos->wdev.iftype]++;
47 +
48 +       iftype_num[new_type]++;
49 +       return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
50 +}
51  
52  static void convert_key_from_CPU(struct brcmf_wsec_key *key,
53                                  struct brcmf_wsec_key_le *key_le)
54 @@ -663,8 +693,14 @@ static struct wireless_dev *brcmf_cfg802
55                                                      struct vif_params *params)
56  {
57         struct wireless_dev *wdev;
58 +       int err;
59  
60         brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
61 +       err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
62 +       if (err) {
63 +               brcmf_err("iface validation failed: err=%d\n", err);
64 +               return ERR_PTR(err);
65 +       }
66         switch (type) {
67         case NL80211_IFTYPE_ADHOC:
68         case NL80211_IFTYPE_STATION:
69 @@ -823,8 +859,12 @@ brcmf_cfg80211_change_iface(struct wiphy
70         s32 ap = 0;
71         s32 err = 0;
72  
73 -       brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type);
74 -
75 +       brcmf_dbg(TRACE, "Enter, idx=%d, type=%d\n", ifp->bssidx, type);
76 +       err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
77 +       if (err) {
78 +               brcmf_err("iface validation failed: err=%d\n", err);
79 +               return err;
80 +       }
81         switch (type) {
82         case NL80211_IFTYPE_MONITOR:
83         case NL80211_IFTYPE_WDS: