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; }
VOID WpaCore_Destroy(THandle hWpaCore) { TWpaCore* pWpaCore = (TWpaCore*)hWpaCore; if(pWpaCore->hIpcWpa) IpcWpa_Destroy(pWpaCore->hIpcWpa); #ifdef CONFIG_WPS if(pWpaCore->WpaSupplParams.pWscPin) os_MemoryFree(pWpaCore->WpaSupplParams.pWscPin); #endif os_MemoryFree(pWpaCore); }
VOID IpcWpa_Destroy(THandle hIpcWpa) { TIpcWpa* pIpcWpa = (TIpcWpa*)hIpcWpa; if (pIpcWpa->pWpaCtrl) IpcWpa_Sockets_Close(pIpcWpa); os_MemoryFree(pIpcWpa); }
VOID CuCommon_Destroy(THandle hCuCommon) { CuCommon_t* pCuCommon = (CuCommon_t*)hCuCommon; if(pCuCommon->hIpcSta) IpcSta_Destroy(pCuCommon->hIpcSta); os_MemoryFree(pCuCommon); }
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); }
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 WpaCore_Destroy(THandle hWpaCore) { TWpaCore* pWpaCore = (TWpaCore*)hWpaCore; #ifdef ANDROID if(pWpaCore->hIpcWpa) { /* Restore configuration back to AP_SCAN 1 for Android */ IpcWpa_Command(pWpaCore->hIpcWpa, (PS8)"AP_SCAN 1", FALSE); IpcWpa_Command(pWpaCore->hIpcWpa, (PS8)"SAVE_CONFIG", FALSE); } #endif if(pWpaCore->hIpcWpa) IpcWpa_Destroy(pWpaCore->hIpcWpa); #ifdef CONFIG_WPS if(pWpaCore->WpaSupplParams.pWscPin) os_MemoryFree(pWpaCore->WpaSupplParams.pWscPin); #endif os_MemoryFree(pWpaCore); }
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); }
VOID CuCmd_Destroy(THandle hCuCmd) { CuCmd_t* pCuCmd = (CuCmd_t*)hCuCmd; if(pCuCmd->hCuCommon) { CuCommon_Destroy(pCuCmd->hCuCommon); } if(pCuCmd->hCuWext) { CuOs_Destroy(pCuCmd->hCuWext); } if(pCuCmd->hIpcEvent) { IpcEvent_Destroy(pCuCmd->hIpcEvent); } os_MemoryFree(pCuCmd); }
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"); os_MemoryFree(pIpcSta); return NULL; } /* set the driver name */ os_strcpy((PS8)pIpcSta->wext_req.ifr_ifrn.ifrn_name, device_name); return pIpcSta; }
VOID CuOs_Destroy(THandle hCuWext) { TCuWext* pCuWext = (TCuWext*)hCuWext; os_MemoryFree(pCuWext); }
/* Return '0' if success */ S32 init_driver( PS8 adapter_name, PS8 eeprom_file_name, PS8 init_file_name, PS8 firmware_file_name ) { PVOID f1 = NULL, f2 = NULL, f3 = NULL; S32 eeprom_image_length = 0; S32 init_file_length = 0; S32 firmware_image_length = 0; U32 req_size = 0; TLoaderFilesData *init_info = NULL; S32 rc = -1; THandle hIpcSta; if( !adapter_name || !*adapter_name ) return rc; os_error_printf(CU_MSG_INFO1, (PS8)"+---------------------------+\n"); os_error_printf(CU_MSG_INFO1, (PS8)"| wlan_loader: initializing |\n"); os_error_printf(CU_MSG_INFO1, (PS8)"+---------------------------+\n"); hIpcSta = IpcSta_Create(adapter_name); if (hIpcSta == NULL) { os_error_printf (CU_MSG_ERROR, (PS8)"wlan_loader: cant allocate IpcSta context\n", eeprom_file_name); goto init_driver_end; } /* Send init request to the driver */ if ( (NULL != eeprom_file_name) && (f1 = os_fopen (eeprom_file_name, OS_FOPEN_READ)) != NULL) { eeprom_image_length = os_getFileSize(f1); if (-1 == eeprom_image_length) { os_error_printf(CU_MSG_ERROR, (PS8)"Cannot get eeprom image file length <%s>\n", eeprom_file_name); goto init_driver_end; } } if ( (NULL != firmware_file_name) && (f2 = os_fopen (firmware_file_name, OS_FOPEN_READ)) != NULL) { firmware_image_length = os_getFileSize(f2); if (-1 == firmware_image_length) { os_error_printf(CU_MSG_ERROR, (PS8)"Cannot get firmware image file length <%s>\n", firmware_file_name); goto init_driver_end; } } if ( (NULL != init_file_name) && (f3 = os_fopen (init_file_name, OS_FOPEN_READ)) != NULL) { init_file_length = os_getFileSize(f3); if (-1 == init_file_length) { os_error_printf(CU_MSG_ERROR, (PS8)"Cannot get init file length <%s>\n", init_file_name); goto init_driver_end; } } /* Now when we can calculate the request length. allocate it and read the files */ req_size = sizeof(TLoaderFilesData) + eeprom_image_length + (init_file_length+1) + firmware_image_length; init_info = (TLoaderFilesData *)os_MemoryAlloc(req_size); if (!init_info) { os_error_printf(CU_MSG_ERROR, (PS8)"No memory to allocate init request (%d bytes)\n", req_size); goto init_driver_end; } init_info->uNvsFileLength = eeprom_image_length; init_info->uFwFileLength = firmware_image_length; init_info->uIniFileLength = init_file_length; if (!f1 || (eeprom_image_length && os_fread(&init_info->data[0], 1, eeprom_image_length, f1)<eeprom_image_length)) { } else os_error_printf(CU_MSG_INFO1, (PS8)"**** nvs file found %s **** \n", eeprom_file_name); if (!f2 || (firmware_image_length && os_fread(&init_info->data[eeprom_image_length], 1, firmware_image_length, f2)<firmware_image_length)) { os_error_printf(CU_MSG_ERROR, (PS8)"Error reading firmware image %s - Aborting...\n", firmware_file_name); goto init_driver_end; } if (!f3 || (init_file_length && os_fread(&init_info->data[eeprom_image_length+firmware_image_length], 1, init_file_length, f3)<init_file_length)) { os_error_printf(CU_MSG_ERROR, (PS8)"Warning: Error in reading init_file %s - Using defaults\n", init_file_name); } /* Load driver defaults */ if(EOALERR_IPC_STA_ERROR_SENDING_WEXT == IPC_STA_Private_Send(hIpcSta, DRIVER_INIT_PARAM, init_info, req_size, NULL, 0)) { os_error_printf(CU_MSG_ERROR, (PS8)"Wlan_loader: Error sending init command (DRIVER_INIT_PARAM) to driver\n"); goto init_driver_end; } /* No Error Found */ rc = 0; init_driver_end: if (f1) os_fclose(f1); if (f2) os_fclose(f2); if (f3) os_fclose(f3); if (init_info) os_MemoryFree(init_info); if (hIpcSta) IpcSta_Destroy(hIpcSta); return rc; }