1 /*
2 * cu_common.c
3 *
4 * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 /****************************************************************************
20 *
21 * MODULE: CU_Common.c
22 *
23 * PURPOSE:
24 *
25 * DESCRIPTION:
26 * ============
27 *
28 *
29 ****************************************************************************/
30
31 /* includes */
32 /************/
33 #include "cu_osapi.h"
34 #include "oserr.h"
35
36 #include "TWDriver.h"
37 #include "convert.h"
38
39 #include "ipc_sta.h"
40 #include "cu_common.h"
41
42 /* defines */
43 /***********/
44
45 /* local types */
46 /***************/
47 /* Module control block */
48 typedef struct CuCommon_t
49 {
50 THandle hIpcSta;
51 } CuCommon_t;
52
53
54 typedef enum
55 {
56 DRIVER_STATUS_IDLE = 0,
57 DRIVER_STATUS_RUNNING = 1
58 } PARAM_OUT_Driver_Status_e;
59
60
61 /* local variables */
62 /*******************/
63
64 /* local fucntions */
65 /*******************/
66
67
68 /* functions */
69 /*************/
CuCommon_Create(THandle * pIpcSta,const PS8 device_name)70 THandle CuCommon_Create(THandle *pIpcSta, const PS8 device_name)
71 {
72 CuCommon_t* pCuCommon = (CuCommon_t*)os_MemoryCAlloc(sizeof(CuCommon_t), sizeof(U8));
73 if(pCuCommon == NULL)
74 {
75 os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - CuCommon_Create - cant allocate control block\n") );
76 return NULL;
77 }
78
79 pCuCommon->hIpcSta = IpcSta_Create(device_name);
80 if(pCuCommon->hIpcSta == NULL)
81 {
82 CuCommon_Destroy(pCuCommon);
83 return NULL;
84 }
85 *pIpcSta = pCuCommon->hIpcSta;
86
87 return pCuCommon;
88 }
89
CuCommon_Destroy(THandle hCuCommon)90 VOID CuCommon_Destroy(THandle hCuCommon)
91 {
92 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
93
94 if(pCuCommon->hIpcSta)
95 IpcSta_Destroy(pCuCommon->hIpcSta);
96
97 os_MemoryFree(pCuCommon);
98 }
99
CuCommon_SetU32(THandle hCuCommon,U32 PrivateIoctlId,U32 Data)100 S32 CuCommon_SetU32(THandle hCuCommon, U32 PrivateIoctlId, U32 Data)
101 {
102 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
103 S32 res;
104
105 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, &Data, sizeof(U32),
106 NULL, 0);
107
108 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
109 return ECUERR_CU_COMMON_ERROR;
110
111 return OK;
112 }
113
CuCommon_GetU32(THandle hCuCommon,U32 PrivateIoctlId,PU32 pData)114 S32 CuCommon_GetU32(THandle hCuCommon, U32 PrivateIoctlId, PU32 pData)
115 {
116 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
117 S32 res;
118
119 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, NULL, 0,
120 pData, sizeof(U32));
121
122 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
123 return ECUERR_CU_COMMON_ERROR;
124
125 return OK;
126 }
127
CuCommon_SetU16(THandle hCuCommon,U32 PrivateIoctlId,U16 Data)128 S32 CuCommon_SetU16(THandle hCuCommon, U32 PrivateIoctlId, U16 Data)
129 {
130 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
131 S32 res;
132
133 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, &Data, sizeof(U16),
134 NULL, 0);
135
136 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
137 return ECUERR_CU_COMMON_ERROR;
138
139 return OK;
140 }
141
CuCommon_SetU8(THandle hCuCommon,U32 PrivateIoctlId,U8 Data)142 S32 CuCommon_SetU8(THandle hCuCommon, U32 PrivateIoctlId, U8 Data)
143 {
144 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
145 S32 res;
146
147 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, &Data, sizeof(U8),
148 NULL, 0);
149
150 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
151 return ECUERR_CU_COMMON_ERROR;
152
153 return OK;
154 }
155
156
CuCommon_GetU8(THandle hCuCommon,U32 PrivateIoctlId,PU8 pData)157 S32 CuCommon_GetU8(THandle hCuCommon, U32 PrivateIoctlId, PU8 pData)
158 {
159 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
160 S32 res;
161
162 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, NULL, 0,
163 pData, sizeof(U8));
164
165 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
166 return ECUERR_CU_COMMON_ERROR;
167
168 return OK;
169 }
170
171
CuCommon_SetBuffer(THandle hCuCommon,U32 PrivateIoctlId,PVOID pBuffer,U32 len)172 S32 CuCommon_SetBuffer(THandle hCuCommon, U32 PrivateIoctlId, PVOID pBuffer, U32 len)
173 {
174 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
175 S32 res;
176
177 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, pBuffer, len,
178 NULL, 0);
179
180 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
181 return ECUERR_CU_COMMON_ERROR;
182
183 return OK;
184 }
185
CuCommon_GetBuffer(THandle hCuCommon,U32 PrivateIoctlId,PVOID pBuffer,U32 len)186 S32 CuCommon_GetBuffer(THandle hCuCommon, U32 PrivateIoctlId, PVOID pBuffer, U32 len)
187 {
188 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
189 S32 res;
190
191 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, NULL, 0,
192 pBuffer, len);
193
194 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
195 return ECUERR_CU_COMMON_ERROR;
196
197 return OK;
198 }
199
CuCommon_GetSetBuffer(THandle hCuCommon,U32 PrivateIoctlId,PVOID pBuffer,U32 len)200 S32 CuCommon_GetSetBuffer(THandle hCuCommon, U32 PrivateIoctlId, PVOID pBuffer, U32 len)
201 {
202 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
203 S32 res;
204
205 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, PrivateIoctlId, pBuffer, len,
206 pBuffer, len);
207
208 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
209 return ECUERR_CU_COMMON_ERROR;
210
211 return OK;
212 }
213
CuCommon_Get_BssidList_Size(THandle hCuCommon,PU32 pSizeOfBssiList)214 S32 CuCommon_Get_BssidList_Size(THandle hCuCommon, PU32 pSizeOfBssiList)
215 {
216 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
217 S32 res;
218
219 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, SCAN_CNCN_BSSID_LIST_SIZE_PARAM, NULL, 0,
220 pSizeOfBssiList, sizeof(U32));
221
222 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
223 return ECUERR_CU_COMMON_ERROR;
224
225 return OK;
226 }
227
CuCommon_GetRssi(THandle hCuCommon,PS8 pdRssi,PS8 pbRssi)228 S32 CuCommon_GetRssi(THandle hCuCommon, PS8 pdRssi, PS8 pbRssi)
229 {
230 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
231 S32 res;
232 TCuCommon_RoamingStatisticsTable buffer;
233
234 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_802_11_RSSI, NULL, 0,
235 &buffer, sizeof(TCuCommon_RoamingStatisticsTable));
236 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
237 return ECUERR_CU_COMMON_ERROR;
238
239 *pdRssi = (S8)buffer.rssi;
240 *pbRssi = (S8)buffer.rssiBeacon;
241
242 return OK;
243 }
244
CuCommon_GetSnr(THandle hCuCommon,PU32 pdSnr,PU32 pbSnr)245 S32 CuCommon_GetSnr(THandle hCuCommon, PU32 pdSnr, PU32 pbSnr)
246 {
247 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
248 S32 res;
249 TCuCommon_RoamingStatisticsTable buffer;
250
251 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TWD_SNR_RATIO_PARAM, NULL, 0,
252 &buffer, sizeof(TCuCommon_RoamingStatisticsTable));
253 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
254 return ECUERR_CU_COMMON_ERROR;
255
256 *pdSnr = (U32)buffer.snr;
257 *pbSnr = (U32)buffer.snrBeacon;
258
259 return OK;
260 }
261
CuCommon_GetTxStatistics(THandle hCuCommon,TIWLN_TX_STATISTICS * pTxCounters,U32 doReset)262 S32 CuCommon_GetTxStatistics(THandle hCuCommon, TIWLN_TX_STATISTICS* pTxCounters, U32 doReset)
263 {
264 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
265 S32 res;
266
267 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_802_11_TX_STATISTICS, pTxCounters, sizeof(TIWLN_TX_STATISTICS),
268 pTxCounters, sizeof(TIWLN_TX_STATISTICS));
269
270 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
271 return ECUERR_CU_COMMON_ERROR;
272
273 if(doReset)
274 {
275 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TX_CTRL_RESET_COUNTERS_PARAM, NULL, 0,
276 NULL, 0);
277 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
278 return ECUERR_CU_COMMON_ERROR;
279 }
280
281 return OK;
282 }
283
CuCommon_Radio_Test(THandle hCuCommon,TTestCmd * data)284 S32 CuCommon_Radio_Test(THandle hCuCommon,TTestCmd* data)
285 {
286 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
287 S32 res;
288
289 res = IPC_STA_Private_Send(pCuCommon->hIpcSta,
290 TWD_RADIO_TEST_PARAM,
291 (PVOID)data,
292 sizeof(TTestCmd),
293 (PVOID)data,
294 sizeof(TTestCmd));
295
296 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
297 {
298 os_error_printf(CU_MSG_INFO2, (PS8)"In CuCommon_Radio_Test: IPC_STA_Private_Send failed\n");
299 return ECUERR_CU_COMMON_ERROR;
300 }
301
302 return OK;
303 }
304
CuCommon_AddKey(THandle hCuCommon,OS_802_11_WEP * pKey)305 S32 CuCommon_AddKey(THandle hCuCommon, OS_802_11_WEP* pKey)
306 {
307 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
308 S32 res;
309 OS_802_11_KEY key;
310
311 os_memset(&key, 0, sizeof(OS_802_11_KEY));
312
313 key.Length = pKey->Length;
314 key.KeyIndex = (pKey->KeyIndex & 0x80000000) | (pKey->KeyIndex & 0x3FFFFFFF);
315 key.KeyLength = pKey->KeyLength;
316 os_memcpy(key.KeyMaterial, pKey->KeyMaterial, pKey->KeyLength);
317
318 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, RSN_ADD_KEY_PARAM, &key, sizeof(OS_802_11_KEY),
319 NULL, 0);
320
321 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
322 return ECUERR_CU_COMMON_ERROR;
323
324 return OK;
325 }
326
CuCommon_RemoveKey(THandle hCuCommon,U32 KeyIndex)327 S32 CuCommon_RemoveKey(THandle hCuCommon, U32 KeyIndex)
328 {
329 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
330 S32 res;
331 OS_802_11_KEY key;
332
333 os_memset(&key, 0, sizeof(OS_802_11_KEY));
334 key.KeyIndex = KeyIndex;
335
336 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, RSN_REMOVE_KEY_PARAM, &key, sizeof(OS_802_11_KEY),
337 NULL, 0);
338
339 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
340 return ECUERR_CU_COMMON_ERROR;
341
342 return OK;
343 }
344
CuCommon_GetDfsChannels(THandle hCuCommon,PU16 pMinDfsChannel,PU16 pMaxDfsChannel)345 S32 CuCommon_GetDfsChannels(THandle hCuCommon, PU16 pMinDfsChannel, PU16 pMaxDfsChannel)
346 {
347 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
348 S32 res;
349 DFS_ChannelRange_t DFS_ChannelRange;
350
351 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_REG_DOMAIN_GET_DFS_RANGE, NULL, 0,
352 &DFS_ChannelRange, sizeof(DFS_ChannelRange_t));
353
354 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
355 return ECUERR_CU_COMMON_ERROR;
356
357 *pMaxDfsChannel = DFS_ChannelRange.maxDFS_channelNum;
358 *pMinDfsChannel = DFS_ChannelRange.minDFS_channelNum;
359
360 return OK;
361 }
362
CuCommon_SetDfsChannels(THandle hCuCommon,U16 MinDfsChannel,U16 MaxDfsChannel)363 S32 CuCommon_SetDfsChannels(THandle hCuCommon, U16 MinDfsChannel, U16 MaxDfsChannel)
364 {
365 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
366 S32 res;
367 DFS_ChannelRange_t DFS_ChannelRange;
368
369 DFS_ChannelRange.maxDFS_channelNum = MaxDfsChannel;
370 DFS_ChannelRange.minDFS_channelNum = MinDfsChannel;
371
372 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_REG_DOMAIN_SET_DFS_RANGE, &DFS_ChannelRange, sizeof(DFS_ChannelRange_t),
373 NULL, 0);
374
375 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
376 return ECUERR_CU_COMMON_ERROR;
377
378 return OK;
379 }
380
CuCommon_PrintDriverDebug(THandle hCuCommon,PVOID pParams,U32 param_size)381 S32 CuCommon_PrintDriverDebug(THandle hCuCommon, PVOID pParams, U32 param_size)
382 {
383 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
384 S32 res;
385
386 if ( pParams == NULL )
387 {
388 return ECUERR_CU_COMMON_ERROR;
389 }
390
391 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_DISPLAY_STATS, pParams, param_size,
392 NULL, 0);
393
394 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
395 return ECUERR_CU_COMMON_ERROR;
396
397 return OK;
398 }
399
CuCommon_PrintDriverDebugBuffer(THandle hCuCommon,U32 func_id,U32 opt_param)400 S32 CuCommon_PrintDriverDebugBuffer(THandle hCuCommon, U32 func_id, U32 opt_param)
401 {
402 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
403 S32 res, len;
404 U8 buf[260]; /* no more then 256 + func id */
405
406 if (opt_param == 0)
407 return ECUERR_CU_ERROR;
408
409 len = os_strlen((PS8)opt_param);
410 *(PU32)buf = func_id;
411 os_memcpy((PS8)buf + sizeof(U32),(PS8)opt_param, len);
412
413 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_DISPLAY_STATS, buf, len + sizeof(U32),
414 NULL, 0);
415
416 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
417 return ECUERR_CU_COMMON_ERROR;
418
419 return OK;
420 }
421
422
CuCommon_GetRxDataFiltersStatistics(THandle hCuCommon,PU32 pUnmatchedPacketsCount,PU32 pMatchedPacketsCount)423 S32 CuCommon_GetRxDataFiltersStatistics(THandle hCuCommon, PU32 pUnmatchedPacketsCount, PU32 pMatchedPacketsCount)
424 {
425 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
426 S32 res;
427 TCuCommon_RxDataFilteringStatistics buffer;
428
429 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_GET_RX_DATA_FILTERS_STATISTICS, NULL, 0,
430 &buffer, sizeof(TCuCommon_RxDataFilteringStatistics));
431
432 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
433 return ECUERR_CU_COMMON_ERROR;
434
435 *pUnmatchedPacketsCount = buffer.unmatchedPacketsCount;
436 os_memcpy(pMatchedPacketsCount, &buffer.matchedPacketsCount, MAX_DATA_FILTERS*sizeof(U32));
437
438 return OK;
439 }
440
441
CuCommon_GetPowerConsumptionStat(THandle hCuCommon,ACXPowerConsumptionTimeStat_t * pPowerstat)442 S32 CuCommon_GetPowerConsumptionStat(THandle hCuCommon, ACXPowerConsumptionTimeStat_t *pPowerstat)
443 {
444 CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
445 ACXPowerConsumptionTimeStat_t tStatistics;
446 S32 res;
447
448
449 res = IPC_STA_Private_Send(pCuCommon->hIpcSta, TIWLN_GET_POWER_CONSUMPTION_STATISTICS, NULL, 0,
450 &tStatistics, sizeof(ACXPowerConsumptionTimeStat_t));
451
452 if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
453 return ECUERR_CU_COMMON_ERROR;
454
455 os_memcpy(pPowerstat, &tStatistics, sizeof(ACXPowerConsumptionTimeStat_t));
456
457 return OK;
458 }
459
460
461
462
463
464
465
466