p2p_nic.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. ** Id: @(#) p2p_nic.c@@
  3. */
  4. /*! \file p2p_nic.c
  5. \brief Wi-Fi Direct Functions that provide operation in NIC's (Network Interface Card) point of view.
  6. This file includes functions which unite multiple hal(Hardware) operations
  7. and also take the responsibility of Software Resource Management in order
  8. to keep the synchronization with Hardware Manipulation.
  9. */
  10. /*******************************************************************************
  11. * C O M P I L E R F L A G S
  12. ********************************************************************************
  13. */
  14. /*******************************************************************************
  15. * E X T E R N A L R E F E R E N C E S
  16. ********************************************************************************
  17. */
  18. #include "precomp.h"
  19. /*******************************************************************************
  20. * C O N S T A N T S
  21. ********************************************************************************
  22. */
  23. /*******************************************************************************
  24. * D A T A T Y P E S
  25. ********************************************************************************
  26. */
  27. /*******************************************************************************
  28. * P U B L I C D A T A
  29. ********************************************************************************
  30. */
  31. /*******************************************************************************
  32. * P R I V A T E D A T A
  33. ********************************************************************************
  34. */
  35. /*******************************************************************************
  36. * M A C R O S
  37. ********************************************************************************
  38. */
  39. /*******************************************************************************
  40. * F U N C T I O N D E C L A R A T I O N S
  41. ********************************************************************************
  42. */
  43. /*******************************************************************************
  44. * F U N C T I O N S
  45. ********************************************************************************
  46. */
  47. /*----------------------------------------------------------------------------*/
  48. /*!
  49. * @brief When Probe Rsp & Beacon frame is received and decide a P2P device,
  50. * this function will be invoked to buffer scan result
  51. *
  52. * @param prAdapter Pointer to the Adapter structure.
  53. * @param prEventScanResult Pointer of EVENT_SCAN_RESULT_T.
  54. *
  55. * @return (none)
  56. */
  57. /*----------------------------------------------------------------------------*/
  58. VOID
  59. nicRxAddP2pDevice(IN P_ADAPTER_T prAdapter,
  60. IN P_EVENT_P2P_DEV_DISCOVER_RESULT_T prP2pResult, IN PUINT_8 pucRxIEBuf, IN UINT_16 u2RxIELength)
  61. {
  62. P_P2P_INFO_T prP2pInfo = (P_P2P_INFO_T) NULL;
  63. P_EVENT_P2P_DEV_DISCOVER_RESULT_T prTargetResult = (P_EVENT_P2P_DEV_DISCOVER_RESULT_T) NULL;
  64. UINT_32 u4Idx = 0;
  65. BOOLEAN bUpdate = FALSE;
  66. PUINT_8 pucIeBuf = (PUINT_8) NULL;
  67. UINT_16 u2IELength = 0;
  68. UINT_8 zeroMac[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
  69. ASSERT(prAdapter);
  70. prP2pInfo = prAdapter->prP2pInfo;
  71. for (u4Idx = 0; u4Idx < prP2pInfo->u4DeviceNum; u4Idx++) {
  72. prTargetResult = &prP2pInfo->arP2pDiscoverResult[u4Idx];
  73. if (EQUAL_MAC_ADDR(prTargetResult->aucDeviceAddr, prP2pResult->aucDeviceAddr)) {
  74. bUpdate = TRUE;
  75. /* Backup OLD buffer result. */
  76. pucIeBuf = prTargetResult->pucIeBuf;
  77. u2IELength = prTargetResult->u2IELength;
  78. /* Update Device Info. */
  79. /* zero */
  80. kalMemZero(prTargetResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T));
  81. /* then buffer */
  82. kalMemCopy(prTargetResult, (PVOID) prP2pResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T));
  83. /* See if new IE length is longer or not. */
  84. if ((u2RxIELength > u2IELength) && (u2IELength != 0)) {
  85. /* Buffer is not enough. */
  86. u2RxIELength = u2IELength;
  87. } else if ((u2IELength == 0) && (u2RxIELength != 0)) {
  88. /* RX new IE buf. */
  89. ASSERT(pucIeBuf == NULL);
  90. pucIeBuf = prP2pInfo->pucCurrIePtr;
  91. if (((ULONG) prP2pInfo->pucCurrIePtr + (ULONG) u2RxIELength) >
  92. (ULONG)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN]) {
  93. /* Common Buffer is no enough. */
  94. u2RxIELength =
  95. (UINT_16) ((ULONG)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN] -
  96. (ULONG) prP2pInfo->pucCurrIePtr);
  97. }
  98. /* Step to next buffer address. */
  99. prP2pInfo->pucCurrIePtr =
  100. (PUINT_8) ((ULONG) prP2pInfo->pucCurrIePtr + (ULONG) u2RxIELength);
  101. }
  102. /* Restore buffer pointer. */
  103. prTargetResult->pucIeBuf = pucIeBuf;
  104. if (pucRxIEBuf) {
  105. /* If new received IE is available.
  106. * Replace the old one & update new IE length.
  107. */
  108. kalMemCopy(pucIeBuf, pucRxIEBuf, u2RxIELength);
  109. prTargetResult->u2IELength = u2RxIELength;
  110. } else {
  111. /* There is no new IE information, keep the old one. */
  112. prTargetResult->u2IELength = u2IELength;
  113. }
  114. }
  115. }
  116. if (!bUpdate) {
  117. /* We would flush the whole scan result after each scan request is issued.
  118. * If P2P device is too many, it may over the scan list.
  119. */
  120. if ((u4Idx < CFG_MAX_NUM_BSS_LIST) && (UNEQUAL_MAC_ADDR(zeroMac, prP2pResult->aucDeviceAddr))) {
  121. /* whsu:XXX */
  122. prTargetResult = &prP2pInfo->arP2pDiscoverResult[u4Idx];
  123. /* zero */
  124. kalMemZero(prTargetResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T));
  125. /* then buffer */
  126. kalMemCopy(prTargetResult, (PVOID) prP2pResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T));
  127. /* printk("DVC FND %d %pM, %pM\n",
  128. prP2pInfo->u4DeviceNum,
  129. prP2pResult->aucDeviceAddr,
  130. prTargetResult->aucDeviceAddr); */
  131. if (u2RxIELength) {
  132. prTargetResult->pucIeBuf = prP2pInfo->pucCurrIePtr;
  133. if (((ULONG) prP2pInfo->pucCurrIePtr + (ULONG) u2RxIELength) >
  134. (ULONG)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN]) {
  135. /* Common Buffer is no enough. */
  136. u2IELength =
  137. (UINT_16) ((ULONG)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN] -
  138. (ULONG) prP2pInfo->pucCurrIePtr);
  139. } else {
  140. u2IELength = u2RxIELength;
  141. }
  142. prP2pInfo->pucCurrIePtr =
  143. (PUINT_8) ((ULONG) prP2pInfo->pucCurrIePtr + (ULONG) u2IELength);
  144. kalMemCopy((PVOID) prTargetResult->pucIeBuf, (PVOID) pucRxIEBuf, (UINT_32) u2IELength);
  145. prTargetResult->u2IELength = u2IELength;
  146. } else {
  147. prTargetResult->pucIeBuf = NULL;
  148. prTargetResult->u2IELength = 0;
  149. }
  150. prP2pInfo->u4DeviceNum++;
  151. } else {
  152. /* TODO: Fixme to replace an old one. (?) */
  153. ASSERT(FALSE);
  154. }
  155. }
  156. } /* nicRxAddP2pDevice */