Пример #1
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;
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
S32 WpaCore_SetPin(THandle hWpaCore, PS8 pPinStr)
{
    TWpaCore* pWpaCore = (TWpaCore*)hWpaCore;
    int len = os_strlen(pPinStr);

    if (len == 0)
        return ECUERR_WPA_CORE_ERROR_IVALID_PIN;

    pWpaCore->WpaSupplParams.pWscPin = (PS8)os_MemoryCAlloc(len, sizeof(char));
    if(!pWpaCore->WpaSupplParams.pWscPin)
        return ECUERR_WPA_CORE_ERROR_CANT_ALLOC_PIN;

    os_strcpy(pWpaCore->WpaSupplParams.pWscPin, pPinStr);

    return OK;
}
Пример #6
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;
}
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;
}
Пример #8
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;
}
Пример #9
0
THandle CuCmd_Create(const PS8 device_name, THandle hConsole, S32 BypassSupplicant, PS8 pSupplIfFile)
{
    THandle hIpcSta;

    CuCmd_t* pCuCmd = (CuCmd_t*)os_MemoryCAlloc(sizeof(CuCmd_t), sizeof(U8));
    if(pCuCmd == NULL)
    {
        os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - CuCmd_Create - cant allocate control block\n");
        return NULL;
    }

    pCuCmd->isDeviceRunning = FALSE;
    pCuCmd->hConsole = hConsole;
    
    pCuCmd->hCuCommon= CuCommon_Create(&hIpcSta, device_name);
    if(pCuCmd->hCuCommon == NULL)
    {   
        CuCmd_Destroy(pCuCmd);
        return NULL;
    }

    pCuCmd->hCuWext= CuOs_Create(hIpcSta);
    if(pCuCmd->hCuWext == NULL)
    {   
        CuCmd_Destroy(pCuCmd);
        return NULL;
    }
#if 0
    pCuCmd->hIpcEvent = (THandle) IpcEvent_Create();
    if(pCuCmd->hIpcEvent == NULL)
    {   
        CuCmd_Destroy(pCuCmd);
        return NULL;
    }

    if(BypassSupplicant)
    {
        /* specify that there is no supplicant */
        pCuCmd->hWpaCore = NULL;
    }
    else
    {
/*#ifndef NO_WPA_SUPPL*/
        S32 res;

        pCuCmd->hWpaCore = WpaCore_Create(&res, pSupplIfFile);
        if((pCuCmd->hWpaCore == NULL) && (res != EOALERR_IPC_WPA_ERROR_CANT_CONNECT_TO_SUPPL))
        {
            CuCmd_Destroy(pCuCmd);
            return NULL;
        }

        if(res == EOALERR_IPC_WPA_ERROR_CANT_CONNECT_TO_SUPPL)
        {
            os_error_printf(CU_MSG_ERROR, (PS8)"******************************************************\n");
            os_error_printf(CU_MSG_ERROR, (PS8)"Connection to supplicant failed\n");
            os_error_printf(CU_MSG_ERROR, (PS8)"******************************************************\n");
        }
        else
        {
            os_error_printf(CU_MSG_INFO2, (PS8)"Connection established with supplicant\n");
        }
/*#endif*/
    }

    CuCmd_Init_Scan_Params(pCuCmd);
#endif
    return pCuCmd;
}