示例#1
0
/** ============================================================================
 *  @func   KFILEDEF_Open
 *
 *  @desc   Opens a file specified by name of file.
 *
 *  @modif  None
 *  ============================================================================
 */
EXPORT_API
DSP_STATUS
KFILEDEF_Open (IN CONST FileName       fileName,
               IN CONST Char8 *        mode,
               OUT      Void **        fileHandlePtr)
{
    DSP_STATUS    status   = DSP_SOK ;
    Uint32        length   = 0       ;
    struct file * fileDesc = NULL    ;
    mm_segment_t  fs                 ;
    KFILEDEF_Object * fileObj = NULL ;

    TRC_3ENTER ("KFILEDEF_Open ()", fileName, mode, fileHandlePtr) ;

    DBC_Require (fileName != NULL) ;
    DBC_Require (mode != NULL) ;
    DBC_Require (fileHandlePtr != NULL) ;

    if (   (fileName      == NULL)
            || (fileHandlePtr == NULL)
            || (mode          == NULL)
            || (mode [0]      != 'r')) {
        status = DSP_EINVALIDARG ;
        SET_FAILURE_REASON ;
    }
    else {
        *fileHandlePtr = NULL ;

        status = GEN_Strlen (fileName, &length) ;

        if (DSP_FAILED (status)) {
            SET_FAILURE_REASON ;
        }
        else if (length == 0) {
            status = DSP_EINVALIDARG ;
            SET_FAILURE_REASON ;
        }
        else {
            status = MEM_Alloc ((Void **) &fileObj,
                                sizeof (KFILEDEF_Object),
                                MEM_DEFAULT) ;
        }
    }

    if (DSP_SUCCEEDED (status)) {
        fs = get_fs () ;
        set_fs (KERNEL_DS) ;

        /*  --------------------------------------------------------------------
         *  Open the file. Initialize the file object
         *  after validating the object returned by kernel.
         *  The third argument is ignored unless creating files.
         *  --------------------------------------------------------------------
         */
        fileDesc = filp_open (fileName, O_RDONLY, 0) ;
        if (   (IS_ERR (fileDesc))
                || (fileDesc == NULL)
                || (fileDesc->f_op == NULL)
                || (fileDesc->f_op->read == NULL)) {
            status = DSP_EFILE ;
            SET_FAILURE_REASON ;
        }
        else {
            fileObj->fileDesc  = fileDesc   ;
            fileObj->fileName  = fileName   ;
            fileObj->curPos    = 0          ;

            /* Get the file size  */
            fileDesc->f_pos = 0u ;

            *fileHandlePtr = (Void *) fileObj ;

            /* Changes for yaffs2 support */
            if (fileDesc->f_op->llseek != NULL) {
                fileObj->size = fileDesc->f_op->llseek (fileDesc,
                                                        0,
                                                        SEEK_END) ;
                fileDesc->f_op->llseek (fileDesc, 0, SEEK_SET) ;
            }
            else {
                fileObj->size = default_llseek (fileDesc,
                                                0,
                                                SEEK_END) ;
                default_llseek (fileDesc, 0, SEEK_SET) ;
            }
        }

        /*  --------------------------------------------------------------------
         *  If the function call failed then free the object allocated before.
         *  --------------------------------------------------------------------
         */
        if (DSP_FAILED (status)) {
            FREE_PTR (*fileHandlePtr) ;
            *fileHandlePtr = NULL ;
        }

        set_fs (fs) ;

    }
    else {
        status = DSP_EFILE ;
        SET_FAILURE_REASON ;
    }


    DBC_Ensure (   DSP_SUCCEEDED (status)
                   || (   DSP_FAILED (status)
                          && (fileHandlePtr != NULL)
                          && (*fileHandlePtr == NULL))) ;

    TRC_1LEAVE ("KFILEDEF_Open", status) ;

    return status ;
}
int dhd_write_rdwr_korics_macaddr(struct dhd_info *dhd, struct ether_addr *mac)
{
	struct file *fp      = NULL;
	char macbuffer[18]   = {0};
	mm_segment_t oldfs   = {0};
	char randommac[3]    = {0};
	char buf[18]         = {0};
	char *filepath_efs       = MACINFO_EFS;
	int is_zeromac       = 0;
	int ret = 0;
	/* MAC address copied from efs/wifi.mac.info */
	fp = filp_open(filepath_efs, O_RDONLY, 0);

	if (IS_ERR(fp)) {
		/* File Doesn't Exist. Create and write mac addr. */
		fp = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666);
		if (IS_ERR(fp)) {
			DHD_ERROR(("[WIFI] %s: File open error\n",
				filepath_efs));
			return -1;
		}

		oldfs = get_fs();
		set_fs(get_ds());

		/* Generating the Random Bytes for
		 * 3 last octects of the MAC address
		 */
		get_random_bytes(randommac, 3);

		sprintf(macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X\n",
			0x60, 0xd0, 0xa9, randommac[0],
			randommac[1], randommac[2]);
		DHD_ERROR(("[WIFI] The Random Generated MAC ID : %s\n",
			macbuffer));

		if (fp->f_mode & FMODE_WRITE) {
			ret = fp->f_op->write(fp,
				(const char *)macbuffer,
				sizeof(macbuffer), &fp->f_pos);
			if (ret < 0)
				DHD_ERROR(("[WIFI] Mac address [%s]"
					" Failed to write into File:"
					" %s\n", macbuffer, filepath_efs));
			else
				DHD_ERROR(("[WIFI] Mac address [%s]"
					" written into File: %s\n",
					macbuffer, filepath_efs));
		}
		set_fs(oldfs);
	} else {
	/* Reading the MAC Address from .mac.info file
	 * (the existed file or just created file)
	 */
	    ret = kernel_read(fp, 0, buf, 18);
		/* to prevent abnormal string display when mac address
		 * is displayed on the screen.
		 */
		buf[17] = '\0';
		/* Remove security log */
		/* DHD_ERROR(("Read MAC : [%s] [%d] \r\n", buf,
		 * strncmp(buf, "00:00:00:00:00:00", 17)));
		 */
		if ((buf[0] == '\0') ||
			(strncmp(buf, "00:00:00:00:00:00", 17) == 0)) {
			is_zeromac = 1;
		}
	}

	if (ret)
		sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
			(unsigned int *)&(mac->octet[0]),
			(unsigned int *)&(mac->octet[1]),
			(unsigned int *)&(mac->octet[2]),
			(unsigned int *)&(mac->octet[3]),
			(unsigned int *)&(mac->octet[4]),
			(unsigned int *)&(mac->octet[5]));
	else
		DHD_INFO(("dhd_bus_start: Reading from the"
			" '%s' returns 0 bytes\n", filepath_efs));

	if (fp)
		filp_close(fp, NULL);

	if (!is_zeromac) {
		/* Writing Newly generated MAC ID to the Dongle */
		if (_dhd_set_mac_address(dhd, 0, mac) == 0)
			DHD_INFO(("dhd_bus_start: MACID is overwritten\n"));
		else
			DHD_ERROR(("dhd_bus_start: _dhd_set_mac_address() "
				"failed\n"));
	} else {
		DHD_ERROR(("dhd_bus_start:Is ZeroMAC BypassWrite.mac.info!\n"));
	}

	return 0;
}
示例#3
0
文件: inode.c 项目: FIT-CVUT/clondike
static int ccfs_readlink(struct dentry *dentry, char __user * buf, int bufsiz)
{
	int rc = 0;
	struct dentry *lower_dentry;
	char *lower_buf;
	mm_segment_t old_fs;

	struct ccfs_inode* inode = ccfs_inode_to_private(dentry->d_inode);


	lower_dentry = ccfs_get_nested_dentry(dentry);
	if (!lower_dentry->d_inode->i_op ||
	    !lower_dentry->d_inode->i_op->readlink) {
		rc = -EINVAL;
		goto out;
	}

	// Do we have link cached?
	if ( inode->link ) {
		rc = strlen(inode->link);
		if (copy_to_user(buf, inode->link, rc)) {
			rc = -EFAULT;
		}
		fsstack_copy_attr_atime(dentry->d_inode,
					lower_dentry->d_inode);

		mdbg(INFO3, "Resolved cached link => [%s:%d]", inode->link, rc);

		goto out;
	}


	/* Released in this function */
	lower_buf = kmalloc(bufsiz, GFP_KERNEL);
	if (lower_buf == NULL) {
		printk(KERN_ERR "Out of memory\n");
		rc = -ENOMEM;
		goto out;
	}

	old_fs = get_fs();
	set_fs(get_ds());
	mdbg(INFO3,"Calling readlink w/ "
			"lower_dentry->d_name.name = [%s]",
			lower_dentry->d_name.name);
	rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
						   (char __user *)lower_buf,
						   bufsiz);
	set_fs(old_fs);
	if (rc >= 0) {	
		// Cache symlinks
		if ( !inode->link ) {
			char* link = kmalloc(rc + 1, GFP_KERNEL);			
			if ( link ) { // Ignore no memory.. we simply do not cache in that case
				memcpy(link, lower_buf, rc);
				inode->link = link;
				inode->link[rc] = '\0';
			}
		}

		if (copy_to_user(buf, lower_buf, rc)) {
			rc = -EFAULT;
		}
		fsstack_copy_attr_atime(dentry->d_inode,
					lower_dentry->d_inode);
	}

	kfree(lower_buf);
out:
	return rc;
}
static int load_std_firmware(int md_id, struct file *filp, struct ccci_image_info *img)
{
	void __iomem *start;
	int ret = 0;
	int check_ret = 0;
	int read_size = 0;
	mm_segment_t curr_fs;
	phys_addr_t load_addr;
	void *end_addr;
	const int size_per_read = 1024 * 1024;
	const int size = 1024;

	curr_fs = get_fs();
	set_fs(KERNEL_DS);

	load_addr = img->address;
	filp->f_pos = img->offset;

	while (1) {
		/* Map 1M memory */
		start = ioremap_nocache((load_addr + read_size), size_per_read);
		/*CCCI_UTIL_DBG_MSG_WITH_ID(md_id, "map 0x%p --> 0x%p\n", (void*)(load_addr+read_size), start); */
		if (start <= 0) {
			CCCI_UTIL_ERR_MSG_WITH_ID(md_id, "image ioremap fail: %p\n", start);
			set_fs(curr_fs);
			return -CCCI_ERR_LOAD_IMG_NOMEM;
		}

		ret = (int)filp->f_op->read(filp, start, size_per_read, &filp->f_pos);
		/*make sure image size isn't 0 */
		if ((ret < 0) || (ret > size_per_read) || ((ret == 0) && (read_size == 0))) {
			CCCI_UTIL_ERR_MSG_WITH_ID(md_id, "image read fail: size=%d\n", ret);
			ret = -CCCI_ERR_LOAD_IMG_FILE_READ;
			goto error;
		} else if (ret == size_per_read) {
			read_size += ret;
			iounmap(start);
		} else {
			read_size += ret;
			/* Note here, signatured image has file tail info. */
			img->size = read_size - img->tail_length;
			CCCI_UTIL_DBG_MSG_WITH_ID(md_id, "%s, image size=0x%x, read size:%d, tail:%d\n",
						  img->file_name, img->size, read_size, img->tail_length);
			iounmap(start);
			break;
		}
	}

	if (img->type == IMG_MD) {
		/* Make sure in one scope */
		start = ioremap_nocache(round_down(load_addr + img->size - 0x4000, 0x4000), 0x4000 * 2);
		end_addr = start + 0x4000 + (img->size - round_down(img->size, 0x4000));
		check_ret = check_md_header(md_id, end_addr, img);
		if (check_ret < 0) {
			ret = check_ret;
			goto error;
		}
		iounmap(start);
	} else if (img->type == IMG_DSP) {
		start = ioremap_nocache(load_addr, size);
		check_ret = check_dsp_header(md_id, start, img);
		if (check_ret < 0) {
			ret = check_ret;
			goto error;
		}
		iounmap(start);
	}

	set_fs(curr_fs);
	CCCI_UTIL_INF_MSG_WITH_ID(md_id, "Load %s (size=0x%x) to 0x%pa\n", img->file_name, read_size, &load_addr);
	return read_size;

 error:
	iounmap(start);
	set_fs(curr_fs);
	return ret;
}
int dhd_read_macaddr(struct dhd_info *dhd, struct ether_addr *mac)
{
	struct file *fp      = NULL;
	char macbuffer[18]   = {0};
	mm_segment_t oldfs   = {0};
	char randommac[3]    = {0};
	char buf[18]         = {0};
	char *filepath_efs       = MACINFO_EFS;
	int ret = 0;

	fp = filp_open(filepath_efs, O_RDONLY, 0);
	if (IS_ERR(fp)) {
start_readmac:
		/* File Doesn't Exist. Create and write mac addr. */
		fp = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666);
		if (IS_ERR(fp)) {
			DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs));
			return -1;
		}
		oldfs = get_fs();
		set_fs(get_ds());

		/* Generating the Random Bytes for 3 last octects of the MAC address */
		get_random_bytes(randommac, 3);

		sprintf(macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X\n",
			0x00, 0x12, 0x34, randommac[0], randommac[1], randommac[2]);
		DHD_ERROR(("[WIFI]The Random Generated MAC ID: %s\n", macbuffer));

		if (fp->f_mode & FMODE_WRITE) {
			ret = fp->f_op->write(fp, (const char *)macbuffer,
			sizeof(macbuffer), &fp->f_pos);
			if (ret < 0)
				DHD_ERROR(("[WIFI]MAC address [%s] Failed to write into File: %s\n",
					macbuffer, filepath_efs));
			else
				DHD_ERROR(("[WIFI]MAC address [%s] written into File: %s\n",
					macbuffer, filepath_efs));
		}
		set_fs(oldfs);
		/* Reading the MAC Address from .mac.info file
		   ( the existed file or just created file)
		 */
		ret = kernel_read(fp, 0, buf, 18);
	} else {
		/* Reading the MAC Address from
		   .mac.info file( the existed file or just created file)
		 */
		ret = kernel_read(fp, 0, buf, 18);
		/* to prevent abnormal string display
		* when mac address is displayed on the screen.
		*/
		buf[17] = '\0';
		if (strncmp(buf, "00:00:00:00:00:00", 17) < 1) {
			DHD_ERROR(("goto start_readmac \r\n"));
			filp_close(fp, NULL);
			goto start_readmac;
		}
	}

	if (ret)
		sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
			(unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]),
			(unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]),
			(unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5]));
	else
		DHD_ERROR(("dhd_bus_start: Reading from the '%s' returns 0 bytes\n", filepath_efs));

	if (fp)
		filp_close(fp, NULL);

	/* Writing Newly generated MAC ID to the Dongle */
	if (_dhd_set_mac_address(dhd, 0, mac) == 0)
		DHD_INFO(("dhd_bus_start: MACID is overwritten\n"));
	else
		DHD_ERROR(("dhd_bus_start: _dhd_set_mac_address() failed\n"));

	return 0;
}
示例#6
0
// TODO: [ChangeFeature][George] refine this function name for general filesystem read operation, not patch only.
INT32 wmt_dev_patch_get (
    UCHAR *pPatchName,
    osal_firmware **ppPatch,
    INT32 padSzBuf
    )
{
    INT32 iRet = -1;
    osal_firmware *pfw;
    uid_t orig_uid;
    gid_t orig_gid;

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
    //struct cred *cred = get_task_cred(current);
    struct cred *cred = (struct cred *)get_current_cred();
#endif

    mm_segment_t orig_fs = get_fs();

    if (*ppPatch) {
        WMT_WARN_FUNC("f/w patch already exists \n");
        if ((*ppPatch)->data) {
            vfree((*ppPatch)->data);
        }
        kfree(*ppPatch);
        *ppPatch = NULL;
    }

    if (!osal_strlen(pPatchName)) {
        WMT_ERR_FUNC("empty f/w name\n");
        osal_assert((osal_strlen(pPatchName) > 0));
        return -1;
    }

    pfw = kzalloc(sizeof(osal_firmware), /*GFP_KERNEL*/GFP_ATOMIC);
    if (!pfw) {
        WMT_ERR_FUNC("kzalloc(%d) fail\n", sizeof(osal_firmware));
        return -2;
    }

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
    orig_uid = cred->fsuid;
    orig_gid = cred->fsgid;
    cred->fsuid = cred->fsgid = 0;
#else
    orig_uid = current->fsuid;
    orig_gid = current->fsgid;
    current->fsuid = current->fsgid = 0;
#endif

    set_fs(get_ds());

    /* load patch file from fs */
    iRet = wmt_dev_read_file(pPatchName, &pfw->data, 0, padSzBuf);
    set_fs(orig_fs);

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
    cred->fsuid = orig_uid;
    cred->fsgid = orig_gid;
#else
    current->fsuid = orig_uid;
    current->fsgid = orig_gid;
#endif

    if (iRet > 0) {
        pfw->size = iRet;
        *ppPatch = pfw;
        WMT_DBG_FUNC("load (%s) to addr(0x%p) success\n", pPatchName, pfw->data);
        return 0;
    }
    else {
        kfree(pfw);
        *ppPatch = NULL;
        WMT_ERR_FUNC("load file (%s) fail, iRet(%d) \n", pPatchName, iRet);
        return -1;
    }
}
示例#7
0
/*
 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
 *
 * This is really horribly ugly.
 */
