IEEE11h.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright (c) 1996, 2005 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. *
  20. * File: IEEE11h.c
  21. *
  22. * Purpose:
  23. *
  24. * Functions:
  25. *
  26. * Revision History:
  27. *
  28. * Author: Yiching Chen
  29. *
  30. * Date: Mar. 31, 2005
  31. *
  32. */
  33. #include "ttype.h"
  34. #include "tmacro.h"
  35. #include "tether.h"
  36. #include "IEEE11h.h"
  37. #include "device.h"
  38. #include "wmgr.h"
  39. #include "rxtx.h"
  40. #include "channel.h"
  41. /*--------------------- Static Definitions -------------------------*/
  42. static int msglevel =MSG_LEVEL_INFO;
  43. #pragma pack(1)
  44. typedef struct _WLAN_FRAME_ACTION {
  45. WLAN_80211HDR_A3 Header;
  46. unsigned char byCategory;
  47. unsigned char byAction;
  48. unsigned char abyVars[1];
  49. } WLAN_FRAME_ACTION, *PWLAN_FRAME_ACTION;
  50. typedef struct _WLAN_FRAME_MSRREQ {
  51. WLAN_80211HDR_A3 Header;
  52. unsigned char byCategory;
  53. unsigned char byAction;
  54. unsigned char byDialogToken;
  55. WLAN_IE_MEASURE_REQ sMSRReqEIDs[1];
  56. } WLAN_FRAME_MSRREQ, *PWLAN_FRAME_MSRREQ;
  57. typedef struct _WLAN_FRAME_MSRREP {
  58. WLAN_80211HDR_A3 Header;
  59. unsigned char byCategory;
  60. unsigned char byAction;
  61. unsigned char byDialogToken;
  62. WLAN_IE_MEASURE_REP sMSRRepEIDs[1];
  63. } WLAN_FRAME_MSRREP, *PWLAN_FRAME_MSRREP;
  64. typedef struct _WLAN_FRAME_TPCREQ {
  65. WLAN_80211HDR_A3 Header;
  66. unsigned char byCategory;
  67. unsigned char byAction;
  68. unsigned char byDialogToken;
  69. WLAN_IE_TPC_REQ sTPCReqEIDs;
  70. } WLAN_FRAME_TPCREQ, *PWLAN_FRAME_TPCREQ;
  71. typedef struct _WLAN_FRAME_TPCREP {
  72. WLAN_80211HDR_A3 Header;
  73. unsigned char byCategory;
  74. unsigned char byAction;
  75. unsigned char byDialogToken;
  76. WLAN_IE_TPC_REP sTPCRepEIDs;
  77. } WLAN_FRAME_TPCREP, *PWLAN_FRAME_TPCREP;
  78. #pragma pack()
  79. // action field reference ieee 802.11h Table 20e
  80. #define ACTION_MSRREQ 0
  81. #define ACTION_MSRREP 1
  82. #define ACTION_TPCREQ 2
  83. #define ACTION_TPCREP 3
  84. #define ACTION_CHSW 4
  85. /*--------------------- Static Classes ----------------------------*/
  86. /*--------------------- Static Variables --------------------------*/
  87. /*--------------------- Static Functions --------------------------*/
  88. static bool s_bRxMSRReq(PSMgmtObject pMgmt, PWLAN_FRAME_MSRREQ pMSRReq,
  89. unsigned int uLength)
  90. {
  91. size_t uNumOfEIDs = 0;
  92. bool bResult = true;
  93. if (uLength <= WLAN_A3FR_MAXLEN) {
  94. memcpy(pMgmt->abyCurrentMSRReq, pMSRReq, uLength);
  95. }
  96. uNumOfEIDs = ((uLength - offsetof(WLAN_FRAME_MSRREQ, sMSRReqEIDs))/ (sizeof(WLAN_IE_MEASURE_REQ)));
  97. pMgmt->pCurrMeasureEIDRep = &(((PWLAN_FRAME_MSRREP) (pMgmt->abyCurrentMSRRep))->sMSRRepEIDs[0]);
  98. pMgmt->uLengthOfRepEIDs = 0;
  99. bResult = CARDbStartMeasure(pMgmt->pAdapter,
  100. ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->sMSRReqEIDs,
  101. uNumOfEIDs
  102. );
  103. return (bResult);
  104. }
  105. static bool s_bRxTPCReq(PSMgmtObject pMgmt, PWLAN_FRAME_TPCREQ pTPCReq, unsigned char byRate, unsigned char byRSSI)
  106. {
  107. PWLAN_FRAME_TPCREP pFrame;
  108. PSTxMgmtPacket pTxPacket = NULL;
  109. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  110. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
  111. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  112. pFrame = (PWLAN_FRAME_TPCREP)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  113. pFrame->Header.wFrameCtl = ( WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
  114. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
  115. );
  116. memcpy( pFrame->Header.abyAddr1, pTPCReq->Header.abyAddr2, WLAN_ADDR_LEN);
  117. memcpy( pFrame->Header.abyAddr2, CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
  118. memcpy( pFrame->Header.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  119. pFrame->byCategory = 0;
  120. pFrame->byAction = 3;
  121. pFrame->byDialogToken = ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->byDialogToken;
  122. pFrame->sTPCRepEIDs.byElementID = WLAN_EID_TPC_REP;
  123. pFrame->sTPCRepEIDs.len = 2;
  124. pFrame->sTPCRepEIDs.byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
  125. switch (byRate) {
  126. case RATE_54M:
  127. pFrame->sTPCRepEIDs.byLinkMargin = 65 - byRSSI;
  128. break;
  129. case RATE_48M:
  130. pFrame->sTPCRepEIDs.byLinkMargin = 66 - byRSSI;
  131. break;
  132. case RATE_36M:
  133. pFrame->sTPCRepEIDs.byLinkMargin = 70 - byRSSI;
  134. break;
  135. case RATE_24M:
  136. pFrame->sTPCRepEIDs.byLinkMargin = 74 - byRSSI;
  137. break;
  138. case RATE_18M:
  139. pFrame->sTPCRepEIDs.byLinkMargin = 77 - byRSSI;
  140. break;
  141. case RATE_12M:
  142. pFrame->sTPCRepEIDs.byLinkMargin = 79 - byRSSI;
  143. break;
  144. case RATE_9M:
  145. pFrame->sTPCRepEIDs.byLinkMargin = 81 - byRSSI;
  146. break;
  147. case RATE_6M:
  148. default:
  149. pFrame->sTPCRepEIDs.byLinkMargin = 82 - byRSSI;
  150. break;
  151. }
  152. pTxPacket->cbMPDULen = sizeof(WLAN_FRAME_TPCREP);
  153. pTxPacket->cbPayloadLen = sizeof(WLAN_FRAME_TPCREP) - WLAN_HDR_ADDR3_LEN;
  154. if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
  155. return (false);
  156. return (true);
  157. // return (CARDbSendPacket(pMgmt->pAdapter, pFrame, PKT_TYPE_802_11_MNG, sizeof(WLAN_FRAME_TPCREP)));
  158. }
  159. /*--------------------- Export Variables --------------------------*/
  160. /*--------------------- Export Functions --------------------------*/
  161. /*+
  162. *
  163. * Description:
  164. * Handles action management frames.
  165. *
  166. * Parameters:
  167. * In:
  168. * pMgmt - Management Object structure
  169. * pRxPacket - Received packet
  170. * Out:
  171. * none
  172. *
  173. * Return Value: None.
  174. *
  175. -*/
  176. bool
  177. IEEE11hbMgrRxAction (
  178. void *pMgmtHandle,
  179. void *pRxPacket
  180. )
  181. {
  182. PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
  183. PWLAN_FRAME_ACTION pAction = NULL;
  184. unsigned int uLength = 0;
  185. PWLAN_IE_CH_SW pChannelSwitch = NULL;
  186. // decode the frame
  187. uLength = ((PSRxMgmtPacket)pRxPacket)->cbMPDULen;
  188. if (uLength > WLAN_A3FR_MAXLEN) {
  189. return (false);
  190. }
  191. pAction = (PWLAN_FRAME_ACTION) (((PSRxMgmtPacket)pRxPacket)->p80211Header);
  192. if (pAction->byCategory == 0) {
  193. switch (pAction->byAction) {
  194. case ACTION_MSRREQ:
  195. return (s_bRxMSRReq(pMgmt, (PWLAN_FRAME_MSRREQ) pAction, uLength));
  196. break;
  197. case ACTION_MSRREP:
  198. break;
  199. case ACTION_TPCREQ:
  200. return (s_bRxTPCReq(pMgmt,
  201. (PWLAN_FRAME_TPCREQ) pAction,
  202. ((PSRxMgmtPacket)pRxPacket)->byRxRate,
  203. (unsigned char) ((PSRxMgmtPacket)pRxPacket)->uRSSI));
  204. break;
  205. case ACTION_TPCREP:
  206. break;
  207. case ACTION_CHSW:
  208. pChannelSwitch = (PWLAN_IE_CH_SW) (pAction->abyVars);
  209. if ((pChannelSwitch->byElementID == WLAN_EID_CH_SWITCH) &&
  210. (pChannelSwitch->len == 3)) {
  211. // valid element id
  212. CARDbChannelSwitch( pMgmt->pAdapter,
  213. pChannelSwitch->byMode,
  214. get_channel_mapping(pMgmt->pAdapter, pChannelSwitch->byChannel, pMgmt->eCurrentPHYMode),
  215. pChannelSwitch->byCount
  216. );
  217. }
  218. break;
  219. default:
  220. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown Action = %d\n", pAction->byAction);
  221. break;
  222. }
  223. } else {
  224. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown Category = %d\n", pAction->byCategory);
  225. pAction->byCategory |= 0x80;
  226. //return (CARDbSendPacket(pMgmt->pAdapter, pAction, PKT_TYPE_802_11_MNG, uLength));
  227. return (true);
  228. }
  229. return (true);
  230. }
  231. bool IEEE11hbMSRRepTx (
  232. void *pMgmtHandle
  233. )
  234. {
  235. PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
  236. PWLAN_FRAME_MSRREP pMSRRep = (PWLAN_FRAME_MSRREP) (pMgmt->abyCurrentMSRRep + sizeof(STxMgmtPacket));
  237. size_t uLength = 0;
  238. PSTxMgmtPacket pTxPacket = NULL;
  239. pTxPacket = (PSTxMgmtPacket)pMgmt->abyCurrentMSRRep;
  240. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
  241. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  242. pMSRRep->Header.wFrameCtl = ( WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
  243. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
  244. );
  245. memcpy( pMSRRep->Header.abyAddr1, ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->Header.abyAddr2, WLAN_ADDR_LEN);
  246. memcpy( pMSRRep->Header.abyAddr2, CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
  247. memcpy( pMSRRep->Header.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  248. pMSRRep->byCategory = 0;
  249. pMSRRep->byAction = 1;
  250. pMSRRep->byDialogToken = ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->byDialogToken;
  251. uLength = pMgmt->uLengthOfRepEIDs + offsetof(WLAN_FRAME_MSRREP, sMSRRepEIDs);
  252. pTxPacket->cbMPDULen = uLength;
  253. pTxPacket->cbPayloadLen = uLength - WLAN_HDR_ADDR3_LEN;
  254. if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
  255. return (false);
  256. return (true);
  257. // return (CARDbSendPacket(pMgmt->pAdapter, pMSRRep, PKT_TYPE_802_11_MNG, uLength));
  258. }