dot11d.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /******************************************************************************
  2. * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
  3. *
  4. * This program is distributed in the hope that it will be useful, but WITHOUT
  5. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  7. * more details.
  8. *
  9. * You should have received a copy of the GNU General Public License along with
  10. * this program; if not, write to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  12. *
  13. * The full GNU General Public License is included in this distribution in the
  14. * file called LICENSE.
  15. *
  16. * Contact Information:
  17. * wlanfae <wlanfae@realtek.com>
  18. ******************************************************************************/
  19. #include "dot11d.h"
  20. struct channel_list {
  21. u8 Channel[32];
  22. u8 Len;
  23. };
  24. static struct channel_list ChannelPlan[] = {
  25. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64,
  26. 149, 153, 157, 161, 165}, 24},
  27. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11},
  28. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56,
  29. 60, 64}, 21},
  30. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  31. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  32. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  33. 56, 60, 64}, 22},
  34. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  35. 56, 60, 64}, 22},
  36. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  37. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  38. 56, 60, 64}, 22},
  39. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  40. 56, 60, 64}, 22},
  41. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14},
  42. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  43. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52,
  44. 56, 60, 64}, 21}
  45. };
  46. void dot11d_init(struct rtllib_device *ieee)
  47. {
  48. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee);
  49. pDot11dInfo->bEnabled = false;
  50. pDot11dInfo->State = DOT11D_STATE_NONE;
  51. pDot11dInfo->CountryIeLen = 0;
  52. memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
  53. memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
  54. RESET_CIE_WATCHDOG(ieee);
  55. }
  56. EXPORT_SYMBOL(dot11d_init);
  57. void Dot11d_Channelmap(u8 channel_plan, struct rtllib_device *ieee)
  58. {
  59. int i, max_chan = 14, min_chan = 1;
  60. ieee->bGlobalDomain = false;
  61. if (ChannelPlan[channel_plan].Len != 0) {
  62. memset(GET_DOT11D_INFO(ieee)->channel_map, 0,
  63. sizeof(GET_DOT11D_INFO(ieee)->channel_map));
  64. for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
  65. if (ChannelPlan[channel_plan].Channel[i] < min_chan ||
  66. ChannelPlan[channel_plan].Channel[i] > max_chan)
  67. break;
  68. GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan
  69. [channel_plan].Channel[i]] = 1;
  70. }
  71. }
  72. switch (channel_plan) {
  73. case COUNTRY_CODE_GLOBAL_DOMAIN:
  74. ieee->bGlobalDomain = true;
  75. for (i = 12; i <= 14; i++)
  76. GET_DOT11D_INFO(ieee)->channel_map[i] = 2;
  77. ieee->IbssStartChnl = 10;
  78. ieee->ibss_maxjoin_chal = 11;
  79. break;
  80. case COUNTRY_CODE_WORLD_WIDE_13:
  81. for (i = 12; i <= 13; i++)
  82. GET_DOT11D_INFO(ieee)->channel_map[i] = 2;
  83. ieee->IbssStartChnl = 10;
  84. ieee->ibss_maxjoin_chal = 11;
  85. break;
  86. default:
  87. ieee->IbssStartChnl = 1;
  88. ieee->ibss_maxjoin_chal = 14;
  89. break;
  90. }
  91. }
  92. EXPORT_SYMBOL(Dot11d_Channelmap);
  93. void Dot11d_Reset(struct rtllib_device *ieee)
  94. {
  95. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee);
  96. u32 i;
  97. memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
  98. memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
  99. for (i = 1; i <= 11; i++)
  100. (pDot11dInfo->channel_map)[i] = 1;
  101. for (i = 12; i <= 14; i++)
  102. (pDot11dInfo->channel_map)[i] = 2;
  103. pDot11dInfo->State = DOT11D_STATE_NONE;
  104. pDot11dInfo->CountryIeLen = 0;
  105. RESET_CIE_WATCHDOG(ieee);
  106. }
  107. void Dot11d_UpdateCountryIe(struct rtllib_device *dev, u8 *pTaddr,
  108. u16 CoutryIeLen, u8 *pCoutryIe)
  109. {
  110. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
  111. u8 i, j, NumTriples, MaxChnlNum;
  112. struct chnl_txpow_triple *pTriple;
  113. memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
  114. memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
  115. MaxChnlNum = 0;
  116. NumTriples = (CoutryIeLen - 3) / 3;
  117. pTriple = (struct chnl_txpow_triple *)(pCoutryIe + 3);
  118. for (i = 0; i < NumTriples; i++) {
  119. if (MaxChnlNum >= pTriple->FirstChnl) {
  120. netdev_info(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
  121. return;
  122. }
  123. if (MAX_CHANNEL_NUMBER < (pTriple->FirstChnl +
  124. pTriple->NumChnls)) {
  125. netdev_info(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n");
  126. return;
  127. }
  128. for (j = 0; j < pTriple->NumChnls; j++) {
  129. pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1;
  130. pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] =
  131. pTriple->MaxTxPowerInDbm;
  132. MaxChnlNum = pTriple->FirstChnl + j;
  133. }
  134. pTriple = (struct chnl_txpow_triple *)((u8 *)pTriple + 3);
  135. }
  136. UPDATE_CIE_SRC(dev, pTaddr);
  137. pDot11dInfo->CountryIeLen = CoutryIeLen;
  138. memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe, CoutryIeLen);
  139. pDot11dInfo->State = DOT11D_STATE_LEARNED;
  140. }
  141. u8 DOT11D_GetMaxTxPwrInDbm(struct rtllib_device *dev, u8 Channel)
  142. {
  143. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
  144. u8 MaxTxPwrInDbm = 255;
  145. if (MAX_CHANNEL_NUMBER < Channel) {
  146. netdev_info(dev->dev, "DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
  147. return MaxTxPwrInDbm;
  148. }
  149. if (pDot11dInfo->channel_map[Channel])
  150. MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
  151. return MaxTxPwrInDbm;
  152. }
  153. void DOT11D_ScanComplete(struct rtllib_device *dev)
  154. {
  155. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
  156. switch (pDot11dInfo->State) {
  157. case DOT11D_STATE_LEARNED:
  158. pDot11dInfo->State = DOT11D_STATE_DONE;
  159. break;
  160. case DOT11D_STATE_DONE:
  161. Dot11d_Reset(dev);
  162. break;
  163. case DOT11D_STATE_NONE:
  164. break;
  165. }
  166. }
  167. int ToLegalChannel(struct rtllib_device *dev, u8 channel)
  168. {
  169. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
  170. u8 default_chn = 0;
  171. u32 i;
  172. for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) {
  173. if (pDot11dInfo->channel_map[i] > 0) {
  174. default_chn = i;
  175. break;
  176. }
  177. }
  178. if (MAX_CHANNEL_NUMBER < channel) {
  179. netdev_err(dev->dev, "%s(): Invalid Channel\n", __func__);
  180. return default_chn;
  181. }
  182. if (pDot11dInfo->channel_map[channel] > 0)
  183. return channel;
  184. return default_chn;
  185. }