]>
Commit | Line | Data |
---|---|---|
727da60b DV |
1 | /* |
2 | * This program is free software; you can redistribute it and/or modify | |
3 | * it under the terms of the GNU General Public License version 2 as | |
4 | * published by the Free Software Foundation. | |
5 | */ | |
6 | #include <net/mac80211.h> | |
7 | #include "ieee80211_i.h" | |
8 | #include "trace.h" | |
9 | #include "driver-ops.h" | |
10 | ||
9aae296a DV |
11 | int drv_add_interface(struct ieee80211_local *local, |
12 | struct ieee80211_sub_if_data *sdata) | |
13 | { | |
14 | int ret; | |
15 | ||
16 | might_sleep(); | |
17 | ||
18 | if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN || | |
19 | (sdata->vif.type == NL80211_IFTYPE_MONITOR && | |
20 | !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) && | |
21 | !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE)))) | |
22 | return -EINVAL; | |
23 | ||
24 | trace_drv_add_interface(local, sdata); | |
25 | ret = local->ops->add_interface(&local->hw, &sdata->vif); | |
26 | trace_drv_return_int(local, ret); | |
27 | ||
28 | if (ret == 0) | |
29 | sdata->flags |= IEEE80211_SDATA_IN_DRIVER; | |
30 | ||
31 | return ret; | |
32 | } | |
33 | ||
34 | int drv_change_interface(struct ieee80211_local *local, | |
35 | struct ieee80211_sub_if_data *sdata, | |
36 | enum nl80211_iftype type, bool p2p) | |
37 | { | |
38 | int ret; | |
39 | ||
40 | might_sleep(); | |
41 | ||
42 | if (!check_sdata_in_driver(sdata)) | |
43 | return -EIO; | |
44 | ||
45 | trace_drv_change_interface(local, sdata, type, p2p); | |
46 | ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p); | |
47 | trace_drv_return_int(local, ret); | |
48 | return ret; | |
49 | } | |
50 | ||
51 | void drv_remove_interface(struct ieee80211_local *local, | |
52 | struct ieee80211_sub_if_data *sdata) | |
53 | { | |
54 | might_sleep(); | |
55 | ||
56 | if (!check_sdata_in_driver(sdata)) | |
57 | return; | |
58 | ||
59 | trace_drv_remove_interface(local, sdata); | |
60 | local->ops->remove_interface(&local->hw, &sdata->vif); | |
61 | sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER; | |
62 | trace_drv_return_void(local); | |
63 | } | |
64 | ||
727da60b DV |
65 | __must_check |
66 | int drv_sta_state(struct ieee80211_local *local, | |
67 | struct ieee80211_sub_if_data *sdata, | |
68 | struct sta_info *sta, | |
69 | enum ieee80211_sta_state old_state, | |
70 | enum ieee80211_sta_state new_state) | |
71 | { | |
72 | int ret = 0; | |
73 | ||
74 | might_sleep(); | |
75 | ||
76 | sdata = get_bss_sdata(sdata); | |
77 | if (!check_sdata_in_driver(sdata)) | |
78 | return -EIO; | |
79 | ||
80 | trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state); | |
81 | if (local->ops->sta_state) { | |
82 | ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta, | |
83 | old_state, new_state); | |
84 | } else if (old_state == IEEE80211_STA_AUTH && | |
85 | new_state == IEEE80211_STA_ASSOC) { | |
86 | ret = drv_sta_add(local, sdata, &sta->sta); | |
87 | if (ret == 0) | |
88 | sta->uploaded = true; | |
89 | } else if (old_state == IEEE80211_STA_ASSOC && | |
90 | new_state == IEEE80211_STA_AUTH) { | |
91 | drv_sta_remove(local, sdata, &sta->sta); | |
92 | } | |
93 | trace_drv_return_int(local, ret); | |
94 | return ret; | |
95 | } | |
b23dcd4a | 96 | |
4fbd572c DV |
97 | void drv_sta_rc_update(struct ieee80211_local *local, |
98 | struct ieee80211_sub_if_data *sdata, | |
99 | struct ieee80211_sta *sta, u32 changed) | |
100 | { | |
101 | sdata = get_bss_sdata(sdata); | |
102 | if (!check_sdata_in_driver(sdata)) | |
103 | return; | |
104 | ||
105 | WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED && | |
106 | (sdata->vif.type != NL80211_IFTYPE_ADHOC && | |
107 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT)); | |
108 | ||
109 | trace_drv_sta_rc_update(local, sdata, sta, changed); | |
110 | if (local->ops->sta_rc_update) | |
111 | local->ops->sta_rc_update(&local->hw, &sdata->vif, | |
112 | sta, changed); | |
113 | ||
114 | trace_drv_return_void(local); | |
115 | } | |
116 | ||
b23dcd4a DV |
117 | int drv_conf_tx(struct ieee80211_local *local, |
118 | struct ieee80211_sub_if_data *sdata, u16 ac, | |
119 | const struct ieee80211_tx_queue_params *params) | |
120 | { | |
121 | int ret = -EOPNOTSUPP; | |
122 | ||
123 | might_sleep(); | |
124 | ||
125 | if (!check_sdata_in_driver(sdata)) | |
126 | return -EIO; | |
127 | ||
128 | if (WARN_ONCE(params->cw_min == 0 || | |
129 | params->cw_min > params->cw_max, | |
130 | "%s: invalid CW_min/CW_max: %d/%d\n", | |
131 | sdata->name, params->cw_min, params->cw_max)) | |
132 | return -EINVAL; | |
133 | ||
134 | trace_drv_conf_tx(local, sdata, ac, params); | |
135 | if (local->ops->conf_tx) | |
136 | ret = local->ops->conf_tx(&local->hw, &sdata->vif, | |
137 | ac, params); | |
138 | trace_drv_return_int(local, ret); | |
139 | return ret; | |
140 | } | |
42677ed3 DV |
141 | |
142 | int drv_switch_vif_chanctx(struct ieee80211_local *local, | |
143 | struct ieee80211_vif_chanctx_switch *vifs, | |
144 | int n_vifs, enum ieee80211_chanctx_switch_mode mode) | |
145 | { | |
146 | int ret = 0; | |
147 | int i; | |
148 | ||
149 | if (!local->ops->switch_vif_chanctx) | |
150 | return -EOPNOTSUPP; | |
151 | ||
152 | for (i = 0; i < n_vifs; i++) { | |
153 | struct ieee80211_chanctx *new_ctx = | |
154 | container_of(vifs[i].new_ctx, | |
155 | struct ieee80211_chanctx, | |
156 | conf); | |
157 | struct ieee80211_chanctx *old_ctx = | |
158 | container_of(vifs[i].old_ctx, | |
159 | struct ieee80211_chanctx, | |
160 | conf); | |
161 | ||
162 | WARN_ON_ONCE(!old_ctx->driver_present); | |
163 | WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS && | |
164 | new_ctx->driver_present) || | |
165 | (mode == CHANCTX_SWMODE_REASSIGN_VIF && | |
166 | !new_ctx->driver_present)); | |
167 | } | |
168 | ||
169 | trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode); | |
170 | ret = local->ops->switch_vif_chanctx(&local->hw, | |
171 | vifs, n_vifs, mode); | |
172 | trace_drv_return_int(local, ret); | |
173 | ||
174 | if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) { | |
175 | for (i = 0; i < n_vifs; i++) { | |
176 | struct ieee80211_chanctx *new_ctx = | |
177 | container_of(vifs[i].new_ctx, | |
178 | struct ieee80211_chanctx, | |
179 | conf); | |
180 | struct ieee80211_chanctx *old_ctx = | |
181 | container_of(vifs[i].old_ctx, | |
182 | struct ieee80211_chanctx, | |
183 | conf); | |
184 | ||
185 | new_ctx->driver_present = true; | |
186 | old_ctx->driver_present = false; | |
187 | } | |
188 | } | |
189 | ||
190 | return ret; | |
191 | } |