asmlinkage int sys_ipc (uint call, int first, int second,
			unsigned long third, void *ptr, long fifth)
{
	int version, ret;

	version = call >> 16; /* hack for backward compatibility */
	call &= 0xffff;

	switch (call) {
	case SEMOP:
		return sys_semtimedop (first, (struct sembuf *)ptr, second,
		                       NULL);
	case SEMTIMEDOP:
		return sys_semtimedop (first, (struct sembuf *)ptr, second,
		                       (const struct timespec __user *)fifth);
	case SEMGET:
		return sys_semget (first, second, third);
	case SEMCTL: {
		union semun fourth;
		if (!ptr)
			return -EINVAL;
		if (get_user(fourth.__pad, (void **) ptr))
			return -EFAULT;
		return sys_semctl (first, second, third, fourth);
	}

	case MSGSND:
		return sys_msgsnd (first, (struct msgbuf *) ptr,
				   second, third);
	case MSGRCV:
		switch (version) {
		case 0: {
			struct ipc_kludge tmp;
			if (!ptr)
				return -EINVAL;

			if (copy_from_user(&tmp,
					   (struct ipc_kludge *) ptr,
					   sizeof (tmp)))
				return -EFAULT;
			return sys_msgrcv (first, tmp.msgp, second,
					   tmp.msgtyp, third);
		}
		default:
			return sys_msgrcv (first,
					   (struct msgbuf *) ptr,
					   second, fifth, third);
		}
	case MSGGET:
		return sys_msgget ((key_t) first, second);
	case MSGCTL:
		return sys_msgctl (first, second, (struct msqid_ds *) ptr);

	case SHMAT:
		switch (version) {
		default: {
			ulong raddr;
			ret = do_shmat (first, (char *) ptr, second, &raddr);
			if (ret)
				return ret;
			return put_user (raddr, (ulong *) third);
		}
		case 1:	/* iBCS2 emulator entry point */
			if (!segment_eq(get_fs(), get_ds()))
				return -EINVAL;
			return do_shmat (first, (char *) ptr, second, (ulong *) third);
		}
	case SHMDT:
		return sys_shmdt ((char *)ptr);
	case SHMGET:
		return sys_shmget (first, second, third);
	case SHMCTL:
		return sys_shmctl (first, second,
				   (struct shmid_ds *) ptr);
	default:
		return -ENOSYS;
	}
}
static void asp01_open_calibration(struct asp01_data *data)
{
	struct file *cal_filp = NULL;
	int i;
	int err = 0;
	int count = CAL_DATA_NUM;
	mm_segment_t old_fs;
#ifdef GRIP_DEBUG
	u8 reg;
#endif

	old_fs = get_fs();
	set_fs(KERNEL_DS);

	cal_filp = filp_open(CALIBRATION_FILE_PATH, O_RDONLY,
			S_IRUGO | S_IWUSR | S_IWGRP);
	if (IS_ERR(cal_filp)) {
		err = PTR_ERR(cal_filp);
		if (err != -ENOENT)
			pr_err("%s: Can't open calibration file\n", __func__);
		else {
			pr_info("%s: need calibration\n", __func__);
			/* calibration status init */
			for (i = 0; i < CAL_DATA_NUM; i++)
				data->cal_data[i] = 0;
		}
		set_fs(old_fs);
		if (err == -ENOENT)
			goto set_init_code;
		else
			return;
	}

	err = cal_filp->f_op->read(cal_filp,
		(char *)data->cal_data,
		CAL_DATA_NUM * sizeof(u8), &cal_filp->f_pos);
	if (err != CAL_DATA_NUM * sizeof(u8))
		pr_err("%s: Can't read the cal data from file\n", __func__);

	filp_close(cal_filp, current->files);
	set_fs(old_fs);

set_init_code:
	for (i = 0; i < CAL_DATA_NUM; i++) {
		if (!data->cal_data[i])
			count -= 1;
	}

	mutex_lock(&data->data_mutex);

	err = asp01_reset(data);
	if (err) {
		pr_err("%s: asp01_reset, err=%d\n",
			__func__, err);
		mutex_unlock(&data->data_mutex);
		return;
	}
#ifdef USE_EEPROM
	if (!count) {
#endif
		err = asp01_init_code_set(data, count);
		if (err < 0) {
			pr_err("%s: asp01_init_code_set, err=%d\n",
				__func__, err);
			mutex_unlock(&data->data_mutex);
			return;
		}
#ifdef USE_EEPROM
	} else
		pr_info("%s: now use eeprom\n", __func__);
#endif
#ifdef GRIP_DEBUG
	/* verifiying MFM value*/
	for (i = 0; i < MFM_DATA_NUM; i++) {
		reg = i2c_smbus_read_byte_data(data->client,
				 REG_MFM_INIT_REF0 + i);
		if (reg < 0) {
			pr_err("%s : i2c read fail, err=%d, %d line\n",
				__func__, reg, __LINE__);
			err = -EIO;
			mutex_unlock(&data->data_mutex);
			return;
		}
		pr_info("%s: verify reg(0x%x) = 0x%x\n", __func__,
			REG_MFM_INIT_REF0 + i, reg);
	}
#endif
	mutex_unlock(&data->data_mutex);

	return;
}
示例#9
0
int InterfaceFileReadbackFromChip(PVOID arg, struct file *flp, unsigned int on_chip_loc)
{
	char *buff, *buff_readback;
	unsigned int reg = 0;
	mm_segment_t oldfs = {0};
	int errno = 0, len = 0, is_config_file = 0;
	loff_t pos = 0;
	static int fw_down;
	INT Status = STATUS_SUCCESS;
	struct bcm_interface_adapter *psIntfAdapter = (struct bcm_interface_adapter *)arg;
	int bytes;

	buff = kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_DMA);
	buff_readback = kmalloc(MAX_TRANSFER_CTRL_BYTE_USB , GFP_DMA);
	if (!buff || !buff_readback) {
		kfree(buff);
		kfree(buff_readback);

		return -ENOMEM;
	}

	is_config_file = (on_chip_loc == CONFIG_BEGIN_ADDR) ? 1 : 0;

	memset(buff_readback, 0, MAX_TRANSFER_CTRL_BYTE_USB);
	memset(buff, 0, MAX_TRANSFER_CTRL_BYTE_USB);
	while (1) {
		oldfs = get_fs();
		set_fs(get_ds());
		len = vfs_read(flp, (void __force __user *)buff, MAX_TRANSFER_CTRL_BYTE_USB, &pos);
		set_fs(oldfs);
		fw_down++;

		if (len <= 0) {
			if (len < 0) {
				BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "len < 0");
				errno = len;
			} else {
				errno = 0;
				BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Got end of file!");
			}
			break;
		}

		bytes = InterfaceRDM(psIntfAdapter, on_chip_loc, buff_readback, len);
		if (bytes < 0) {
			Status = bytes;
			BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "RDM of len %d Failed! %d", len, reg);
			goto exit;
		}
		reg++;
		if ((len-sizeof(unsigned int)) < 4) {
			if (memcmp(buff_readback, buff, len)) {
				BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Firmware Download is not proper %d", fw_down);
				BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Length is: %d", len);
				Status = -EIO;
				goto exit;
			}
		} else {
			len -= 4;

			while (len) {
				if (*(unsigned int *)&buff_readback[len] != *(unsigned int *)&buff[len]) {
					BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Firmware Download is not proper %d", fw_down);
					BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Val from Binary %x, Val From Read Back %x ", *(unsigned int *)&buff[len], *(unsigned int*)&buff_readback[len]);
					BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "len =%x!!!", len);
					Status = -EIO;
					goto exit;
				}
				len -= 4;
			}
		}
		on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB;
	} /* End of while(1) */

