522-mac80211_configure_antenna_gain.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. --- a/include/net/cfg80211.h
  2. +++ b/include/net/cfg80211.h
  3. @@ -2214,6 +2214,7 @@ struct cfg80211_qos_map {
  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. @@ -2450,6 +2451,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. @@ -1075,6 +1075,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. @@ -1096,6 +1097,7 @@ struct ieee80211_conf {
  29. u32 flags;
  30. int power_level, dynamic_ps_timeout;
  31. int max_sleep_period;
  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. @@ -1638,6 +1638,9 @@ enum nl80211_commands {
  38. * @NL80211_ATTR_SMPS_MODE: SMPS mode to use (ap mode). see
  39. * &enum nl80211_smps_mode.
  40. *
  41. + * @NL80211_ATTR_WIPHY_ANTENNA_GAIN: Configured antenna gain. Used to reduce
  42. + * transmit power to stay within regulatory limits. u32, dBi.
  43. + *
  44. * @NL80211_ATTR_MAX: highest attribute number currently defined
  45. * @__NL80211_ATTR_AFTER_LAST: internal use
  46. */
  47. @@ -1990,6 +1993,8 @@ enum nl80211_attrs {
  48. NL80211_ATTR_SMPS_MODE,
  49. + NL80211_ATTR_WIPHY_ANTENNA_GAIN,
  50. +
  51. /* add attributes here, update the policy in nl80211.c */
  52. __NL80211_ATTR_AFTER_LAST,
  53. --- a/net/mac80211/cfg.c
  54. +++ b/net/mac80211/cfg.c
  55. @@ -2091,6 +2091,19 @@ static int ieee80211_get_tx_power(struct
  56. return 0;
  57. }
  58. +static int ieee80211_set_antenna_gain(struct wiphy *wiphy, int dbi)
  59. +{
  60. + struct ieee80211_local *local = wiphy_priv(wiphy);
  61. +
  62. + if (dbi < 0)
  63. + return -EINVAL;
  64. +
  65. + local->user_antenna_gain = dbi;
  66. + ieee80211_hw_config(local, 0);
  67. +
  68. + return 0;
  69. +}
  70. +
  71. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  72. const u8 *addr)
  73. {
  74. @@ -3572,6 +3585,7 @@ const struct cfg80211_ops mac80211_confi
  75. .set_wiphy_params = ieee80211_set_wiphy_params,
  76. .set_tx_power = ieee80211_set_tx_power,
  77. .get_tx_power = ieee80211_get_tx_power,
  78. + .set_antenna_gain = ieee80211_set_antenna_gain,
  79. .set_wds_peer = ieee80211_set_wds_peer,
  80. .rfkill_poll = ieee80211_rfkill_poll,
  81. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  82. --- a/net/mac80211/ieee80211_i.h
  83. +++ b/net/mac80211/ieee80211_i.h
  84. @@ -1280,6 +1280,7 @@ struct ieee80211_local {
  85. int dynamic_ps_forced_timeout;
  86. int user_power_level; /* in dBm, for all interfaces */
  87. + int user_antenna_gain; /* in dBi */
  88. enum ieee80211_smps_mode smps_mode;
  89. --- a/net/mac80211/main.c
  90. +++ b/net/mac80211/main.c
  91. @@ -98,7 +98,7 @@ static u32 ieee80211_hw_conf_chan(struct
  92. struct ieee80211_sub_if_data *sdata;
  93. struct cfg80211_chan_def chandef = {};
  94. u32 changed = 0;
  95. - int power;
  96. + int power, max_power;
  97. u32 offchannel_flag;
  98. offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  99. @@ -155,6 +155,12 @@ static u32 ieee80211_hw_conf_chan(struct
  100. }
  101. rcu_read_unlock();
  102. + max_power = chandef.chan->max_reg_power;
  103. + if (local->user_antenna_gain > 0) {
  104. + max_power -= local->user_antenna_gain;
  105. + power = min(power, max_power);
  106. + }
  107. +
  108. if (local->hw.conf.power_level != power) {
  109. changed |= IEEE80211_CONF_CHANGE_POWER;
  110. local->hw.cur_power_level = power;
  111. @@ -586,6 +592,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(
  112. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  113. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  114. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  115. + local->user_antenna_gain = 0;
  116. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  117. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  118. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  119. --- a/net/wireless/nl80211.c
  120. +++ b/net/wireless/nl80211.c
  121. @@ -395,6 +395,7 @@ static const struct nla_policy nl80211_p
  122. [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
  123. [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
  124. [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
  125. + [NL80211_ATTR_WIPHY_ANTENNA_GAIN] = { .type = NLA_U32 },
  126. };
  127. /* policy for the key attributes */
  128. @@ -2179,6 +2180,20 @@ static int nl80211_set_wiphy(struct sk_b
  129. return result;
  130. }
  131. + if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_GAIN]) {
  132. + int idx, dbi = 0;
  133. +
  134. + if (!rdev->ops->set_antenna_gain)
  135. + return -EOPNOTSUPP;
  136. +
  137. + idx = NL80211_ATTR_WIPHY_ANTENNA_GAIN;
  138. + dbi = nla_get_u32(info->attrs[idx]);
  139. +
  140. + result = rdev->ops->set_antenna_gain(&rdev->wiphy, dbi);
  141. + if (result)
  142. + return result;
  143. + }
  144. +
  145. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  146. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
  147. u32 tx_ant, rx_ant;