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

@return         0 --success, otherwise fail
@brief Set / Get scan configuration parameters @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return 0 -- success otherwise fail
static int
woal_set_get_scan_cfg(moal_private *priv, struct iwreq *wrq)
{
	int ret = 0;
	int data[7], copy_len;
	mlan_ds_scan *scan = NULL;
	mlan_ioctl_req *req = NULL;
	int data_length = wrq->u.data.length;
	mlan_status status = MLAN_STATUS_SUCCESS;
	int arg_len = 0;
	ENTER();
	arg_len = 7;
	copy_len = MIN(sizeof(data), sizeof(int) * data_length);
	req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_scan));
	if (req == NULL) {
		ret = -ENOMEM;
		goto done;
	}
	if (data_length > arg_len) {
		ret = -EINVAL;
		goto done;
	}
	scan = (mlan_ds_scan *)req->pbuf;
	scan->sub_command = MLAN_OID_SCAN_CONFIG;
	req->req_id = MLAN_IOCTL_SCAN;
	memset(data, 0, sizeof(data));
	if (data_length) {
		if (copy_from_user(data, wrq->u.data.pointer, copy_len)) {
			PRINTM(MERROR, "Copy from user failed\n");
			ret = -EFAULT;
			goto done;
		}
		if ((data[0] < 0) || (data[0] > MLAN_SCAN_TYPE_PASSIVE)) {
			PRINTM(MERROR, "Invalid argument for scan type\n");
			ret = -EINVAL;
			goto done;
		}
		if ((data[1] < 0) || (data[1] > MLAN_SCAN_MODE_ANY)) {
			PRINTM(MERROR, "Invalid argument for scan mode\n");
			ret = -EINVAL;
			goto done;
		}
		if ((data[2] < 0) || (data[2] > MAX_PROBES)) {
			PRINTM(MERROR, "Invalid argument for scan probes\n");
			ret = -EINVAL;
			goto done;
		}
		if (((data[3] < 0) ||
		     (data[3] > MRVDRV_MAX_ACTIVE_SCAN_CHAN_TIME)) ||
		    ((data[4] < 0) ||
		     (data[4] > MRVDRV_MAX_ACTIVE_SCAN_CHAN_TIME)) ||
		    ((data[5] < 0) ||
		     (data[5] > MRVDRV_MAX_PASSIVE_SCAN_CHAN_TIME))) {
			PRINTM(MERROR, "Invalid argument for scan time\n");
			ret = -EINVAL;
			goto done;
		}
		if ((data[6] < 0) || (data[6] > 1)) {
			PRINTM(MERROR, "Invalid argument for extended scan\n");
			ret = -EINVAL;
			goto done;
		}
		req->action = MLAN_ACT_SET;
		memcpy(&scan->param.scan_cfg, data, sizeof(data));
	} else
		req->action = MLAN_ACT_GET;
	status = woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT);
	if (status != MLAN_STATUS_SUCCESS) {
		ret = -EFAULT;
		goto done;
	}
	if (!data_length) {
		memcpy(data, &scan->param.scan_cfg, sizeof(data));
		if (copy_to_user(wrq->u.data.pointer, data, sizeof(data))) {
			ret = -EFAULT;
			goto done;
		}
		wrq->u.data.length = arg_len;
	}
done:
	if (status != MLAN_STATUS_PENDING)
		kfree(req);
	LEAVE();
	return ret;
}
static int woal_set_get_scan_cfg ( moal_private * priv , struct iwreq * wrq ) { int ret = 0 ; int data [ 7 ] , copy_len ; mlan_ds_scan * scan = NULL ; mlan_ioctl_req * req = NULL ; int data_length = wrq -> u . data . length ; mlan_status status = MLAN_STATUS_SUCCESS ; int arg_len = 0 ; ENTER ( ) ; arg_len = 7 ; copy_len = MIN ( sizeof ( data ) , sizeof ( int ) * data_length ) ; req = woal_alloc_mlan_ioctl_req ( sizeof ( mlan_ds_scan ) ) ; if ( req == NULL ) { ret = - ENOMEM ; goto done ; } if ( data_length > arg_len ) { ret = - EINVAL ; goto done ; } scan = ( mlan_ds_scan * ) req -> pbuf ; scan -> sub_command = MLAN_OID_SCAN_CONFIG ; req -> req_id = MLAN_IOCTL_SCAN ; memset ( data , 0 , sizeof ( data ) ) ; if ( data_length ) { if ( copy_from_user ( data , wrq -> u . data . pointer , copy_len ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } if ( ( data [ 0 ] < 0 ) || ( data [ 0 ] > MLAN_SCAN_TYPE_PASSIVE ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( ( data [ 1 ] < 0 ) || ( data [ 1 ] > MLAN_SCAN_MODE_ANY ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( ( data [ 2 ] < 0 ) || ( data [ 2 ] > MAX_PROBES ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( ( ( data [ 3 ] < 0 ) || ( data [ 3 ] > MRVDRV_MAX_ACTIVE_SCAN_CHAN_TIME ) ) || ( ( data [ 4 ] < 0 ) || ( data [ 4 ] > MRVDRV_MAX_ACTIVE_SCAN_CHAN_TIME ) ) || ( ( data [ 5 ] < 0 ) || ( data [ 5 ] > MRVDRV_MAX_PASSIVE_SCAN_CHAN_TIME ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( ( data [ 6 ] < 0 ) || ( data [ 6 ] > 1 ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } req -> action = MLAN_ACT_SET ; memcpy ( & scan -> param . scan_cfg , data , sizeof ( data ) ) ; } else req -> action = MLAN_ACT_GET ; status = woal_request_ioctl ( priv , req , MOAL_IOCTL_WAIT ) ; if ( status != MLAN_STATUS_SUCCESS ) { ret = - EFAULT ; goto done ; } if ( ! data_length ) { memcpy ( data , & scan -> param . scan_cfg , sizeof ( data ) ) ; if ( copy_to_user ( wrq -> u . data . pointer , data , sizeof ( data ) ) ) { ret = - EFAULT ; goto done ; } wrq -> u . data . length = arg_len ; } done : if ( status != MLAN_STATUS_PENDING ) kfree ( req ) ; LEAVE ( ) ; return ret ; }
@brief Set/Get scan configuration parameters
 @param priv     A pointer to moal_private structure
 @param wrq      A pointer to iwreq structure
@brief Set / Get scan configuration parameters @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure