40757e3777f047dcc331e9b8d082da204c994284
[openwrt/staging/wigyori.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Tue, 4 Jun 2024 14:31:09 +0200
3 Subject: [PATCH] wifi: nl80211: split helper function from
4 nl80211_put_iface_combinations
5
6 Create a helper function that puts the data from struct
7 ieee80211_iface_combination to a nl80211 message.
8 This will be used for adding per-radio interface combination data.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12
13 --- a/net/wireless/nl80211.c
14 +++ b/net/wireless/nl80211.c
15 @@ -1620,71 +1620,78 @@ nla_put_failure:
16 return -ENOBUFS;
17 }
18
19 -static int nl80211_put_iface_combinations(struct wiphy *wiphy,
20 - struct sk_buff *msg,
21 - bool large)
22 +static int nl80211_put_ifcomb_data(struct sk_buff *msg, bool large, int idx,
23 + const struct ieee80211_iface_combination *c)
24 {
25 - struct nlattr *nl_combis;
26 - int i, j;
27 + struct nlattr *nl_combi, *nl_limits;
28 + int i;
29
30 - nl_combis = nla_nest_start_noflag(msg,
31 - NL80211_ATTR_INTERFACE_COMBINATIONS);
32 - if (!nl_combis)
33 + nl_combi = nla_nest_start_noflag(msg, idx);
34 + if (!nl_combi)
35 goto nla_put_failure;
36
37 - for (i = 0; i < wiphy->n_iface_combinations; i++) {
38 - const struct ieee80211_iface_combination *c;
39 - struct nlattr *nl_combi, *nl_limits;
40 + nl_limits = nla_nest_start_noflag(msg, NL80211_IFACE_COMB_LIMITS);
41 + if (!nl_limits)
42 + goto nla_put_failure;
43
44 - c = &wiphy->iface_combinations[i];
45 + for (i = 0; i < c->n_limits; i++) {
46 + struct nlattr *nl_limit;
47
48 - nl_combi = nla_nest_start_noflag(msg, i + 1);
49 - if (!nl_combi)
50 + nl_limit = nla_nest_start_noflag(msg, i + 1);
51 + if (!nl_limit)
52 goto nla_put_failure;
53 -
54 - nl_limits = nla_nest_start_noflag(msg,
55 - NL80211_IFACE_COMB_LIMITS);
56 - if (!nl_limits)
57 + if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, c->limits[i].max))
58 goto nla_put_failure;
59 + if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
60 + c->limits[i].types))
61 + goto nla_put_failure;
62 + nla_nest_end(msg, nl_limit);
63 + }
64
65 - for (j = 0; j < c->n_limits; j++) {
66 - struct nlattr *nl_limit;
67 + nla_nest_end(msg, nl_limits);
68
69 - nl_limit = nla_nest_start_noflag(msg, j + 1);
70 - if (!nl_limit)
71 - goto nla_put_failure;
72 - if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
73 - c->limits[j].max))
74 - goto nla_put_failure;
75 - if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
76 - c->limits[j].types))
77 - goto nla_put_failure;
78 - nla_nest_end(msg, nl_limit);
79 - }
80 + if (c->beacon_int_infra_match &&
81 + nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
82 + goto nla_put_failure;
83 + if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
84 + c->num_different_channels) ||
85 + nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
86 + c->max_interfaces))
87 + goto nla_put_failure;
88 + if (large &&
89 + (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
90 + c->radar_detect_widths) ||
91 + nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
92 + c->radar_detect_regions)))
93 + goto nla_put_failure;
94 + if (c->beacon_int_min_gcd &&
95 + nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
96 + c->beacon_int_min_gcd))
97 + goto nla_put_failure;
98
99 - nla_nest_end(msg, nl_limits);
100 + nla_nest_end(msg, nl_combi);
101
102 - if (c->beacon_int_infra_match &&
103 - nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
104 - goto nla_put_failure;
105 - if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
106 - c->num_different_channels) ||
107 - nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
108 - c->max_interfaces))
109 - goto nla_put_failure;
110 - if (large &&
111 - (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
112 - c->radar_detect_widths) ||
113 - nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
114 - c->radar_detect_regions)))
115 - goto nla_put_failure;
116 - if (c->beacon_int_min_gcd &&
117 - nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
118 - c->beacon_int_min_gcd))
119 - goto nla_put_failure;
120 + return 0;
121 +nla_put_failure:
122 + return -ENOBUFS;
123 +}
124
125 - nla_nest_end(msg, nl_combi);
126 - }
127 +static int nl80211_put_iface_combinations(struct wiphy *wiphy,
128 + struct sk_buff *msg,
129 + bool large)
130 +{
131 + struct nlattr *nl_combis;
132 + int i;
133 +
134 + nl_combis = nla_nest_start_noflag(msg,
135 + NL80211_ATTR_INTERFACE_COMBINATIONS);
136 + if (!nl_combis)
137 + goto nla_put_failure;
138 +
139 + for (i = 0; i < wiphy->n_iface_combinations; i++)
140 + if (nl80211_put_ifcomb_data(msg, large, i + 1,
141 + &wiphy->iface_combinations[i]))
142 + goto nla_put_failure;
143
144 nla_nest_end(msg, nl_combis);
145