qlink_util.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2015-2016 Quantenna Communications, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/nl80211.h>
  16. #include "qlink_util.h"
  17. u16 qlink_iface_type_to_nl_mask(u16 qlink_type)
  18. {
  19. u16 result = 0;
  20. switch (qlink_type) {
  21. case QLINK_IFTYPE_AP:
  22. result |= BIT(NL80211_IFTYPE_AP);
  23. break;
  24. case QLINK_IFTYPE_STATION:
  25. result |= BIT(NL80211_IFTYPE_STATION);
  26. break;
  27. case QLINK_IFTYPE_ADHOC:
  28. result |= BIT(NL80211_IFTYPE_ADHOC);
  29. break;
  30. case QLINK_IFTYPE_MONITOR:
  31. result |= BIT(NL80211_IFTYPE_MONITOR);
  32. break;
  33. case QLINK_IFTYPE_WDS:
  34. result |= BIT(NL80211_IFTYPE_WDS);
  35. break;
  36. case QLINK_IFTYPE_AP_VLAN:
  37. result |= BIT(NL80211_IFTYPE_AP_VLAN);
  38. break;
  39. }
  40. return result;
  41. }
  42. u8 qlink_chan_width_mask_to_nl(u16 qlink_mask)
  43. {
  44. u8 result = 0;
  45. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_5))
  46. result |= BIT(NL80211_CHAN_WIDTH_5);
  47. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_10))
  48. result |= BIT(NL80211_CHAN_WIDTH_10);
  49. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_20_NOHT))
  50. result |= BIT(NL80211_CHAN_WIDTH_20_NOHT);
  51. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_20))
  52. result |= BIT(NL80211_CHAN_WIDTH_20);
  53. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_40))
  54. result |= BIT(NL80211_CHAN_WIDTH_40);
  55. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_80))
  56. result |= BIT(NL80211_CHAN_WIDTH_80);
  57. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_80P80))
  58. result |= BIT(NL80211_CHAN_WIDTH_80P80);
  59. if (qlink_mask & BIT(QLINK_CHAN_WIDTH_160))
  60. result |= BIT(NL80211_CHAN_WIDTH_160);
  61. return result;
  62. }
  63. static enum nl80211_chan_width qlink_chanwidth_to_nl(u8 qlw)
  64. {
  65. switch (qlw) {
  66. case QLINK_CHAN_WIDTH_20_NOHT:
  67. return NL80211_CHAN_WIDTH_20_NOHT;
  68. case QLINK_CHAN_WIDTH_20:
  69. return NL80211_CHAN_WIDTH_20;
  70. case QLINK_CHAN_WIDTH_40:
  71. return NL80211_CHAN_WIDTH_40;
  72. case QLINK_CHAN_WIDTH_80:
  73. return NL80211_CHAN_WIDTH_80;
  74. case QLINK_CHAN_WIDTH_80P80:
  75. return NL80211_CHAN_WIDTH_80P80;
  76. case QLINK_CHAN_WIDTH_160:
  77. return NL80211_CHAN_WIDTH_160;
  78. case QLINK_CHAN_WIDTH_5:
  79. return NL80211_CHAN_WIDTH_5;
  80. case QLINK_CHAN_WIDTH_10:
  81. return NL80211_CHAN_WIDTH_10;
  82. default:
  83. return -1;
  84. }
  85. }
  86. void qlink_chandef_q2cfg(struct wiphy *wiphy,
  87. const struct qlink_chandef *qch,
  88. struct cfg80211_chan_def *chdef)
  89. {
  90. chdef->center_freq1 = le16_to_cpu(qch->center_freq1);
  91. chdef->center_freq2 = le16_to_cpu(qch->center_freq2);
  92. chdef->width = qlink_chanwidth_to_nl(qch->width);
  93. switch (chdef->width) {
  94. case NL80211_CHAN_WIDTH_20_NOHT:
  95. case NL80211_CHAN_WIDTH_20:
  96. case NL80211_CHAN_WIDTH_5:
  97. case NL80211_CHAN_WIDTH_10:
  98. chdef->chan = ieee80211_get_channel(wiphy, chdef->center_freq1);
  99. break;
  100. case NL80211_CHAN_WIDTH_40:
  101. case NL80211_CHAN_WIDTH_80:
  102. case NL80211_CHAN_WIDTH_80P80:
  103. case NL80211_CHAN_WIDTH_160:
  104. chdef->chan = ieee80211_get_channel(wiphy,
  105. chdef->center_freq1 - 10);
  106. break;
  107. default:
  108. chdef->chan = NULL;
  109. break;
  110. }
  111. }
  112. static u8 qlink_chanwidth_nl_to_qlink(enum nl80211_chan_width nlwidth)
  113. {
  114. switch (nlwidth) {
  115. case NL80211_CHAN_WIDTH_20_NOHT:
  116. return QLINK_CHAN_WIDTH_20_NOHT;
  117. case NL80211_CHAN_WIDTH_20:
  118. return QLINK_CHAN_WIDTH_20;
  119. case NL80211_CHAN_WIDTH_40:
  120. return QLINK_CHAN_WIDTH_40;
  121. case NL80211_CHAN_WIDTH_80:
  122. return QLINK_CHAN_WIDTH_80;
  123. case NL80211_CHAN_WIDTH_80P80:
  124. return QLINK_CHAN_WIDTH_80P80;
  125. case NL80211_CHAN_WIDTH_160:
  126. return QLINK_CHAN_WIDTH_160;
  127. case NL80211_CHAN_WIDTH_5:
  128. return QLINK_CHAN_WIDTH_5;
  129. case NL80211_CHAN_WIDTH_10:
  130. return QLINK_CHAN_WIDTH_10;
  131. default:
  132. return -1;
  133. }
  134. }
  135. void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
  136. struct qlink_chandef *qch)
  137. {
  138. qch->center_freq1 = cpu_to_le16(chdef->center_freq1);
  139. qch->center_freq2 = cpu_to_le16(chdef->center_freq2);
  140. qch->width = qlink_chanwidth_nl_to_qlink(chdef->width);
  141. }
  142. enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val)
  143. {
  144. switch (nl_val) {
  145. case NL80211_HIDDEN_SSID_ZERO_LEN:
  146. return QLINK_HIDDEN_SSID_ZERO_LEN;
  147. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  148. return QLINK_HIDDEN_SSID_ZERO_CONTENTS;
  149. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  150. default:
  151. return QLINK_HIDDEN_SSID_NOT_IN_USE;
  152. }
  153. }