Denys Vlasenko | 727da60 | 2015-07-15 14:56:05 +0200 | [diff] [blame] | 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 | |
Denys Vlasenko | 9aae296 | 2015-09-18 15:19:38 +0200 | [diff] [blame^] | 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 | |
Denys Vlasenko | 727da60 | 2015-07-15 14:56:05 +0200 | [diff] [blame] | 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 | } |
Denys Vlasenko | b23dcd4 | 2015-09-18 15:19:34 +0200 | [diff] [blame] | 96 | |
Denys Vlasenko | 4fbd572 | 2015-09-18 15:19:35 +0200 | [diff] [blame] | 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 | |
Denys Vlasenko | b23dcd4 | 2015-09-18 15:19:34 +0200 | [diff] [blame] | 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 | } |