int main(int argc, const char** argv) { FT_WM_WIFI_REQ req; memset(&req, 0, sizeof(FT_WM_WIFI_REQ)); META_WIFI_Register(wifi_info_callback); if (META_WIFI_init(&req) == false) { printf("WLAN init failed\n"); return -1; } #if 0 req.type = WIFI_CMD_SET_OID; META_WIFI_OP(&req, NULL, 0); req.type = WIFI_CMD_QUERY_OID; META_WIFI_OP(&req, NULL, 0); #endif META_WIFI_deinit(); META_WIFI_Register(NULL); return 0; }
int META_WIFI_init(void) { int count = 100; if(1 == wifi_init){ ERR("wifi is already initilized.\n"); return true; } #if 0 if (!wifi_is_loaded()){ ERR("[META_WIFI] loading wifi driver ... ...\n"); if (wifi_insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) { ERR("[META_WIFI] failed to load wifi driver!!!\n"); goto error; } } #endif usleep(200000); wifi_set_power(1); sched_yield(); while (count-- > 0) { if (ifc_init() == 0) { if (ifc_up("wlan0") == 0) { ifc_close(); break; } ERR("[META_WIFI] ifc_up(wlan0) failed\n"); ifc_close(); } else { ERR("[META_WIFI] ifc_init() failed\n"); } usleep(100000); } if (count == 0) goto error; if (wifi_skfd == -1) wifi_skfd = openNetHandle(); if (wifi_skfd < 0) { META_WIFI_deinit(); goto error; } wifi_init = 1; return true; error: wifi_set_power(0); return false; }
void META_WIFI_OP(FT_WM_WIFI_REQ *req, char *peer_buf, unsigned short peer_len) { unsigned int i; int ret = -1; FT_WM_WIFI_CNF cnf; OID_STRUC *poid = NULL; unsigned long avail_sz; NVRAM_ACCESS_STRUCT *pnvram = NULL; F_INFO kFileInfo; int iFD; void *ret_buf = NULL, *allocated_buf = NULL; unsigned int ret_size = 0; //modify for wifi init/deinit flow // if (NULL == req || NULL == peer_buf || wifi_skfd < 0 || !wifi_init) { // printf("[META_WIFI] Invalid arguments or operation\n"); // goto exit; // } DBG("META_WIFI_OP OP is %d\n", req->type); //for the compaliance of the former meta tool if(!wifi_init && WIFI_CMD_INIT != req->type){ if(true != META_WIFI_init()){ ERR("!wifi_init & META_WIFI_init fail\n"); ret = -1; goto exit; } else DBG("Init for the compaliance of the former meta tool.\n"); } // OID operation if(WIFI_CMD_SET_OID == req->type || WIFI_CMD_QUERY_OID == req->type) { if (NULL == (poid = (OID_STRUC *)malloc(peer_len))) { ERR("[META_WIFI] No memory\n"); goto exit; } // for later freeing allocated_buf = (void *)poid; memcpy(poid, peer_buf, peer_len); if (WIFI_CMD_SET_OID == req->type) { for (i = 0; i < poid->SetOidPara.dataLen; i++) { DBG("[META_WIFI] OIDReq : data[%d] = 0x%x\n", i, poid->SetOidPara.data[i]); } ret = setIWreq(wifi_skfd, "wlan0", poid->SetOidPara.oid, poid->SetOidPara.data, poid->SetOidPara.dataLen, &avail_sz); DBG("[META_WIFI] SET_OID, OID: 0x%x, len: %d, ret: %d\n", poid->SetOidPara.oid, poid->SetOidPara.dataLen, ret); } else if (WIFI_CMD_QUERY_OID == req->type) { ret = getIWreq(wifi_skfd, "wlan0", poid->QueryOidPara.oid, poid->QueryOidPara.data, poid->QueryOidPara.dataLen, &avail_sz); DBG("[META_WIFI] QUERY_OID, OID: 0x%x, len: %d, ret: %d\n", poid->QueryOidPara.oid, poid->QueryOidPara.dataLen, ret); } if (ret == 0 && WIFI_CMD_QUERY_OID == req->type) { ret_buf = (void *)poid; ret_size = avail_sz+8; } } // NVRAM access else if(WIFI_CMD_NVRAM_WRITE_ACCESS == req->type || WIFI_CMD_NVRAM_READ_ACCESS == req->type) { if (NULL == (pnvram = (NVRAM_ACCESS_STRUCT *)malloc(peer_len))) { ERR("[META_WIFI] No memory\n"); goto exit; } // for later freeing allocated_buf = (void *)pnvram; memcpy(pnvram, peer_buf, peer_len); if(peer_len < (offsetof(NVRAM_ACCESS_STRUCT, data) + pnvram->dataLen)) { ERR("[META_WIFI] Mimatched NVRAM content length: (%d / %d)\n", peer_len, offsetof(NVRAM_ACCESS_STRUCT, data) + pnvram->dataLen); goto exit; } kFileInfo = NVM_ReadFileVerInfo(AP_CFG_RDEB_FILE_WIFI_LID); if(WIFI_CMD_NVRAM_READ_ACCESS == req->type) { /* post-check for read access */ if(NVM_ProtectDataFile(AP_CFG_RDEB_FILE_WIFI_LID, 0) != 1) { ERR("[META_WIFI] NVM_ProtectDataFile(): get failed\n"); goto exit; } iFD = open(kFileInfo.cFileName, O_RDONLY, S_IRUSR); if(iFD) { lseek(iFD, pnvram->dataOffset, SEEK_SET); read(iFD, pnvram->data, pnvram->dataLen); close(iFD); ret = 0; } } else if(WIFI_CMD_NVRAM_WRITE_ACCESS == req->type) { iFD = open(kFileInfo.cFileName, O_WRONLY|O_CREAT, S_IRUSR); if(iFD) { lseek(iFD, pnvram->dataOffset, SEEK_SET); write(iFD, pnvram->data, pnvram->dataLen); close(iFD); /* invoke protect data file mechanism */ if(NVM_ProtectDataFile(AP_CFG_RDEB_FILE_WIFI_LID, 1) != 1) { ERR("[META_WIFI] NVM_ProtectDataFile(): set failed\n"); ret = -1; } else { // invoke auto backup mechanism NVM_AddBackupFileNum(AP_CFG_RDEB_FILE_WIFI_LID); ret = 0; } } } if (ret == 0 && WIFI_CMD_NVRAM_READ_ACCESS == req->type) { ret_buf = (void *)pnvram; ret_size = offsetof(NVRAM_ACCESS_STRUCT, data) + pnvram->dataLen; } } else if(WIFI_CMD_INIT == req->type){ if(true != META_WIFI_init()) ret = -1; else ret = 0; } else if(WIFI_CMD_DEINIT == req->type){ META_WIFI_deinit(); ret = 0; } exit: memset(&cnf, 0, sizeof(FT_WM_WIFI_CNF)); cnf.header.token = req->header.token; cnf.header.id = FT_WIFI_CNF_ID; cnf.type = req->type; cnf.status = META_SUCCESS; /* CHECKME!! Need to confirm the value of drv_status */ cnf.drv_status = ret == 0 ? (long)true : (long)false; wifi_send_resp(&cnf, ret_buf, ret_size); FREEIF(allocated_buf); return; }