diff options
author | Dmitry Shmidt <dimitrysh@google.com> | 2010-01-28 13:44:01 -0800 |
---|---|---|
committer | Dmitry Shmidt <dimitrysh@google.com> | 2010-01-28 13:44:01 -0800 |
commit | a615fb1650af6e111053506f1b764b28a5b4631d (patch) | |
tree | 331681301f38dbc47007e77f21039b0d82c2741c /wl1271/CUDK/os/linux | |
parent | 3295ef74aeb37c12e327c5b1b258c1d84bcd2fa5 (diff) | |
download | wlan-a615fb1650af6e111053506f1b764b28a5b4631d.tar.gz |
wl1271: Initial M4 drop based on WiLink_Driver_6.1.0.0.115
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'wl1271/CUDK/os/linux')
-rw-r--r-- | wl1271/CUDK/os/linux/Android.mk | 1 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/inc/ParsEvent.h | 58 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/inc/cu_os.h | 62 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/inc/ipc_event.h | 44 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/inc/ipc_sta.h | 43 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/inc/ipc_wpa.h | 45 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/inc/os_trans.h | 40 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/Android.mk | 66 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/ParsEvent.c | 279 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/cu_wext.c | 487 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/ipc_event.c | 681 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/ipc_sta.c | 195 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/ipc_wpa.c | 173 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/makefile | 136 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/os_trans.c | 168 | ||||
-rw-r--r-- | wl1271/CUDK/os/linux/src/osapi.c | 609 |
16 files changed, 3087 insertions, 0 deletions
diff --git a/wl1271/CUDK/os/linux/Android.mk b/wl1271/CUDK/os/linux/Android.mk new file mode 100644 index 00000000..5053e7d6 --- /dev/null +++ b/wl1271/CUDK/os/linux/Android.mk @@ -0,0 +1 @@ +include $(call all-subdir-makefiles) diff --git a/wl1271/CUDK/os/linux/inc/ParsEvent.h b/wl1271/CUDK/os/linux/inc/ParsEvent.h new file mode 100644 index 00000000..335cb3cb --- /dev/null +++ b/wl1271/CUDK/os/linux/inc/ParsEvent.h @@ -0,0 +1,58 @@ +/* + * ParsEvent.h + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************/ +/* */ +/* MODULE: ParsEvent.h */ +/* PURPOSE: */ +/* */ +/****************************************************************************/ +#ifndef _WIRELESS_TOOLS_H_ +#define _WIRELESS_TOOLS_H_ + +/* defines */ +/***********/ + +/* types */ +/*********/ + +/* Structure used for parsing event streams, such as Wireless Events + * and scan results */ +typedef struct stream_descr +{ + char * end; /* End of the stream */ + char * current; /* Current event in stream of events */ + char * value; /* Current value in event */ +} stream_descr; + +/* + * Scan state and meta-information, used to decode events... + */ +typedef struct iwscan_state +{ + /* State */ + int ap_num; /* Access Point number 1->N */ + int val_index; /* Value in table 0->(N-1) */ +} iwscan_state; + +/* functions */ +/*************/ +int
ParsEvent_GetEvent(struct stream_descr* pEventStream, struct iw_event* pEvent); + +#endif /* _WIRELESS_TOOLS_H_ */ + diff --git a/wl1271/CUDK/os/linux/inc/cu_os.h b/wl1271/CUDK/os/linux/inc/cu_os.h new file mode 100644 index 00000000..bc8f67e4 --- /dev/null +++ b/wl1271/CUDK/os/linux/inc/cu_os.h @@ -0,0 +1,62 @@ +/* + * cu_os.h + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************/ +/* */ +/* MODULE: CuWext.h */ +/* PURPOSE: */ +/* */ +/****************************************************************************/ +#ifndef _CU_WEXT_H_ +#define _CU_WEXT_H_ + +#include "cu_osapi.h" +#include "osDot11.h" + +/* defines */ +/***********/ +#define MAX_SSID_LEN 32 +#define MAX_PATH 260 + +/* types */ +/*********/ + +/* functions */ +/*************/ + +S32 CuOs_GetDriverThreadId(THandle hCuWext, U32* threadid); + +THandle CuOs_Create(THandle hIpcSta); +VOID CuOs_Destroy(THandle hCuWext); + +S32 CuOs_Get_SSID(THandle hCuWext, OS_802_11_SSID* ssid); +S32 CuOs_Get_BSSID(THandle hCuWext, TMacAddr bssid); +S32 CuOs_GetCurrentChannel(THandle hCuWext, U32* channel); +S32 CuOs_Start_Scan(THandle hCuWext, OS_802_11_SSID* ssid, TI_UINT8 scanType); +S32 CuOs_GetBssidList(THandle hCuWext, OS_802_11_BSSID_LIST_EX *bssidList); +S32 CuOs_Set_BSSID(THandle hCuWext, TMacAddr bssid); +S32 CuOs_Set_ESSID(THandle hCuWext, OS_802_11_SSID* ssid); +S32 CuOs_GetTxPowerLevel(THandle hCuWext, S32* pTxPowerLevel); +S32 CuOs_SetTxPowerLevel(THandle hCuWext, S32 txPowerLevel); +S32 CuOs_GetRtsTh(THandle hCuWext, PS32 pRtsTh); +S32 CuOs_SetRtsTh(THandle hCuWext, S32 RtsTh); +S32 CuOs_GetFragTh(THandle hCuWext, PS32 pFragTh); +S32 CuOs_SetFragTh(THandle hCuWext, S32 FragTh); + +#endif /* _CU_WEXT_H_ */ + diff --git a/wl1271/CUDK/os/linux/inc/ipc_event.h b/wl1271/CUDK/os/linux/inc/ipc_event.h new file mode 100644 index 00000000..f548e140 --- /dev/null +++ b/wl1271/CUDK/os/linux/inc/ipc_event.h @@ -0,0 +1,44 @@ +/* + * ipc_event.h + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************/ +/* */ +/* MODULE: IPC_Event.h */ +/* PURPOSE: */ +/* */ +/****************************************************************************/ +#ifndef _IPC_EVENT_H_ +#define _IPC_EVENT_H_ + +/* defines */ +/***********/ + +/* types */ +/*********/ + +/* functions */ +/*************/ +THandle IpcEvent_Create(VOID); +VOID IpcEvent_Destroy(THandle hIpcEvent); + +S32 IpcEvent_EnableEvent(THandle hIpcEvent, U32 event); +S32 IpcEvent_DisableEvent(THandle hIpcEvent, U32 event); +S32 IpcEvent_UpdateDebugLevel(THandle hIpcEvent, S32 debug_level); + +#endif /* _IPC_EVENT_H_ */ + diff --git a/wl1271/CUDK/os/linux/inc/ipc_sta.h b/wl1271/CUDK/os/linux/inc/ipc_sta.h new file mode 100644 index 00000000..375d15e5 --- /dev/null +++ b/wl1271/CUDK/os/linux/inc/ipc_sta.h @@ -0,0 +1,43 @@ +/* + * ipc_sta.h + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************/ +/* */ +/* MODULE: IPC_STA.h */ +/* PURPOSE: */ +/* */ +/****************************************************************************/ +#ifndef _IPC_STA_H_ +#define _IPC_STA_H_ + +#include "oserr.h" + +/* defines */ +/***********/ + +/* types */ +/*********/ + +/* functions */ +/*************/ +THandle IpcSta_Create(const PS8 device_name); +VOID IpcSta_Destroy(THandle hIpcSta); +S32 IPC_STA_Private_Send(THandle hIpcSta, U32 ioctl_cmd, PVOID bufIn, U32 sizeIn, PVOID bufOut, U32 sizeOut); +S32 IPC_STA_Wext_Send(THandle hIpcSta, U32 wext_request_id, PVOID p_iwreq_data, U32 len); +#endif /* _IPC_STA_H_ */ + diff --git a/wl1271/CUDK/os/linux/inc/ipc_wpa.h b/wl1271/CUDK/os/linux/inc/ipc_wpa.h new file mode 100644 index 00000000..11556717 --- /dev/null +++ b/wl1271/CUDK/os/linux/inc/ipc_wpa.h @@ -0,0 +1,45 @@ +/* + * ipc_wpa.h + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************/ +/* */ +/* MODULE: Ipc_Wpa.h */ +/* PURPOSE: */ +/* */ +/****************************************************************************/ +#ifndef _IPC_WPA_H_ +#define _IPC_WPA_H_ + +/* defines */ +/***********/ +#define IPC_WPA_RESP_MAX_LEN 256 + +/* types */ +/*********/ + +/* functions */ +/*************/ +THandle IpcWpa_Create(PS32 pRes, PS8 pSupplIfFile); +VOID IpcWpa_Destroy(THandle hIpcWpa); + +S32 IpcWpa_Command(THandle hIpcWpa, PS8 cmd, S32 print); +S32 IpcWpa_CommandWithResp(THandle hIpcWpa, PS8 cmd, S32 print, PS8 pResp, PU32 pRespLen); + + +#endif /* _IPC_WPA_H_ */ + diff --git a/wl1271/CUDK/os/linux/inc/os_trans.h b/wl1271/CUDK/os/linux/inc/os_trans.h new file mode 100644 index 00000000..21026dd6 --- /dev/null +++ b/wl1271/CUDK/os/linux/inc/os_trans.h @@ -0,0 +1,40 @@ +/* + * os_trans.h + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _OS_TRANS_H +#define _OS_TRANS_H + +#include "cu_osapi.h" +#include "tidef.h" + +#ifndef SOCKET_ERROR +#define SOCKET_ERROR -1 +#endif + +#define MAX_QUEUE_LENGTH 5//maximum length the queue of pending connections + +typedef int SOCKET; + +TI_BOOL os_trans_create(VOID); +TI_BOOL os_socket (THandle* pSock); +TI_BOOL os_bind (THandle sock, U16 port); +TI_BOOL os_sockWaitForConnection (THandle socket_id, THandle* pConnSock); +TI_BOOL os_sockSend (THandle socket_id, PS8 buffer, U32 bufferSize); +VOID os_trans_destroy(VOID); +S32 os_sockRecv (THandle socket_id, PU8 pBuffer, U32 bufferSize, TI_SIZE_T flags); + +#endif diff --git a/wl1271/CUDK/os/linux/src/Android.mk b/wl1271/CUDK/os/linux/src/Android.mk new file mode 100644 index 00000000..0fc7c7e1 --- /dev/null +++ b/wl1271/CUDK/os/linux/src/Android.mk @@ -0,0 +1,66 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +STATIC_LIB ?= y +DEBUG ?= y +BUILD_SUPPL ?= y +WPA_ENTERPRISE ?= y + +ifeq ($(DEBUG),y) + DEBUGFLAGS = -O2 -g -DDEBUG -DTI_DBG -fno-builtin +else + DEBUGFLAGS = -O2 +endif + +WILINK_ROOT = ../../../.. +CUDK_ROOT = $(WILINK_ROOT)/CUDK +TI_SUPP_LIB_DIR = $(WILINK_ROOT)/../../../../external/wpa_supplicant + +DK_DEFINES = +ifeq ($(WPA_ENTERPRISE), y) + DK_DEFINES += -D WPA_ENTERPRISE +endif + +ifeq ($(BUILD_SUPPL), y) + DK_DEFINES += -D WPA_SUPPLICANT -D CONFIG_CTRL_IFACE -D CONFIG_CTRL_IFACE_UNIX + -include external/wpa_supplicant/.config + ifeq ($(CONFIG_WPS), y) + DK_DEFINES += -DCONFIG_WPS + endif +endif + +LOCAL_CFLAGS+= \ + -Wall -Wstrict-prototypes $(DEBUGFLAGS) -D__LINUX__ $(DK_DEFINES) -D__BYTE_ORDER_LITTLE_ENDIAN -fno-common #-pipe + +LOCAL_SRC_FILES:= \ + cu_wext.c \ + ipc_sta.c \ + ipc_event.c \ + ipc_wpa.c \ + os_trans.c \ + ParsEvent.c \ + osapi.c + + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../inc \ + $(LOCAL_PATH)/../../common/inc \ + $(LOCAL_PATH)/$(WILINK_ROOT)/stad/Export_Inc \ + $(LOCAL_PATH)/$(WILINK_ROOT)/stad/src/Sta_Management \ + $(LOCAL_PATH)/$(WILINK_ROOT)/stad/src/Application \ + $(LOCAL_PATH)/$(WILINK_ROOT)/utils \ + $(LOCAL_PATH)/$(WILINK_ROOT)/Txn \ + $(LOCAL_PATH)/$(WILINK_ROOT)/TWD/TWDriver \ + $(LOCAL_PATH)/$(WILINK_ROOT)/TWD/FirmwareApi \ + $(LOCAL_PATH)/$(WILINK_ROOT)/TWD/FW_Transfer/Export_Inc \ + $(LOCAL_PATH)/$(WILINK_ROOT)/TWD/TwIf \ + $(LOCAL_PATH)/$(WILINK_ROOT)/platforms/os/linux/inc \ + $(LOCAL_PATH)/$(WILINK_ROOT)/platforms/os/common/inc \ + $(LOCAL_PATH)/$(WILINK_ROOT)/TWD/FirmwareApi \ + external/wpa_supplicant \ + $(LOCAL_PATH)/$(CUDK_ROOT)/configurationutility/inc + +LOCAL_MODULE:=libtiOsLib + +include $(BUILD_STATIC_LIBRARY) + diff --git a/wl1271/CUDK/os/linux/src/ParsEvent.c b/wl1271/CUDK/os/linux/src/ParsEvent.c new file mode 100644 index 00000000..b75070bf --- /dev/null +++ b/wl1271/CUDK/os/linux/src/ParsEvent.c @@ -0,0 +1,279 @@ +/* + * ParsEvent.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** +* +* MODULE: ParsEvent.c +* +* PURPOSE: +* +* DESCRIPTION: +* ============ +* +* +****************************************************************************/ + +/* includes */ +/************/ +#include <stdint.h> +#include <sys/types.h> +#ifdef ANDROID +#include <net/if_ether.h> +#else +#include <netinet/if_ether.h> +#endif +#include <linux/rtnetlink.h> +#include <linux/if.h> +#include <linux/wireless.h> +#include "ParsEvent.h" +#include "cu_osapi.h" + +#define IW_DESCR_FLAG_NONE 0x0000 +#define IW_DESCR_FLAG_DUMP 0x0001 +#define IW_DESCR_FLAG_EVENT 0x0002 +#define IW_DESCR_FLAG_RESTRICT 0x0004 +#define IW_DESCR_FLAG_NOMAX 0x0008 +#define IW_DESCR_FLAG_WAIT 0x0100 + +/* local types */ +/***************/ +static int ParsEvent_GetEventParam( unsigned short uEventCmd, + unsigned int* uEventLen, + unsigned int* pEventFlag, + unsigned short* pMaxPayload, + unsigned short* pPayloadNum, + unsigned int* bIsPoint); +/** + * \fn ParsEvent_GetEvent() + * \brief get next event from the event stream. + * support the following events that CLI uses: SIOCGIWAP, SIOCGIWESSID, SIOCGIWNAME, SIOCGIWMODE, + * SIOCGIWFREQ, IWEVQUAL, SIOCGIWENCODE, SIOCGIWRATE, IWEVCUSTOM, + * IWEVMICHAELMICFAILURE, SIOCGIWSCAN, IWEVASSOCREQIE, IWEVASSOCRESPIE, + * IWEVPMKIDCAND. + * \note + * \param pEventStream - Event stream pointer. + * \param pEvent - return Event. + * \return value > 0 meens valide event + * \sa + */ +int
ParsEvent_GetEvent(struct stream_descr* pEventStream, struct iw_event* pEvent) + +{ + unsigned int uStatus = 0; + char* pPtr; + unsigned int uEventLen = 1; + unsigned int uDataLen = 0; + unsigned int uEventFlag = 0; + unsigned short uMaxPayload = 0; + unsigned short uPayloadNum = 0; + unsigned int uMoreLen; + unsigned int bIsPoint = 0; + + /* Check validity */ + if((pEventStream->current + IW_EV_LCP_LEN) > pEventStream->end) + { + return 0; + } + + /* copy tha event */ + os_memcpy((char *)pEvent, pEventStream->current, IW_EV_LCP_LEN); + + /* Check validity */ + if(pEvent->len <= IW_EV_LCP_LEN) + { + return 0; + } + + /* get event parameters */ + uStatus = ParsEvent_GetEventParam(
pEvent->cmd, &uEventLen, &uEventFlag, &uMaxPayload, &uPayloadNum, &bIsPoint); + + if(uEventLen <= IW_EV_LCP_LEN) + { + /* jump to next event */ + pEventStream->current += pEvent->len; + return 1; + } + + /* get payload */ + if(pEventStream->value == NULL) + { + pPtr = pEventStream->current + IW_EV_LCP_LEN; + } + else + { + pPtr = pEventStream->value; + } + + uDataLen = uEventLen - IW_EV_LCP_LEN; + + /* Check validity */ + if((pPtr + uDataLen) > pEventStream->end) + { + /* jump to next event */ + pEventStream->current += pEvent->len; + return 0; + } + + if(bIsPoint == TRUE) + { + os_memcpy((char *) pEvent + IW_EV_LCP_LEN + IW_EV_POINT_OFF,
pPtr, uDataLen); + } + else + { + os_memcpy((char *) pEvent + IW_EV_LCP_LEN, pPtr, uDataLen); + } + + /* jump to next event */ + pPtr = pPtr + uDataLen; + + if(bIsPoint == FALSE) + { + /* verify more values */ + if((pPtr + uDataLen) > (pEventStream->current + pEvent->len)) + { + pEventStream->current += pEvent->len; + pEventStream->value = NULL; + } + else + { + pEventStream->value = pPtr; + } + + } + else + { + uMoreLen = pEvent->len - uEventLen; + + if((uMoreLen == 0) || + ( uStatus == 0) || + (!(uEventFlag & IW_DESCR_FLAG_NOMAX) && (pEvent->u.data.length > uMaxPayload)) || + ((pEvent->u.data.length * uPayloadNum) > uMoreLen) + ) + { + pEvent->u.data.pointer = NULL; + } + else + { + pEvent->u.data.pointer = pPtr; + } + + pEventStream->current += pEvent->len; + } + + return 1; +} + + +static int ParsEvent_GetEventParam( unsigned short uEventCmd, + unsigned int* uEventLen, + unsigned int* pEventFlag, + unsigned short* pMaxPayload, + unsigned short* pPayloadNum, + unsigned int* bIsPoint) +{ + + switch(uEventCmd) + { + case SIOCGIWAP: + *uEventLen = IW_EV_ADDR_LEN; + *pEventFlag = IW_DESCR_FLAG_DUMP; + *bIsPoint = FALSE; + break; + + case SIOCGIWESSID: + *uEventLen = IW_EV_POINT_LEN; + *pEventFlag = IW_DESCR_FLAG_DUMP; + *pMaxPayload = IW_ESSID_MAX_SIZE + 1; + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + + case SIOCGIWNAME: + *uEventLen = IW_EV_CHAR_LEN; + *pEventFlag = IW_DESCR_FLAG_DUMP; + *bIsPoint = FALSE; + break; + case SIOCGIWMODE: + *uEventLen = IW_EV_UINT_LEN; + *pEventFlag = IW_DESCR_FLAG_DUMP; + *bIsPoint = FALSE; + break; + case SIOCGIWFREQ: + *uEventLen = IW_EV_FREQ_LEN; + *pEventFlag = IW_DESCR_FLAG_DUMP; + *bIsPoint = FALSE; + break; + case IWEVQUAL: + *uEventLen = IW_EV_QUAL_LEN; + *bIsPoint = FALSE; + break; + case SIOCGIWENCODE: + *uEventLen = IW_EV_POINT_LEN; + *pEventFlag = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT; + *pMaxPayload = IW_ENCODING_TOKEN_MAX; + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + case SIOCGIWRATE: + *uEventLen = IW_EV_PARAM_LEN; + *bIsPoint = FALSE; + break; + case IWEVCUSTOM: + *uEventLen = IW_EV_POINT_LEN; + *pMaxPayload = IW_CUSTOM_MAX; + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + case IWEVMICHAELMICFAILURE: + *uEventLen = IW_EV_POINT_LEN; + *pMaxPayload = sizeof(struct iw_michaelmicfailure); + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + case SIOCGIWSCAN: + *uEventLen = IW_EV_POINT_LEN; + *pEventFlag = IW_DESCR_FLAG_NOMAX; + *pMaxPayload = IW_SCAN_MAX_DATA; + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + case IWEVASSOCREQIE: + *uEventLen = IW_EV_POINT_LEN; + *pMaxPayload = IW_GENERIC_IE_MAX; + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + case IWEVASSOCRESPIE : + *uEventLen = IW_EV_POINT_LEN; + *pMaxPayload = IW_GENERIC_IE_MAX; + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + case IWEVPMKIDCAND: + *uEventLen = IW_EV_POINT_LEN; + *pMaxPayload = sizeof(struct iw_pmkid_cand); + *pPayloadNum = 1; + *bIsPoint = TRUE; + break; + default: + return 0; + } + + return 1; +} + diff --git a/wl1271/CUDK/os/linux/src/cu_wext.c b/wl1271/CUDK/os/linux/src/cu_wext.c new file mode 100644 index 00000000..3294a430 --- /dev/null +++ b/wl1271/CUDK/os/linux/src/cu_wext.c @@ -0,0 +1,487 @@ +/* + * cu_wext.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** +* +* MODULE: CU_Wext.c +* +* PURPOSE: +* +* DESCRIPTION: +* ============ +* +* +****************************************************************************/ + +/* includes */ +/************/ +#include "cu_osapi.h" +#include "oserr.h" +#include <linux/if.h> +#include <linux/rtnetlink.h> +#include <linux/wireless.h> +#include <string.h> + +#include "TWDriver.h" +#include "STADExternalIf.h" +#include "ParsEvent.h" +#include "ipc_sta.h" +#include "cu_os.h" + +/* defines */ +/***********/ + +/* local types */ +/***************/ +/* Module control block */ +typedef struct +{ + THandle hIpcSta; + union iwreq_data req_data; + + struct iw_scan_req *scan_req; + U16 scan_flag; +} TCuWext; + +/* local variables */ +/*******************/ + +/* local fucntions */ +/*******************/ +static S32 CuWext_FillBssidList(struct iw_event *iwe, OS_802_11_BSSID_EX* bssidList, S32 index) +{ + S32 res = 0; + switch(iwe->cmd) + { + case SIOCGIWAP: + os_memcpy(bssidList[index].MacAddress, iwe->u.ap_addr.sa_data, MAC_ADDR_LEN); + bssidList[index].Configuration.BeaconPeriod = 0; /* default configuration */ + res = 1; + break; + case SIOCGIWESSID: + bssidList[index-1].Ssid.SsidLength = iwe->u.data.length; + os_memcpy(bssidList[index-1].Ssid.Ssid, iwe->u.data.pointer, bssidList[index-1].Ssid.SsidLength); + if(iwe->u.data.length != MAX_SSID_LEN) + bssidList[index-1].Ssid.Ssid[bssidList[index-1].Ssid.SsidLength] = 0; + break; + case SIOCGIWNAME: + { + int i; + S8 buffer[IFNAMSIZ]; + static const char *ieee80211_modes[] = { + "?", + "IEEE 802.11 B", + "IEEE 802.11 A", + "IEEE 802.11 BG", + "IEEE 802.11 ABG" }; + + os_memset(buffer, 0, IFNAMSIZ); + os_memcpy(buffer, iwe->u.name, IFNAMSIZ); + for(i=0;i<SIZE_ARR(ieee80211_modes); i++) + if (0 == os_strcmp((PS8)ieee80211_modes[i], buffer)) + break; + bssidList[index-1].NetworkTypeInUse = i; + } + break; + case SIOCGIWMODE: + if(iwe->u.mode == IW_MODE_ADHOC) + bssidList[index-1].InfrastructureMode = os802_11IBSS; + else if (iwe->u.mode == IW_MODE_INFRA) + bssidList[index-1].InfrastructureMode = os802_11Infrastructure; + else if (iwe->u.mode == IW_MODE_AUTO) + bssidList[index-1].InfrastructureMode = os802_11AutoUnknown; + else + bssidList[index-1].InfrastructureMode = os802_11InfrastructureMax; + + break; + case SIOCGIWFREQ: + bssidList[index-1].Configuration.Union.channel = iwe->u.freq.m; + break; + case IWEVQUAL: + bssidList[index-1].Rssi = (S8)iwe->u.qual.level; + break; + case SIOCGIWENCODE: + if(iwe->u.data.flags == (IW_ENCODE_ENABLED | IW_ENCODE_NOKEY)) + { + bssidList[index-1].Privacy = TRUE; + bssidList[index-1].Capabilities |= CAP_PRIVACY_MASK<<CAP_PRIVACY_SHIFT; + } + else + { + bssidList[index-1].Privacy = FALSE; + bssidList[index-1].Capabilities &= ~(CAP_PRIVACY_MASK<<CAP_PRIVACY_SHIFT); + } + break; + case SIOCGIWRATE: + break; + case IWEVCUSTOM: + { + S8 buffer[100]; + + os_memset(buffer, 0, 100); + os_memcpy(buffer, iwe->u.data.pointer, iwe->u.data.length); + + if(!os_strncmp(buffer, (PS8)"Bcn", 3)) + { + char *p1; + p1 = strtok(&buffer[10], " "); + bssidList[index-1].Configuration.BeaconPeriod = atoi(p1); + } + } + break; + } + + return res; +} + + +/* functions */ +/*************/ + +THandle CuOs_Create(THandle hIpcSta) +{ + TCuWext* pCuWext = (TCuWext*)os_MemoryCAlloc(sizeof(TCuWext), sizeof(U8)); + if(pCuWext == NULL) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - CuOs_Create - cant allocate control block\n"); + return NULL; + } + + pCuWext->hIpcSta = hIpcSta; + + return pCuWext; +} + +VOID CuOs_Destroy(THandle hCuWext) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + + os_MemoryFree(pCuWext); +} + +S32 CuOs_Get_SSID(THandle hCuWext, OS_802_11_SSID* ssid) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(ssid->Ssid, 0, sizeof(OS_802_11_SSID) - sizeof(U32)); + + pCuWext->req_data.essid.pointer = (PVOID)ssid->Ssid; + pCuWext->req_data.essid.length = sizeof(OS_802_11_SSID) - sizeof(U32); + pCuWext->req_data.essid.flags = 0; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWESSID, &pCuWext->req_data, sizeof(struct iw_point)); + if(res != OK) + return res; + + ssid->SsidLength = pCuWext->req_data.essid.length; + + return OK; +} + +S32 CuOs_Get_BSSID(THandle hCuWext, TMacAddr bssid) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res,i; + + os_memset(&pCuWext->req_data.ap_addr, 0x00, sizeof(struct sockaddr)); + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWAP, &pCuWext->req_data, sizeof(struct sockaddr)); + if(res != OK) + return res; + + for(i=0;i<MAC_ADDR_LEN;i++) + bssid[i] = pCuWext->req_data.ap_addr.sa_data[i]; + + return OK; +} + +S32 CuOs_GetCurrentChannel(THandle hCuWext, U32* channel) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + pCuWext->req_data.freq.m = 0; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWFREQ, &pCuWext->req_data, sizeof(struct iw_freq )); + if(res != OK) + return res; + + *channel = pCuWext->req_data.freq.m; + + return OK; +} + +/*Usage example of SIOCGIWSTATS. This WEXT is used by wireless tools such as iwconfig, iwlib etc.*/ +S32 CuOs_GetCurrentStats(THandle hCuWext, S32* rssi) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + struct iw_statistics stat; + *rssi = 0; + + pCuWext->req_data.data.pointer = &stat; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWSTATS, &pCuWext->req_data, sizeof(struct iw_statistics)); + if(res != OK) + return res; + + *rssi = stat.qual.level; + + return OK; +} + +S32 CuOs_Start_Scan(THandle hCuWext, OS_802_11_SSID* ssid, U8 scanType) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + struct iw_scan_req tReq; + S32 res; + + if (ssid->SsidLength > IW_ESSID_MAX_SIZE) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - CuOs_Start_Scan - too long SSID (%lu)\n",ssid->SsidLength); + return OSAL_ERROR; + } + + if (ssid->Ssid[0] && ssid->SsidLength) + { + os_memset(&tReq, 0, sizeof(tReq)); + tReq.essid_len = ssid->SsidLength; + /* + * tReq.bssid.sa_family = ARPHRD_ETHER; + * os_memset(tReq.bssid.sa_data, 0xff, ETH_ALEN); + */ + os_memcpy(tReq.essid, ssid->Ssid, ssid->SsidLength); + pCuWext->scan_req = &tReq; + pCuWext->req_data.data.flags = IW_SCAN_THIS_ESSID; + } + else + { + pCuWext->req_data.data.flags = 0; + } + + tReq.scan_type = scanType; + pCuWext->req_data.data.pointer = &tReq; + pCuWext->req_data.data.length = sizeof(struct iw_scan_req); + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCSIWSCAN, &pCuWext->req_data, sizeof(struct iw_point)); + if(res != OK) + return res; + + return OK; +} + +S32 CuOs_GetBssidList(THandle hCuWext, OS_802_11_BSSID_LIST_EX *bssidList) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res, NumberOfItems; + + /* allocate the scan result buffer */ + U8* buffer = os_MemoryCAlloc(IW_SCAN_MAX_DATA, sizeof(U8)); + if(buffer == NULL) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - CuOs_Get_BssidList - cant allocate scan result buffer\n"); + return EOALERR_CU_WEXT_ERROR_CANT_ALLOCATE; + } + + NumberOfItems = 0; + pCuWext->req_data.data.pointer = buffer; + pCuWext->req_data.data.flags = 0; + do + { + pCuWext->req_data.data.length = IW_SCAN_MAX_DATA; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWSCAN, &pCuWext->req_data, sizeof(struct iw_point)); + if(res != OK) + { + os_MemoryFree(buffer); + return res; + } + + /* parse the scan results */ + if(pCuWext->req_data.data.length) + { + struct iw_event iwe; + struct stream_descr stream; + S32 ret; + + /* init the event stream */ + os_memset((char *)&stream, '\0', sizeof(struct stream_descr)); + stream.current = (char *)buffer; + stream.end = (char *)(buffer + pCuWext->req_data.data.length); + + do + { + /* Extract an event and print it */ + ret = ParsEvent_GetEvent(&stream, &iwe); + if(ret > 0) + NumberOfItems += CuWext_FillBssidList(&iwe, bssidList->Bssid, NumberOfItems); + } + while(ret > 0); + } + + } while(pCuWext->req_data.data.flags); + + bssidList->NumberOfItems = NumberOfItems; + + /* free the scan result buffer */ + os_MemoryFree(buffer); + + return OK; +} + + +S32 CuOs_Set_BSSID(THandle hCuWext, TMacAddr bssid) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memcpy(pCuWext->req_data.ap_addr.sa_data, bssid, MAC_ADDR_LEN); + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCSIWAP, &pCuWext->req_data, sizeof(struct sockaddr)); + + if(res != OK) + return res; + + return OK; +} + +S32 CuOs_Set_ESSID(THandle hCuWext, OS_802_11_SSID* ssid) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + pCuWext->req_data.essid.pointer = (PVOID)ssid->Ssid; + pCuWext->req_data.essid.length = ssid->SsidLength; + if(ssid->SsidLength) + pCuWext->req_data.essid.flags = 1; + else + pCuWext->req_data.essid.flags = 0; + pCuWext->req_data.essid.flags |= SET_SSID_WITHOUT_SUPPL; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCSIWESSID, &pCuWext->req_data, sizeof(struct sockaddr)); + + if(res != OK) + return res; + + return OK; +} + +S32 CuOs_GetTxPowerLevel(THandle hCuWext, S32* pTxPowerLevel) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(&pCuWext->req_data.txpower, 0, sizeof(struct iw_param)); + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWTXPOW, &pCuWext->req_data, sizeof(struct iw_param)); + + if(res != OK) + return res; + + *pTxPowerLevel = pCuWext->req_data.txpower.value; + + return OK; +} + +S32 CuOs_SetTxPowerLevel(THandle hCuWext, S32 txPowerLevel) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(&pCuWext->req_data.txpower, 0, sizeof(struct iw_param)); + + pCuWext->req_data.txpower.value = txPowerLevel; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCSIWTXPOW, &pCuWext->req_data, sizeof(struct iw_param)); + + if(res != OK) + return res; + + return OK; +} + +S32 CuOs_GetRtsTh(THandle hCuWext, PS32 pRtsTh) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(&pCuWext->req_data.rts, 0, sizeof(struct iw_param)); + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWRTS, &pCuWext->req_data, sizeof(struct iw_param)); + if(res != OK) + return res; + + *pRtsTh = pCuWext->req_data.rts.value; + + return OK; +} + + +S32 CuOs_SetRtsTh(THandle hCuWext, S32 RtsTh) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(&pCuWext->req_data.rts, 0, sizeof(struct iw_param)); + pCuWext->req_data.rts.value = RtsTh; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCSIWRTS, &pCuWext->req_data, sizeof(struct iw_param)); + if(res != OK) + return res; + + + + return OK; +} + +S32 CuOs_GetFragTh(THandle hCuWext, PS32 pFragTh) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(&pCuWext->req_data.frag, 0, sizeof(struct iw_param)); + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCGIWFRAG, &pCuWext->req_data, sizeof(struct iw_param)); + if(res != OK) + return res; + + *pFragTh = pCuWext->req_data.frag.value; + + return OK; +} + +S32 CuOs_SetFragTh(THandle hCuWext, S32 FragTh) +{ + TCuWext* pCuWext = (TCuWext*)hCuWext; + S32 res; + + os_memset(&pCuWext->req_data.frag, 0, sizeof(struct iw_param)); + pCuWext->req_data.frag.value = FragTh; + + res = IPC_STA_Wext_Send(pCuWext->hIpcSta, SIOCSIWFRAG, &pCuWext->req_data, sizeof(struct iw_param)); + if(res != OK) + return res; + + return OK; +} +/*stab function (should be filled later on for Linux to get ThreadID of the WLAN driver*/ +S32 CuOs_GetDriverThreadId(THandle hCuWext, U32* threadid) +{ + return OK; +} diff --git a/wl1271/CUDK/os/linux/src/ipc_event.c b/wl1271/CUDK/os/linux/src/ipc_event.c new file mode 100644 index 00000000..ede0a4b6 --- /dev/null +++ b/wl1271/CUDK/os/linux/src/ipc_event.c @@ -0,0 +1,681 @@ +/* + * ipc_event.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** +* +* MODULE: IPC_Event.c +* +* PURPOSE: +* +* DESCRIPTION: +* ============ +* +* +****************************************************************************/ + +/* includes */ +/************/ +#include <sys/types.h> +#include <sys/socket.h> +#include <linux/if.h> +#include <linux/rtnetlink.h> +#include <signal.h> +#include <sys/mman.h> +#include <unistd.h> +#include <linux/wireless.h> + +#include "cu_osapi.h" +#include "oserr.h" +#include "TWDriver.h" +#include "STADExternalIf.h" +#include "ParsEvent.h" +#include "ipc_event.h" + + +/* defines */ +/***********/ +#define PIPE_READ 0 +#define PIPE_WRITE 1 +#define IPC_EVENT_KEY ((key_t)123456789) + +/* IPC evemt messages to child */ +#define IPC_EVENT_MSG_KILL "IPC_EVENT_MSG_KILL" +#define IPC_EVENT_MSG_UPDATE_DEBUG_LEVEL "IPC_EVENT_MSG_UPDATE_DEBUG_LEVEL" +#define IPC_EVENT_MSG_MAX_LEN 50 + +/* local types */ +/***************/ +typedef struct IpcEvent_Shared_Memory_t +{ + int pipe_fields[2]; + u64 event_mask; + union + { + S32 debug_level; + } content; +} IpcEvent_Shared_Memory_t; + +/* Module control block */ +typedef struct IpcEvent_t +{ + IpcEvent_Shared_Memory_t* p_shared_memory; + S32 child_process_id; + S32 pipe_to_child; +} IpcEvent_t; + +typedef struct IpcEvent_Child_t +{ + S32 STA_socket; + IpcEvent_Shared_Memory_t* p_shared_memory; + S32 pipe_from_parent; +} IpcEvent_Child_t; + +/* local variables */ +/*******************/ +VOID g_tester_send_event(U8 event_index); +/* local fucntions */ +/*******************/ +static VOID IpcEvent_SendMessageToChild(IpcEvent_t* pIpcEvent, PS8 msg) +{ + write(pIpcEvent->pipe_to_child, msg, os_strlen(msg)); +} + +static S32 IpcEvent_Sockets_Open(VOID) +{ + S32 skfd; + struct sockaddr_nl local; + + skfd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (skfd < 0) + { + return -1; + } + + os_memset(&local, 0, sizeof(local)); + local.nl_family = AF_NETLINK; + local.nl_groups = RTMGRP_LINK; + if (bind(skfd, (struct sockaddr *) &local, sizeof(local)) < 0) + { + close(skfd); + return -2; + } + + return skfd; +} + +static inline VOID IpcEvent_Sockets_Close(S32 skfd) +{ + close(skfd); +} + +void ProcessLoggerMessage(PU8 data, U16 len); + +static VOID IpcEvent_PrintEvent(IpcEvent_Child_t* pIpcEventChild, U32 EventId, TI_UINT8* pData, S32 DataLen) +{ + + if(pIpcEventChild->p_shared_memory->event_mask & ((u64)1<<EventId)) + { + switch(EventId) + { + + + case IPC_EVENT_DISASSOCIATED: + { + OS_802_11_DISASSOCIATE_REASON_T *pDisAssoc; + + if (NULL == pData) + { + return; + } + else + { + pDisAssoc = (OS_802_11_DISASSOCIATE_REASON_T*)pData; + } + + switch(pDisAssoc->eDisAssocType) + { + case OS_DISASSOC_STATUS_UNSPECIFIED: + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated with unspecified reason (User/SG/Recovery)\n"); + break; + case OS_DISASSOC_STATUS_AUTH_REJECT: + if (pDisAssoc->uStatusCode == STATUS_PACKET_REJ_TIMEOUT) + { + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to no Auth response \n"); + } + else + { + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to Auth response packet with reason = %d\n", pDisAssoc->uStatusCode); + } + break; + case OS_DISASSOC_STATUS_ASSOC_REJECT: + if (pDisAssoc->uStatusCode == STATUS_PACKET_REJ_TIMEOUT) + { + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to no Assoc response \n"); + } + else + { + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to Assoc response packet with reason = %d\n", pDisAssoc->uStatusCode); + } + break; + case OS_DISASSOC_STATUS_SECURITY_FAILURE: + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to RSN failure\n"); + break; + case OS_DISASSOC_STATUS_AP_DEAUTHENTICATE: + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to AP deAuthenticate packet with reason = %d\n", pDisAssoc->uStatusCode); + break; + case OS_DISASSOC_STATUS_AP_DISASSOCIATE: + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to AP disAssoc packet with reason = %d\n", pDisAssoc->uStatusCode); + break; + case OS_DISASSOC_STATUS_ROAMING_TRIGGER: + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated due to roaming trigger = %d\n", pDisAssoc->uStatusCode); + break; + default: + os_error_printf(CU_MSG_ERROR, "CLI Event - Disassociated with unknown reason = %d\n", pDisAssoc->eDisAssocType); + break; + } + + break; /* the end of the IPC_EVENT_DISASSOCIATED case */ + } + case IPC_EVENT_ASSOCIATED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_ASSOCIATED\n"); + break; + case IPC_EVENT_MEDIA_SPECIFIC: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_MEDIA_SPECIFIC\n"); + break; + case IPC_EVENT_SCAN_COMPLETE: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_SCAN_COMPLETE\n"); + break; + /* custom events */ + case IPC_EVENT_SCAN_STOPPED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_SCAN_STOPPED\n"); + break; + case IPC_EVENT_LINK_SPEED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_LINK_SPEED\n"); + break; + case IPC_EVENT_AUTH_SUCC: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_AUTH_SUCC\n"); + break; + case IPC_EVENT_CCKM_START: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_CCKM_START\n"); + break; + case IPC_EVENT_EAPOL: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_EAPOL\n"); + break; + case IPC_EVENT_RE_AUTH_STARTED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_RE_AUTH_STARTED\n"); + break; + case IPC_EVENT_RE_AUTH_COMPLETED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_RE_AUTH_COMPLETED\n"); + break; + case IPC_EVENT_RE_AUTH_TERMINATED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_RE_AUTH_TERMINATED\n"); + break; + case IPC_EVENT_BOUND: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_BOUND\n"); + break; + case IPC_EVENT_UNBOUND: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_UNBOUND\n"); + break; + case IPC_EVENT_PREAUTH_EAPOL: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_PREAUTH_EAPOL\n"); + break; + case IPC_EVENT_LOW_RSSI: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_LOW_RSSI\n"); + break; + case IPC_EVENT_TSPEC_STATUS: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_TSPEC_STATUS\n"); + + OS_802_11_QOS_TSPEC_PARAMS* tspec = (OS_802_11_QOS_TSPEC_PARAMS*)pData; + os_error_printf(CU_MSG_ERROR, "CLI Event - IPC_EVENT_TSPEC_STATUS -- (ReasonCode = %d) \n",tspec->uReasonCode); + os_error_printf(CU_MSG_ERROR, "Tspec Parameters (as received through event handler):\n"); + os_error_printf(CU_MSG_ERROR, "-----------------------------------------------------\n"); + os_error_printf(CU_MSG_ERROR, "userPriority = %d\n",tspec->uUserPriority); + os_error_printf(CU_MSG_ERROR, "uNominalMSDUsize = %d\n",tspec->uNominalMSDUsize); + os_error_printf(CU_MSG_ERROR, "uMeanDataRate = %d\n",tspec->uMeanDataRate); + os_error_printf(CU_MSG_ERROR, "uMinimumPHYRate = %d\n",tspec->uMinimumPHYRate); + os_error_printf(CU_MSG_ERROR, "uSurplusBandwidthAllowance = %d\n",tspec->uSurplusBandwidthAllowance); + os_error_printf(CU_MSG_ERROR, "uAPSDFlag = %d\n",tspec->uAPSDFlag); + os_error_printf(CU_MSG_ERROR, "MinimumServiceInterval = %d\n",tspec->uMinimumServiceInterval); + os_error_printf(CU_MSG_ERROR, "MaximumServiceInterval = %d\n",tspec->uMaximumServiceInterval); + os_error_printf(CU_MSG_ERROR, "uMediumTime = %d\n\n",tspec->uMediumTime); + + break; + case IPC_EVENT_TSPEC_RATE_STATUS: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_TSPEC_RATE_STATUS\n"); + break; + case IPC_EVENT_MEDIUM_TIME_CROSS: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_MEDIUM_TIME_CROSS\n"); + break; + case IPC_EVENT_ROAMING_COMPLETE: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_ROAMING_COMPLETE\n"); + break; + case IPC_EVENT_EAP_AUTH_FAILURE: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_EAP_AUTH_FAILURE\n"); + break; + case IPC_EVENT_WPA2_PREAUTHENTICATION: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_WPA2_PREAUTHENTICATION\n"); + break; + case IPC_EVENT_TRAFFIC_INTENSITY_THRESHOLD_CROSSED: + { + U32 *crossInfo = (U32 *)pData; + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_TRAFFIC_INTENSITY_THRESHOLD_CROSSED\n"); + os_error_printf(CU_MSG_ERROR, (PS8)"Threshold(High=0, Low=1) crossed= %d\n", crossInfo[0]); + os_error_printf(CU_MSG_ERROR, (PS8)"Direction(Above=0, Below=1) crossed= %d\n", crossInfo[1]); + break; + } + case IPC_EVENT_SCAN_FAILED: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_SCAN_FAILED\n"); + break; + case IPC_EVENT_WPS_SESSION_OVERLAP: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_WPS_SESSION_OVERLAP\n"); + break; + case IPC_EVENT_RSSI_SNR_TRIGGER: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_RSSI_SNR_TRIGGER (index = %d), Data = %d\n", (S8)(*(pData + 2) - 1),(S8)(*pData)); + break; + case IPC_EVENT_TIMEOUT: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_TIMEOUT\n"); + break; + case IPC_EVENT_GWSI: + os_error_printf(CU_MSG_ERROR, (PS8)"IpcEvent_PrintEvent - received IPC_EVENT_GWSI\n"); + break; + case IPC_EVENT_LOGGER: +#ifdef ETH_SUPPORT + ProcessLoggerMessage(pData, (U16)DataLen); +#endif + break; + default : + os_error_printf(CU_MSG_ERROR, (PS8)"**** Unknow EventId %d ****\n", EventId); + } + } +} + +static VOID IpcEvent_wext_event_wireless(IpcEvent_Child_t* pIpcEventChild, PS8 data, S32 len) +{ + struct iw_event iwe; + struct stream_descr stream; + S32 ret; + IPC_EV_DATA* pEvent; + U32 EventId = 0; + + /* init the event stream */ + os_memset((char *)&stream, '\0', sizeof(struct stream_descr)); + stream.current = (char *)data; + stream.end = (char *)(data + len); + + do + { + /* Extract an event and print it */ + ret = ParsEvent_GetEvent(&stream, &iwe); + + if(ret <= 0) + break; + + switch (iwe.cmd) + { + case SIOCGIWAP: + if((iwe.u.ap_addr.sa_data[0] == 0) && + (iwe.u.ap_addr.sa_data[1] == 0) && + (iwe.u.ap_addr.sa_data[2] == 0) && + (iwe.u.ap_addr.sa_data[3] == 0) && + (iwe.u.ap_addr.sa_data[4] == 0) && + (iwe.u.ap_addr.sa_data[5] == 0)) + { + EventId=IPC_EVENT_DISASSOCIATED; + IpcEvent_PrintEvent(pIpcEventChild, EventId, NULL,0); + } + else + { +#ifdef XCC_MODULE_INCLUDED + /* Send a signal to the udhcpc application to trigger the renew request */ + system("killall -SIGUSR1 udhcpc"); +#endif + EventId=IPC_EVENT_ASSOCIATED; + IpcEvent_PrintEvent(pIpcEventChild, EventId, NULL,0); + } + break; + case IWEVMICHAELMICFAILURE: + EventId=IPC_EVENT_MEDIA_SPECIFIC; + IpcEvent_PrintEvent(pIpcEventChild, EventId, NULL,0); + break; + case IWEVCUSTOM: + pEvent = (IPC_EV_DATA*)iwe.u.data.pointer; + if (pEvent) + { + EventId = (U32)pEvent->EvParams.uEventType; + IpcEvent_PrintEvent (pIpcEventChild, EventId, pEvent->uBuffer, pEvent->uBufferSize); + } + break; + case SIOCGIWSCAN: + EventId=IPC_EVENT_SCAN_COMPLETE; + IpcEvent_PrintEvent(pIpcEventChild, EventId, NULL,0); + break; + case IWEVASSOCREQIE: + /* NOP */ + break; + case IWEVASSOCRESPIE: + /* NOP */ + break; + case IWEVPMKIDCAND: + EventId=IPC_EVENT_MEDIA_SPECIFIC; + IpcEvent_PrintEvent(pIpcEventChild, EventId, NULL,0); + break; + } + + g_tester_send_event((U8) EventId); + + } + while(1); +} + +static VOID IpcEvent_wext_event_rtm_newlink(IpcEvent_Child_t* pIpcEventChild, struct nlmsghdr *h, + S32 len) +{ + struct ifinfomsg *ifi; + S32 attrlen, nlmsg_len, rta_len; + struct rtattr * attr; + + if (len < sizeof(*ifi)) + return; + + ifi = NLMSG_DATA(h); + + /* + if ((if_nametoindex("wlan") != ifi->ifi_index) && (if_nametoindex("wifi") != ifi->ifi_index)) + { + os_error_printf(CU_MSG_ERROR, "ERROR - IpcEvent_wext_event_rtm_newlink - Ignore event for foreign ifindex %d", + ifi->ifi_index); + return; + } + */ + + nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg)); + + attrlen = h->nlmsg_len - nlmsg_len; + if (attrlen < 0) + return; + + attr = (struct rtattr *) (((char *) ifi) + nlmsg_len); + + rta_len = RTA_ALIGN(sizeof(struct rtattr)); + while (RTA_OK(attr, attrlen)) { + if (attr->rta_type == IFLA_WIRELESS) + { + IpcEvent_wext_event_wireless(pIpcEventChild, ((PS8) attr) + rta_len, + attr->rta_len - rta_len); + } + else if (attr->rta_type == IFLA_IFNAME) + { + os_error_printf(CU_MSG_WARNING, (PS8)"WARNING - IpcEvent_wext_event_rtm_newlink - unsupported rta_type = IFLA_IFNAME\n"); + + } + attr = RTA_NEXT(attr, attrlen); + } +} + +static VOID IpcEvent_Handle_STA_Event(IpcEvent_Child_t* pIpcEventChild) +{ + S8 buf[512]; + S32 left; + struct sockaddr_nl from; + socklen_t fromlen; + struct nlmsghdr *h; + + fromlen = sizeof(from); + left = recvfrom(pIpcEventChild->STA_socket, buf, sizeof(buf), MSG_DONTWAIT, + (struct sockaddr *) &from, &fromlen); + if (left < 0) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Handle_STA_Event - cant recv from socket %X .\n", + pIpcEventChild->STA_socket); + return; + } + + h = (struct nlmsghdr *) buf; + + while (left >= sizeof(*h)) + { + S32 len, plen; + + len = h->nlmsg_len; + plen = len - sizeof(*h); + if (len > left || plen < 0) { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Handle_STA_Event - Malformed netlink message: len=%d left=%d plen=%d", + len, left, plen); + break; + } + + switch (h->nlmsg_type) + { + case RTM_NEWLINK: + IpcEvent_wext_event_rtm_newlink(pIpcEventChild, h, plen); + break; + } + + len = NLMSG_ALIGN(len); + left -= len; + h = (struct nlmsghdr *) ((char *) h + len); + } + + if (left > 0) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Handle_STA_Event - %d extra bytes in the end of netlink ", + left); + IpcEvent_Handle_STA_Event(pIpcEventChild); + } + +} + +static S32 IpcEvent_Handle_Parent_Event(IpcEvent_Child_t* pIpcEventChild) +{ + S8 msg[IPC_EVENT_MSG_MAX_LEN]; + + S32 msgLen = read(pIpcEventChild->pipe_from_parent,msg, IPC_EVENT_MSG_MAX_LEN); + msg[msgLen] = 0; + + if(!os_strcmp(msg, (PS8)IPC_EVENT_MSG_KILL)) + { + return TRUE; + } + if(!os_strcmp(msg, (PS8)IPC_EVENT_MSG_UPDATE_DEBUG_LEVEL)) + { +/* g_debug_level= pIpcEventChild->p_shared_memory->content.debug_level;*/ + return FALSE; + }else + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Handle_Parent_Event - unknown msgLen=%d msg=|%s| \n",msgLen,msg); + + return FALSE; + +} + +static VOID IpcEvent_Child_Destroy(IpcEvent_Child_t* pIpcEventChild) +{ + if(pIpcEventChild->STA_socket) + { + IpcEvent_Sockets_Close(pIpcEventChild->STA_socket); + } + +} + +static VOID IpcEvent_Child(IpcEvent_Child_t* pIpcEventChild) +{ + /* open the socket from the driver */ + pIpcEventChild->STA_socket = IpcEvent_Sockets_Open(); + if(pIpcEventChild->STA_socket < 0) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant open socket for communication with the driver (%d)\n",pIpcEventChild->STA_socket); + return; + } + + while(1) + { + fd_set read_set; /* File descriptors for select */ + S32 ret; + + FD_ZERO(&read_set); + FD_SET(pIpcEventChild->STA_socket, &read_set); + FD_SET(pIpcEventChild->pipe_from_parent, &read_set); + +#ifndef ANDROID + ret = select(max(pIpcEventChild->pipe_from_parent,pIpcEventChild->STA_socket) + 1, + &read_set, NULL, NULL, NULL); +#else + ret = select(pIpcEventChild->STA_socket + 1, + &read_set, NULL, NULL, NULL); +#endif + + if(ret < 0) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Child - Unhandled signal - exiting...\n"); + break; + } + if(ret == 0) { continue; } /* Check for interface discovery events. */ + if(FD_ISSET(pIpcEventChild->STA_socket, &read_set)) + IpcEvent_Handle_STA_Event(pIpcEventChild); + +#ifndef ANDROID + if(FD_ISSET(pIpcEventChild->pipe_from_parent, &read_set)) + { + S32 exit = IpcEvent_Handle_Parent_Event(pIpcEventChild); + if(exit) + break; + } +#endif + + } + + IpcEvent_Child_Destroy(pIpcEventChild); +} + +/* functions */ +/*************/ +THandle IpcEvent_Create(VOID) +{ + IpcEvent_t* pIpcEvent = (IpcEvent_t*)os_MemoryCAlloc(sizeof(IpcEvent_t), sizeof(U8)); + if(pIpcEvent == NULL) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant allocate control block\n"); + return NULL; + } + + /* create a shared memory space */ + pIpcEvent->p_shared_memory = mmap(0, sizeof(IpcEvent_Shared_Memory_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); + if ( pIpcEvent->p_shared_memory == ((PVOID)-1)) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant allocate shared memory\n"); + IpcEvent_Destroy(pIpcEvent); + return NULL; + } + + /* create a pipe */ + pipe(pIpcEvent->p_shared_memory->pipe_fields); + + /* set the event mask to all disabled */ + pIpcEvent->p_shared_memory->event_mask = 0; + + /* Create a child process */ + pIpcEvent->child_process_id = fork(); + + if (0 == pIpcEvent->child_process_id) + { + /******************/ + /* Child process */ + /****************/ + IpcEvent_Child_t* pIpcEventChild = (IpcEvent_Child_t*)os_MemoryCAlloc(sizeof(IpcEvent_Child_t), sizeof(U8)); + if(pIpcEventChild == NULL) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant allocate child control block\n"); + _exit(1); + } + + pIpcEventChild->p_shared_memory = pIpcEvent->p_shared_memory; + + pIpcEventChild->pipe_from_parent = pIpcEventChild->p_shared_memory->pipe_fields[PIPE_READ]; + close(pIpcEventChild->p_shared_memory->pipe_fields[PIPE_WRITE]); + + IpcEvent_Child(pIpcEventChild); + + os_MemoryFree(pIpcEventChild); + + _exit(0); + } + + pIpcEvent->pipe_to_child = pIpcEvent->p_shared_memory->pipe_fields[PIPE_WRITE]; + close(pIpcEvent->p_shared_memory->pipe_fields[PIPE_READ]); + + return pIpcEvent; +} + +VOID IpcEvent_Destroy(THandle hIpcEvent) +{ + IpcEvent_t* pIpcEvent = (IpcEvent_t*)hIpcEvent; + + if((pIpcEvent->p_shared_memory != ((PVOID)-1)) && (pIpcEvent->p_shared_memory)) + { + munmap(pIpcEvent->p_shared_memory, sizeof(IpcEvent_Shared_Memory_t)); + } + + /* kill child process */ + kill(pIpcEvent->child_process_id, SIGKILL); + + os_MemoryFree(pIpcEvent); + +} + +S32 IpcEvent_EnableEvent(THandle hIpcEvent, U32 event) +{ + IpcEvent_t* pIpcEvent = (IpcEvent_t*)hIpcEvent; + + if(pIpcEvent->p_shared_memory->event_mask & ((u64)1 << event)) + { + return EOALERR_IPC_EVENT_ERROR_EVENT_ALREADY_ENABLED; + } + else + { + pIpcEvent->p_shared_memory->event_mask |= ((u64)1 << event); + } + + return OK; + +} + +S32 IpcEvent_DisableEvent(THandle hIpcEvent, U32 event) +{ + IpcEvent_t* pIpcEvent = (IpcEvent_t*)hIpcEvent; + + if(!(pIpcEvent->p_shared_memory->event_mask & (1 << event))) + { + return EOALERR_IPC_EVENT_ERROR_EVENT_ALREADY_DISABLED; + } + else + { + pIpcEvent->p_shared_memory->event_mask &= ~(1 << event); + } + + return OK; +} + +S32 IpcEvent_UpdateDebugLevel(THandle hIpcEvent, S32 debug_level) +{ + IpcEvent_t* pIpcEvent = (IpcEvent_t*)hIpcEvent; + + pIpcEvent->p_shared_memory->content.debug_level = debug_level; + IpcEvent_SendMessageToChild(pIpcEvent, (PS8)IPC_EVENT_MSG_UPDATE_DEBUG_LEVEL); + + return OK; +} + diff --git a/wl1271/CUDK/os/linux/src/ipc_sta.c b/wl1271/CUDK/os/linux/src/ipc_sta.c new file mode 100644 index 00000000..51fa239c --- /dev/null +++ b/wl1271/CUDK/os/linux/src/ipc_sta.c @@ -0,0 +1,195 @@ +/* + * ipc_sta.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** +* +* MODULE: IPC_STA.c +* +* PURPOSE: +* +* DESCRIPTION: +* ============ +* +* +****************************************************************************/ + +/* includes */ +/************/ +#include <sys/types.h> +#include <sys/socket.h> +#include <linux/if.h> +#include <linux/rtnetlink.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <linux/wireless.h> +#include "cu_osapi.h" +#include "oserr.h" +#include "STADExternalIf.h" +#include "ipc_sta.h" + +/* defines */ +/***********/ + +/* local types */ +/***************/ +/* Module control block */ +typedef struct IpcSta_t +{ + struct iwreq wext_req; + ti_private_cmd_t private_cmd; + S32 STA_socket; + +} IpcSta_t; + +/* local variables */ +/*******************/ + +/* local fucntions */ +/*******************/ + +/* + * IpcSta_Sockets_Open - Open a socket. + * Depending on the protocol present, open the right socket. The socket + * will allow us to talk to the driver. + */ +static S32 IpcSta_Sockets_Open(VOID) +{ + static const S32 families[] = { + AF_INET, AF_IPX, AF_APPLETALK + }; + U32 i; + S32 sock; + + /* + * Now pick any (exisiting) useful socket family for generic queries + * Note : don't open all the socket, only returns when one matches, + * all protocols might not be valid. + * Workaround by Jim Kaba <jkaba@sarnoff.com> + * Note : in 2001% of the case, we will just open the inet_sock. + * The remaining 2002% case are not fully correct... + */ + + /* Try all families we support */ + for(i = 0; i < sizeof(families)/sizeof(int); ++i) + { + /* Try to open the socket, if success returns it */ + sock = socket(families[i], SOCK_DGRAM, 0); + if(sock >= 0) + return sock; + } + + return -1; +} + +/* + * IpcSta_Sockets_Close - Close the socket used for ioctl. + */ +static inline VOID IpcSta_Sockets_Close(S32 skfd) +{ + close(skfd); +} + + +/* functions */ +/*************/ +THandle IpcSta_Create(const PS8 device_name) +{ + IpcSta_t* pIpcSta = (IpcSta_t*)os_MemoryCAlloc(sizeof(IpcSta_t), sizeof(U8)); + if(pIpcSta == NULL) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcSta_Create - cant allocate control block\n"); + return NULL; + } + + /* open the socket to the driver */ + pIpcSta->STA_socket = IpcSta_Sockets_Open(); + if(pIpcSta->STA_socket == -1) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcSta_Create - cant open socket for communication with the driver\n"); + return NULL; + } + + /* set the driver name */ + os_strcpy((PS8)pIpcSta->wext_req.ifr_ifrn.ifrn_name, device_name); + + return pIpcSta; +} + +VOID IpcSta_Destroy(THandle hIpcSta) +{ + IpcSta_t* pIpcSta = (IpcSta_t*)hIpcSta; + + /* close the socket to the driver */ + IpcSta_Sockets_Close(pIpcSta->STA_socket); + + os_MemoryFree(pIpcSta); +} + +S32 IPC_STA_Private_Send(THandle hIpcSta, U32 ioctl_cmd, PVOID bufIn, U32 sizeIn, + PVOID bufOut, U32 sizeOut) + +{ + IpcSta_t* pIpcSta = (IpcSta_t*)hIpcSta; + S32 res; + + pIpcSta ->private_cmd.cmd = ioctl_cmd; + if(bufOut == NULL) + pIpcSta ->private_cmd.flags = PRIVATE_CMD_SET_FLAG; + else + pIpcSta ->private_cmd.flags = PRIVATE_CMD_GET_FLAG; + + pIpcSta ->private_cmd.in_buffer = bufIn; + pIpcSta ->private_cmd.in_buffer_len = sizeIn; + pIpcSta ->private_cmd.out_buffer = bufOut; + pIpcSta ->private_cmd.out_buffer_len = sizeOut; + + + pIpcSta->wext_req.u.data.pointer = &pIpcSta->private_cmd; + pIpcSta->wext_req.u.data.length = sizeof(ti_private_cmd_t); + pIpcSta->wext_req.u.data.flags = 0; + + res = ioctl(pIpcSta->STA_socket, SIOCIWFIRSTPRIV, &pIpcSta->wext_req); + if(res != OK) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IPC_STA_Private_Send - error sending Wext private IOCTL to STA driver (ioctl_cmd = %x, res = %d, errno = %d)\n", ioctl_cmd,res,errno); + return EOALERR_IPC_STA_ERROR_SENDING_WEXT; + } + + return OK; +} + +S32 IPC_STA_Wext_Send(THandle hIpcSta, U32 wext_request_id, PVOID p_iwreq_data, U32 len) +{ + IpcSta_t* pIpcSta = (IpcSta_t*)hIpcSta; + S32 res; + + os_memcpy(&pIpcSta->wext_req.u.data, p_iwreq_data, len); + + res = ioctl(pIpcSta->STA_socket, wext_request_id, &pIpcSta->wext_req); + if(res != OK) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IPC_STA_Wext_Send - error sending Wext IOCTL to STA driver (wext_request_id = 0x%x, res = %d, errno = %d)\n",wext_request_id,res,errno); + return EOALERR_IPC_STA_ERROR_SENDING_WEXT; + } + + os_memcpy(p_iwreq_data, &pIpcSta->wext_req.u.data, len); + + return OK; +} + diff --git a/wl1271/CUDK/os/linux/src/ipc_wpa.c b/wl1271/CUDK/os/linux/src/ipc_wpa.c new file mode 100644 index 00000000..5fd3d263 --- /dev/null +++ b/wl1271/CUDK/os/linux/src/ipc_wpa.c @@ -0,0 +1,173 @@ +/* + * ipc_wpa.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** +* +* MODULE: Ipc_Wpa.c +* +* PURPOSE: +* +* DESCRIPTION: +* ============ +* +* +****************************************************************************/ + +/* includes */ +/************/ +#include <sys/types.h> + + +#include "cu_osapi.h" +#include "oserr.h" +#include "wpa_ctrl.h" +#include "ipc_wpa.h" + +/* defines */ +/***********/ +#define IPC_WPA_CTRL_OPEN_RETRIES 5 + +/* local types */ +/***************/ +/* Module control block */ +typedef struct TIpcWpa +{ + struct wpa_ctrl *pWpaCtrl; +#if 0 + S32 socket; + struct sockaddr_in local; + struct sockaddr_in dest; +#endif +} TIpcWpa; + +/* local variables */ +/*******************/ + +/* local fucntions */ +/*******************/ +static S32 IpcWpa_Sockets_Open(TIpcWpa* pIpcWpa, PS8 pSupplIfFile) +{ + S32 i; + + for(i=0; i< IPC_WPA_CTRL_OPEN_RETRIES; i++) + { + pIpcWpa->pWpaCtrl = wpa_ctrl_open((char*)pSupplIfFile); + if(pIpcWpa->pWpaCtrl) + break; + } + + if(pIpcWpa->pWpaCtrl == NULL) + { + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcWpa_Sockets_Open - can't connect the socket\n"); + return EOALERR_IPC_WPA_ERROR_CANT_CONNECT_TO_SUPPL; + } + + return OK; +} + +static VOID IpcWpa_Sockets_Close(TIpcWpa* pIpcWpa) +{ + wpa_ctrl_close(pIpcWpa->pWpaCtrl); +} + + +/* functions */ +/*************/ +THandle IpcWpa_Create(PS32 pRes, PS8 pSupplIfFile) +{ + TIpcWpa* pIpcWpa = (TIpcWpa*)os_MemoryCAlloc(sizeof(TIpcWpa), sizeof(U8)); + if(pIpcWpa == NULL) + { + *pRes = OK; + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcWpa_Create - cant allocate control block\n"); + return NULL; + } + + *pRes = IpcWpa_Sockets_Open(pIpcWpa, pSupplIfFile); + if(*pRes) + { + IpcWpa_Destroy(pIpcWpa); + return NULL; + } + + return pIpcWpa; +} + +VOID IpcWpa_Destroy(THandle hIpcWpa) +{ + TIpcWpa* pIpcWpa = (TIpcWpa*)hIpcWpa; + + if(pIpcWpa->pWpaCtrl) + IpcWpa_Sockets_Close(pIpcWpa); + + os_MemoryFree(pIpcWpa); +} + +S32 IpcWpa_Command(THandle hIpcWpa, PS8 cmd, S32 print) +{ + TIpcWpa* pIpcWpa = (TIpcWpa*)hIpcWpa; + S8 Resp[IPC_WPA_RESP_MAX_LEN]; + TI_SIZE_T RespLen = IPC_WPA_RESP_MAX_LEN - 1; + S32 ret; + + ret = wpa_ctrl_request(pIpcWpa->pWpaCtrl, (char*)cmd, os_strlen(cmd), (char*)Resp, (size_t*)&RespLen, NULL); + + if (ret == -2) + { + os_error_printf(CU_MSG_ERROR, (PS8)"'%s' command timed out.\n", cmd); + return EOALERR_IPC_WPA_ERROR_CMD_TIMEOUT; + } + else if (ret < 0) + { + os_error_printf(CU_MSG_ERROR, (PS8)"'%s' command failed (%d).\n", cmd, ret); + return EOALERR_IPC_WPA_ERROR_CMD_FAILED; + } + if (print) + { + Resp[RespLen] = '\0'; + os_error_printf(CU_MSG_INFO2, (PS8)"%s", Resp); + } + return OK; +} + +S32 IpcWpa_CommandWithResp(THandle hIpcWpa, PS8 cmd, S32 print, PS8 pResp, PU32 pRespLen) +{ + TIpcWpa* pIpcWpa = (TIpcWpa*)hIpcWpa; + S32 ret; + + *pRespLen = IPC_WPA_RESP_MAX_LEN - 1; + ret = wpa_ctrl_request(pIpcWpa->pWpaCtrl, (char*)cmd, os_strlen(cmd), (char*)pResp, (size_t*)pRespLen, NULL); + + if (ret == -2) + { + os_error_printf(CU_MSG_ERROR, (PS8)"'%s' command timed out.\n", cmd); + return EOALERR_IPC_WPA_ERROR_CMD_TIMEOUT; + } + else if (ret < 0) + { + os_error_printf(CU_MSG_ERROR, (PS8)"'%s' command failed.\n", cmd); + return EOALERR_IPC_WPA_ERROR_CMD_FAILED; + } + if (print) + { + pResp[*pRespLen] = '\0'; + os_error_printf(CU_MSG_INFO2, (PS8)"%s", pResp); + } + return OK; +} + diff --git a/wl1271/CUDK/os/linux/src/makefile b/wl1271/CUDK/os/linux/src/makefile new file mode 100644 index 00000000..2bca27c0 --- /dev/null +++ b/wl1271/CUDK/os/linux/src/makefile @@ -0,0 +1,136 @@ +STATIC_LIB ?= y +DEBUG ?= y +BUILD_SUPPL ?= y +SUPPL ?= ANDROID +WPA_ENTERPRISE ?= y +ETH_SUPPORT ?= n + +ifeq ($(DEBUG),y) + DEBUGFLAGS = -O2 -g -DDEBUG -DTI_DBG -fno-builtin +else + DEBUGFLAGS = -O2 +endif + +WILINK_ROOT = ../../../.. +CUDK_ROOT = $(WILINK_ROOT)/CUDK +LIB_NAME = tiOsLib +OUTPUT_DIR ?= $(CUDK_ROOT)/output + +DK_DEFINES = +ifeq ($(WPA_ENTERPRISE), y) + DK_DEFINES += -D WPA_ENTERPRISE +endif + +ifeq ($(BUILD_SUPPL), y) + DK_DEFINES += -D WPA_SUPPLICANT -D CONFIG_CTRL_IFACE -D CONFIG_CTRL_IFACE_UNIX + -include $(CUDK_ROOT)/$(TI_SUPP_LIB_DIR)/.config + ifeq ($(CONFIG_EAP_WSC), y) + DK_DEFINES += -DCONFIG_EAP_WSC + endif +endif + +ifeq ($(STATIC_LIB),y) + TARGET = $(OUTPUT_DIR)/$(LIB_NAME).a +else + TARGET = $(OUTPUT_DIR)/$(LIB_NAME).so +endif + +ifeq ($(ETH_SUPPORT), y) + DK_DEFINES += -DETH_SUPPORT +endif + +SRCS := \ + cu_wext.c \ + ipc_sta.c \ + ipc_event.c \ + ipc_wpa.c \ + os_trans.c \ + ParsEvent.c \ + osapi.c +ifeq ($(BUILD_SUPPL), y) +SRCS += \ + $(CUDK_ROOT)/$(TI_SUPP_LIB_DIR)/wpa_ctrl.c +endif + +OBJS = $(SRCS:.c=.o) + +DEPS = $(SRCS:%.c=%.d) + +ARMFLAGS = -fno-common -pipe + +INCLUDES = \ + -I ../inc \ + -I ../../common/inc \ + -I $(WILINK_ROOT)/stad/Export_Inc \ + -I $(WILINK_ROOT)/stad/src/Sta_Management \ + -I $(WILINK_ROOT)/stad/src/Application \ + -I $(WILINK_ROOT)/utils \ + -I $(WILINK_ROOT)/Txn \ + -I $(WILINK_ROOT)/TWD/TWDriver \ + -I $(WILINK_ROOT)/TWD/FirmwareApi \ + -I $(WILINK_ROOT)/TWD/FW_Transfer/Export_Inc \ + -I $(WILINK_ROOT)/TWD/TwIf \ + -I $(WILINK_ROOT)/platforms/os/linux/inc \ + -I $(WILINK_ROOT)/platforms/os/common/inc \ + -I $(WILINK_ROOT)/TWD/FirmwareApi \ + -I $(CUDK_ROOT)/$(TI_SUPP_LIB_DIR) \ + -I $(CUDK_ROOT)/configurationutility/inc + +CFLAGS = -Wall -Wstrict-prototypes $(DEBUGFLAGS) $(INCLUDES) -D__LINUX__ $(DK_DEFINES) -D__BYTE_ORDER_LITTLE_ENDIAN + +ifneq "$(CROSS_COMPILE)" "" #compile for ARM + CFLAGS += $(ARMFLAGS) + # strip symbols +ifneq "$(DEBUG)" "y" + LDFLAGS = -s +endif + +endif # CROSS_COMPILE != "" + +.PHONY: all + +all: $(TARGET) + +$(OUTPUT_DIR)/$(LIB_NAME).a: $(OBJS) + rm -f $@ + $(CROSS_COMPILE)$(AR) -q $@ $^ + +$(OUTPUT_DIR)/$(LIB_NAME).so: $(OBJS) + rm -f $@ + $(CROSS_COMPILE)gcc -shared $(CFLAGS) $(OBJS) -lc -o $@ + $(CROSS_COMPILE)strip $@ + +ifeq ("$(findstring $(MAKECMDGOALS), clean cleanall)", "") +-include .depend +endif + +%.o: %.cpp + @echo $@ + @$(CROSS_COMPILE)gcc $(CFLAGS) -c $^ -o $@ + +%.o: %.c + @echo $@ + @$(CROSS_COMPILE)gcc -s $(CFLAGS) -c $< -o $@ + +%.i: %.c + @$(CROSS_COMPILE)gcc $(CFLAGS) -E -c $< > $@ + +%.d: %.c + @echo $@ + @$(CROSS_COMPILE)gcc $< -MT$(^:%.c=%.o) -M $(CFLAGS) > $@ + +%.d: %.cpp + @echo $@ + @$(CROSS_COMPILE)gcc $< -MT$(^:%.cpp=%.o) -M $(CFLAGS) > $@ + +.depend: $(DEPS) + rm -f $@ + for aa in $^; do cat $$aa >> $@; done + +.PHONY: clean +clean: + @echo cleaning OS library... + rm -f .depend $(OBJS) $(DEPS) $(SRCS:.c=.i) *.ko .*.cmd .*.flags *.mod.c *~ *.~* $(TARGET) + +cleanall: clean + diff --git a/wl1271/CUDK/os/linux/src/os_trans.c b/wl1271/CUDK/os/linux/src/os_trans.c new file mode 100644 index 00000000..c235626c --- /dev/null +++ b/wl1271/CUDK/os/linux/src/os_trans.c @@ -0,0 +1,168 @@ +/* + * os_trans.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <unistd.h> + + +#include "cu_osapi.h" +#include "os_trans.h" + +TI_BOOL os_trans_create() +{ + return TRUE; +} + + +TI_BOOL os_socket (THandle* pSock) +{ + SOCKET socket_id; + TI_BOOL optval = TRUE; + + socket_id = socket(PF_INET, SOCK_STREAM, 0); + + if (socket_id==SOCKET_ERROR) + { + /* Error opening socket */ + os_error_printf(CU_MSG_ERROR, "%s: error opening socket.\n", __FUNCTION__); + return (FALSE); + } + + /*************************/ + /* Configure the socket */ + /***********************/ + + if (setsockopt(socket_id, SOL_SOCKET, SO_REUSEADDR, (const THandle)&optval, sizeof(optval)) == OSAL_ERROR) { + /* Error setting socket option */ + os_error_printf(CU_MSG_ERROR, "%s: error setting socket option. Error %d\n", __FUNCTION__, os_get_last_error()); + close(socket_id); //close socket + return FALSE; + } + + *pSock = (THandle) socket_id; + + return TRUE; +} + + +TI_BOOL os_bind (THandle sock, U16 port) +{ + struct sockaddr_in server_addr; + TI_SIZE_T result; + + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = htonl (INADDR_ANY); + server_addr.sin_port = htons(port); + + result = bind((SOCKET)sock, (struct sockaddr *)&server_addr, sizeof(server_addr)); + + if (result != OK) { + /* Error binding socket */ + os_error_printf(CU_MSG_ERROR, "%s: error binding socket. Error %d\n", __FUNCTION__, os_get_last_error()); + close((SOCKET)sock); + return(FALSE); + } + + return TRUE; +} + + +TI_BOOL os_sockWaitForConnection (THandle socket_id, THandle* pConnSock) +{ + struct sockaddr_in client_addr; + socklen_t client_addr_len; + TI_SIZE_T result; + + result = listen((SOCKET)socket_id, MAX_QUEUE_LENGTH); + + if (result == OSAL_ERROR) { + /* Error listening to socket */ + /* os_error_printf(CU_MSG_ERROR, "%s: error listening to socket. Error %d\n", __FUNCTION__, errno); + *pConnSock = NULL; + closesocket((SOCKET)socket_id); + return(FALSE);*/ + } + + /**********************/ + /* Accept connection */ + /********************/ + client_addr_len = sizeof(client_addr); + + /* We suppose to get new socket id after accept (blocking action) */ + result = accept((SOCKET)socket_id, (struct sockaddr *)&client_addr, &client_addr_len); + + if (result == OSAL_ERROR) { + *pConnSock = NULL; + /* Error accepting connection */ + os_error_printf(CU_MSG_ERROR, "%s: error accepting connection. Error %d\n", __FUNCTION__, os_get_last_error()); + close((SOCKET) socket_id); + return(FALSE); + } + + *pConnSock = (THandle) result; + + return TRUE; +} + + +TI_BOOL os_sockSend (THandle socket_id, PS8 buffer, U32 bufferSize) +{ + TI_SIZE_T result; + + /* Write to the socket */ + result = send( (SOCKET) socket_id, buffer, (U32)bufferSize, 0); + if (result == SOCKET_ERROR) { + + /**************************/ + /* Error writing to port */ + /************************/ + os_error_printf(CU_MSG_ERROR, "%s: Error writing to socket (result = %d), error %d\n", + __FUNCTION__, result, os_get_last_error()); + + return FALSE; + } + + return TRUE; +} + +VOID os_trans_destroy() +{ + +} + +S32 os_sockRecv (THandle socket_id, PU8 pBuffer, U32 bufferSize, TI_SIZE_T flags) + +{ + TI_SIZE_T result; + + /* Read from the socket */ + result = recv((SOCKET)socket_id, pBuffer, bufferSize, flags); + if (result == SOCKET_ERROR) { + + /***************************/ + /* Error reading from port */ + /***************************/ + + os_error_printf(CU_MSG_ERROR, "%s: Error reading from socket (result = %d), error %d\n", __FUNCTION__, result, os_get_last_error()); + } + + return (S32)result; +} + diff --git a/wl1271/CUDK/os/linux/src/osapi.c b/wl1271/CUDK/os/linux/src/osapi.c new file mode 100644 index 00000000..c088fbac --- /dev/null +++ b/wl1271/CUDK/os/linux/src/osapi.c @@ -0,0 +1,609 @@ +/* + * osapi.c + * + * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** +* +* MODULE: osapi.c +* +* PURPOSE: +* +* DESCRIPTION: +* ============ +* OS Memory API for user mode application (CUDK) +* +****************************************************************************/ + +/* includes */ +/************/ +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <unistd.h> +#include <signal.h> +#include <errno.h> +#include "cu_os.h" +#include "cu_osapi.h" + +/* defines */ +/***********/ +#define MAX_HOST_MESSAGE_SIZE 512 + +S32 ipc_pipe[2]; + +extern S32 user_main (S32 argc, PPS8 argv); + +/** + * \fn main + * \brief Main entry point to a user-mode program + * + * This is the main() function for a user mode program, or the entry point + * called by the OS, This calls an OS-abstracted main function + * + * \param argc - command line argument count + * \param argv - command line arguments + * \return 0 on success, any other value indicates error + * \sa user_main + */ +int main (int argc, char** argv) +{ + return user_main (argc, (PPS8)argv); +} + +/**************************************************************************************** + * os_error_printf() + **************************************************************************************** +DESCRIPTION: This function prints a debug message + +ARGUMENTS: OsContext - our adapter context. + arg_list - string to output with arguments + +RETURN: None +*****************************************************************************************/ +VOID os_error_printf(S32 debug_level, const PS8 arg_list ,...) +{ + static int g_debug_level = CU_MSG_ERROR; + va_list ap; + S8 msg[MAX_HOST_MESSAGE_SIZE]; + + if (debug_level < g_debug_level) + return; + + /* Format the message */ + va_start(ap, arg_list); + vsprintf((char*)msg, (char*)arg_list, ap); + va_end(ap); + + /* print the message */ + fprintf(stderr, (char*)msg); +} + +/**************************************************************************************** + * os_strcpy() + **************************************************************************************** +DESCRIPTION: wrapper to the OS strcpy fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +inline PS8 os_strcpy(PS8 dest, const PS8 src) +{ + return (PS8)strcpy((char*)dest, (char*)src); +} + +/**************************************************************************************** + * os_strncpy() + **************************************************************************************** +DESCRIPTION: wrapper to the OS strncpy fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +PS8 os_strncpy(PS8 dest, const PS8 src, S32 n) +{ + return (PS8)strncpy((char*)dest, (char*)src, n); +} + +/**************************************************************************************** + * os_sprintf() + **************************************************************************************** +DESCRIPTION: wrapper to the OS sprintf fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +S32 os_sprintf(PS8 str, const PS8 arg_list, ...) +{ + va_list ap; + S8 msg[MAX_HOST_MESSAGE_SIZE]; + + va_start(ap, arg_list); + vsprintf((char*)msg, (char*)arg_list, ap); + va_end(ap); + + return sprintf((char*)str, (char*)msg); +} + +/**************************************************************************************** + * os_Printf() + **************************************************************************************** +DESCRIPTION: wrapper to the OS printf fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +S32 os_Printf(const PS8 buffer) +{ + return printf((char*)buffer); +} + + +/**************************************************************************************** + * os_strcat() + **************************************************************************************** +DESCRIPTION: wrapper to the OS strcat fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +PS8 os_strcat(PS8 dest, const PS8 src) +{ + return (PS8)strcat((char*)dest, (char*)src); +} + +/**************************************************************************************** + * os_strlen() + **************************************************************************************** +DESCRIPTION: wrapper to the OS strlen fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +U32 os_strlen(const PS8 s) +{ + return strlen((char*)s); +} + +/**************************************************************************************** + * os_memoryCAlloc() + **************************************************************************************** +DESCRIPTION: Allocates an array in memory with elements initialized to 0. + +ARGUMENTS: OsContext - our adapter context. + Number - Number of elements + Size - Length in bytes of each element + +RETURN: Pointer to the allocated memory. +*****************************************************************************************/ +PVOID os_MemoryCAlloc(U32 Number, U32 Size) +{ + return calloc(Number, Size); +} + +/**************************************************************************************** + * os_memoryAlloc() + **************************************************************************************** +DESCRIPTION: Allocates resident (nonpaged) system-space memory. + +ARGUMENTS: OsContext - our adapter context. + Size - Specifies the size, in bytes, to be allocated. + +RETURN: Pointer to the allocated memory. +*****************************************************************************************/ +PVOID os_MemoryAlloc(U32 Size) +{ + return malloc(Size); +} + +/**************************************************************************************** + * os_memoryFree() + **************************************************************************************** +DESCRIPTION: This function releases a block of memory previously allocated with the + os_memoryAlloc function. + + +ARGUMENTS: OsContext - our adapter context. + pMemPtr - Pointer to the base virtual address of the allocated memory. + This address was returned by the os_memoryAlloc function. + Size - Redundant, needed only for kernel mode. + +RETURN: None +*****************************************************************************************/ +VOID os_MemoryFree(PVOID pMemPtr) +{ + free(pMemPtr); +} + +/**************************************************************************************** + * os_memset() + **************************************************************************************** +DESCRIPTION: wrapper to the OS memset fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +PVOID os_memset(PVOID s, U8 c, U32 n) +{ + return memset(s, c, n); +} + +/**************************************************************************************** + * os_memcpy() + **************************************************************************************** +DESCRIPTION: wrapper to the OS memcpy fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +PVOID os_memcpy(PVOID dest, const PVOID src, U32 n) +{ + return memcpy(dest, src, n); +} + +/**************************************************************************************** + * os_memcmp() + **************************************************************************************** +DESCRIPTION: wrapper to the OS memcmp fucntion + +ARGUMENTS: + +RETURN: +*****************************************************************************************/ +S32 os_memcmp(const PVOID s1, const PVOID s2, S32 n) +{ + return memcmp(s1, s2, n); +} + +/************************************************************************ + * os_strcmp * + ************************************************************************ +DESCRIPTION: wrapper to the OS strcmp fucntion + +CONTEXT: +************************************************************************/ +S32 os_strcmp(const PS8 s1, const PS8 s2) +{ + return strcmp((char*)s1,(char*)s2); +} + + +/************************************************************************ + * os_strncmp * + ************************************************************************ +DESCRIPTION: wrapper to the OS strcmp fucntion + +CONTEXT: +************************************************************************/ +S32 os_strncmp(const PS8 s1, const PS8 s2, U32 n) +{ + return strncmp((char*)s1,(char*)s2,n); +} + +/************************************************************************ + * os_sscanf * + ************************************************************************ +DESCRIPTION: wrapper to the OS sscanf fucntion + +CONTEXT: +************************************************************************/ +S32 os_sscanf(const PS8 str, const PS8 arg_list, ...) +{ + va_list ap; + S8 msg[MAX_HOST_MESSAGE_SIZE]; + + va_start(ap, arg_list); + vsprintf((char*)msg, (char*)arg_list, ap); + va_end(ap); + + return sscanf((char*)str, (char*)msg); +} + +/************************************************************************ + * os_strchr * + ************************************************************************ +DESCRIPTION: wrapper to the OS strchr fucntion + +CONTEXT: +************************************************************************/ +PS8 os_strchr(const PS8 s, S32 c) +{ + return (PS8)strchr((char*)s,c); +} + +/************************************************************************ + * os_strtol * + ************************************************************************ +DESCRIPTION: wrapper to the OS strtol fucntion + +CONTEXT: +************************************************************************/ +S32 os_strtol(const PS8 nptr, PPS8 endptr, S32 base) +{ + return strtol((char*)nptr, (char**)endptr, base); +} + +/************************************************************************ + * os_strtoul * + ************************************************************************ +DESCRIPTION: wrapper to the OS strtoul fucntion + +CONTEXT: +************************************************************************/ +U32 os_strtoul(const PS8 nptr, PPS8 endptr, S32 base) +{ + return strtoul((char*)nptr, (char**)endptr, base); +} + +/************************************************************************ + * os_tolower * + ************************************************************************ +DESCRIPTION: wrapper to the OS tolower fucntion + +CONTEXT: +************************************************************************/ +S32 os_tolower(S32 c) +{ + return tolower(c); +} + +/************************************************************************ + * os_tolower * + ************************************************************************ +DESCRIPTION: wrapper to the OS tolower fucntion + +CONTEXT: +************************************************************************/ +S32 os_isupper(S32 c) +{ + return isupper(c); +} + +/************************************************************************ + * os_tolower * + ************************************************************************ +DESCRIPTION: wrapper to the OS tolower fucntion + +CONTEXT: +************************************************************************/ +S32 os_toupper(S32 c) +{ + return toupper(c); + +} + +/************************************************************************ + * os_atoi * + ************************************************************************ +DESCRIPTION: wrapper to the OS atoi fucntion + +CONTEXT: +************************************************************************/ +S32 os_atoi(const PS8 str) +{ + return (S32)atoi(str); +} + +/************************************************************************ + * os_fopen * + ************************************************************************ +DESCRIPTION: wrapper to the OS fopen fucntion + +CONTEXT: +************************************************************************/ +PVOID os_fopen(const PS8 path, os_fopen_mode_e mode) +{ + switch(mode) + { + case OS_FOPEN_READ: + return fopen((char*)path, "r"); + case OS_FOPEN_READ_BINARY: + return fopen((char*)path, "rb"); + case OS_FOPEN_WRITE: + return fopen(path, "w"); + case OS_FOPEN_WRITE_BINARY: + return fopen(path, "wb"); + + + default: + return NULL; + } +} + +/************************************************************************ + * os_getFileSize * + ************************************************************************ +DESCRIPTION: wrapper to the OS fopen fucntion + +CONTEXT: +************************************************************************/ +S32 os_getFileSize (PVOID file) +{ + S32 size; + + if (fseek(file, 0, SEEK_END)) + { + os_error_printf (CU_MSG_ERROR, (PS8)"Cannot seek file to end\n"); + return -1; + } + size = ftell(file); + rewind(file); + return size; +} + +/************************************************************************ + * os_fgets * + ************************************************************************ +DESCRIPTION: wrapper to the OS fgets fucntion + +CONTEXT: +************************************************************************/ +inline PS8 os_fgets(PS8 s, S32 size, PVOID stream) +{ + return (PS8)fgets((char*)s, size, stream); +} + +/************************************************************************ + * os_fread * + ************************************************************************ +DESCRIPTION: wrapper to the OS fread fucntion + +CONTEXT: +************************************************************************/ +inline S32 os_fread (PVOID ptr, S32 size, S32 nmemb, PVOID stream) +{ + return fread (ptr, size, nmemb, stream); +} + +/************************************************************************ + * os_fwrite * + ************************************************************************ +DESCRIPTION: wrapper to the OS fwrite fucntion + +CONTEXT: +************************************************************************/ +S32 os_fwrite (PVOID ptr, S32 size, S32 nmemb, PVOID stream) +{ + return fwrite (ptr, size, nmemb, stream); +} + +/************************************************************************ + * os_fclose * + ************************************************************************ +DESCRIPTION: wrapper to the OS fclose fucntion + +CONTEXT: +************************************************************************/ +inline S32 os_fclose(PVOID stream) +{ + return fclose(stream); +} + +/************************************************************************ + * os_getInputString * + ************************************************************************ +DESCRIPTION: get the input string for the console from the appropiate inputs + +CONTEXT: +************************************************************************/ +S32 os_getInputString(PS8 inbuf, S32 len) +{ + fd_set read_set; + S32 max_fd_index; + S32 result; + S32 pid; + + /* + * Wait for one of two external events: + * ----------------------------------- + * + * 1. Data received from STDIN + * 2. Data received from the event process + */ + + /* Prepare the read set fields */ + FD_ZERO(&read_set); + FD_SET(0, &read_set); + FD_SET(ipc_pipe[0], &read_set); + + /* Determine the maximum index of the file descriptor */ + max_fd_index = max(0, ipc_pipe[0]) + 1; + + /* Wait for event - blocking */ + result = select(max_fd_index, &read_set, NULL, NULL, NULL); + + if (result > 0) + { + if (FD_ISSET(0, &read_set)) + { + /* Data received from STDIN */ + if ( fgets( (char*)inbuf, len, stdin ) == NULL ) + return FALSE; + else + return TRUE; + } + + if (FD_ISSET(ipc_pipe[0], &read_set)) + { + /**********************************/ + /* Data received from TCP client */ + /********************************/ + result = read(ipc_pipe[0], inbuf, len); + + /* Get the pid of the calling process */ + pid = *(inbuf + 0) | (*(inbuf + 1) << 8); + + /* + Signal the calling process (tell him that we have + received the command, and he can send us another one + */ + if (pid != 0xFFFF) + { + kill(pid, SIGUSR1); + } + + if ( result <= 0 ) + return FALSE; + else + return TRUE; + } + } + + /* Error */ + os_error_printf(CU_MSG_ERROR, (PS8)"Input selection mismatch (0x%x)...\n", read_set); + return FALSE; +} + +/************************************************************************ + * os_Catch_CtrlC_Signal * + ************************************************************************ +DESCRIPTION: register to catch the Ctrl+C signal + +CONTEXT: +************************************************************************/ +VOID os_Catch_CtrlC_Signal(PVOID SignalCB) +{ + if(signal(SIGINT, SignalCB) == SIG_ERR) + os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - os_Catch_CtrlC_Signal - cant catch Ctrl+C signal\n"); +} + + +VOID os_OsSpecificCmdParams(S32 argc, PS8* argv) +{ +} + +VOID os_InitOsSpecificModules(VOID) +{ +} + +VOID os_DeInitOsSpecificModules(VOID) +{ +} + +TI_SIZE_T os_get_last_error() +{ + return errno; +} |