p2p_scan.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. ** Id: @(#) p2p_scan.c@@
  3. */
  4. /*! \file "p2p_scan.c"
  5. \brief This file defines the p2p scan profile and the processing function of
  6. scan result for SCAN Module.
  7. The SCAN Profile selection is part of SCAN MODULE and responsible for defining
  8. SCAN Parameters - e.g. MIN_CHANNEL_TIME, number of scan channels.
  9. In this file we also define the process of SCAN Result including adding, searching
  10. and removing SCAN record from the list.
  11. */
  12. /*******************************************************************************
  13. * C O M P I L E R F L A G S
  14. ********************************************************************************
  15. */
  16. /*******************************************************************************
  17. * E X T E R N A L R E F E R E N C E S
  18. ********************************************************************************
  19. */
  20. #include "precomp.h"
  21. /*******************************************************************************
  22. * C O N S T A N T S
  23. ********************************************************************************
  24. */
  25. /*******************************************************************************
  26. * D A T A T Y P E S
  27. ********************************************************************************
  28. */
  29. /*******************************************************************************
  30. * P U B L I C D A T A
  31. ********************************************************************************
  32. */
  33. /*******************************************************************************
  34. * P R I V A T E D A T A
  35. ********************************************************************************
  36. */
  37. /*******************************************************************************
  38. * M A C R O S
  39. ********************************************************************************
  40. */
  41. /*******************************************************************************
  42. * F U N C T I O N D E C L A R A T I O N S
  43. ********************************************************************************
  44. */
  45. /*******************************************************************************
  46. * F U N C T I O N S
  47. ********************************************************************************
  48. */
  49. VOID
  50. scanP2pProcessBeaconAndProbeResp(IN P_ADAPTER_T prAdapter,
  51. IN P_SW_RFB_T prSwRfb,
  52. IN P_WLAN_STATUS prStatus,
  53. IN P_BSS_DESC_T prBssDesc, IN P_WLAN_BEACON_FRAME_T prWlanBeaconFrame)
  54. {
  55. BOOLEAN fgIsSkipThisBeacon = FALSE;
  56. if (prBssDesc->fgIsP2PPresent) {
  57. if ((prBssDesc->fgIsConnected) && /* P2P GC connected. */
  58. ((prWlanBeaconFrame->u2FrameCtrl & MASK_FRAME_TYPE) == MAC_FRAME_BEACON) /* TX Beacon */
  59. ) {
  60. UINT_32 u4Idx = 0;
  61. P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T) NULL;
  62. for (u4Idx = 0; u4Idx < BSS_INFO_NUM; u4Idx++) {
  63. /* Check BSS for P2P. */
  64. /* Check BSSID. */
  65. prP2pBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, (UINT_8) u4Idx);
  66. if (!IS_BSS_ACTIVE(prP2pBssInfo))
  67. continue;
  68. if ((prP2pBssInfo->eNetworkType != NETWORK_TYPE_P2P) ||
  69. (UNEQUAL_MAC_ADDR(prP2pBssInfo->aucBSSID, prBssDesc->aucBSSID)
  70. ||
  71. (!EQUAL_SSID
  72. (prP2pBssInfo->aucSSID, prP2pBssInfo->ucSSIDLen,
  73. prBssDesc->aucSSID, prBssDesc->ucSSIDLen)))) {
  74. continue;
  75. }
  76. if ((prP2pBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE) && /* P2P GC */
  77. (prP2pBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED)) { /* Connected */
  78. fgIsSkipThisBeacon = TRUE;
  79. if ((!prP2pBssInfo->ucDTIMPeriod)) { /* First Time. */
  80. prP2pBssInfo->ucDTIMPeriod = prBssDesc->ucDTIMPeriod;
  81. nicPmIndicateBssConnected(prAdapter, prP2pBssInfo->ucBssIndex);
  82. }
  83. }
  84. }
  85. }
  86. do {
  87. RF_CHANNEL_INFO_T rChannelInfo;
  88. ASSERT_BREAK((prSwRfb != NULL) && (prBssDesc != NULL));
  89. if (((prWlanBeaconFrame->u2FrameCtrl & MASK_FRAME_TYPE) != MAC_FRAME_PROBE_RSP)) {
  90. /* Only report Probe Response frame to supplicant except passive scan. */
  91. /* Probe response collect much more information. */
  92. if (fgIsSkipThisBeacon)
  93. break;
  94. }
  95. rChannelInfo.ucChannelNum = prBssDesc->ucChannelNum;
  96. rChannelInfo.eBand = prBssDesc->eBand;
  97. prBssDesc->fgIsP2PReport = TRUE;
  98. DBGLOG(P2P, STATE, "indicate %s [%d]\n", prBssDesc->aucSSID, prBssDesc->ucChannelNum);
  99. kalP2PIndicateBssInfo(prAdapter->prGlueInfo,
  100. (PUINT_8) prSwRfb->pvHeader,
  101. (UINT_32) prSwRfb->u2PacketLen,
  102. &rChannelInfo, RCPI_TO_dBm(prBssDesc->ucRCPI));
  103. } while (FALSE);
  104. }
  105. }
  106. VOID scnEventReturnChannel(IN P_ADAPTER_T prAdapter, IN UINT_8 ucScnSeqNum)
  107. {
  108. CMD_SCAN_CANCEL rCmdScanCancel;
  109. /* send cancel message to firmware domain */
  110. rCmdScanCancel.ucSeqNum = ucScnSeqNum;
  111. rCmdScanCancel.ucIsExtChannel = (UINT_8) FALSE;
  112. wlanSendSetQueryCmd(prAdapter,
  113. CMD_ID_SCAN_CANCEL,
  114. TRUE,
  115. FALSE, FALSE, NULL, NULL, sizeof(CMD_SCAN_CANCEL), (PUINT_8)&rCmdScanCancel, NULL, 0);
  116. } /* scnEventReturnChannel */
  117. VOID scanRemoveAllP2pBssDesc(IN P_ADAPTER_T prAdapter)
  118. {
  119. P_LINK_T prBSSDescList;
  120. P_BSS_DESC_T prBssDesc;
  121. P_BSS_DESC_T prBSSDescNext;
  122. ASSERT(prAdapter);
  123. prBSSDescList = &(prAdapter->rWifiVar.rScanInfo.rBSSDescList);
  124. /* Search BSS Desc from current SCAN result list. */
  125. LINK_FOR_EACH_ENTRY_SAFE(prBssDesc, prBSSDescNext, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  126. scanRemoveP2pBssDesc(prAdapter, prBssDesc);
  127. }
  128. } /* scanRemoveAllP2pBssDesc */
  129. VOID scanRemoveP2pBssDesc(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBssDesc)
  130. {
  131. } /* scanRemoveP2pBssDesc */
  132. P_BSS_DESC_T scanP2pSearchDesc(IN P_ADAPTER_T prAdapter, IN P_P2P_CONNECTION_REQ_INFO_T prConnReqInfo)
  133. {
  134. P_BSS_DESC_T prCandidateBssDesc = (P_BSS_DESC_T) NULL, prBssDesc = (P_BSS_DESC_T) NULL;
  135. P_LINK_T prBssDescList = (P_LINK_T) NULL;
  136. do {
  137. if ((prAdapter == NULL) || (prConnReqInfo == NULL))
  138. break;
  139. prBssDescList = &(prAdapter->rWifiVar.rScanInfo.rBSSDescList);
  140. DBGLOG(P2P, LOUD, "Connecting to BSSID: " MACSTR "\n", MAC2STR(prConnReqInfo->aucBssid));
  141. DBGLOG(P2P, LOUD,
  142. "Connecting to SSID:%s, length:%d\n", prConnReqInfo->rSsidStruct.aucSsid,
  143. prConnReqInfo->rSsidStruct.ucSsidLen);
  144. LINK_FOR_EACH_ENTRY(prBssDesc, prBssDescList, rLinkEntry, BSS_DESC_T) {
  145. DBGLOG(P2P, LOUD, "Checking BSS: " MACSTR "\n", MAC2STR(prBssDesc->aucBSSID));
  146. if (prBssDesc->eBSSType != BSS_TYPE_INFRASTRUCTURE) {
  147. DBGLOG(P2P, LOUD, "Ignore mismatch BSS type.\n");
  148. continue;
  149. }
  150. if (UNEQUAL_MAC_ADDR(prBssDesc->aucBSSID, prConnReqInfo->aucBssid)) {
  151. DBGLOG(P2P, LOUD, "Ignore mismatch BSSID.\n");
  152. continue;
  153. }
  154. /* SSID should be the same? SSID is vary for each connection. so... */
  155. if (UNEQUAL_SSID(prConnReqInfo->rSsidStruct.aucSsid,
  156. prConnReqInfo->rSsidStruct.ucSsidLen,
  157. prBssDesc->aucSSID, prBssDesc->ucSSIDLen)) {
  158. DBGLOG(P2P, TRACE,
  159. "Connecting to BSSID: " MACSTR "\n", MAC2STR(prConnReqInfo->aucBssid));
  160. DBGLOG(P2P, TRACE,
  161. "Connecting to SSID:%s, length:%d\n",
  162. prConnReqInfo->rSsidStruct.aucSsid, prConnReqInfo->rSsidStruct.ucSsidLen);
  163. DBGLOG(P2P, TRACE,
  164. "Checking SSID:%s, length:%d\n", prBssDesc->aucSSID, prBssDesc->ucSSIDLen);
  165. DBGLOG(P2P, TRACE, "Ignore mismatch SSID, (But BSSID match).\n");
  166. /* ASSERT(FALSE); */ /*let p2p re-scan again */
  167. continue;
  168. }
  169. if (!prBssDesc->fgIsP2PPresent) {
  170. DBGLOG(P2P, ERROR, "SSID, BSSID, BSSTYPE match, but no P2P IE present.\n");
  171. continue;
  172. }
  173. /* Final decision. */
  174. prCandidateBssDesc = prBssDesc;
  175. break;
  176. }
  177. } while (FALSE);
  178. return prCandidateBssDesc;
  179. } /* scanP2pSearchDesc */