コード例 #1
0
//-----------------------------------------------------------------------------
FT_AP_Editor_write_cnf	META_Editor_WriteFile_OP(
	FT_AP_Editor_write_req *pReq,
    char *peer_buf,
    unsigned short peer_len)
{
	FT_AP_Editor_write_cnf kCnf;
	F_INFO kFileInfo;
	int iNvmRecSize = 0, iWriteSize;
	F_ID iFD;
	bool IsRead = false;

	memset(&kCnf, 0, sizeof(FT_AP_Editor_write_cnf));
	kCnf.file_idx 		= pReq->file_idx;
	kCnf.para 			= pReq->para;
	
	if ((peer_buf == NULL) || (peer_len == 0)) {
		NVRAM_LOG("Error AP_Editor_WriteFile Peer Buffer Error\n");
		kCnf.status = META_FAILED;
		return kCnf;
	}
	
	iFD = NVM_GetFileDesc(pReq->file_idx,&(kFileInfo.i4RecSize),&(kFileInfo.i4RecNum),IsRead);
	if (iFD.iFileDesc == -1) {
		NVRAM_LOG("Error AP_Editor_WriteFile can't open file: file index-%d, %d\n", 
			pReq->file_idx, iNvmRecSize);
		kCnf.status = META_FAILED;
		return kCnf;
	}
	iNvmRecSize = kFileInfo.i4RecSize;
	if ((pReq->para > kFileInfo.i4RecNum) || (peer_len > kFileInfo.i4RecSize)) {
		NVRAM_LOG("Error AP_Editor_WriteFile para: %d, %d, %d\n", pReq->file_idx, pReq->para, peer_len);
		NVM_CloseFileDesc(iFD);
		kCnf.status = META_FAILED;
		return kCnf;

	}
	lseek(iFD.iFileDesc, (pReq->para - 1) * iNvmRecSize, SEEK_CUR);
	iWriteSize = write(iFD.iFileDesc, peer_buf, iNvmRecSize);
	if(iNvmRecSize != iWriteSize){
		NVRAM_LOG("Error AP_Editor_WriteFile :Write size not match:iWriteSize(%d),iNvmRecSize(%d),error:%s\n",iWriteSize,iNvmRecSize,strerror(errno));
		NVM_CloseFileDesc(iFD);
		kCnf.status = META_FAILED;
		return kCnf;
	}
	NVM_CloseFileDesc(iFD);

	kCnf.write_status = META_STATUS_SUCCESS;
	kCnf.status = META_SUCCESS;

	NVRAM_LOG("AP_Editor_WriteFile result: file_idx-%d para-%d write-%d\n", pReq->file_idx, pReq->para, iWriteSize);
	NVRAM_LOG("AddBackupFileNum Begin");
	NVM_AddBackupFileNum(pReq->file_idx);
	NVRAM_LOG("AddBackupFileNum End");
	return kCnf;
}
コード例 #2
0
//-----------------------------------------------------------------------------
FT_AP_Editor_write_cnf	META_Editor_WriteFile_OP(
	FT_AP_Editor_write_req *pReq,
    char *peer_buf,
    unsigned short peer_len)
{
	FT_AP_Editor_write_cnf kCnf;
	F_INFO kFileInfo;
	int iNvmRecSize, iWriteSize;
	int iFD;

	memset(&kCnf, 0, sizeof(FT_AP_Editor_write_cnf));
	kCnf.file_idx 		= pReq->file_idx;
	kCnf.para 			= pReq->para;
	
	kFileInfo = NVM_ReadFileVerInfo(pReq->file_idx);
	iNvmRecSize = kFileInfo.i4RecSize;
	if ((pReq->para > kFileInfo.i4RecNum) || (peer_len > kFileInfo.i4RecSize)) {
		NVRAM_LOG("Error AP_Editor_WriteFile para: %d, %d, %d\n", pReq->file_idx, pReq->para, peer_len);
		kCnf.status = META_FAILED;
		return kCnf;

	}
	if ((peer_buf == NULL) || (peer_len == 0)) {
		NVRAM_LOG("Error AP_Editor_WriteFile Peer Buffer Error\n");
		kCnf.status = META_FAILED;
		return kCnf;
	}

	iFD = open(kFileInfo.cFileName, O_RDWR, S_IRUSR);
	if (iFD == -1) {
		NVRAM_LOG("Error AP_Editor_WriteFile can't open file: file index-%d, %d\n", 
			pReq->file_idx, iNvmRecSize);
		kCnf.status = META_FAILED;
		return kCnf;
	}

	lseek(iFD, (pReq->para - 1) * iNvmRecSize, SEEK_SET);
	iWriteSize = write(iFD, peer_buf, iNvmRecSize);
	close(iFD);

	kCnf.write_status = META_STATUS_SUCCESS;
	kCnf.status = META_SUCCESS;

	NVRAM_LOG("AP_Editor_WriteFile result: file_idx-%d para-%d write-%d\n", pReq->file_idx, pReq->para, iWriteSize);
	NVRAM_LOG("AddBackupFileNum Begin");
	NVM_AddBackupFileNum(pReq->file_idx);
	NVRAM_LOG("AddBackupFileNum End");
	return kCnf;
}
コード例 #3
0
ファイル: meta_wifi.c プロジェクト: Scorpio92/mediatek
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;
}