exit:
	kfree(buff);
	kfree(buff_readback);
	return Status;
}
示例#10
0
int timod_putmsg(unsigned int fd, char *ctl_buf, int ctl_len,
			char *data_buf, int data_len, int flags)
{
	int ret, error, terror;
	char *buf;
	struct file *filp;
	struct inode *ino;
	struct sol_socket_struct *sock;
	mm_segment_t old_fs = get_fs();
	long args[6];
	int (*sys_socketcall)(int, unsigned long *) =
		(int (*)(int, unsigned long *))SYS(socketcall);
	int (*sys_sendto)(int, void *, size_t, unsigned, struct sockaddr *, int) =
		(int (*)(int, void *, size_t, unsigned, struct sockaddr *, int))SYS(sendto);
	read_lock(&current->files->file_lock);
	filp = fcheck(fd);
	read_unlock(&current->files->file_lock);
	if (!filp)
		return -EBADF;
	ino = filp->f_dentry->d_inode;
	sock = (struct sol_socket_struct *)filp->private_data;
	SOLD("entry");
	if (get_user(ret, (int *)A(ctl_buf)))
		return -EFAULT;
	switch (ret) {
	case T_BIND_REQ:
	{
		struct T_bind_req req;
		
		SOLDD(("bind %016lx(%016lx)\n", sock, filp));
		SOLD("T_BIND_REQ");
		if (sock->state != TS_UNBND) {
			timod_error(fd, T_BIND_REQ, TOUTSTATE, 0);
			return 0;
		}
		SOLD("state ok");
		if (copy_from_user(&req, ctl_buf, sizeof(req))) {
			timod_error(fd, T_BIND_REQ, TSYSERR, EFAULT);
			return 0;
		}
		SOLD("got ctl req");
		if (req.ADDR_offset && req.ADDR_length) {
			if (req.ADDR_length > BUF_SIZE) {
				timod_error(fd, T_BIND_REQ, TSYSERR, EFAULT);
				return 0;
			}
			SOLD("req size ok");
			buf = getpage();
			if (copy_from_user(buf, ctl_buf + req.ADDR_offset, req.ADDR_length)) {
				timod_error(fd, T_BIND_REQ, TSYSERR, EFAULT);
				putpage(buf);
				return 0;
			}
			SOLD("got ctl data");
			args[0] = fd;
			args[1] = (long)buf;
			args[2] = req.ADDR_length;
			SOLD("calling BIND");
			set_fs(KERNEL_DS);
			error = sys_socketcall(SYS_BIND, args);
			set_fs(old_fs);
			putpage(buf);
			SOLD("BIND returned");
		} else 
			error = 0;
		if (!error) {
			struct T_primsg *it;
			if (req.CONIND_number) {
	  			args[0] = fd;
  				args[1] = req.CONIND_number;
  				SOLD("calling LISTEN");
  				set_fs(KERNEL_DS);
	  			error = sys_socketcall(SYS_LISTEN, args);
  				set_fs(old_fs);
  				SOLD("LISTEN done");
  			}
			it = timod_mkctl(sizeof(struct T_bind_ack)+sizeof(struct sockaddr));
			if (it) {
				struct T_bind_ack *ack;

				ack = (struct T_bind_ack *)&it->type;
				ack->PRIM_type = T_BIND_ACK;
				ack->ADDR_offset = sizeof(*ack);
				ack->ADDR_length = sizeof(struct sockaddr);
				ack->CONIND_number = req.CONIND_number;
				args[0] = fd;
				args[1] = (long)(ack+sizeof(*ack));
				args[2] = (long)&ack->ADDR_length;
				set_fs(KERNEL_DS);
				sys_socketcall(SYS_GETSOCKNAME,args);
				set_fs(old_fs);
				sock->state = TS_IDLE;
				timod_ok(fd, T_BIND_REQ);
				timod_queue_end(fd, it);
				SOLD("BIND done");
				return 0;
			}
		}
		SOLD("some error");
		switch (error) {
			case -EINVAL:
				terror = TOUTSTATE;
				error = 0;
				break;
			case -EACCES:
				terror = TACCES;
				error = 0;
				break;
			case -EADDRNOTAVAIL:
			case -EADDRINUSE:
				terror = TNOADDR;
				error = 0;
				break;
			default:
				terror = TSYSERR;
				break;
		}
		timod_error(fd, T_BIND_REQ, terror, -error);
		SOLD("BIND done");
		return 0;
	}
	case T_CONN_REQ:
	{
		struct T_conn_req req;
		unsigned short oldflags;
		struct T_primsg *it;
		SOLD("T_CONN_REQ");
		if (sock->state != TS_UNBND && sock->state != TS_IDLE) {
			timod_error(fd, T_CONN_REQ, TOUTSTATE, 0);
			return 0;
		}
		SOLD("state ok");
		if (copy_from_user(&req, ctl_buf, sizeof(req))) {
			timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
			return 0;
		}
		SOLD("got ctl req");
		if (ctl_len > BUF_SIZE) {
			timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
			return 0;
		}
		SOLD("req size ok");
		buf = getpage();
		if (copy_from_user(buf, ctl_buf, ctl_len)) {
			timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
			putpage(buf);
			return 0;
		}
#ifdef DEBUG_SOLARIS		
		{
			char * ptr = buf;
			int len = ctl_len;
			printk("returned data (%d bytes): ",len);
			while( len-- ) {
				if (!(len & 7))
					printk(" ");
				printk("%02x",(unsigned char)*ptr++);
			}
			printk("\n");
		}
#endif
		SOLD("got ctl data");
		args[0] = fd;
		args[1] = (long)buf+req.DEST_offset;
		args[2] = req.DEST_length;
		oldflags = filp->f_flags;
		filp->f_flags &= ~O_NONBLOCK;
		SOLD("calling CONNECT");
		set_fs(KERNEL_DS);
		error = sys_socketcall(SYS_CONNECT, args);
		set_fs(old_fs);
		filp->f_flags = oldflags;
		SOLD("CONNECT done");
		if (!error) {
			struct T_conn_con *con;
			SOLD("no error");
			it = timod_mkctl(ctl_len);
			if (!it) {
				putpage(buf);
				return -ENOMEM;
			}
			con = (struct T_conn_con *)&it->type;
#ifdef DEBUG_SOLARIS			
			{
				char * ptr = buf;
				int len = ctl_len;
				printk("returned data (%d bytes): ",len);
				while( len-- ) {
					if (!(len & 7))
						printk(" ");
					printk("%02x",(unsigned char)*ptr++);
				}
				printk("\n");
			}
#endif
			memcpy(con, buf, ctl_len);
			SOLD("copied ctl_buf");
			con->PRIM_type = T_CONN_CON;
			sock->state = TS_DATA_XFER;
		} else {
			struct T_discon_ind *dis;
			SOLD("some error");
			it = timod_mkctl(sizeof(*dis));
			if (!it) {
				putpage(buf);
				return -ENOMEM;
			}
			SOLD("got primsg");
			dis = (struct T_discon_ind *)&it->type;
			dis->PRIM_type = T_DISCON_IND;
			dis->DISCON_reason = -error;	/* FIXME: convert this as in iABI_errors() */
			dis->SEQ_number = 0;
		}
		putpage(buf);
		timod_ok(fd, T_CONN_REQ);
		it->pri = 0;
		timod_queue_end(fd, it);
		SOLD("CONNECT done");
		return 0;
	}
	case T_OPTMGMT_REQ:
	{
		struct T_optmgmt_req req;
		SOLD("OPTMGMT_REQ");
		if (copy_from_user(&req, ctl_buf, sizeof(req)))
			return -EFAULT;
		SOLD("got req");
		return timod_optmgmt(fd, req.MGMT_flags,
				req.OPT_offset > 0 ? ctl_buf + req.OPT_offset : NULL,
				req.OPT_length, 1);
	}
	case T_UNITDATA_REQ:
	{
		struct T_unitdata_req req;
		
		int err;
		SOLD("T_UNITDATA_REQ");
		if (sock->state != TS_IDLE && sock->state != TS_DATA_XFER) {
			timod_error(fd, T_CONN_REQ, TOUTSTATE, 0);
			return 0;
		}
		SOLD("state ok");
		if (copy_from_user(&req, ctl_buf, sizeof(req))) {
			timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
			return 0;
		}
		SOLD("got ctl req");
#ifdef DEBUG_SOLARIS		
		{
			char * ptr = ctl_buf+req.DEST_offset;
			int len = req.DEST_length;
			printk("socket address (%d bytes): ",len);
			while( len-- ) {
				char c;
				if (get_user(c,ptr))
					printk("??");
				else
					printk("%02x",(unsigned char)c);
				ptr++;
			}
			printk("\n");
		}
#endif		
		err = sys_sendto(fd, data_buf, data_len, 0, req.DEST_length > 0 ? (struct sockaddr*)(ctl_buf+req.DEST_offset) : NULL, req.DEST_length);
		if (err == data_len)
			return 0;
		if(err >= 0) {
			printk("timod: sendto failed to send all the data\n");
			return 0;
		}
		timod_error(fd, T_CONN_REQ, TSYSERR, -err);
		return 0;
	}
	default:
		printk(KERN_INFO "timod_putmsg: unsupported command %u.\n", ret);
		break;
	}
	return -EINVAL;
}
示例#11
0
int timod_getmsg(unsigned int fd, char *ctl_buf, int ctl_maxlen, s32 *ctl_len,
			char *data_buf, int data_maxlen, s32 *data_len, int *flags_p)
{
	int error;
	int oldflags;
	struct file *filp;
	struct inode *ino;
	struct sol_socket_struct *sock;
	struct T_unitdata_ind udi;
	mm_segment_t old_fs = get_fs();
	long args[6];
	char *tmpbuf;
	int tmplen;
	int (*sys_socketcall)(int, unsigned long *) =
		(int (*)(int, unsigned long *))SYS(socketcall);
	int (*sys_recvfrom)(int, void *, size_t, unsigned, struct sockaddr *, int *);
	
	SOLD("entry");
	SOLDD(("%u %p %d %p %p %d %p %d\n", fd, ctl_buf, ctl_maxlen, ctl_len, data_buf, data_maxlen, data_len, *flags_p));
	read_lock(&current->files->file_lock);
	filp = fcheck(fd);
	read_unlock(&current->files->file_lock);
	if (!filp)
		return -EBADF;
	ino = filp->f_dentry->d_inode;
	sock = (struct sol_socket_struct *)filp->private_data;
	SOLDD(("%p %p\n", sock->pfirst, sock->pfirst ? sock->pfirst->next : NULL));
	if ( ctl_maxlen > 0 && !sock->pfirst && ino->u.socket_i.type == SOCK_STREAM
		&& sock->state == TS_IDLE) {
		SOLD("calling LISTEN");
		args[0] = fd;
		args[1] = -1;
		set_fs(KERNEL_DS);
		sys_socketcall(SYS_LISTEN, args);
		set_fs(old_fs);
		SOLD("LISTEN done");
	}
	if (!(filp->f_flags & O_NONBLOCK)) {
		poll_table wait_table, *wait;

		poll_initwait(&wait_table);
		wait = &wait_table;
		for(;;) {
			SOLD("loop");
			set_current_state(TASK_INTERRUPTIBLE);
			/* ! ( l<0 || ( l>=0 && ( ! pfirst || (flags == HIPRI && pri != HIPRI) ) ) ) */ 
			/* ( ! l<0 && ! ( l>=0 && ( ! pfirst || (flags == HIPRI && pri != HIPRI) ) ) ) */ 
			/* ( l>=0 && ( ! l>=0 || ! ( ! pfirst || (flags == HIPRI && pri != HIPRI) ) ) ) */ 
			/* ( l>=0 && ( l<0 || ( pfirst && ! (flags == HIPRI && pri != HIPRI) ) ) ) */ 
			/* ( l>=0 && ( l<0 || ( pfirst && (flags != HIPRI || pri == HIPRI) ) ) ) */ 
			/* ( l>=0 && ( pfirst && (flags != HIPRI || pri == HIPRI) ) ) */ 
			if (ctl_maxlen >= 0 && sock->pfirst && (*flags_p != MSG_HIPRI || sock->pfirst->pri == MSG_HIPRI))
				break;
			SOLD("cond 1 passed");
			if (
			#if 1
				*flags_p != MSG_HIPRI &&
			#endif
				((filp->f_op->poll(filp, wait) & POLLIN) ||
				(filp->f_op->poll(filp, NULL) & POLLIN) ||
				signal_pending(current))
			) {
				break;
			}
			if( *flags_p == MSG_HIPRI ) {
				SOLD("avoiding lockup");
				break ;
			}
			if(wait_table.error) {
				SOLD("wait-table error");
				poll_freewait(&wait_table);
				return wait_table.error;
			}
			SOLD("scheduling");
			schedule();
		}
		SOLD("loop done");
		current->state = TASK_RUNNING;
		poll_freewait(&wait_table);
		if (signal_pending(current)) {
			SOLD("signal pending");
			return -EINTR;
		}
	}
	if (ctl_maxlen >= 0 && sock->pfirst) {
		struct T_primsg *it = sock->pfirst;
		int l = min_t(int, ctl_maxlen, it->length);
		SCHECK_MAGIC((char*)((u64)(((char *)&it->type)+sock->offset+it->length+7)&~7),MKCTL_MAGIC);
		SOLD("purting ctl data");
		if(copy_to_user(ctl_buf,
			(char*)&it->type + sock->offset, l))
			return -EFAULT;
		SOLD("pur it");
		if(put_user(l, ctl_len))
			return -EFAULT;
		SOLD("set ctl_len");
		*flags_p = it->pri;
		it->length -= l;
		if (it->length) {
			SOLD("more ctl");
			sock->offset += l;
			return MORECTL;
		} else {
			SOLD("removing message");
			sock->pfirst = it->next;
			if (!sock->pfirst)
				sock->plast = NULL;
			SOLDD(("getmsg kfree %016lx->%016lx\n", it, sock->pfirst));
			mykfree(it);
			sock->offset = 0;
			SOLD("ctl done");
			return 0;
		}
	}
	*flags_p = 0;
	if (ctl_maxlen >= 0) {
		SOLD("ACCEPT perhaps?");
		if (ino->u.socket_i.type == SOCK_STREAM && sock->state == TS_IDLE) {
			struct T_conn_ind ind;
			char *buf = getpage();
			int len = BUF_SIZE;

			SOLD("trying ACCEPT");
			if (put_user(ctl_maxlen - sizeof(ind), ctl_len))
				return -EFAULT;
			args[0] = fd;
			args[1] = (long)buf;
			args[2] = (long)&len;
			oldflags = filp->f_flags;
			filp->f_flags |= O_NONBLOCK;
			SOLD("calling ACCEPT");
			set_fs(KERNEL_DS);
			error = sys_socketcall(SYS_ACCEPT, args);
			set_fs(old_fs);
			filp->f_flags = oldflags;
			if (error < 0) {
				SOLD("some error");
				putpage(buf);
				return error;
			}
			if (error) {
				SOLD("connect");
				putpage(buf);
				if (sizeof(ind) > ctl_maxlen) {
					SOLD("generating CONN_IND");
					ind.PRIM_type = T_CONN_IND;
					ind.SRC_length = len;
					ind.SRC_offset = sizeof(ind);
					ind.OPT_length = ind.OPT_offset = 0;
					ind.SEQ_number = error;
					if(copy_to_user(ctl_buf, &ind, sizeof(ind))||
					   put_user(sizeof(ind)+ind.SRC_length,ctl_len))
						return -EFAULT;
					SOLD("CONN_IND created");
				}
				if (data_maxlen >= 0)
					put_user(0, data_len);
				SOLD("CONN_IND done");
				return 0;
			}
			if (len>ctl_maxlen) {
				SOLD("data don't fit");
				putpage(buf);
				return -EFAULT;		/* XXX - is this ok ? */
			}
			if(copy_to_user(ctl_buf,buf,len) || put_user(len,ctl_len)){
				SOLD("can't copy data");
				putpage(buf);
				return -EFAULT;
			}
			SOLD("ACCEPT done");
			putpage(buf);
		}
	}
	SOLD("checking data req");
	if (data_maxlen <= 0) {
		if (data_maxlen == 0)
			put_user(0, data_len);
		if (ctl_maxlen >= 0)
			put_user(0, ctl_len);
		return -EAGAIN;
	}
	SOLD("wants data");
	if (ctl_maxlen > sizeof(udi) && sock->state == TS_IDLE) {
		SOLD("udi fits");
		tmpbuf = ctl_buf + sizeof(udi);
		tmplen = ctl_maxlen - sizeof(udi);
	} else {
		SOLD("udi does not fit");
		tmpbuf = NULL;
		tmplen = 0;
	}
	if (put_user(tmplen, ctl_len))
		return -EFAULT;
	SOLD("set ctl_len");
	oldflags = filp->f_flags;
	filp->f_flags |= O_NONBLOCK;
	SOLD("calling recvfrom");
	sys_recvfrom = (int (*)(int, void *, size_t, unsigned, struct sockaddr *, int *))SYS(recvfrom);
	error = sys_recvfrom(fd, data_buf, data_maxlen, 0, (struct sockaddr*)tmpbuf, ctl_len);
	filp->f_flags = oldflags;
	if (error < 0)
		return error;
	SOLD("error >= 0" ) ;
	if (error && ctl_maxlen > sizeof(udi) && sock->state == TS_IDLE) {
		SOLD("generating udi");
		udi.PRIM_type = T_UNITDATA_IND;
		get_user(udi.SRC_length, ctl_len);
		udi.SRC_offset = sizeof(udi);
		udi.OPT_length = udi.OPT_offset = 0;
		copy_to_user(ctl_buf, &udi, sizeof(udi));
		put_user(sizeof(udi)+udi.SRC_length, ctl_len);
		SOLD("udi done");
	} else
		put_user(0, ctl_len);
	put_user(error, data_len);
	SOLD("done");
	return 0;
}
示例#12
0
static int timod_optmgmt(unsigned int fd, int flag, char *opt_buf, int opt_len, int do_ret)
{
	int error, failed;
	int ret_space, ret_len;
	long args[5];
	char *ret_pos,*ret_buf;
	int (*sys_socketcall)(int, unsigned long *) =
		(int (*)(int, unsigned long *))SYS(socketcall);
	mm_segment_t old_fs = get_fs();

	SOLD("entry");
	SOLDD(("fd %u flg %u buf %p len %u doret %u",fd,flag,opt_buf,opt_len,do_ret));
	if (!do_ret && (!opt_buf || opt_len <= 0))
		return 0;
	SOLD("getting page");
	ret_pos = ret_buf = getpage();
	ret_space = BUF_SIZE;
	ret_len = 0;
	
	error = failed = 0;
	SOLD("looping");
	while(opt_len >= sizeof(struct opthdr)) {
		struct opthdr *opt;
		int orig_opt_len; 
		SOLD("loop start");
		opt = (struct opthdr *)ret_pos; 
		if (ret_space < sizeof(struct opthdr)) {
			failed = TSYSERR;
			break;
		}
		SOLD("getting opthdr");
		if (copy_from_user(opt, opt_buf, sizeof(struct opthdr)) ||
			opt->len > opt_len) {
			failed = TBADOPT;
			break;
		}
		SOLD("got opthdr");
		if (flag == T_NEGOTIATE) {
			char *buf;
			
			SOLD("handling T_NEGOTIATE");
			buf = ret_pos + sizeof(struct opthdr);
			if (ret_space < opt->len + sizeof(struct opthdr) ||
				copy_from_user(buf, opt_buf+sizeof(struct opthdr), opt->len)) {
				failed = TSYSERR;
				break;
			}
			SOLD("got optdata");
			args[0] = fd;
			args[1] = opt->level;
			args[2] = opt->name;
			args[3] = (long)buf;
			args[4] = opt->len;
			SOLD("calling SETSOCKOPT");
			set_fs(KERNEL_DS);
			error = sys_socketcall(SYS_SETSOCKOPT, args);
			set_fs(old_fs);
			if (error) {
				failed = TBADOPT;
				break;
			}
			SOLD("SETSOCKOPT ok");
		}
		orig_opt_len = opt->len;
		opt->len = ret_space - sizeof(struct opthdr);
		if (opt->len < 0) {
			failed = TSYSERR;
			break;
		}
		args[0] = fd;
		args[1] = opt->level;
		args[2] = opt->name;
		args[3] = (long)(ret_pos+sizeof(struct opthdr));
		args[4] = (long)&opt->len;
		SOLD("calling GETSOCKOPT");
		set_fs(KERNEL_DS);
		error = sys_socketcall(SYS_GETSOCKOPT, args);
		set_fs(old_fs);;
		if (error) {
			failed = TBADOPT;
			break;
		}
		SOLD("GETSOCKOPT ok");
		ret_space -= sizeof(struct opthdr) + opt->len;
		ret_len += sizeof(struct opthdr) + opt->len;
		ret_pos += sizeof(struct opthdr) + opt->len;
		opt_len -= sizeof(struct opthdr) + orig_opt_len;
		opt_buf += sizeof(struct opthdr) + orig_opt_len;
		SOLD("loop end");
	}
	SOLD("loop done");
	if (do_ret) {
		SOLD("generating ret msg");
		if (failed)
			timod_error(fd, T_OPTMGMT_REQ, failed, -error);
		else {
			struct T_primsg *it;
			it = timod_mkctl(sizeof(struct T_optmgmt_ack) + ret_len);
			if (it) {
				struct T_optmgmt_ack *ack =
					(struct T_optmgmt_ack *)&it->type;
				SOLD("got primsg");
				ack->PRIM_type = T_OPTMGMT_ACK;
				ack->OPT_length = ret_len;
				ack->OPT_offset = sizeof(struct T_optmgmt_ack);
				ack->MGMT_flags = (failed ? T_FAILURE : flag);
				memcpy(((char*)ack)+sizeof(struct T_optmgmt_ack),
					ret_buf, ret_len);
				timod_queue(fd, it);
			}
		}
	}
	SOLDD(("put_page %p\n", ret_buf));
	putpage(ret_buf);
	SOLD("done");	
	return 0;
}
int mh1_fetch_shading_tbl(struct spich_data *spich, uint8_t *table, int size)
{
	int error = 0;
	struct spi_message msg;

	printk("%s : Enter!! \n", __func__);

	if (!error) {

		struct spi_transfer cmd2 = {	//send frimware
			.cs_change = 1,
			.delay_usecs = 0,
			.speed_hz = (u32)spich->spi_freq_mhz,
			.tx_buf = table,
			.rx_buf = NULL,
			.len	= (int)size,
			.tx_dma = 0,
			.rx_dma = 0,
			.bits_per_word = 0,
		};

		mutex_lock(&spich->buf_lock);

		mh1_spi_write_set(spich);

		spi_message_init(&msg);
		spi_message_add_tail(&cmd2,  &msg);
		error = spi_sync(spich->spi, &msg);
		if (error)
			dev_err(&spich->spi->dev, "spi_sync failed.\n");

		mutex_unlock(&spich->buf_lock);

	}

	printk("%s done\n", __func__);

	return error;

}

int mh1_fetch_image_from_sd(struct spich_data *spich)
{
	int error = 0;
	struct spi_message msg;
	struct file *fp = NULL;

	mm_segment_t old_fs = get_fs();

	long fsize, nread;
	uint8_t *buf_mh1 = NULL;

	pr_err("%s : Enter!! \n", __func__);

	set_fs(KERNEL_DS);

	fp = filp_open("/system/media/RS_MH1.BIN", O_RDONLY, 0);
	if (IS_ERR(fp)) {
		pr_err("failed to open %s, err %ld. load from kernel/firmware\n",
			"/system/media/RS_MH1.BIN", PTR_ERR(fp));

		error = mh1_fetch_image(mh1_spich);
		if (error){
			pr_err("%s : load failed!! \n", __func__);
			goto out;
		}else{
			pr_err("%s : load success from kernel/firmware!! \n", __func__);
			return error;
		}
	}

	fsize = fp->f_path.dentry->d_inode->i_size;

	buf_mh1 = kmalloc(fsize, GFP_KERNEL);
	if (!buf_mh1) {
		pr_err("failed to allocate memory\n");
		error = -ENOMEM;
		goto out;
	}

	nread = vfs_read(fp, (char __user *)buf_mh1, fsize, &fp->f_pos);
	if (nread != fsize) {
		pr_err("failed to read firmware file, %ld Bytes\n", nread);
		error = -EIO;
		goto out;
	}

	filp_close(fp, current->files);

	if (!error) {

		struct spi_transfer cmd2 = {	//send frimware
			.cs_change = 1,
			.delay_usecs = 0,
			.speed_hz = (u32)spich->spi_freq_mhz,
			.tx_buf = buf_mh1,
			.rx_buf = NULL,
			.len	= fsize,
			.tx_dma = 0,
			.rx_dma = 0,
			.bits_per_word = 0,
		};

		mutex_lock(&spich->buf_lock);

		mh1_spi_write_set(spich);

		spi_message_init(&msg);
		spi_message_add_tail(&cmd2,  &msg);
		error = spi_sync(spich->spi, &msg);
		if (error)
			dev_err(&spich->spi->dev, "spi_sync failed.\n");

		mutex_unlock(&spich->buf_lock);

	}

	pr_err("%s:mh1_fetch_image done\n", __func__);

out:
	if (buf_mh1)
		kfree(buf_mh1);

	if (!IS_ERR(fp))
		filp_close(fp, current->files);

	set_fs(old_fs);

	pr_err("X");

	return error;

}

int mh1_fetch_image(struct spich_data *spich)
{
	int error = 0;
	struct spi_message msg;
	const struct firmware *fw_entry=NULL;

//	char tx_buffer[8] = {0x4, 0x7, 0x74, 0xe0, 0x1, 0x0, 0x0, 0x0}; // send frimware
//	char rx_buffer[1] = {0};

	if(strlen(mh1_inbuilt_fw_name_list) > 0)
	{
		error = request_firmware(&fw_entry,
				mh1_inbuilt_fw_name_list,
				&spich->spi->dev);
		if (error != 0)
		{
			printk( "%s: Firmware image %s not available\n", __func__, mh1_inbuilt_fw_name_list);
			return 1;
		}
	}

	printk("MH1 Firmware image size = %zu\n", fw_entry->size);

	if (!error) {
/*
		struct spi_transfer cmd1 = {	//send frimware
			.cs_change = 1,
			.delay_usecs = 0,
			.speed_hz = (u32)spich->spi_freq_mhz,
			.tx_buf = tx_buffer,
			.rx_buf = NULL,
			.len    = 8,
			.tx_dma = 0,
			.rx_dma = 0,
			.bits_per_word = 0,
		};
*/
		struct spi_transfer cmd2 = {	//send frimware
			.cs_change = 1,
			.delay_usecs = 0,
			.speed_hz = (u32)spich->spi_freq_mhz,
			.tx_buf =(u8*) fw_entry->data,
			.rx_buf = NULL,
			.len	= (int)fw_entry->size,
			.tx_dma = 0,
			.rx_dma = 0,
			.bits_per_word = 0,
		};

/*
		struct spi_transfer data = {
			.cs_change = 1,
			.delay_usecs = 0,
			.speed_hz = (u32)spich->spi_freq_mhz,
			.tx_buf = NULL,
			.rx_buf = rx_buffer,
			.len    = 1,
			.tx_dma = 0,
			.rx_dma = 0,
			.bits_per_word = 0,
		};
*/
		mutex_lock(&spich->buf_lock);

//Send Firmware
/*
		mh1_spi_write_set(spich);

		spi_message_init(&msg);
		spi_message_add_tail(&cmd1,  &msg);

		error = spi_sync(spich->spi, &msg);
		if (error)
			dev_err(&spich->spi->dev, "spi_sync failed.\n");

		mh1_spi_read_set(spich);

		spi_message_init(&msg);
		spi_message_add_tail(&data,  &msg);
		error = spi_sync(spich->spi, &msg);
		if (error)
			dev_err(&spich->spi->dev, "spi_sync failed.\n");

		printk("MH1 rx_buffer = %d\n", rx_buffer[0]);
*/
// Send Firmware
		mh1_spi_write_set(spich);

		spi_message_init(&msg);
		spi_message_add_tail(&cmd2,  &msg);
		error = spi_sync(spich->spi, &msg);
		if (error)
			dev_err(&spich->spi->dev, "spi_sync failed.\n");

		mutex_unlock(&spich->buf_lock);

	}

	pr_err("%s:mh1_fetch_image done\n", __func__);

	if (fw_entry)
		release_firmware(fw_entry);

	return error;
}
#endif

void Spi_Cs_Configuration(int number)
{
	if(number==1){ //cs3, TDMB
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS0].gpio,0);
	#if defined (CONFIG_MACH_MSM8992_PPLUS_KR)
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS3].gpio,0);
	#endif
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS2].gpio,1);
	}
	else if(number==2){ //cs2, STM
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS0].gpio,0);
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS2].gpio,0);
	#if defined (CONFIG_MACH_MSM8992_PPLUS_KR)
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS3].gpio,1);
	#endif
	}
	else if(number==3){ //cs0, MH1
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS0].gpio,1);
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS2].gpio,1);
	#if defined (CONFIG_MACH_MSM8992_PPLUS_KR)
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS3].gpio,1);
	#endif
	}
	else if(number==4){ //default state
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS0].gpio,0);
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS2].gpio,1);
	#if defined (CONFIG_MACH_MSM8992_PPLUS_KR)
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_CS3].gpio,1);
	#endif
	}
}

EXPORT_SYMBOL(Spi_Cs_Configuration);




struct spich_data *spich_p;
const char *stm_inbuilt_fw_name_list;

void spi_transfer(u8 *tx_buf,u8 *rx_buf,int size)
{

	int error = 0;
	struct spi_message msg;
    struct spi_transfer cmd2 = {	//send frimware
		.cs_change = 1,
		.delay_usecs = 10,
		.speed_hz = 5*1024*1024,
		.tx_buf =(u8*)tx_buf,
		.rx_buf = (u8*)rx_buf,
		.len	= (int)size,
		.tx_dma = 0,
		.rx_dma = 0,
		.bits_per_word = 8,
	};
//	mutex_lock(&spich_p->buf_lock);
	spi_message_init(&msg);
	spi_message_add_tail(&cmd2,  &msg);
	error = spi_sync(spich_p->spi, &msg);
	if (error)
		dev_err(&spich_p->spi->dev, "spi_sync failed.\n");

//	mutex_unlock(&spich_p->buf_lock);

}


void  StmResetHub( uint8_t tmp) {
	int gpio_state[5] = {0,};
    printk("STM %s START status : %d \n",__func__,tmp);
	if(gpio_state[0] == 0){
	    gpio_set_value(spich_p->gpio_array[GPIO_IDX_LDOEN].gpio,1);
	    mdelay(spich_p->pre_reset_delay);
	}
	if(tmp==STM_SYSTEM) {
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_BOOT0].gpio,1);
	}
	else if(tmp == STM_RESET) {
		gpio_set_value(spich_p->gpio_array[GPIO_IDX_BOOT0].gpio,0);
	}
	else if(tmp == STM_SHUTDOWN) {
        if(spich_p->pre_reset_delay==0){
		    gpio_set_value(spich_p->gpio_array[GPIO_IDX_LDOEN].gpio,0);
        }
		return;
	}
	mdelay(spich_p->pre_reset_delay*50);// if under rev.A reset_delay is 20ms
	gpio_set_value(spich_p->gpio_array[GPIO_IDX_NRST].gpio, 0);
	mdelay(spich_p->pre_reset_delay+3);
	gpio_set_value(spich_p->gpio_array[GPIO_IDX_NRST].gpio, 1);

    printk("STM %s END status : %d \n",__func__,tmp);
	return;
}
示例#14
0
/** ============================================================================
 *  @func   KFILEDEF_Seek
 *
 *  @desc   Repositions the file pointer according to specified arguments.
 *
 *  @modif  None
 *  ============================================================================
 */
EXPORT_API
DSP_STATUS
KFILEDEF_Seek (IN  Void *          fileHandle,
               IN  Int32           offset,
               IN  KFILE_FileSeek  origin)
{
    DSP_STATUS    status   = DSP_SOK ;
    struct file * fileDesc = NULL    ;
    mm_segment_t  fs                 ;
    KFILEDEF_Object * fileObj = NULL ;

    TRC_3ENTER ("KFILEDEF_Seek", fileHandle, offset, origin) ;

    DBC_Require (fileHandle != NULL) ;
    DBC_Require (   (origin == KFILE_SeekSet)
                    || (origin == KFILE_SeekCur)
                    || (origin == KFILE_SeekEnd)) ;

    if (fileHandle == NULL) {
        status = DSP_EFILE ;
        SET_FAILURE_REASON ;
    }
    else {
        fileObj = (KFILEDEF_Object *) fileHandle ;
        fs = get_fs () ;
        set_fs (get_ds()) ;

        fileDesc = fileObj->fileDesc ; ;
        switch (origin)
        {
        case KFILE_SeekSet:
            if (   (offset < 0)
                    || (offset > fileObj->size)) {
                status = DSP_ERANGE ;
                SET_FAILURE_REASON ;
            }
            else {
                /* Changes for yaffs2 support */
                if (fileDesc->f_op->llseek != NULL) {
                    fileObj->curPos = fileDesc->f_op->llseek (fileDesc,
                                      offset,
                                      SEEK_SET) ;
                }
                else {
                    fileObj->curPos = default_llseek (fileDesc,
                                                      offset,
                                                      SEEK_SET) ;
                }
            }
            break ;

        case KFILE_SeekCur:
            if (   ((fileObj->curPos + offset) > fileObj->size)
                    || ((fileObj->curPos + offset) < 0)) {
                status = DSP_ERANGE ;
                SET_FAILURE_REASON ;
            }
            else {
                /* Changes for yaffs2 support */
                if (fileDesc->f_op->llseek != NULL) {
                    fileObj->curPos = fileDesc->f_op->llseek (fileDesc,
                                      offset,
                                      SEEK_CUR) ;
                }
                else {
                    fileObj->curPos = default_llseek (fileDesc,
                                                      offset,
                                                      SEEK_CUR) ;
                }
            }
            break ;

        case KFILE_SeekEnd:
            /*  ----------------------------------------------------------------
             *  A negative offset indicates offset from the end of file.
             *  Check that the specified offset is not beyond
             *  the bounds of the file.
             *  ----------------------------------------------------------------
             */
            if (   (-offset < 0)
                    || (-offset > fileObj->size)) {
                status = DSP_ERANGE ;
                SET_FAILURE_REASON ;
            }
            else {
                /* Changes for yaffs2 support */
                if (fileDesc->f_op->llseek != NULL) {
                    fileObj->curPos = fileDesc->f_op->llseek (fileDesc,
                                      offset,
                                      SEEK_END) ;
                }
                else {
                    fileObj->curPos = default_llseek (fileDesc,
                                                      offset,
                                                      SEEK_END) ;
                }
            }
            break ;

        default:
            TRC_0PRINT (TRC_LEVEL7, "Invalid origin specified\n") ;
            status = DSP_EINVALIDARG ;
            SET_FAILURE_REASON ;
            break ;
        }
        set_fs (fs) ;
    }

    TRC_1LEAVE ("KFILEDEF_Seek", status) ;

    return status ;
}
示例#15
0
int
dhd_read_macaddr(struct dhd_info *dhd, struct ether_addr *mac)
{
    struct file *fp      = NULL;
    struct file *fpnv      = NULL;
    char macbuffer[18]   = {0};
    mm_segment_t oldfs   = {0};
	char randommac[3]    = {0};
	char buf[18]         = {0};
	char* filepath       = "/data/.mac.info";
#ifdef CONFIG_TARGET_LOCALE_VZW
    char* nvfilepath       = "/data/misc/wifi/.nvmac.info";
#else
    char* nvfilepath       = "/data/.nvmac.info";
#endif
	int ret = 0;

	//MAC address copied from nv
	fpnv = filp_open(nvfilepath, O_RDONLY, 0);
	if (IS_ERR(fpnv)) {
start_readmac:
		fpnv = NULL;
		fp = filp_open(filepath, O_RDONLY, 0);
		if (IS_ERR(fp)) {
			/* File Doesn't Exist. Create and write mac addr.*/
			fp = filp_open(filepath, O_RDWR | O_CREAT, 0666);
			if(IS_ERR(fp)) {
				DHD_ERROR(("[WIFI] %s: File open error\n", filepath));
				return -1;
			}

			oldfs = get_fs();
			set_fs(get_ds());

			/* Generating the Random Bytes for 3 last octects of the MAC address */
			get_random_bytes(randommac, 3);
			
			sprintf(macbuffer,"%02X:%02X:%02X:%02X:%02X:%02X\n",
				0x60,0xd0,0xa9,randommac[0],randommac[1],randommac[2]);
			DHD_ERROR(("[WIFI] The Random Generated MAC ID : %s\n", macbuffer));

			if(fp->f_mode & FMODE_WRITE) {			
				ret = fp->f_op->write(fp, (const char *)macbuffer, sizeof(macbuffer), &fp->f_pos);
				if(ret < 0)
					DHD_ERROR(("[WIFI] Mac address [%s] Failed to write into File: %s\n", macbuffer, filepath));
				else
					DHD_INFO(("[WIFI] Mac address [%s] written into File: %s\n", macbuffer, filepath));
			}
			set_fs(oldfs);
		}
		/* Reading the MAC Address from .mac.info file( the existed file or just created file)*/
		//rtn_value=kernel_read(fp, fp->f_pos, buf, 18);	
		ret = kernel_read(fp, 0, buf, 18);	
	}
	else {
		/* Reading the MAC Address from .nvmac.info file( the existed file or just created file)*/
		ret = kernel_read(fpnv, 0, buf, 18);
		buf[17] ='\0';   // to prevent abnormal string display when mac address is displayed on the screen. 
		DHD_ERROR(("Read MAC : [%s] [%d] \r\n" , buf, strncmp(buf , "00:00:00:00:00:00" , 17)));
		if(strncmp(buf , "00:00:00:00:00:00" , 17) == 0) {
			filp_close(fpnv, NULL);
			goto start_readmac;
		}

		fp = filp_open(filepath, O_RDWR | O_CREAT, 0666); // File is always created.
		if(IS_ERR(fp)) {
			DHD_ERROR(("[WIFI] %s: File open error\n", filepath));
			if (fpnv)
				filp_close(fpnv, NULL);
			return -1;
		}
		else {
			oldfs = get_fs();
			set_fs(get_ds());
			
			if(fp->f_mode & FMODE_WRITE) {
				ret = fp->f_op->write(fp, (const char *)buf, sizeof(buf), &fp->f_pos);
				if(ret < 0)
					DHD_ERROR(("[WIFI] Mac address [%s] Failed to write into File: %s\n", buf, filepath));
				else
					DHD_INFO(("[WIFI] Mac address [%s] written into File: %s\n", buf, filepath));
			}       
			set_fs(oldfs);

			ret = kernel_read(fp, 0, buf, 18);	
		}

	}

	if(ret)
		sscanf(buf,"%02X:%02X:%02X:%02X:%02X:%02X",
			   mac->octet[0], mac->octet[1], mac->octet[2], 
			   mac->octet[3], mac->octet[4], mac->octet[5]);
	else
		DHD_ERROR(("dhd_bus_start: Reading from the '%s' returns 0 bytes\n", filepath));

	if (fp)
		filp_close(fp, NULL);
	if (fpnv)
		filp_close(fpnv, NULL);    	

	/* Writing Newly generated MAC ID to the Dongle */
	if (0 == _dhd_set_mac_address(dhd, 0, mac))
		DHD_INFO(("dhd_bus_start: MACID is overwritten\n"));
	else
		DHD_ERROR(("dhd_bus_start: _dhd_set_mac_address() failed\n"));

    return 0;
}
示例#16
0
static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
{
	struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
	struct kiocb kiocb;
	struct iov_iter iter;
	ssize_t ret;

	init_sync_kiocb(&kiocb, filp);
	kiocb.ki_pos = *ppos;
	iov_iter_init(&iter, WRITE, &iov, 1, len);

	ret = filp->f_op->write_iter(&kiocb, &iter);
	BUG_ON(ret == -EIOCBQUEUED);
	if (ret > 0)
		*ppos = kiocb.ki_pos;
	return ret;
}

ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
		    loff_t *pos)
{
	if (file->f_op->write)
		return file->f_op->write(file, p, count, pos);
	else if (file->f_op->write_iter)
		return new_sync_write(file, p, count, pos);
	else
		return -EINVAL;
}
EXPORT_SYMBOL(__vfs_write);

vfs_readf_t vfs_readf(struct file *file)
{
	const struct file_operations *fop = file->f_op;

	if (fop->read)
		return fop->read;
	if (fop->read_iter)
		return new_sync_read;
	return ERR_PTR(-ENOSYS);
}
EXPORT_SYMBOL(vfs_readf);

