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