software/drivers/sd8887/src/wlan/mlinux/moal_priv.c
/**
 *  @brief Read/Write adapter registers value
 *
 *  @param priv         A pointer to moal_private structure
 *  @param wrq          A pointer to iwreq structure
 *
 *  @return             0 --success, otherwise fail
 */
@brief Read/Write adapter registers value
@param priv         A pointer to moal_private structure
@param wrq          A pointer to iwreq structure

@return             0 --success, otherwise fail
@brief Read / Write adapter registers value @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return 0 -- success otherwise fail
static int
woal_reg_read_write(moal_private *priv, struct iwreq *wrq)
{
	int data[3], copy_len;
	int ret = 0;
	mlan_ioctl_req *req = NULL;
	mlan_ds_reg_mem *reg = NULL;
	int data_length = wrq->u.data.length;
	mlan_status status = MLAN_STATUS_SUCCESS;
	ENTER();
	memset(data, 0, sizeof(data));
	copy_len = MIN(sizeof(data), sizeof(int) * data_length);
	req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_reg_mem));
	if (req == NULL) {
		ret = -ENOMEM;
		goto done;
	}
	reg = (mlan_ds_reg_mem *)req->pbuf;
	reg->sub_command = MLAN_OID_REG_RW;
	req->req_id = MLAN_IOCTL_REG_MEM;
	if (data_length == 2) {
		req->action = MLAN_ACT_GET;
	} else if (data_length == 3) {
		req->action = MLAN_ACT_SET;
	} else {
		ret = -EINVAL;
		goto done;
	}
	if (copy_from_user(data, wrq->u.data.pointer, copy_len)) {
		PRINTM(MERROR, "Copy from user failed\n");
		ret = -EFAULT;
		goto done;
	}
	reg->param.reg_rw.type = (t_u32)data[0];
	reg->param.reg_rw.offset = (t_u32)data[1];
	if (data_length == 3)
		reg->param.reg_rw.value = (t_u32)data[2];
	status = woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT);
	if (status != MLAN_STATUS_SUCCESS) {
		ret = -EFAULT;
		goto done;
	}
	if (req->action == MLAN_ACT_GET) {
		if (copy_to_user
		    (wrq->u.data.pointer, &reg->param.reg_rw.value,
		     sizeof(int))) {
			PRINTM(MERROR, "Copy to user failed\n");
			ret = -EFAULT;
			goto done;
		}
		wrq->u.data.length = 1;
	}
done:
	if (status != MLAN_STATUS_PENDING)
		kfree(req);
	LEAVE();
	return ret;
}
static int woal_reg_read_write ( moal_private * priv , struct iwreq * wrq ) { int data [ 3 ] , copy_len ; int ret = 0 ; mlan_ioctl_req * req = NULL ; mlan_ds_reg_mem * reg = NULL ; int data_length = wrq -> u . data . length ; mlan_status status = MLAN_STATUS_SUCCESS ; ENTER ( ) ; memset ( data , 0 , sizeof ( data ) ) ; copy_len = MIN ( sizeof ( data ) , sizeof ( int ) * data_length ) ; req = woal_alloc_mlan_ioctl_req ( sizeof ( mlan_ds_reg_mem ) ) ; if ( req == NULL ) { ret = - ENOMEM ; goto done ; } reg = ( mlan_ds_reg_mem * ) req -> pbuf ; reg -> sub_command = MLAN_OID_REG_RW ; req -> req_id = MLAN_IOCTL_REG_MEM ; if ( data_length == 2 ) { req -> action = MLAN_ACT_GET ; } else if ( data_length == 3 ) { req -> action = MLAN_ACT_SET ; } else { ret = - EINVAL ; goto done ; } if ( copy_from_user ( data , wrq -> u . data . pointer , copy_len ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } reg -> param . reg_rw . type = ( t_u32 ) data [ 0 ] ; reg -> param . reg_rw . offset = ( t_u32 ) data [ 1 ] ; if ( data_length == 3 ) reg -> param . reg_rw . value = ( t_u32 ) data [ 2 ] ; status = woal_request_ioctl ( priv , req , MOAL_IOCTL_WAIT ) ; if ( status != MLAN_STATUS_SUCCESS ) { ret = - EFAULT ; goto done ; } if ( req -> action == MLAN_ACT_GET ) { if ( copy_to_user ( wrq -> u . data . pointer , & reg -> param . reg_rw . value , sizeof ( int ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } wrq -> u . data . length = 1 ; } done : if ( status != MLAN_STATUS_PENDING ) kfree ( req ) ; LEAVE ( ) ; return ret ; }
@brief Read/Write adapter registers value
  @param priv         A pointer to moal_private structure
  @param wrq          A pointer to iwreq structure
@brief Read / Write adapter registers value @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure