software/drivers/sd8887/src/wlan/mlinux/moal_ioctl.c
/**
 *  @brief host command ioctl function
 *
 *  @param priv     A pointer to moal_private structure
 *  @param wrq      A pointer to iwreq structure
 *  @return         0 --success, otherwise fail
 */
@brief host command ioctl function
@param priv     A pointer to moal_private structure
@param wrq      A pointer to iwreq structure
@return         0 --success, otherwise fail
@brief host command ioctl function @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return 0 -- success otherwise fail
int
woal_host_command(moal_private *priv, struct iwreq *wrq)
{
	HostCmd_Header cmd_header;
	int ret = 0;
	mlan_ds_misc_cfg *misc = NULL;
	mlan_ioctl_req *req = NULL;
	mlan_status status = MLAN_STATUS_SUCCESS;
	ENTER();
	if (wrq->u.data.pointer == NULL) {
		PRINTM(MERROR, "hostcmd IOCTL corrupt data\n");
		ret = -EINVAL;
		goto done;
	}
	req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_misc_cfg));
	if (req == NULL) {
		ret = -ENOMEM;
		goto done;
	}
	misc = (mlan_ds_misc_cfg *)req->pbuf;
	memset(&cmd_header, 0, sizeof(cmd_header));
	if (copy_from_user
	    (&cmd_header, wrq->u.data.pointer, sizeof(HostCmd_Header))) {
		PRINTM(MERROR, "copy from user failed: Host command header\n");
		ret = -EFAULT;
		goto done;
	}
	misc->param.hostcmd.len = woal_le16_to_cpu(cmd_header.size);
	PRINTM(MINFO, "Host command len = %u\n", misc->param.hostcmd.len);
	if (!misc->param.hostcmd.len ||
	    misc->param.hostcmd.len > MRVDRV_SIZE_OF_CMD_BUFFER) {
		PRINTM(MERROR, "Invalid data buffer length\n");
		ret = -EINVAL;
		goto done;
	}
	if (copy_from_user
	    (misc->param.hostcmd.cmd, wrq->u.data.pointer,
	     woal_le16_to_cpu(cmd_header.size))) {
		PRINTM(MERROR, "copy from user failed\n");
		ret = -EFAULT;
		goto done;
	}
	misc->sub_command = MLAN_OID_MISC_HOST_CMD;
	req->req_id = MLAN_IOCTL_MISC_CFG;
	status = woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT);
	if (status != MLAN_STATUS_SUCCESS) {
		ret = -EFAULT;
		goto done;
	}
	if (copy_to_user
	    (wrq->u.data.pointer, (t_u8 *)misc->param.hostcmd.cmd,
	     misc->param.hostcmd.len)) {
		ret = -EFAULT;
		goto done;
	}
	wrq->u.data.length = misc->param.hostcmd.len;
done:
	if (status != MLAN_STATUS_PENDING)
		kfree(req);
	LEAVE();
	return ret;
}
int woal_host_command ( moal_private * priv , struct iwreq * wrq ) { HostCmd_Header cmd_header ; int ret = 0 ; mlan_ds_misc_cfg * misc = NULL ; mlan_ioctl_req * req = NULL ; mlan_status status = MLAN_STATUS_SUCCESS ; ENTER ( ) ; if ( wrq -> u . data . pointer == NULL ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } req = woal_alloc_mlan_ioctl_req ( sizeof ( mlan_ds_misc_cfg ) ) ; if ( req == NULL ) { ret = - ENOMEM ; goto done ; } misc = ( mlan_ds_misc_cfg * ) req -> pbuf ; memset ( & cmd_header , 0 , sizeof ( cmd_header ) ) ; if ( copy_from_user ( & cmd_header , wrq -> u . data . pointer , sizeof ( HostCmd_Header ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } misc -> param . hostcmd . len = woal_le16_to_cpu ( cmd_header . size ) ; PRINTM ( MINFO , " \n " , misc -> param . hostcmd . len ) ; if ( ! misc -> param . hostcmd . len || misc -> param . hostcmd . len > MRVDRV_SIZE_OF_CMD_BUFFER ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( copy_from_user ( misc -> param . hostcmd . cmd , wrq -> u . data . pointer , woal_le16_to_cpu ( cmd_header . size ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } misc -> sub_command = MLAN_OID_MISC_HOST_CMD ; req -> req_id = MLAN_IOCTL_MISC_CFG ; status = woal_request_ioctl ( priv , req , MOAL_IOCTL_WAIT ) ; if ( status != MLAN_STATUS_SUCCESS ) { ret = - EFAULT ; goto done ; } if ( copy_to_user ( wrq -> u . data . pointer , ( t_u8 * ) misc -> param . hostcmd . cmd , misc -> param . hostcmd . len ) ) { ret = - EFAULT ; goto done ; } wrq -> u . data . length = misc -> param . hostcmd . len ; done : if ( status != MLAN_STATUS_PENDING ) kfree ( req ) ; LEAVE ( ) ; return ret ; }
@brief host command ioctl function
  @param priv     A pointer to moal_private structure
  @param wrq      A pointer to iwreq structure
  @return         0 --success, otherwise fail
@brief host command ioctl function @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return 0 -- success otherwise fail
/* Sanity check */ /* get command header */ /* get the whole command from user */