522-mac80211_configure_antenna_gain.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. --- a/include/net/cfg80211.h
  2. +++ b/include/net/cfg80211.h
  3. @@ -2959,6 +2959,7 @@ struct cfg80211_external_auth_params {
  4. * (as advertised by the nl80211 feature flag.)
  5. * @get_tx_power: store the current TX power into the dbm variable;
  6. * return 0 if successful
  7. + * @set_antenna_gain: set antenna gain to reduce maximum tx power if necessary
  8. *
  9. * @set_wds_peer: set the WDS peer for a WDS interface
  10. *
  11. @@ -3259,6 +3260,7 @@ struct cfg80211_ops {
  12. enum nl80211_tx_power_setting type, int mbm);
  13. int (*get_tx_power)(struct wiphy *wiphy, struct wireless_dev *wdev,
  14. int *dbm);
  15. + int (*set_antenna_gain)(struct wiphy *wiphy, int dbi);
  16. int (*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev,
  17. const u8 *addr);
  18. --- a/include/net/mac80211.h
  19. +++ b/include/net/mac80211.h
  20. @@ -1389,6 +1389,7 @@ enum ieee80211_smps_mode {
  21. *
  22. * @power_level: requested transmit power (in dBm), backward compatibility
  23. * value only that is set to the minimum of all interfaces
  24. + * @max_antenna_gain: maximum antenna gain adjusted by user config (in dBi)
  25. *
  26. * @chandef: the channel definition to tune to
  27. * @radar_enabled: whether radar detection is enabled
  28. @@ -1409,6 +1410,7 @@ enum ieee80211_smps_mode {
  29. struct ieee80211_conf {
  30. u32 flags;
  31. int power_level, dynamic_ps_timeout;
  32. + int max_antenna_gain;
  33. u16 listen_interval;
  34. u8 ps_dtim_period;
  35. --- a/include/uapi/linux/nl80211.h
  36. +++ b/include/uapi/linux/nl80211.h
  37. @@ -2241,6 +2241,26 @@ enum nl80211_commands {
  38. * association request when used with NL80211_CMD_NEW_STATION). Can be set
  39. * only if %NL80211_STA_FLAG_WME is set.
  40. *
  41. + * @NL80211_ATTR_FTM_RESPONDER: nested attribute which user-space can include
  42. + * in %NL80211_CMD_START_AP or %NL80211_CMD_SET_BEACON for fine timing
  43. + * measurement (FTM) responder functionality and containing parameters as
  44. + * possible, see &enum nl80211_ftm_responder_attr
  45. + *
  46. + * @NL80211_ATTR_FTM_RESPONDER_STATS: Nested attribute with FTM responder
  47. + * statistics, see &enum nl80211_ftm_responder_stats.
  48. + *
  49. + * @NL80211_ATTR_TIMEOUT: Timeout for the given operation in milliseconds (u32),
  50. + * if the attribute is not given no timeout is requested. Note that 0 is an
  51. + * invalid value.
  52. + *
  53. + * @NL80211_ATTR_PEER_MEASUREMENTS: peer measurements request (and result)
  54. + * data, uses nested attributes specified in
  55. + * &enum nl80211_peer_measurement_attrs.
  56. + * This is also used for capability advertisement in the wiphy information,
  57. + * with the appropriate sub-attributes.
  58. + * @NL80211_ATTR_WIPHY_ANTENNA_GAIN: Configured antenna gain. Used to reduce
  59. + * transmit power to stay within regulatory limits. u32, dBi.
  60. + *
  61. * @NUM_NL80211_ATTR: total number of nl80211_attrs available
  62. * @NL80211_ATTR_MAX: highest attribute number currently defined
  63. * @__NL80211_ATTR_AFTER_LAST: internal use
  64. @@ -2682,6 +2702,16 @@ enum nl80211_attrs {
  65. NL80211_ATTR_HE_CAPABILITY,
  66. + NL80211_ATTR_FTM_RESPONDER,
  67. +
  68. + NL80211_ATTR_FTM_RESPONDER_STATS,
  69. +
  70. + NL80211_ATTR_TIMEOUT,
  71. +
  72. + NL80211_ATTR_PEER_MEASUREMENTS,
  73. +
  74. + NL80211_ATTR_WIPHY_ANTENNA_GAIN,
  75. +
  76. /* add attributes here, update the policy in nl80211.c */
  77. __NL80211_ATTR_AFTER_LAST,
  78. --- a/net/mac80211/cfg.c
  79. +++ b/net/mac80211/cfg.c
  80. @@ -2494,6 +2494,19 @@ static int ieee80211_get_tx_power(struct
  81. return 0;
  82. }
  83. +static int ieee80211_set_antenna_gain(struct wiphy *wiphy, int dbi)
  84. +{
  85. + struct ieee80211_local *local = wiphy_priv(wiphy);
  86. +
  87. + if (dbi < 0)
  88. + return -EINVAL;
  89. +
  90. + local->user_antenna_gain = dbi;
  91. + ieee80211_hw_config(local, 0);
  92. +
  93. + return 0;
  94. +}
  95. +
  96. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  97. const u8 *addr)
  98. {
  99. @@ -3861,6 +3874,7 @@ const struct cfg80211_ops mac80211_confi
  100. .set_wiphy_params = ieee80211_set_wiphy_params,
  101. .set_tx_power = ieee80211_set_tx_power,
  102. .get_tx_power = ieee80211_get_tx_power,
  103. + .set_antenna_gain = ieee80211_set_antenna_gain,
  104. .set_wds_peer = ieee80211_set_wds_peer,
  105. .rfkill_poll = ieee80211_rfkill_poll,
  106. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  107. --- a/net/mac80211/ieee80211_i.h
  108. +++ b/net/mac80211/ieee80211_i.h
  109. @@ -1352,6 +1352,7 @@ struct ieee80211_local {
  110. int dynamic_ps_forced_timeout;
  111. int user_power_level; /* in dBm, for all interfaces */
  112. + int user_antenna_gain; /* in dBi */
  113. enum ieee80211_smps_mode smps_mode;
  114. --- a/net/mac80211/main.c
  115. +++ b/net/mac80211/main.c
  116. @@ -94,7 +94,7 @@ static u32 ieee80211_hw_conf_chan(struct
  117. struct ieee80211_sub_if_data *sdata;
  118. struct cfg80211_chan_def chandef = {};
  119. u32 changed = 0;
  120. - int power;
  121. + int power, max_power;
  122. u32 offchannel_flag;
  123. offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  124. @@ -151,6 +151,12 @@ static u32 ieee80211_hw_conf_chan(struct
  125. }
  126. rcu_read_unlock();
  127. + max_power = chandef.chan->max_reg_power;
  128. + if (local->user_antenna_gain > 0) {
  129. + max_power -= local->user_antenna_gain;
  130. + power = min(power, max_power);
  131. + }
  132. +
  133. if (local->hw.conf.power_level != power) {
  134. changed |= IEEE80211_CONF_CHANGE_POWER;
  135. local->hw.conf.power_level = power;
  136. @@ -626,6 +632,7 @@ struct ieee80211_hw *ieee80211_alloc_hw_
  137. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  138. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  139. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  140. + local->user_antenna_gain = 0;
  141. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  142. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  143. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  144. --- a/net/wireless/nl80211.c
  145. +++ b/net/wireless/nl80211.c
  146. @@ -430,6 +430,7 @@ static const struct nla_policy nl80211_p
  147. [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
  148. [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
  149. .len = NL80211_HE_MAX_CAPABILITY_LEN },
  150. + [NL80211_ATTR_WIPHY_ANTENNA_GAIN] = { .type = NLA_U32 },
  151. };
  152. /* policy for the key attributes */
  153. @@ -2587,6 +2588,20 @@ static int nl80211_set_wiphy(struct sk_b
  154. if (result)
  155. return result;
  156. }
  157. +
  158. + if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_GAIN]) {
  159. + int idx, dbi = 0;
  160. +
  161. + if (!rdev->ops->set_antenna_gain)
  162. + return -EOPNOTSUPP;
  163. +
  164. + idx = NL80211_ATTR_WIPHY_ANTENNA_GAIN;
  165. + dbi = nla_get_u32(info->attrs[idx]);
  166. +
  167. + result = rdev->ops->set_antenna_gain(&rdev->wiphy, dbi);
  168. + if (result)
  169. + return result;
  170. + }
  171. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  172. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {