Пример #1
0
static int pdp_activate(pdp_arg_t *pdp_arg, unsigned type, unsigned flags)
{
	int ret;
	struct pdp_info *dev;
	struct net_device *net;

	dev = vmalloc(sizeof(struct pdp_info) + MAX_PDP_PACKET_LEN);
	if (dev == NULL) {
		DPRINTK(1, "out of memory\n");
		return -ENOMEM;
	}
	memset(dev, 0, sizeof(struct pdp_info));

	/* @LDK@ added by gykim on 20070203 for adjusting IPC 3.0 spec. */
	if (type == DEV_TYPE_NET) {
		dev->id = pdp_arg->id + g_adjust;
	}

	else {
		dev->id = pdp_arg->id;
	}
	/* @LDK@ added by gykim on 20070203 for adjusting IPC 3.0 spec. */

	dev->type = type;
	dev->flags = flags;
	dev->tx_buf = (u8 *)(dev + 1);

	if (type == DEV_TYPE_NET) {
		net = vnet_add_dev((void *)dev);
		if (net == NULL) {
			vfree(dev);
			return -ENOMEM;
		}

		dev->vn_dev.net = net;
		strcpy(pdp_arg->ifname, net->name);

		down(&pdp_lock);
		ret = pdp_add_dev(dev);
		if (ret < 0) {
			EPRINTK("pdp_add_dev() failed\n");
			up(&pdp_lock);
			vnet_del_dev(dev->vn_dev.net);
			vfree(dev);
			return ret;
		}
		pdp_net_activation_count++;
		up(&pdp_lock);

		DPRINTK(1, "%s(id: %u) network device created\n", 
			net->name, dev->id);
	} else if (type == DEV_TYPE_SERIAL) {
		init_MUTEX(&dev->vs_dev.write_lock);
		strcpy(dev->vs_dev.tty_name, pdp_arg->ifname);

		ret = vs_add_dev(dev);
		if (ret < 0) {
			vfree(dev);
			return ret;
		}

		down(&pdp_lock);
		ret = pdp_add_dev(dev);
		if (ret < 0) {
			DPRINTK(1, "pdp_add_dev() failed\n");
			up(&pdp_lock);
			vs_del_dev(dev);
			vfree(dev);
			return ret;
		}
		up(&pdp_lock);

		{
			struct tty_driver * tty_driver = get_tty_driver_by_id(dev);

			DPRINTK(1, "%s(id: %u) serial device is created.\n",
					tty_driver->name, dev->id);
		}
	}

	return 0;
}
Пример #2
0
static int pdp_activate(struct pdp_arg *pdp_arg, unsigned type, unsigned flags)
{
	int ret;
	struct pdp_info *dev;
	struct net_device *net;

	dev = vmalloc(sizeof(struct pdp_info) + MAX_PDP_PACKET_LEN);
	if (dev == NULL) {
		pr_err("[MULTIPDP] out of memory\n");
		return -ENOMEM;
	}
	memset(dev, 0, sizeof(struct pdp_info));

	/* @LDK@ added by gykim on 20070203 for adjusting IPC 3.0 spec. */
	if (type == DEV_TYPE_NET)
		dev->id = pdp_arg->id + g_adjust;
	else
	    dev->id = pdp_arg->id;

	/* @LDK@ added by gykim on 20070203 for adjusting IPC 3.0 spec. */
	dev->type = type;
	dev->flags = flags;
	dev->tx_buf = (u8 *) (dev + 1);

	if (type == DEV_TYPE_NET) {
		net = vnet_add_dev((void *)dev);
		if (net == NULL) {
			pr_err("[MULTIPDP] vnet_add_dev is failed");
			vfree(dev);
			return -ENOMEM;
		}

		dev->vn_dev.net = net;

		strncpy(pdp_arg->ifname,
				net->name,
				APP_NAME_MAX_LEN);

		down(&pdp_lock);
		ret = pdp_add_dev(dev);
		if (ret < 0) {
			pr_err("[MULTIPDP] pdp_add_dev() failed\n");
			up(&pdp_lock);
			vnet_del_dev(dev->vn_dev.net);
			vfree(dev);
			return ret;
		}
		pdp_net_activation_count++;
		up(&pdp_lock);

		DPRINTK(2, "%s(id: %u) network device created\n",
			net->name, dev->id);
	} else if (type == DEV_TYPE_SERIAL) {
		init_MUTEX(&dev->vs_dev.write_lock);

		strncpy(dev->vs_dev.tty_name,
				pdp_arg->ifname,
				APP_NAME_MAX_LEN);

		ret = vs_add_dev(dev);
		if (ret < 0) {
			vfree(dev);
			return ret;
		}

		down(&pdp_lock);
		ret = pdp_add_dev(dev);
		if (ret < 0) {
			pr_err("[MULTIPDP] pdp_add_dev() failed\n");
			up(&pdp_lock);
			vs_del_dev(dev);
			vfree(dev);
			return ret;
		}
		up(&pdp_lock);
		DPRINTK(2, "serial device is created id[%u]\n",
				dev->id);
	}

	return 0;
}