vfs_writef_t vfs_writef(struct file *file)
{
	const struct file_operations *fop = file->f_op;

	if (fop->write)
		return fop->write;
	if (fop->write_iter)
		return new_sync_write;
	return ERR_PTR(-ENOSYS);
}
EXPORT_SYMBOL(vfs_writef);

ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
{
	mm_segment_t old_fs;
	const char __user *p;
	ssize_t ret;

	if (!(file->f_mode & FMODE_CAN_WRITE))
		return -EINVAL;

	old_fs = get_fs();
	set_fs(get_ds());
	p = (__force const char __user *)buf;
	if (count > MAX_RW_COUNT)
		count =  MAX_RW_COUNT;
	ret = __vfs_write(file, p, count, pos);
	set_fs(old_fs);
	if (ret > 0) {
		fsnotify_modify(file);
		add_wchar(current, ret);
	}
	inc_syscw(current);
	return ret;
}
示例#17
0
文件: fcntl.c 项目: asmalldev/linux
COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
		       compat_ulong_t, arg)
{
	mm_segment_t old_fs;
	struct flock f;
	long ret;
	unsigned int conv_cmd;

	switch (cmd) {
	case F_GETLK:
	case F_SETLK:
	case F_SETLKW:
		ret = get_compat_flock(&f, compat_ptr(arg));
		if (ret != 0)
			break;
		old_fs = get_fs();
		set_fs(KERNEL_DS);
		ret = sys_fcntl(fd, cmd, (unsigned long)&f);
		set_fs(old_fs);
		if (cmd == F_GETLK && ret == 0) {
			/* GETLK was successful and we need to return the data...
			 * but it needs to fit in the compat structure.
			 * l_start shouldn't be too big, unless the original
			 * start + end is greater than COMPAT_OFF_T_MAX, in which
			 * case the app was asking for trouble, so we return
			 * -EOVERFLOW in that case.
			 * l_len could be too big, in which case we just truncate it,
			 * and only allow the app to see that part of the conflicting
			 * lock that might make sense to it anyway
			 */

			if (f.l_start > COMPAT_OFF_T_MAX)
				ret = -EOVERFLOW;
			if (f.l_len > COMPAT_OFF_T_MAX)
				f.l_len = COMPAT_OFF_T_MAX;
			if (ret == 0)
				ret = put_compat_flock(&f, compat_ptr(arg));
		}
		break;

	case F_GETLK64:
	case F_SETLK64:
	case F_SETLKW64:
	case F_OFD_GETLK:
	case F_OFD_SETLK:
	case F_OFD_SETLKW:
		ret = get_compat_flock64(&f, compat_ptr(arg));
		if (ret != 0)
			break;
		old_fs = get_fs();
		set_fs(KERNEL_DS);
		conv_cmd = convert_fcntl_cmd(cmd);
		ret = sys_fcntl(fd, conv_cmd, (unsigned long)&f);
		set_fs(old_fs);
		if ((conv_cmd == F_GETLK || conv_cmd == F_OFD_GETLK) && ret == 0) {
			/* need to return lock information - see above for commentary */
			if (f.l_start > COMPAT_LOFF_T_MAX)
				ret = -EOVERFLOW;
			if (f.l_len > COMPAT_LOFF_T_MAX)
				f.l_len = COMPAT_LOFF_T_MAX;
			if (ret == 0)
				ret = put_compat_flock64(&f, compat_ptr(arg));
		}
		break;

	default:
		ret = sys_fcntl(fd, cmd, arg);
		break;
	}
	return ret;
}
/*
 * Will be obsoleted ...
 */
int rdr_save_file(const char *dir, const char *file_header,
			const void *address, u32 length)
{
	int fd, ret;
	long bytes;
	mm_segment_t old_fs;
	char new_filename[RDR_FNAME_LEN] = {0};

	if (NULL == dir || NULL == file_header) {
		DUMP_LOG(0);
		return -1;
	}

	if ((strlen((const char *)dir) + strlen((const char *)file_header))
				>= RDR_FNAME_LEN) {
		DUMP_LOG(0);
		return -1;
	}

	old_fs = get_fs();
	set_fs(KERNEL_DS);

	fd = rdr_open_dir(dir);
	if (fd < 0) {
		DUMP_LOG(fd);
		set_fs(old_fs);
		return -1;
	}

	ret = del_old_file(dir, file_header, (unsigned int)fd, file_header);
	if (0 != ret) {
		DUMP_LOG(ret);
		rdr_file_close(fd);
		set_fs(old_fs);
		return -1;
	}

	rdr_file_close(fd);

	memset(new_filename, 0, sizeof(new_filename));
	snprintf(new_filename, sizeof(new_filename), "%s%s%02d.bin",
			dir, file_header, 0);

	fd = sys_creat(new_filename, 0644);
	if (fd < 0) {
		DUMP_LOG(fd);
		set_fs(old_fs);
		return -1;
	}

	bytes = sys_write((unsigned int)fd, (const char *)address, length);
	if ((u32)bytes != length) {
		DUMP_LOG((int)bytes);
		rdr_file_close(fd);
		set_fs(old_fs);
		return -1;
	}
	sys_fsync(fd);
	rdr_file_close(fd);
	set_fs(old_fs);
	pr_info("rdr:save file %s success ...", new_filename);

	return 0;
}
示例#19
0
asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
{
	struct rt_signal_frame __user *sf;
	unsigned int psr, pc, npc;
	__siginfo_fpu_t __user *fpu_save;
	__siginfo_rwin_t __user *rwin_save;
	mm_segment_t old_fs;
	sigset_t set;
	stack_t st;
	int err;

	synchronize_user_stack();
	sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
	if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
	    (((unsigned long) sf) & 0x03))
		goto segv;

	err = __get_user(pc, &sf->regs.pc);
	err |= __get_user(npc, &sf->regs.npc);
	err |= ((pc | npc) & 0x03);

	err |= __get_user(regs->y, &sf->regs.y);
	err |= __get_user(psr, &sf->regs.psr);

	err |= __copy_from_user(&regs->u_regs[UREG_G1],
				&sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));

	regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);

	/* Prevent syscall restart.  */
	pt_regs_clear_syscall(regs);

	err |= __get_user(fpu_save, &sf->fpu_save);
	if (!err && fpu_save)
		err |= restore_fpu_state(regs, fpu_save);
	err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
	
	err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
	
	if (err)
		goto segv;
		
	regs->pc = pc;
	regs->npc = npc;
	
	/* It is more difficult to avoid calling this function than to
	 * call it and ignore errors.
	 */
	old_fs = get_fs();
	set_fs(KERNEL_DS);
	do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
	set_fs(old_fs);

	err |= __get_user(rwin_save, &sf->rwin_save);
	if (!err && rwin_save) {
		if (restore_rwin_state(rwin_save))
			goto segv;
	}

	sigdelsetmask(&set, ~_BLOCKABLE);
	set_current_blocked(&set);
	return;
