software/drivers/sd8887/src/wlan/mlinux/moal_ioctl.c
/**
 *  @brief CUSTOM_IE ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
@brief CUSTOM_IE ioctl handler
@param dev      A pointer to net_device structure
@param req      A pointer to ifreq structure
@return         0 --success, otherwise fail
@brief CUSTOM_IE ioctl handler @param dev A pointer to net_device structure @param req A pointer to ifreq structure @return 0 -- success otherwise fail
int
woal_custom_ie_ioctl(struct net_device *dev, struct ifreq *req)
{
	moal_private *priv = (moal_private *)netdev_priv(dev);
	mlan_ioctl_req *ioctl_req = NULL;
	mlan_ds_misc_cfg *misc = NULL;
	mlan_ds_misc_custom_ie *custom_ie = NULL;
	int ret = 0;
	mlan_status status = MLAN_STATUS_SUCCESS;
	gfp_t flag;
	ENTER();
	if (req->ifr_data == NULL) {
		PRINTM(MERROR, "woal_custom_ie_ioctl() corrupt data\n");
		ret = -EFAULT;
		goto done;
	}
	flag = (in_atomic() || irqs_disabled())? GFP_ATOMIC : GFP_KERNEL;
	custom_ie = kzalloc(sizeof(mlan_ds_misc_custom_ie), flag);
	if (!custom_ie) {
		ret = -ENOMEM;
		goto done;
	}
	if (copy_from_user
	    (custom_ie, req->ifr_data, sizeof(mlan_ds_misc_custom_ie))) {
		PRINTM(MERROR, "Copy from user failed\n");
		ret = -EFAULT;
		goto done;
	}
	ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_misc_cfg));
	if (ioctl_req == NULL) {
		ret = -ENOMEM;
		goto done;
	}
	misc = (mlan_ds_misc_cfg *)ioctl_req->pbuf;
	misc->sub_command = MLAN_OID_MISC_CUSTOM_IE;
	ioctl_req->req_id = MLAN_IOCTL_MISC_CFG;
	if ((custom_ie->len == 0)||(custom_ie->len ==
				    sizeof(custom_ie->ie_data_list[0].
					   ie_index)))
		ioctl_req->action = MLAN_ACT_GET;
	else
		ioctl_req->action = MLAN_ACT_SET;
	memcpy(&misc->param.cust_ie, custom_ie, sizeof(mlan_ds_misc_custom_ie));
	status = woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT);
	if (status != MLAN_STATUS_SUCCESS) {
		ret = -EFAULT;
		goto done;
	}
	if (ioctl_req->action == MLAN_ACT_GET) {
		if (copy_to_user
		    (req->ifr_data, &misc->param.cust_ie,
		     sizeof(mlan_ds_misc_custom_ie))) {
			PRINTM(MERROR, "Copy to user failed!\n");
			ret = -EFAULT;
			goto done;
		}
	} else if (ioctl_req->status_code == MLAN_ERROR_IOCTL_FAIL) {
		ret = EFAULT;
	}
done:
	if (status != MLAN_STATUS_PENDING)
		kfree(ioctl_req);
	kfree(custom_ie);
	LEAVE();
	return ret;
}
int woal_custom_ie_ioctl ( struct net_device * dev , struct ifreq * req ) { moal_private * priv = ( moal_private * ) netdev_priv ( dev ) ; mlan_ioctl_req * ioctl_req = NULL ; mlan_ds_misc_cfg * misc = NULL ; mlan_ds_misc_custom_ie * custom_ie = NULL ; int ret = 0 ; mlan_status status = MLAN_STATUS_SUCCESS ; gfp_t flag ; ENTER ( ) ; if ( req -> ifr_data == NULL ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } flag = ( in_atomic ( ) || irqs_disabled ( ) ) ? GFP_ATOMIC : GFP_KERNEL ; custom_ie = kzalloc ( sizeof ( mlan_ds_misc_custom_ie ) , flag ) ; if ( ! custom_ie ) { ret = - ENOMEM ; goto done ; } if ( copy_from_user ( custom_ie , req -> ifr_data , sizeof ( mlan_ds_misc_custom_ie ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } ioctl_req = woal_alloc_mlan_ioctl_req ( sizeof ( mlan_ds_misc_cfg ) ) ; if ( ioctl_req == NULL ) { ret = - ENOMEM ; goto done ; } misc = ( mlan_ds_misc_cfg * ) ioctl_req -> pbuf ; misc -> sub_command = MLAN_OID_MISC_CUSTOM_IE ; ioctl_req -> req_id = MLAN_IOCTL_MISC_CFG ; if ( ( custom_ie -> len == 0 ) || ( custom_ie -> len == sizeof ( custom_ie -> ie_data_list [ 0 ] . ie_index ) ) ) ioctl_req -> action = MLAN_ACT_GET ; else ioctl_req -> action = MLAN_ACT_SET ; memcpy ( & misc -> param . cust_ie , custom_ie , sizeof ( mlan_ds_misc_custom_ie ) ) ; status = woal_request_ioctl ( priv , ioctl_req , MOAL_IOCTL_WAIT ) ; if ( status != MLAN_STATUS_SUCCESS ) { ret = - EFAULT ; goto done ; } if ( ioctl_req -> action == MLAN_ACT_GET ) { if ( copy_to_user ( req -> ifr_data , & misc -> param . cust_ie , sizeof ( mlan_ds_misc_custom_ie ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } } else if ( ioctl_req -> status_code == MLAN_ERROR_IOCTL_FAIL ) { ret = EFAULT ; } done : if ( status != MLAN_STATUS_PENDING ) kfree ( ioctl_req ) ; kfree ( custom_ie ) ; LEAVE ( ) ; return ret ; }
@brief CUSTOM_IE ioctl handler
  @param dev      A pointer to net_device structure
  @param req      A pointer to ifreq structure
  @return         0 --success, otherwise fail
@brief CUSTOM_IE ioctl handler @param dev A pointer to net_device structure @param req A pointer to ifreq structure @return 0 -- success otherwise fail
/* Sanity check */ /* send a separate error code to indicate error from driver */