100-coverage_class.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --- a/info.c
  2. +++ b/info.c
  3. @@ -156,6 +156,14 @@ static int print_phy_handler(struct nl_m
  4. printf("\tRTS threshold: %d\n", rts);
  5. }
  6. + if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
  7. + unsigned char coverage;
  8. +
  9. + coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
  10. + /* See handle_distance() for an explanation where the '450' comes from */
  11. + printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
  12. + }
  13. +
  14. if (!tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES])
  15. goto commands;
  16. --- a/phy.c
  17. +++ b/phy.c
  18. @@ -164,3 +164,61 @@ static int handle_netns(struct nl80211_s
  19. COMMAND(set, netns, "<pid>",
  20. NL80211_CMD_SET_WIPHY_NETNS, 0, CIB_PHY, handle_netns,
  21. "Put this wireless device into a different network namespace");
  22. +
  23. +static int handle_coverage(struct nl80211_state *state,
  24. + struct nl_cb *cb,
  25. + struct nl_msg *msg,
  26. + int argc, char **argv)
  27. +{
  28. + unsigned int coverage;
  29. +
  30. + if (argc != 1)
  31. + return 1;
  32. +
  33. + coverage = strtoul(argv[0], NULL, 10);
  34. + if (coverage > 255)
  35. + return 1;
  36. +
  37. + NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, coverage);
  38. +
  39. + return 0;
  40. + nla_put_failure:
  41. + return -ENOBUFS;
  42. +}
  43. +COMMAND(set, coverage, "<coverage class>",
  44. + NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_coverage,
  45. + "Set coverage class (1 for every 3 usec of air propagation time).\n"
  46. + "Valid values: 0 - 255.");
  47. +
  48. +static int handle_distance(struct nl80211_state *state,
  49. + struct nl_cb *cb,
  50. + struct nl_msg *msg,
  51. + int argc, char **argv)
  52. +{
  53. + unsigned int distance, coverage;
  54. +
  55. + if (argc != 1)
  56. + return 1;
  57. +
  58. + distance = strtoul(argv[0], NULL, 10);
  59. +
  60. + /*
  61. + * Divide double the distance by the speed of light in m/usec (300) to
  62. + * get round-trip time in microseconds and then divide the result by
  63. + * three to get coverage class as specified in IEEE 802.11-2007 table
  64. + * 7-27. Values are rounded upwards.
  65. + */
  66. + coverage = (distance + 449) / 450;
  67. + if (coverage > 255)
  68. + return 1;
  69. +
  70. + NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, coverage);
  71. +
  72. + return 0;
  73. + nla_put_failure:
  74. + return -ENOBUFS;
  75. +}
  76. +COMMAND(set, distance, "<distance>",
  77. + NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_distance,
  78. + "Set appropriate coverage class for given link distance in meters.\n"
  79. + "Valid values: 0 - 114750");