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
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.
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 --- a/net/wireless/nl80211.c
14 +++ b/net/wireless/nl80211.c
15 @@ -1620,71 +1620,78 @@ nla_put_failure:
19 -static int nl80211_put_iface_combinations(struct wiphy *wiphy,
20 - struct sk_buff *msg,
22 +static int nl80211_put_ifcomb_data(struct sk_buff *msg, bool large, int idx,
23 + const struct ieee80211_iface_combination *c)
25 - struct nlattr *nl_combis;
27 + struct nlattr *nl_combi, *nl_limits;
30 - nl_combis = nla_nest_start_noflag(msg,
31 - NL80211_ATTR_INTERFACE_COMBINATIONS);
33 + nl_combi = nla_nest_start_noflag(msg, idx);
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);
42 + goto nla_put_failure;
44 - c = &wiphy->iface_combinations[i];
45 + for (i = 0; i < c->n_limits; i++) {
46 + struct nlattr *nl_limit;
48 - nl_combi = nla_nest_start_noflag(msg, i + 1);
50 + nl_limit = nla_nest_start_noflag(msg, i + 1);
54 - nl_limits = nla_nest_start_noflag(msg,
55 - NL80211_IFACE_COMB_LIMITS);
57 + if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, c->limits[i].max))
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);
65 - for (j = 0; j < c->n_limits; j++) {
66 - struct nlattr *nl_limit;
67 + nla_nest_end(msg, nl_limits);
69 - nl_limit = nla_nest_start_noflag(msg, j + 1);
71 - goto nla_put_failure;
72 - if (nla_put_u32(msg, NL80211_IFACE_LIMIT_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);
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,
87 + goto nla_put_failure;
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;
99 - nla_nest_end(msg, nl_limits);
100 + nla_nest_end(msg, nl_combi);
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;
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;
125 - nla_nest_end(msg, nl_combi);
127 +static int nl80211_put_iface_combinations(struct wiphy *wiphy,
128 + struct sk_buff *msg,
131 + struct nlattr *nl_combis;
134 + nl_combis = nla_nest_start_noflag(msg,
135 + NL80211_ATTR_INTERFACE_COMBINATIONS);
137 + goto nla_put_failure;
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;
144 nla_nest_end(msg, nl_combis);