software/drivers/sd8887/src/wlan/mlinux/moal_priv.c
/**
 * @brief Configure sleep parameters
 *
 * @param priv         A pointer to moal_private structure
 * @param wrq         A pointer to iwreq structure
 *
 * @return             0 --success, otherwise fail
 */
@brief Configure sleep parameters
@param priv         A pointer to moal_private structure
@param wrq         A pointer to iwreq structure

@return             0 --success, otherwise fail
@brief Configure sleep parameters @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return 0 -- success otherwise fail
static int
woal_sleep_params_ioctl(moal_private *priv, struct iwreq *wrq)
{
	int ret = 0;
	mlan_ioctl_req *req = NULL;
	mlan_ds_pm_cfg *pm = NULL;
	mlan_ds_sleep_params *psleep_params = NULL;
	int data[6] = { 0 }, i, copy_len;
	int data_length = wrq->u.data.length;
#ifdef DEBUG_LEVEL1
	char err_str[][36] = { {"sleep clock error in ppm"},
	{"wakeup offset in usec"},
	{"clock stabilization time in usec"},
	{"control periodic calibration(0-2)"},
	{"control of external sleepClock(0-2)"},
	{"value of reserved for debug"}
	};
#endif
	mlan_status status = MLAN_STATUS_SUCCESS;
	ENTER();
	copy_len = MIN(sizeof(data), sizeof(int) * data_length);
	req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_pm_cfg));
	if (req == NULL) {
		LEAVE();
		return -ENOMEM;
	}
	pm = (mlan_ds_pm_cfg *)req->pbuf;
	pm->sub_command = MLAN_OID_PM_CFG_SLEEP_PARAMS;
	req->req_id = MLAN_IOCTL_PM_CFG;
	psleep_params = (pmlan_ds_sleep_params)&pm->param.sleep_params;
	if (data_length == 0) {
		req->action = MLAN_ACT_GET;
	} else if (data_length == 6) {
		if (copy_from_user(data, wrq->u.data.pointer, copy_len)) {
			PRINTM(MERROR, "S_PARAMS: copy from user failed\n");
			ret = -EINVAL;
			goto done;
		}
#define MIN_VAL 0x0000
#define MAX_VAL 0xFFFF
		for (i = 0; i < 6; i++) {
			if ((i == 3) || (i == 4)) {
				continue;
			}
			if (data[i] < MIN_VAL || data[i] > MAX_VAL) {
				PRINTM(MERROR, "Invalid %s (0-65535)!\n",
				       err_str[i]);
				ret = -EINVAL;
				goto done;
			}
		}
		if (data[3] < 0 || data[3] > 2) {
			PRINTM(MERROR,
			       "Invalid control periodic calibration (0-2)!\n");
			ret = -EINVAL;
			goto done;
		}
		if (data[4] < 0 || data[4] > 2) {
			PRINTM(MERROR,
			       "Invalid control of external sleep clock (0-2)!\n");
			ret = -EINVAL;
			goto done;
		}
		req->action = MLAN_ACT_SET;
		psleep_params->error = data[0];
		psleep_params->offset = data[1];
		psleep_params->stable_time = data[2];
		psleep_params->cal_control = data[3];
		psleep_params->ext_sleep_clk = data[4];
		psleep_params->reserved = data[5];
	} else {
		ret = -EINVAL;
		goto done;
	}
	status = woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT);
	if (status != MLAN_STATUS_SUCCESS) {
		ret = -EFAULT;
		goto done;
	}
	data[0] = psleep_params->error;
	data[1] = psleep_params->offset;
	data[2] = psleep_params->stable_time;
	data[3] = psleep_params->cal_control;
	data[4] = psleep_params->ext_sleep_clk;
	data[5] = psleep_params->reserved;
	wrq->u.data.length = 6;
	if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) *
			 wrq->u.data.length)) {
		PRINTM(MERROR, "QCONFIG: copy to user failed\n");
		ret = -EFAULT;
		goto done;
	}
done:
	if (status != MLAN_STATUS_PENDING)
		kfree(req);
	LEAVE();
	return ret;
}
static int woal_sleep_params_ioctl ( moal_private * priv , struct iwreq * wrq ) { int ret = 0 ; mlan_ioctl_req * req = NULL ; mlan_ds_pm_cfg * pm = NULL ; mlan_ds_sleep_params * psleep_params = NULL ; int data [ 6 ] = { 0 } , i , copy_len ; int data_length = wrq -> u . data . length ; #ifdef DEBUG_LEVEL1 char err_str [ ] [ 36 ] = { { " " } , { " " } , { " " } , { " " } , { " " } , { " " } } ; #endif mlan_status status = MLAN_STATUS_SUCCESS ; ENTER ( ) ; copy_len = MIN ( sizeof ( data ) , sizeof ( int ) * data_length ) ; req = woal_alloc_mlan_ioctl_req ( sizeof ( mlan_ds_pm_cfg ) ) ; if ( req == NULL ) { LEAVE ( ) ; return - ENOMEM ; } pm = ( mlan_ds_pm_cfg * ) req -> pbuf ; pm -> sub_command = MLAN_OID_PM_CFG_SLEEP_PARAMS ; req -> req_id = MLAN_IOCTL_PM_CFG ; psleep_params = ( pmlan_ds_sleep_params ) & pm -> param . sleep_params ; if ( data_length == 0 ) { req -> action = MLAN_ACT_GET ; } else if ( data_length == 6 ) { if ( copy_from_user ( data , wrq -> u . data . pointer , copy_len ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } #define MIN_VAL  0x0000 #define MAX_VAL  0xFFFF for ( i = 0 ; i < 6 ; i ++ ) { if ( ( i == 3 ) || ( i == 4 ) ) { continue ; } if ( data [ i ] < MIN_VAL || data [ i ] > MAX_VAL ) { PRINTM ( MERROR , " \n " , err_str [ i ] ) ; ret = - EINVAL ; goto done ; } } if ( data [ 3 ] < 0 || data [ 3 ] > 2 ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( data [ 4 ] < 0 || data [ 4 ] > 2 ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } req -> action = MLAN_ACT_SET ; psleep_params -> error = data [ 0 ] ; psleep_params -> offset = data [ 1 ] ; psleep_params -> stable_time = data [ 2 ] ; psleep_params -> cal_control = data [ 3 ] ; psleep_params -> ext_sleep_clk = data [ 4 ] ; psleep_params -> reserved = data [ 5 ] ; } else { ret = - EINVAL ; goto done ; } status = woal_request_ioctl ( priv , req , MOAL_IOCTL_WAIT ) ; if ( status != MLAN_STATUS_SUCCESS ) { ret = - EFAULT ; goto done ; } data [ 0 ] = psleep_params -> error ; data [ 1 ] = psleep_params -> offset ; data [ 2 ] = psleep_params -> stable_time ; data [ 3 ] = psleep_params -> cal_control ; data [ 4 ] = psleep_params -> ext_sleep_clk ; data [ 5 ] = psleep_params -> reserved ; wrq -> u . data . length = 6 ; if ( copy_to_user ( wrq -> u . data . pointer , data , sizeof ( int ) * wrq -> u . data . length ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } done : if ( status != MLAN_STATUS_PENDING ) kfree ( req ) ; LEAVE ( ) ; return ret ; }
@brief Configure sleep parameters
 @param priv         A pointer to moal_private structure
 @param wrq         A pointer to iwreq structure
@brief Configure sleep parameters @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure
/* copy_from_user failed  */ /* These two cases are handled below the loop */