1
0

522-mac80211_configure_antenna_gain.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. --- a/include/net/cfg80211.h
  2. +++ b/include/net/cfg80211.h
  3. @@ -2660,6 +2660,7 @@ struct cfg80211_nan_func {
  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. @@ -2940,6 +2941,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. @@ -1325,6 +1325,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. @@ -1345,6 +1346,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. @@ -2002,6 +2002,9 @@ enum nl80211_commands {
  38. * u32 attribute with an &enum nl80211_timeout_reason value. This is used,
  39. * e.g., with %NL80211_CMD_CONNECT event.
  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. @@ -2413,6 +2416,8 @@ enum nl80211_attrs {
  48. NL80211_ATTR_TIMEOUT_REASON,
  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. @@ -2396,6 +2396,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. @@ -3627,6 +3640,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. @@ -1370,6 +1370,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. @@ -93,7 +93,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. @@ -150,6 +150,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. @@ -589,6 +595,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. @@ -424,6 +424,7 @@ static const struct nla_policy nl80211_p
  122. .len = sizeof(struct nl80211_bss_select_rssi_adjust)
  123. },
  124. [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
  125. + [NL80211_ATTR_WIPHY_ANTENNA_GAIN] = { .type = NLA_U32 },
  126. };
  127. /* policy for the key attributes */
  128. @@ -2385,6 +2386,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]) {