dot11d.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. * The full GNU General Public License is included in this distribution in the
  10. * file called LICENSE.
  11. *
  12. * Contact Information:
  13. * wlanfae <wlanfae@realtek.com>
  14. ******************************************************************************/
  15. #include "dot11d.h"
  16. struct channel_list {
  17. u8 Channel[32];
  18. u8 Len;
  19. };
  20. static struct channel_list ChannelPlan[] = {
  21. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64,
  22. 149, 153, 157, 161, 165}, 24},
  23. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11},
  24. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56,
  25. 60, 64}, 21},
  26. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  27. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  28. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  29. 56, 60, 64}, 22},
  30. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  31. 56, 60, 64}, 22},
  32. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  33. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  34. 56, 60, 64}, 22},
  35. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52,
  36. 56, 60, 64}, 22},
  37. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14},
  38. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  39. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52,
  40. 56, 60, 64}, 21}
  41. };
  42. void dot11d_init(struct rtllib_device *ieee)
  43. {
  44. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee);
  45. pDot11dInfo->bEnabled = false;
  46. pDot11dInfo->State = DOT11D_STATE_NONE;
  47. pDot11dInfo->CountryIeLen = 0;
  48. memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
  49. memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER + 1);
  50. RESET_CIE_WATCHDOG(ieee);
  51. }
  52. EXPORT_SYMBOL(dot11d_init);
  53. void Dot11d_Channelmap(u8 channel_plan, struct rtllib_device *ieee)
  54. {
  55. int i, max_chan = 14, min_chan = 1;
  56. ieee->bGlobalDomain = false;
  57. if (ChannelPlan[channel_plan].Len != 0) {
  58. memset(GET_DOT11D_INFO(ieee)->channel_map, 0,
  59. sizeof(GET_DOT11D_INFO(ieee)->channel_map));
  60. for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
  61. if (ChannelPlan[channel_plan].Channel[i] < min_chan ||
  62. ChannelPlan[channel_plan].Channel[i] > max_chan)
  63. break;
  64. GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan
  65. [channel_plan].Channel[i]] = 1;
  66. }
  67. }
  68. switch (channel_plan) {
  69. case COUNTRY_CODE_GLOBAL_DOMAIN:
  70. ieee->bGlobalDomain = true;
  71. for (i = 12; i <= 14; i++)
  72. GET_DOT11D_INFO(ieee)->channel_map[i] = 2;
  73. ieee->IbssStartChnl = 10;
  74. ieee->ibss_maxjoin_chal = 11;
  75. break;
  76. case COUNTRY_CODE_WORLD_WIDE_13:
  77. for (i = 12; i <= 13; i++)
  78. GET_DOT11D_INFO(ieee)->channel_map[i] = 2;
  79. ieee->IbssStartChnl = 10;
  80. ieee->ibss_maxjoin_chal = 11;
  81. break;
  82. default:
  83. ieee->IbssStartChnl = 1;
  84. ieee->ibss_maxjoin_chal = 14;
  85. break;
  86. }
  87. }
  88. EXPORT_SYMBOL(Dot11d_Channelmap);
  89. void Dot11d_Reset(struct rtllib_device *ieee)
  90. {
  91. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee);
  92. u32 i;
  93. memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
  94. memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER + 1);
  95. for (i = 1; i <= 11; i++)
  96. (pDot11dInfo->channel_map)[i] = 1;
  97. for (i = 12; i <= 14; i++)
  98. (pDot11dInfo->channel_map)[i] = 2;
  99. pDot11dInfo->State = DOT11D_STATE_NONE;
  100. pDot11dInfo->CountryIeLen = 0;
  101. RESET_CIE_WATCHDOG(ieee);
  102. }
  103. void Dot11d_UpdateCountryIe(struct rtllib_device *dev, u8 *pTaddr,
  104. u16 CoutryIeLen, u8 *pCoutryIe)
  105. {
  106. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
  107. u8 i, j, NumTriples, MaxChnlNum;
  108. struct chnl_txpow_triple *pTriple;
  109. memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
  110. memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER + 1);
  111. MaxChnlNum = 0;
  112. NumTriples = (CoutryIeLen - 3) / 3;
  113. pTriple = (struct chnl_txpow_triple *)(pCoutryIe + 3);
  114. for (i = 0; i < NumTriples; i++) {
  115. if (MaxChnlNum >= pTriple->FirstChnl) {
  116. netdev_info(dev->dev,
  117. "%s: Invalid country IE, skip it......1\n",
  118. __func__);
  119. return;
  120. }
  121. if (MAX_CHANNEL_NUMBER < (pTriple->FirstChnl +
  122. pTriple->NumChnls)) {
  123. netdev_info(dev->dev,
  124. "%s: Invalid country IE, skip it......2\n",
  125. __func__);
  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. void DOT11D_ScanComplete(struct rtllib_device *dev)
  142. {
  143. struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
  144. switch (pDot11dInfo->State) {
  145. case DOT11D_STATE_LEARNED:
  146. pDot11dInfo->State = DOT11D_STATE_DONE;
  147. break;
  148. case DOT11D_STATE_DONE:
  149. Dot11d_Reset(dev);
  150. break;
  151. case DOT11D_STATE_NONE:
  152. break;
  153. }
  154. }