segv:
	force_sig(SIGSEGV, current);
}
/*this function used in little file , only write once.  */
int rdr_append_file(char *filename, void *address, u32 length, u32 max_size)
{
	int ret = 0;
	int fd;
	int bytes;
	int len;
	mm_segment_t old_fs;
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	ret = rdr_create_dir(OM_ROOT_PATH);
	if (0 != ret) {
		pr_err("<%s()>, create dir [%s] failed! ret = %d\n",
				__func__, OM_ROOT_PATH, ret);
		goto out;
	}

	ret = sys_access(filename, 0);
	if (0 != ret) {
		fd = sys_open(filename, O_CREAT | O_RDWR, 0664);/*create file */
		if (fd < 0) {
			pr_err("<%s()>,createOopen fail,r:%d\n",
				__func__, fd);
			goto out;
		}
	} else {
		fd = sys_open(filename, O_APPEND | O_RDWR, 0664);
		if (fd < 0) {
			pr_err("<%s()>,appendOpen failed:r:%d\n", __func__, fd);
			goto out;
		}
	}

	len = sys_lseek(fd, 0, SEEK_END);
	if (len < 0) {
		pr_err("<%s()>, seek failed! ret = %d\n", __func__, len);
		ret = sys_close(fd);
		goto out;
	}

	if (len > max_size) {
		sys_close(fd);
		ret = sys_unlink(filename);
		if (0 != ret) {
			pr_err("<%s()>, remove failed!ret:%d\n", __func__, ret);
			goto out;
		}

		/*rebuild reset file*/
		fd = sys_open(filename, O_CREAT | O_RDWR, 0664);
		if (fd < 0) {
			pr_err("<%s()>, create failed! ret:%d\n", __func__, fd);
			goto out;
		}
	}

	bytes = sys_write(fd, address, length);
	if (bytes != length) {
		pr_err("<%s()>, write data failed! ret:%d\n", __func__, bytes);
		ret = sys_close(fd);
		goto out;
	}

	sys_fsync(fd);
	ret = sys_close(fd);
	if (0 != ret) {
		pr_err("<%s()>, close failed! ret = %d\n", __func__, ret);
		ret = -1;
		goto out;
	}

	ret = 0;

out:
	set_fs(old_fs);
	/*pr_info("rdr: <%s()>, save end. ret = %d\n", __func__, ret);*/
	return ret;
}
void ssp_dump_task(struct work_struct *work) {
#ifdef CONFIG_SENSORS_SSP_BBD
	pr_err("[SSPBBD]:TODO:%s()\n", __func__);
#else

	struct ssp_big *big;
	struct file *dump_file;
	struct ssp_msg *msg;
	char *buffer;
	char strFilePath[60];
	struct timeval cur_time;
	int iTimeTemp;
	mm_segment_t fs;
	int buf_len, packet_len, residue, iRet = 0, index = 0 ,iRetTrans=0 ,iRetWrite=0;

	big = container_of(work, struct ssp_big, work);
	pr_err("[SSP]: %s - start ssp dumping (%d)(%d)\n", __func__,big->data->bMcuDumpMode,big->data->uDumpCnt);
	big->data->uDumpCnt++;
	wake_lock(&big->data->ssp_wake_lock);

	fs = get_fs();
	set_fs(get_ds());

	if(big->data->bMcuDumpMode == true)
	{
		do_gettimeofday(&cur_time);
		iTimeTemp = (int) cur_time.tv_sec;

		sprintf(strFilePath, "%s%d.txt", DUMP_FILE_PATH, iTimeTemp);

		dump_file = filp_open(strFilePath, O_RDWR | O_CREAT | O_APPEND, 0666);
		if (IS_ERR(dump_file)) {
			pr_err("[SSP]: %s - Can't open dump file\n", __func__);
			set_fs(fs);
			iRet = PTR_ERR(dump_file);
			wake_unlock(&big->data->ssp_wake_lock);
			kfree(big);
			return;
		}
	}
	else
		dump_file = NULL;

	buf_len = big->length > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : big->length;
	buffer = kzalloc(buf_len, GFP_KERNEL);
	residue = big->length;

	while (residue > 0) {
		packet_len = residue > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : residue;

		msg = kzalloc(sizeof(*msg), GFP_KERNEL);
		msg->cmd = MSG2SSP_AP_GET_BIG_DATA;
		msg->length = packet_len;
		msg->options = AP2HUB_READ | (index++ << SSP_INDEX);
		msg->data = big->addr;
		msg->buffer = buffer;
		msg->free_buffer = 0;

		iRetTrans = ssp_spi_sync(big->data, msg, 1000);
		if (iRetTrans != SUCCESS) {
			pr_err("[SSP]: %s - Fail to receive data %d (%d)\n", __func__, iRetTrans,residue);
			break;
		}
		if(big->data->bMcuDumpMode == true)
		{
			iRetWrite = vfs_write(dump_file, (char __user *) buffer, packet_len,
				&dump_file->f_pos);
			if (iRetWrite < 0) {
			pr_err("[SSP]: %s - Can't write dump to file\n", __func__);
			break;
			}
		}
		residue -= packet_len;
	}

	if(big->data->bMcuDumpMode == true && (iRetTrans != SUCCESS || iRetWrite < 0) )
	{
		char FAILSTRING[100];
		sprintf(FAILSTRING,"FAIL OCCURED(%d)(%d)(%d)",iRetTrans,iRetWrite,big->length);
		vfs_write(dump_file, (char __user *) FAILSTRING, strlen(FAILSTRING),&dump_file->f_pos);
	}

	big->data->bDumping = false;
	if(big->data->bMcuDumpMode == true)
		filp_close(dump_file, current->files);

	set_fs(fs);

	wake_unlock(&big->data->ssp_wake_lock);
	kfree(buffer);
	kfree(big);

	pr_err("[SSP]: %s done\n", __func__);
#endif
}
int rdr_dir_list(char *path, rdr_funcptr_3 f, u64 arg1, u64 arg2, int *cnt, int type)
{
	int fd = -1, nread, bpos, ret = 0, tmp_cnt = 0;
	char *buf;
	struct linux_dirent *d;
	char d_type;
	mm_segment_t old_fs;
	char fullname[RDR_FNAME_LEN];

	old_fs = get_fs();
	set_fs(KERNEL_DS);

	fd = sys_open(path, O_RDONLY, 0664);/*create file */
	if (fd < 0) {
		pr_err("rdr:%s(),open %s fail,r:%d\n", __func__, path, fd);
		ret = -1;
		goto out;
	}

	buf = vmalloc(RDRDIRSIZ);
	if (buf == NULL) {
		pr_err("rdr:%s():vmalloc failed\n", __func__);
		ret = -1;
		goto out;
	}

	for (;;) {
		nread = sys_getdents(fd, (struct linux_dirent *)buf, RDRDIRSIZ);
		if (nread == -1) {
			pr_err("rdr:%s():sys_getdents failed\n", __func__);
			ret = -1;
			break;
		}

		if (nread == 0) {
			ret = 0;
			break;
		}

		for (bpos = 0; bpos < nread;) {
			d = (struct linux_dirent *)(buf + bpos);
			d_type = *(buf + bpos + d->d_reclen - 1);
			if ((d_type == type) && (f != NULL)) {
				snprintf(fullname, sizeof(fullname), "%s%s", path, d->d_name);
				rdr_debug("fullname:%s", fullname);
				f((u64)fullname, arg1, arg2);
			}
			if (d_type == type)
				tmp_cnt++;
			bpos += d->d_reclen;
		}
	}
	if (cnt != (int *)0)
		*cnt = tmp_cnt;
	vfree(buf);
out:
	if (fd >= 0)
		sys_close(fd);
	set_fs(old_fs);
	return ret;
}
int dhd_write_macaddr(struct ether_addr *mac)
{
	char *filepath_data      = MACINFO;
	char *filepath_efs      = MACINFO_EFS;

	struct file *fp_mac = NULL;
	char buf[18]      = {0};
	mm_segment_t oldfs    = {0};
	int ret = -1;
	int retry_count = 0;

startwrite:

	sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n",
		mac->octet[0], mac->octet[1], mac->octet[2],
		mac->octet[3], mac->octet[4], mac->octet[5]);

	/* File will be created /data/.mac.info. */
	fp_mac = filp_open(filepath_data, O_RDWR | O_CREAT, 0666);

	if (IS_ERR(fp_mac)) {
		DHD_ERROR(("[WIFI] %s: File open error\n", filepath_data));
		return -1;
	} else {
		oldfs = get_fs();
		set_fs(get_ds());

		if (fp_mac->f_mode & FMODE_WRITE) {
			ret = fp_mac->f_op->write(fp_mac, (const char *)buf,
				sizeof(buf), &fp_mac->f_pos);
			if (ret < 0)
				DHD_ERROR(("[WIFI] Mac address [%s] Failed to"
				" write into File: %s\n", buf, filepath_data));
			else
				DHD_INFO(("[WIFI] Mac address [%s] written"
				" into File: %s\n", buf, filepath_data));
		}
		set_fs(oldfs);
		filp_close(fp_mac, NULL);
	}
	/* check .mac.info file is 0 byte */
	fp_mac = filp_open(filepath_data, O_RDONLY, 0);
	ret = kernel_read(fp_mac, 0, buf, 18);

	if ((ret == 0) && (retry_count++ < 3)) {
		filp_close(fp_mac, NULL);
		goto startwrite;
	}

	filp_close(fp_mac, NULL);
	/* end of /data/.mac.info */

	if (filepath_efs == NULL) {
		DHD_ERROR(("[WIFI]%s : no efs filepath", __func__));
		return 0;
	}

	/* File will be created /efs/wifi/.mac.info. */
	fp_mac = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666);

	if (IS_ERR(fp_mac)) {
		DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs));
		return -1;
	} else {
		oldfs = get_fs();
		set_fs(get_ds());

		if (fp_mac->f_mode & FMODE_WRITE) {
			ret = fp_mac->f_op->write(fp_mac, (const char *)buf,
				sizeof(buf), &fp_mac->f_pos);
			if (ret < 0)
				DHD_ERROR(("[WIFI] Mac address [%s] Failed to"
				" write into File: %s\n", buf, filepath_efs));
			else
				DHD_INFO(("[WIFI] Mac address [%s] written"
				" into File: %s\n", buf, filepath_efs));
		}
		set_fs(oldfs);
		filp_close(fp_mac, NULL);
	}

	/* check .mac.info file is 0 byte */
	fp_mac = filp_open(filepath_efs, O_RDONLY, 0);
	ret = kernel_read(fp_mac, 0, buf, 18);

	if ((ret == 0) && (retry_count++ < 3)) {
		filp_close(fp_mac, NULL);
		goto startwrite;
	}

	filp_close(fp_mac, NULL);

	return 0;
}
void rdr_rm_over3_file(char *path)
{
	int ret, i, j;
	mm_segment_t old_fs;
	struct kstat m_stat;
	char fn[RDR_FNAME_LEN];

	char *name_tab;
	size_t tab_siz;
	char *pn;

	if (path == NULL)
		return;
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	pr_info("rdr:%s():begin to del too many dir\n", __func__);
	/* check path , if path isnt exist, return. */
	ret = vfs_stat(path, &m_stat);
	if (ret) {
		rdr_debug("dir not exist, dont upload and archive");
		goto out;
	}
	rdr_dir_list(path, NULL, 0, 0, &ret, DT_DIR);
	rdr_debug("the filefolder in %s dir :%d", path, ret);

	if (ret > 3) {
		tab_siz = ret * RDR_RGZNAME_SZ;
		name_tab = vmalloc(tab_siz);
		if (name_tab == NULL) {
			pr_err("rdr:%s():name_tab alloc fail.\n", __func__);
			goto out;
		}
		memset(name_tab, 0, tab_siz);
		rdr_dir_list(path, (rdr_funcptr_3)rdr_get_timedir_name,
				(u64)name_tab, (u64)ret, (int *)0, DT_DIR);

		for (i = 0; i < ret; i++) {
			pn = name_tab + i * RDR_RGZNAME_SZ;
			if (*pn == '\0')
				break;
			rdr_debug("dir:%s, seq:%d", pn, i);
		}
		rdr_debug("has %d time dir", i);
		if (i > 3) {
			sort(name_tab, i, RDR_RGZNAME_SZ, rdr_cmp, NULL);
			for (j = 0; j < i - 3; j++) {
				pn = name_tab + j * RDR_RGZNAME_SZ;
				snprintf(fn, sizeof(fn), "%s%s/", path, pn);
				pr_info("rdr:rm folder %s and all files\n", fn);
				rdr_dir_list(fn, (rdr_funcptr_3)rdr_rm_file,
							0, 0, (int *)0, DT_REG);
				rdr_rm_dir(fn);
			}
		}

		vfree(name_tab);
	}
out:
	set_fs(old_fs);
}
int dhd_write_rdwr_macaddr(struct ether_addr *mac)
{
	char *filepath_data = MACINFO;
	char *filepath_efs = MACINFO_EFS;
	struct file *fp_mac = NULL;
	char buf[18]      = {0};
	mm_segment_t oldfs    = {0};
	int ret = -1;

	if ((g_imac_flag != MACADDR_COB) && (g_imac_flag != MACADDR_MOD))
		return 0;

	sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n",
		mac->octet[0], mac->octet[1], mac->octet[2],
		mac->octet[3], mac->octet[4], mac->octet[5]);

	/* /efs/wifi/.mac.info will be created */
	fp_mac = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666);
	if (IS_ERR(fp_mac)) {
		DHD_ERROR(("[WIFI] %s: File open error\n", filepath_data));
		return -1;
	}	else {
		oldfs = get_fs();
		set_fs(get_ds());

		if (fp_mac->f_mode & FMODE_WRITE) {
			ret = fp_mac->f_op->write(fp_mac, (const char *)buf,
				sizeof(buf), &fp_mac->f_pos);
			if (ret < 0)
				DHD_ERROR(("[WIFI] Mac address [%s] Failed"
				" to write into File: %s\n", buf, filepath_data));
			else
				DHD_INFO(("[WIFI] Mac address [%s] written"
				" into File: %s\n", buf, filepath_data));
		}
		set_fs(oldfs);
		filp_close(fp_mac, NULL);
	}
	/* /data/.mac.info will be created */
	fp_mac = filp_open(filepath_data, O_RDWR | O_CREAT, 0666);
	if (IS_ERR(fp_mac)) {
		DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs));
		return -1;
	}	else {
		oldfs = get_fs();
		set_fs(get_ds());

		if (fp_mac->f_mode & FMODE_WRITE) {
			ret = fp_mac->f_op->write(fp_mac, (const char *)buf,
				sizeof(buf), &fp_mac->f_pos);
			if (ret < 0)
				DHD_ERROR(("[WIFI] Mac address [%s] Failed"
				" to write into File: %s\n", buf, filepath_efs));
			else
				DHD_INFO(("[WIFI] Mac address [%s] written"
				" into File: %s\n", buf, filepath_efs));
		}
		set_fs(oldfs);
		filp_close(fp_mac, NULL);
	}

	return 0;

}
void rdr_upload(char *path, char *timedir, char *ecore)
{
	int ret, i;
	mm_segment_t old_fs;
	struct kstat m_stat;
	char dst[RDR_FNAME_LEN] = {0};
	char fn[RDR_FNAME_LEN];
	int rdrbin_tag = 0;

	char *name_tab;
	size_t tab_siz;
	char *pn;
	char rgz[RDR_FNAME_LEN];

	if (path == NULL)
		return;
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	/* check path , if path isnt exist, return. */
	ret = vfs_stat(path, &m_stat);
	if (ret) {
		rdr_debug("dir not exist, dont upload and archive");
		goto out;
	}

	/* check rdr/rdx/dfx, select the best one, delete others. */
	snprintf(dst, sizeof(dst), "%s%s/", path, timedir);
	ret = vfs_stat(dst, &m_stat);
	if (ret) {
		rdr_debug("dir %s not exist", dst);
		goto out;
	}
	rdr_dir_list(dst, NULL, 0, 0, &ret, DT_REG);
	if (ret > 1) {
		tab_siz = ret * RDR_RGZNAME_SZ;
		rdr_debug("the files in %s dir :%d", dst, ret);

		name_tab = vmalloc(tab_siz);
		if (name_tab == NULL) {
			pr_err("rdr:%s():name_tab alloc fail.\n", __func__);
			goto out;
		}
		memset(name_tab, 0, tab_siz);
		rdr_dir_list(dst, (rdr_funcptr_3)rdr_get_8m_name,
				(u64)name_tab, (u64)ret, (int *)0, DT_REG);

		for (i = 0; i < ret; i++) {
			pn = name_tab + i * RDR_RGZNAME_SZ;
			if (*pn == '\0')
				break;
			if (!strncmp("rdr.bin", pn, 7)) {
				pr_info("rdr:find rdr.bin, del other bin\n");
				snprintf(fn, sizeof(fn), "%srdx.bin", dst);
				sys_unlink(fn);
				snprintf(fn, sizeof(fn), "%sdfx.bin", dst);
				sys_unlink(fn);
				rdrbin_tag = 1;
				break;
			}
		}
		if (rdrbin_tag == 0) {
			for (i = 0; i < ret; i++) {
				pn = name_tab + i * RDR_RGZNAME_SZ;
				if (*pn == '\0')
					break;
				if (!strncmp("dfx.bin", pn, 7)) {
					pr_info("rdr:find dfx.bin,rm others\n");
					snprintf(fn, sizeof(fn), "%srdx.bin", dst);
					sys_unlink(fn);
					break;
				}
			}
		}
		vfree(name_tab);
	}

	memset(rgz, 0, sizeof(rgz));
	/* zip or upload it. */
#ifdef CONFIG_SRECORDER
	rdr_zip_dir(dst, rgz, sizeof(rgz));
	rdr_create_dir(SRECORDER_PATH);
	rdr_debug("rgz:%s", rgz);
	ret = sys_rename(rgz, SRECORDER_FILE);
	if (ret < 0)
		pr_err("rdr:rename %s to %s failed\n", rgz, SRECORDER_FILE);
#else
	if ((ecore != NULL) &&
		(!strncmp(ecore, RDR_STR_CORE_CP, strlen(RDR_STR_CORE_CP)))) {
		rdr_zip_dir(dst, rgz, sizeof(rgz));
		snprintf(fn, sizeof(fn), "%sup/cp.rgz", OM_ROOT_PATH);
		rdr_create_dir(fn);
		sys_unlink(fn);
		ret = sys_rename(rgz, fn);
		if (ret < 0)
			pr_err("rdr:rename %s to %s failed\n", rgz, fn);
		else
			pr_info("rdr:mv from %s to %s OK\n", rgz, fn);
	}
	rdr_up2apr(dst, ecore);
#endif
	/* if the file counts of path dir over 3, delete it. */
	rdr_rm_over3_file(path);
out:
	set_fs(old_fs);
}
示例#27
0
static void start(struct work_struct *work)
{
	int err,size;
	rrep * tmp_rrep;
	int bufsize = 10;
        unsigned char buf[bufsize+1];
	mm_segment_t oldfs;
	//current->flags |= PF_NOFREEZE;
	//allow_signal(SIGKILL);
	my_work = (my_work_t *)work;
		if ( 
              (err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &my_work->sock_send)) < 0 )
        {
                printk(KERN_INFO MODULE_NAME": Could not create a datagram socket, error = %d\n", -ENXIO);
                return;
        }
	if((tmp_rrep = (rrep *) kmalloc(sizeof(rrep), GFP_ATOMIC)) == NULL)
	{
		printk(KERN_INFO MODULE_NAME": Could not create a datagram socket, error = %d\n", -ENXIO);
		return;
	}
        memset(&my_work->addr, 0, sizeof(struct sockaddr));
        memset(&my_work->addr_send, 0, sizeof(struct sockaddr));
        my_work->addr_send.sin_family = AF_INET;

        //my_work->addr_send.sin_addr.s_addr = htonl(INADDR_SEND);
	my_work->addr_send.sin_addr.s_addr = in_aton("192.168.123.3");
        my_work->addr_send.sin_port = htons(CONNECT_PORT);
	//sock_set_flag(my_work->sock_send,SOCK_BROADCAST);
	if ((err = my_work->sock_send->ops->bind(my_work->sock_send, (struct sockaddr *)&my_work->addr_send, sizeof(struct sockaddr)) < 0 ))
        {
                printk(KERN_INFO MODULE_NAME": Could not bind or connect to socket, error = %d\n", -err);
                goto close_and_out;
        }
	oldfs=get_fs();
	set_fs(KERNEL_DS);
	set_fs(oldfs);
	//printk(KERN_INFO MODULE_NAME": listening on port %d\n", DEFAULT_PORT);
	//for (;;)
        //{
		//printk(KERN_INFO MODULE_NAME"Inside for loop\n");
                //memset(&buf, 0, bufsize+1);
                //size = receive(my_work->sock, &my_work->addr, buf, bufsize);
		//if (signal_pending(current))
                  //      break;
		//printk("\nsize=%d",size);
                

                        

                        
                        
                        strcpy(tmp_rrep->type, "BROADCAST MESSAGE SENT");
			printk(KERN_INFO MODULE_NAME":String Value:%s",tmp_rrep->type);
                        send(my_work->sock_send, &my_work->addr_send, tmp_rrep, sizeof(rrep));
			kfree(tmp_rrep);
			msleep(500);
        //}

close_and_out:
        sock_release(my_work->sock_send);
        my_work->sock = NULL;
        my_work->sock_send = NULL;

}
void rdr_upload_and_archive(char *path, char *timedir, char *ecore)
{
	int ret, i, j;
	mm_segment_t old_fs;
	struct kstat m_stat;
	char dst[RDR_FNAME_LEN] = {0};
	char rgz[RDR_ZIP_FNAME_LEN];
	char dstname[RDR_ZIP_FNAME_LEN];
	char pjname[RDR_ZIP_FNAME_LEN];
	char *name;

	if (path == NULL)
		return;
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	/* check path , if path isnt exist, return. */
	ret = vfs_stat(path, &m_stat);
	if (ret) {
		rdr_debug("dir not exist, dont upload and archive");
		goto out;
	}

	/* prepare dest dir : upload */
	snprintf(dst, RDR_FNAME_LEN, "%sup/", path);
	rdr_create_dir(dst);
	/* Maybe up dir has already existed and has some files.so delete it. */
	rdr_dir_list(dst, (rdr_funcptr_3)rdr_rm_file, 0, 0, (int *)0, DT_REG);

	/* find dfx/rdr/rdx file and mov to up dir */
	rdr_dir_list(path, (rdr_funcptr_3)rdr_mov2up, (u64)dst, 0, (int *)0, DT_REG);
	rdr_dir_list(dst, NULL, 0, 0, &ret, DT_REG);
	if (ret > 1) {
		char *name_tab;
		size_t tab_siz = ret * RDR_RGZNAME_SZ;
		rdr_debug("the files in up dir :%d", ret);

		name_tab = vmalloc(tab_siz);
		if (name_tab == NULL) {
			pr_err("rdr:%s():name_tab alloc fail.\n", __func__);
			goto out;
		}
		memset(name_tab, 0, tab_siz);
		rdr_dir_list(dst, (rdr_funcptr_3)rdr_getname,
				(u64)name_tab, (u64)ret, (int *)0, DT_REG);
		sort(name_tab, ret, RDR_RGZNAME_SZ, rdr_cmp, NULL);

		for (i = 0; i < ret; i++) {
			for (j = i + 1; j < ret; j++) {
				char *mi = name_tab + RDR_RGZNAME_SZ * i;
				char *mj = name_tab + RDR_RGZNAME_SZ * j;
				char *pi = rdr_get_mainname(mi, dstname,
							RDR_ZIP_FNAME_LEN);
				char *pj = rdr_get_mainname(mj, pjname,
							RDR_ZIP_FNAME_LEN);
				char *fi = rdr_get_file_postfix(mi);
				char *fj = rdr_get_file_postfix(mj);
				if ((pi == NULL) || (pj == NULL) || (fi == NULL)
					|| (fj == NULL))
					continue;
				rdr_debug("cmp filename:pi:%s,pj:%s", pi, pj);
				if (!strncmp(pi, pj, RDR_RGZNAME_SZ)) {
					if (!strncmp(fi, "rdr", 3) ||
						(!strncmp(fi, "dfx", 3) &&
						!strncmp(fj, "rdx", 3)))
						strnswp(mi, mj, RDR_RGZNAME_SZ);
					snprintf(rgz, RDR_ZIP_FNAME_LEN, "%s%s",
						dst, mi);
					rdr_debug("del same file: %s", rgz);
					sys_unlink(rgz);
				}
			}
		}

		vfree(name_tab);
	} else if (ret == 0) {
		rdr_debug("up dir has no file, return");
		return;
	}

	/* zip upload dir */
	memset(rgz, 0, sizeof(rgz));
	rdr_zip_dir(dst, rgz, sizeof(rgz));

	/* delete up dfx/rdr/rdx file in up, and the file that size is 0 */
	rdr_dir_list(dst, (rdr_funcptr_3)rdr_rm_8m0, 0, 0, (int *)0, DT_REG);

	/* cp zip from up to bk dir */
	snprintf(dst, RDR_FNAME_LEN, "%sbk/", path);
	rdr_create_dir(dst);
	name = rdr_get_file_name(rgz);
	snprintf(dstname, RDR_ZIP_FNAME_LEN, "%s%s", dst, name);
	rdr_copy_file(dstname, rgz);
	pr_info("rdr:%s:copy last words to %s OK!\n", __func__, dstname);

	snprintf(dst, RDR_FNAME_LEN, "%sup/", path);
#ifdef CONFIG_SRECORDER
	/* cp zip to srecorder dir */
	rdr_create_dir(SRECORDER_PATH);
	/*snprintf(dstname, RDR_ZIP_FNAME_LEN, "%s%s", SRECORDER_PATH, name);*/
	ret = rdr_copy_file(SRECORDER_FILE, rgz);
	if (ret != 0)
		pr_err("rdr:%s():cp to srecorder fail,ret:%d\n", __func__, ret);
	rdr_debug("copy to srecorder dir ok");
	rdr_dir_list(dst, (rdr_funcptr_3)rdr_rm_file, 0, 0, (int *)0, DT_REG);
#else
	/* upload rgz in up dir and delete */
	rdr_up2apr(dst, ecore);
	/*not delete up now, we'll del it nexttime for log_exception is async */
	/*rdr_dir_list(dst, (rdr_funcptr_3)rdr_rm_file, 0, 0, (int *)0, DT_REG);*/
#endif
	/*rdr_rm_dir(dst); NOTE:up dir is offen used, so dont delete it. */

	/* check bk dir, delete extra file. */
	snprintf(dst, RDR_FNAME_LEN, "%sbk/", path);
	rdr_dir_list(dst, NULL, 0, 0, &ret, DT_REG);
	if (ret > 3) {
		char *rgz_name_tab;
		size_t tab_siz = ret * RDR_RGZNAME_SZ;
		rdr_debug("the files cnt in bk dir :%d", ret);

		rgz_name_tab = vmalloc(tab_siz);
		if (rgz_name_tab == NULL) {
			pr_err("rdr:%s():rgz_name_tab alloc fail.\n", __func__);
			goto out;
		}
		memset(rgz_name_tab, 0, tab_siz);
		rdr_dir_list(dst, (rdr_funcptr_3)rdr_getname,
				(u64)rgz_name_tab, (u64)ret, (int *)0, DT_REG);
		sort(rgz_name_tab, ret, RDR_RGZNAME_SZ, rdr_cmp, NULL);

		for (i = 0; i < (ret - 3); i++) {
			snprintf(rgz, RDR_ZIP_FNAME_LEN, "%s%s",
				dst, rgz_name_tab + RDR_RGZNAME_SZ * i);
			rdr_debug("del %s", rgz);
			sys_unlink(rgz);
		}

		vfree(rgz_name_tab);
	}

out:
	set_fs(old_fs);
}
static void last_kmsg_work_function(struct work_struct *dat)
{
	char *buffer;
	struct file *fp;
	struct file *fp_proc;
	struct file *fp_mounts;
	mm_segment_t old_fs;
	ssize_t result;
	//**************************************
	//mmcblk0p8 just for t30 branch
	//**************************************
	char mount_point[32] = "mmcblk0p8";
	#define PMC_RST_STATUS_WDT (1)
	#define PMC_RST_STATUS_SW   (3)

	printk(KERN_INFO "dump last_kmsg starting\n");

	buffer=kmalloc(SZ_1M, GFP_KERNEL);
	memset(buffer, 0, SZ_1M);

	if(!buffer){
		printk(KERN_INFO "last_kmsg_work_function:alloc buffer fail!\n");
		return;
	}

	if (last_kmsg_log_filename() < 0){
		printk(KERN_INFO "%s folder doesn't exist, and create fail !\n", DATA_LOGS);
		kfree(buffer);
		return ;
	}

	old_fs = get_fs();
	set_fs(KERNEL_DS);

	while(1)
	{
		fp_mounts = filp_open("/proc/mounts" , O_RDONLY, 0);
		if (PTR_ERR(fp_mounts) == -ENOENT)
		{
			printk(KERN_INFO "last_kmsg_work_function:open /proc/mounts fail!\n");
			msleep(1000);
		}
		else
		{
			vfs_read(fp_mounts, buffer, SZ_1M, &fp_mounts->f_pos);

			if(!strstr(buffer, mount_point))
			{
				printk(KERN_INFO "last_kmsg_work_function:mmcblk0p8 was not mounted yet!\n");
				filp_close(fp_mounts,NULL);
				msleep(1000);
			}
			else
			{
				break;
			}
		}
	}

	memset(buffer, 0, SZ_1M);

	last_kmsg_get_time();
	strcat(rd_log_file, rd_kernel_time);

	if (boot_reason==PMC_RST_STATUS_WDT)
	{
		strcat(rd_log_file,".log_wdt");
	}
	else if (boot_reason==PMC_RST_STATUS_SW )
	{
		strcat(rd_log_file,".log_SwReboot");
	}
	else
	{
		strcat(rd_log_file,".log_normal");
	}

	fp_proc = filp_open("/proc/last_kmsg" , O_RDONLY, 0);
	if (PTR_ERR(fp_proc) == -ENOENT)
	{
		printk(KERN_INFO "last_kmsg_work_function:last_kmsg is empty!\n");
		filp_close(fp_mounts,NULL);
		set_fs(old_fs);
		kfree(buffer);
		return ;
	}

	fp = filp_open(rd_log_file , O_APPEND | O_RDWR | O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
	if (PTR_ERR(fp) == -ENOENT)
	{
		printk(KERN_INFO "last_kmsg_work_function:open log file fail!\n");
		filp_close(fp_mounts,NULL);
		filp_close(fp_proc,NULL);
		set_fs(old_fs);
		kfree(buffer);
		return ;
	}

	result=vfs_read(fp_proc, buffer, SZ_1M, &fp_proc->f_pos);
	if( result < 0 )
	{
		printk(KERN_INFO "last_kmsg_work_function:read last_kmsg fail!\n");
	}
	else
	{
		result=vfs_write(fp, buffer, result, &fp->f_pos);
		if( result < 0 )
			printk(KERN_INFO "last_kmsg_work_function:write last_kmsg fail!\n");
	}

	filp_close(fp_mounts,NULL);
	filp_close(fp_proc,NULL);
	filp_close(fp,NULL);
	set_fs(old_fs);
	kfree(buffer);
	printk(KERN_INFO "last_kmsg file: %s\n", rd_log_file);
	return;

}
int mDNIe_txtbuf_to_parsing(char const*  pFilepath)
{
	struct file *filp;
	char	*dp;
	long	l;
	loff_t  pos;
	int     ret, num;
	mm_segment_t fs;

	mutex_lock(&mdnie_use);

	fs = get_fs();
	set_fs(get_ds());

	if(!pFilepath){
		printk("Error : mDNIe_txtbuf_to_parsing has invalid filepath. \n");
		goto parse_err;
	}

	filp = filp_open(pFilepath, O_RDONLY, 0);

	if (IS_ERR(filp)) {
		printk("file open error:%d\n", (s32)filp);
		goto parse_err;
	}

	l = filp->f_path.dentry->d_inode->i_size;
	dp = kmalloc(l+10, GFP_KERNEL);		/* add cushion : origianl code is 'dp = kmalloc(l, GFP_KERNEL);' */
	if (dp == NULL) {
		printk(KERN_INFO "Out of Memory!\n");
		filp_close(filp, current->files);
		goto parse_err;
	}
	pos = 0;
	memset(dp, 0, l);
	ret = vfs_read(filp, (char __user *)dp, l, &pos);   /* P1_LSJ : DE08 : died at here  */

	if (ret != l) {
		printk(KERN_INFO "<CMC623> Failed to read file (ret = %d)\n", ret);
		kfree(dp);
		filp_close(filp, current->files);
		goto parse_err;
	}

	filp_close(filp, current->files);
	set_fs(fs);
	num = parse_text(dp, l);
	if (!num) {
		printk("Nothing to parse!\n");
		kfree(dp);
		goto parse_err;
	}

	mDNIe_data[num] = END_SEQ;
	mDNIe_Tuning_Mode = TRUE;
	mDNIe_tuning_set();

	kfree(dp);

	mutex_unlock(&mdnie_use);
	return (num / 2);

parse_err:
	mutex_unlock(&mdnie_use);
	return -1;
}