software/drivers/sd8887/src/wlan/mlinux/moal_priv.c
/**
 *  @brief Set/Get Host Sleep configuration
 *
 *  @param priv             A pointer to moal_private structure
 *  @param wrq              A pointer to iwreq structure
 *  @param invoke_hostcmd   MTRUE --invoke HostCmd, otherwise MFALSE
 *
 *  @return                 0 --success, otherwise fail
 */
@brief Set/Get Host Sleep configuration
@param priv             A pointer to moal_private structure
@param wrq              A pointer to iwreq structure
@param invoke_hostcmd   MTRUE --invoke HostCmd, otherwise MFALSE

@return                 0 --success, otherwise fail
@brief Set / Get Host Sleep configuration @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @param invoke_hostcmd MTRUE -- invoke HostCmd otherwise MFALSE @return 0 -- success otherwise fail
static int
woal_hs_cfg(moal_private *priv, struct iwreq *wrq, BOOLEAN invoke_hostcmd)
{
	int data[3], copy_len;
	int ret = 0;
	mlan_ds_hs_cfg hscfg;
	t_u16 action;
	mlan_bss_info bss_info;
	int data_length = wrq->u.data.length;
	ENTER();
	memset(data, 0, sizeof(data));
	memset(&hscfg, 0, sizeof(mlan_ds_hs_cfg));
	copy_len = MIN(sizeof(data), sizeof(int) * data_length);
	if (data_length == 0) {
		action = MLAN_ACT_GET;
	} else {
		action = MLAN_ACT_SET;
		if (data_length >= 1 && data_length <= 3) {
			if (copy_from_user(data, wrq->u.data.pointer, copy_len)) {
				PRINTM(MERROR, "Copy from user failed\n");
				ret = -EFAULT;
				goto done;
			}
		} else {
			PRINTM(MERROR, "Invalid arguments\n");
			ret = -EINVAL;
			goto done;
		}
	}
	if (data_length &&
	    (data[0] != HOST_SLEEP_CFG_CANCEL || invoke_hostcmd == MFALSE)) {
		memset(&bss_info, 0, sizeof(bss_info));
		woal_get_bss_info(priv, MOAL_IOCTL_WAIT, &bss_info);
		if (bss_info.is_hs_configured) {
			PRINTM(MERROR, "HS already configured\n");
			ret = -EFAULT;
			goto done;
		}
	}
	if (data_length >= 1 && data_length < 3) {
		woal_set_get_hs_params(priv, MLAN_ACT_GET, MOAL_IOCTL_WAIT,
				       &hscfg);
	}
	if (data_length)
		hscfg.conditions = data[0];
	if (data_length >= 2)
		hscfg.gpio = data[1];
	if (data_length == 3)
		hscfg.gap = data[2];
	if ((invoke_hostcmd == MTRUE) && (action == MLAN_ACT_SET)) {
		hscfg.is_invoke_hostcmd = MFALSE;
		if (MLAN_STATUS_SUCCESS !=
		    woal_set_get_hs_params(priv, MLAN_ACT_SET, MOAL_IOCTL_WAIT,
					   &hscfg)) {
			ret = -EFAULT;
			goto done;
		}
	}
	hscfg.is_invoke_hostcmd = invoke_hostcmd;
	if (MLAN_STATUS_SUCCESS !=
	    woal_set_get_hs_params(priv, action, MOAL_IOCTL_WAIT, &hscfg)) {
		ret = -EFAULT;
		goto done;
	}
	if (action == MLAN_ACT_GET) {
		data[0] = hscfg.conditions;
		data[1] = hscfg.gpio;
		data[2] = hscfg.gap;
		wrq->u.data.length = 3;
		if (copy_to_user
		    (wrq->u.data.pointer, data,
		     sizeof(int) * wrq->u.data.length)) {
			PRINTM(MERROR, "Copy to user failed\n");
			ret = -EFAULT;
			goto done;
		}
	}
done:
	LEAVE();
	return ret;
}
static int woal_hs_cfg ( moal_private * priv , struct iwreq * wrq , BOOLEAN invoke_hostcmd ) { int data [ 3 ] , copy_len ; int ret = 0 ; mlan_ds_hs_cfg hscfg ; t_u16 action ; mlan_bss_info bss_info ; int data_length = wrq -> u . data . length ; ENTER ( ) ; memset ( data , 0 , sizeof ( data ) ) ; memset ( & hscfg , 0 , sizeof ( mlan_ds_hs_cfg ) ) ; copy_len = MIN ( sizeof ( data ) , sizeof ( int ) * data_length ) ; if ( data_length == 0 ) { action = MLAN_ACT_GET ; } else { action = MLAN_ACT_SET ; if ( data_length >= 1 && data_length <= 3 ) { if ( copy_from_user ( data , wrq -> u . data . pointer , copy_len ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } } else { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } } if ( data_length && ( data [ 0 ] != HOST_SLEEP_CFG_CANCEL || invoke_hostcmd == MFALSE ) ) { memset ( & bss_info , 0 , sizeof ( bss_info ) ) ; woal_get_bss_info ( priv , MOAL_IOCTL_WAIT , & bss_info ) ; if ( bss_info . is_hs_configured ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } } if ( data_length >= 1 && data_length < 3 ) { woal_set_get_hs_params ( priv , MLAN_ACT_GET , MOAL_IOCTL_WAIT , & hscfg ) ; } if ( data_length ) hscfg . conditions = data [ 0 ] ; if ( data_length >= 2 ) hscfg . gpio = data [ 1 ] ; if ( data_length == 3 ) hscfg . gap = data [ 2 ] ; if ( ( invoke_hostcmd == MTRUE ) && ( action == MLAN_ACT_SET ) ) { hscfg . is_invoke_hostcmd = MFALSE ; if ( MLAN_STATUS_SUCCESS != woal_set_get_hs_params ( priv , MLAN_ACT_SET , MOAL_IOCTL_WAIT , & hscfg ) ) { ret = - EFAULT ; goto done ; } } hscfg . is_invoke_hostcmd = invoke_hostcmd ; if ( MLAN_STATUS_SUCCESS != woal_set_get_hs_params ( priv , action , MOAL_IOCTL_WAIT , & hscfg ) ) { ret = - EFAULT ; goto done ; } if ( action == MLAN_ACT_GET ) { data [ 0 ] = hscfg . conditions ; data [ 1 ] = hscfg . gpio ; data [ 2 ] = hscfg . gap ; wrq -> u . data . length = 3 ; if ( copy_to_user ( wrq -> u . data . pointer , data , sizeof ( int ) * wrq -> u . data . length ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } } done : LEAVE ( ) ; return ret ; }
@brief Set/Get Host Sleep configuration
  @param priv             A pointer to moal_private structure
  @param wrq              A pointer to iwreq structure
  @param invoke_hostcmd   MTRUE --invoke HostCmd, otherwise MFALSE
@brief Set / Get Host Sleep configuration @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @param invoke_hostcmd MTRUE -- invoke HostCmd otherwise MFALSE
/* HS config is blocked if HS is already activated */ /* Do a GET first if some arguments are not provided */ /* Need to issue an extra IOCTL first to set up parameters */