522-mac80211_configure_antenna_gain.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. --- a/include/net/cfg80211.h
  2. +++ b/include/net/cfg80211.h
  3. @@ -2972,6 +2972,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. @@ -3275,6 +3276,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. @@ -1395,6 +1395,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. @@ -1415,6 +1416,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. @@ -2244,6 +2244,9 @@ enum nl80211_commands {
  38. * @NL80211_ATTR_AIRTIME_WEIGHT: Station's weight when scheduled by the airtime
  39. * scheduler.
  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. * @NUM_NL80211_ATTR: total number of nl80211_attrs available
  45. * @NL80211_ATTR_MAX: highest attribute number currently defined
  46. * @__NL80211_ATTR_AFTER_LAST: internal use
  47. @@ -2693,6 +2696,8 @@ enum nl80211_attrs {
  48. NL80211_ATTR_AIRTIME_WEIGHT,
  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. @@ -2456,6 +2456,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. @@ -3845,6 +3858,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. @@ -1365,6 +1365,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. @@ -94,7 +94,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. @@ -151,6 +151,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.conf.power_level = power;
  111. @@ -626,6 +632,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. @@ -470,6 +470,7 @@ static const struct nla_policy nl80211_p
  122. [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
  123. .len = NL80211_HE_MAX_CAPABILITY_LEN },
  124. [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
  125. + [NL80211_ATTR_WIPHY_ANTENNA_GAIN] = { .type = NLA_U32 },
  126. };
  127. /* policy for the key attributes */
  128. @@ -2629,6 +2630,20 @@ static int nl80211_set_wiphy(struct sk_b
  129. if (result)
  130. return result;
  131. }
  132. +
  133. + if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_GAIN]) {
  134. + int idx, dbi = 0;
  135. +
  136. + if (!rdev->ops->set_antenna_gain)
  137. + return -EOPNOTSUPP;
  138. +
  139. + idx = NL80211_ATTR_WIPHY_ANTENNA_GAIN;
  140. + dbi = nla_get_u32(info->attrs[idx]);
  141. +
  142. + result = rdev->ops->set_antenna_gain(&rdev->wiphy, dbi);
  143. + if (result)
  144. + return result;
  145. + }
  146. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  147. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {