Пример #1
0
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;
}
Пример #2
0
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);

	/* If read() fails it returns -1. Avoid buffer out of boundary */
	if (msgLen < 0) {
		os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Handle_Parent_Event - read() failed!\n");

		return FALSE;
	}

	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 S32 RunShellCmd(S8 *cmd)
{
	/*  We'd like to execute the command using the regular call to system(). But system() assumes the existence of
	   /bin/sh  in the file system which doesn't exist in Android zoom2 shell, where shell is in /system/bin/sh
	   So if /bin/sh is not found run the command using fork&exec and assume that the shell is invoked using /system/bin/sh
	*/
	if (access("/bin/sh", F_OK) != -1)
	{
		return system(cmd);
	}
	else
	{
		/*Spawn a child to run the program.*/
		pid_t pid=fork();
	
		if (pid == -1)
		{
			os_error_printf(CU_MSG_ERROR, (PS8)("Fork failed!\n"));
			return -1;
		}
		else if (pid==0) 
		{ 
			/* child process */
			execl("/system/bin/sh", "sh", "-c", cmd, NULL);
			os_error_printf(CU_MSG_ERROR, (PS8)("Exec failed!\n"));
			return -1;
		}
		else 
		{   /* pid!=0; parent process */
			waitpid(pid,0,0); /* wait for child to exit */
		}
	}
	return 0;

}
S32 print_usage(VOID)
{
    os_error_printf (CU_MSG_INFO1, (PS8)"Usage: ./wlan_loader [driver_name] [options]\n");
    os_error_printf (CU_MSG_INFO1, (PS8)"   -e <filename>  - eeprom image file name. default=./nvs_map.bin\n");
    os_error_printf (CU_MSG_INFO1, (PS8)"   -n - no eeprom file\n");
    os_error_printf (CU_MSG_INFO1, (PS8)"   -i <filename>  - init file name. default=tiwlan.ini\n");
    os_error_printf (CU_MSG_INFO1, (PS8)"   -f <filename>  - firmware image file name. default=firmware.bin\n");
    return 1;
}
Пример #5
0
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;
}
Пример #6
0
VOID IpcEvent_ReconfigHostapd(void)
{
    int res =0 ;
    char cmd[100];
    char temp = '"';

    sprintf(cmd, "/bin/sh -c %cbusybox killall -SIGHUP hostapd%c",temp ,temp);

    os_error_printf(CU_MSG_ERROR, "\nReconfiguring Hostapd Started... \n" );
    res = system(cmd);
    os_error_printf(CU_MSG_ERROR, "\nReconfiguring Hostapd Finished. \n" );
}
Пример #7
0
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);
    }
    
}
Пример #8
0
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);
}
Пример #9
0
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;
}
Пример #10
0
THandle WpaCore_Create(PS32 pRes, PS8 pSupplIfFile)
{
    TWpaCore* pWpaCore = (TWpaCore*)os_MemoryCAlloc(sizeof(TWpaCore), sizeof(U8));
    if(pWpaCore == NULL)
    {
        *pRes = OK;
        os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - WpaCore_Create - cant allocate control block\n");
        return NULL;
    }

    pWpaCore->hIpcWpa = IpcWpa_Create(pRes, pSupplIfFile);
    if(pWpaCore->hIpcWpa == NULL)
    {
        WpaCore_Destroy(pWpaCore);
        return NULL;
    }

    WpaCore_InitWpaParams(pWpaCore);

    pWpaCore->CurrentNetwork = -1;

    /* send default configuration to the supplicant */
    IpcWpa_Command(pWpaCore->hIpcWpa, (PS8)"AP_SCAN 2", FALSE);

    return pWpaCore;
}
Пример #11
0
S32 WpaCore_SetEncryptionGroup(THandle hWpaCore, OS_802_11_ENCRYPTION_TYPES EncryptionType)
{
    TWpaCore* pWpaCore = (TWpaCore*)hWpaCore;

    pWpaCore->WpaParams.EncryptionTypeGroup = EncryptionType;

    switch (EncryptionType)
    {
    case OS_ENCRYPTION_TYPE_NONE:
        os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - WpaCore_SetEncryptionGroup - group encryption cant be NONE\n");
        break;
    case OS_ENCRYPTION_TYPE_WEP:
        pWpaCore->WpaSupplParams.group = WPA_CIPHER_WEP40;
        break;

    case OS_ENCRYPTION_TYPE_TKIP:
        pWpaCore->WpaSupplParams.group = WPA_CIPHER_TKIP;
        break;
    case OS_ENCRYPTION_TYPE_AES:
        pWpaCore->WpaSupplParams.group = WPA_CIPHER_CCMP;
        break;
    }

    return OK;
}
Пример #12
0
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;
}
Пример #13
0
S32 WpaCore_SetAuthMode(THandle hWpaCore, OS_802_11_AUTHENTICATION_MODE AuthMode)
{
	TWpaCore* pWpaCore = (TWpaCore*)hWpaCore;

	pWpaCore->WpaParams.AuthMode = AuthMode;

	switch (AuthMode)
	{
		case os802_11AuthModeOpen:
			pWpaCore->WpaSupplParams.proto = 0;
            pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_NONE;
            pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_OPEN;
            break;
		case os802_11AuthModeShared:
			pWpaCore->WpaSupplParams.proto = 0;
            pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_NONE;
            pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_SHARED;
            break;
        case os802_11AuthModeAutoSwitch:
            pWpaCore->WpaSupplParams.proto = 0;
            pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_NONE;
            pWpaCore->WpaSupplParams.auth_alg = (WPA_AUTH_ALG_SHARED | WPA_AUTH_ALG_OPEN);
            break;
        case os802_11AuthModeWPANone:
			pWpaCore->WpaSupplParams.proto = WPA_PROTO_WPA;
			pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_WPA_NONE;
			pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_OPEN;
			break;
		case os802_11AuthModeWPAPSK:
			pWpaCore->WpaSupplParams.proto = WPA_PROTO_WPA;
			pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_PSK;
			pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_OPEN;
			break;
		case os802_11AuthModeWPA2PSK:
			pWpaCore->WpaSupplParams.proto = WPA_PROTO_RSN;
			pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_PSK;
			pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_OPEN;
			break;
        case os802_11AuthModeWPA:
            pWpaCore->WpaSupplParams.proto = WPA_PROTO_WPA;
            pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_IEEE8021X;
            pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_OPEN;
            break;
       case os802_11AuthModeWPA2:
            pWpaCore->WpaSupplParams.proto = WPA_PROTO_RSN;
            pWpaCore->WpaSupplParams.key_mgmt = WPA_KEY_MGMT_IEEE8021X;
            pWpaCore->WpaSupplParams.auth_alg = WPA_AUTH_ALG_OPEN;
            break;

        default:
			os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - WpaCore_SetAuthMode - unknown authentication mode (%d)!!!\n", AuthMode);
            return ECUERR_WPA_CORE_ERROR_UNKNOWN_AUTH_MODE;
	}

	return OK;
}	
Пример #14
0
int check_and_set_property(char *prop_name, char *prop_val)
{
    char prop_status[PROPERTY_VALUE_MAX];
    int count;

    for(count=4;( count != 0 );count--) {
        property_set(prop_name, prop_val);
        if( property_get(prop_name, prop_status, NULL) &&
            (strcmp(prop_status, prop_val) == 0) )
	    break;
    }
    if( count ) {
        os_error_printf(CU_MSG_ERROR, (PS8)"Set property %s = %s - Ok\n", prop_name, prop_val);
    }
    else {
        os_error_printf(CU_MSG_ERROR, (PS8)"Set property %s = %s - Fail\n", prop_name, prop_val);
    }
    return( count );
}
Пример #15
0
TI_BOOL loggerConn_sendMsg (THandle loggerConn, PS8 buffer, U32 bufferSize)
{
	PLOG_CONN_DATA LogConn = (PLOG_CONN_DATA) loggerConn;
	if(LogConn->data_sock == NULL)
    {
        os_error_printf(CU_MSG_ERROR, "**** ERROR LogConn->data_sock is NULL ****\n");    
        return FALSE;
    }

	return os_sockSend(LogConn->data_sock, buffer, bufferSize);
}
Пример #16
0
S32 WpaCore_Disassociate(THandle hWpaCore)
{
    TWpaCore* pWpaCore = (TWpaCore*)hWpaCore;
    S8 cmd[256];

    os_sprintf(cmd, (PS8)"DISABLE_NETWORK %d", pWpaCore->CurrentNetwork);
    if (IpcWpa_Command(pWpaCore->hIpcWpa, cmd, 1))
    {
        os_error_printf(CU_MSG_ERROR, (PS8)"Failed to disconnect from current ssid\n");
        return ECUERR_WPA_CORE_ERROR_FAILED_DISCONNECT_SSID;
    }

    pWpaCore->CurrentNetwork = -1;
    IpcWpa_Command(pWpaCore->hIpcWpa, (PS8)"SAVE_CONFIG", 0);

#if 0 /* for futur WPS work */
    if(pWpaCore->CurrentNetwork == -1)
    {
        os_sprintf(cmd, (PS8)"LIST_NETWORKS");
        if (IpcWpa_Command(pWpaCore->hIpcWpa, cmd, 1))
        {
            os_error_printf(CU_MSG_ERROR, (PS8)"Failed to disconnect from current ssid\n");
            return ECUERR_WPA_CORE_ERROR_FAILED_DISCONNECT_SSID;
        }
    }
    else
    {
        os_sprintf(cmd, (PS8)"DISABLE_NETWORK %d", pWpaCore->CurrentNetwork);
        if (IpcWpa_Command(pWpaCore->hIpcWpa, cmd, 1))
        {
            os_error_printf(CU_MSG_ERROR, (PS8)"Failed to disconnect from current ssid\n");
            return ECUERR_WPA_CORE_ERROR_FAILED_DISCONNECT_SSID;
        }

        pWpaCore->CurrentNetwork = -1;
        IpcWpa_Command(pWpaCore->hIpcWpa, (PS8)"SAVE_CONFIG", 0);
    }
#endif /* #if 0 for futur WPS work */

    return OK;
}
Пример #17
0
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;
}
Пример #18
0
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;
}
Пример #19
0
/************************************************************************
 *                        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;
}
Пример #20
0
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;
}
Пример #21
0
VOID CuCmd_ReportSeverityLevel(THandle hCuCmd, ConParm_t parm[], U16 nParms)
{
    CuCmd_t* pCuCmd = (CuCmd_t*)hCuCmd;
    U8 SeverityTable[REPORT_SEVERITY_MAX];
    S32 index = 0;
    PS8 SeverityValue = (PS8)(parm[0].value);

    /* Get the current report severity */
    if (!CuCommon_GetBuffer(pCuCmd->hCuCommon, REPORT_SEVERITY_TABLE_PARAM, SeverityTable, REPORT_SEVERITY_MAX))    
    {
        if(nParms == 0)
        {            
            S32 i;

            os_error_printf(CU_MSG_INFO2, (PS8)"Severity:\n");
            os_error_printf(CU_MSG_INFO2, (PS8)"-------------------------------\n");
            os_error_printf(CU_MSG_INFO2, (PS8)"%14s\tState\t%s\n", (PS8)"Severity level", (PS8)"Desc");

            for( i=1; i<SIZE_ARR(report_severity); i++ )
            {
                os_error_printf(CU_MSG_INFO2, (PS8)"%d\t%c\t%s\n", report_severity[i].value, (SeverityTable[i] == '1') ? '+' : ' ', report_severity[i].name );
            }

            os_error_printf(CU_MSG_INFO2, (PS8)"* Use '0' to clear all table.\n");
            os_error_printf(CU_MSG_INFO2, (PS8)"* Use '%d' (max index) to set all table.\n", REPORT_SEVERITY_MAX);            
        }
        else
        {
            for (index = 0; index < REPORT_SEVERITY_MAX; index ++)
            {
                if (SeverityValue[index] == '0')
                {
                    SeverityTable[index] = '0';
                } 
                else
                {
                    SeverityTable[index] = '1';
                }
            }
            CuCommon_SetBuffer(pCuCmd->hCuCommon, REPORT_SEVERITY_TABLE_PARAM, SeverityTable, REPORT_SEVERITY_MAX);
        }
    }
    else
    {
        os_error_printf(CU_MSG_ERROR, (PS8)"Error retriving the severity table from the driver\n");
    }
}
Пример #22
0
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;
}
Пример #23
0
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);
    }
}
Пример #24
0
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;
}
Пример #25
0
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;
}
THandle CuCommon_Create(THandle *pIpcSta, const PS8 device_name)
{
    CuCommon_t* pCuCommon = (CuCommon_t*)os_MemoryCAlloc(sizeof(CuCommon_t), sizeof(U8));
    if(pCuCommon == NULL)
    {
        os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - CuCommon_Create - cant allocate control block\n") );
        return NULL;
    }

    pCuCommon->hIpcSta = IpcSta_Create(device_name);
    if(pCuCommon->hIpcSta == NULL)
    {   
        CuCommon_Destroy(pCuCommon);
        return NULL;
    }
    *pIpcSta = pCuCommon->hIpcSta;

    return pCuCommon;
}
S32 CuCommon_Radio_Test(THandle hCuCommon,TTestCmd* data)
{
    CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon;
    S32 res;

	res = IPC_STA_Private_Send(pCuCommon->hIpcSta, 
							   TWD_RADIO_TEST_PARAM, 
							   (PVOID)data, 
							   sizeof(TTestCmd),
							   (PVOID)data, 
							   sizeof(TTestCmd));

    if(res == EOALERR_IPC_STA_ERROR_SENDING_WEXT)
	{
		os_error_printf(CU_MSG_INFO2, (PS8)"In CuCommon_Radio_Test: IPC_STA_Private_Send failed\n");            
		return ECUERR_CU_COMMON_ERROR;
	}

    return OK;  
}
Пример #28
0
/************************************************************************
 *                        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 ) <= 0 )
                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;
}
Пример #29
0
/************************************************************************
 *                        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");
}
Пример #30
0
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); 
        }
    } 
   
}