Example #1
0
/**
 * Fetch device from proxy list
 */
static DBusGProxy *get_device(const char *path)
{
	device_object *dev = get_device_object(path);

	if (dev)
		return dev->proxy;

	return NULL;
}
Example #2
0
/**
 * Remove device path from device proxy list
 */
static void remove_device(const char *path)
{
	device_object *dev = get_device_object(path);

	if (dev) {
		g_free(dev->path);
		g_free(dev->addr);
		g_free(dev->adapter);
		g_object_unref(dev->proxy);
		g_free(dev);
		llist_remove(devices(), dev);
	}
}
Example #3
0
/**
 * Add channel into channel proxy list
 */
static guint64 add_channel(const char *path, const char *device, int fd,
						gboolean initiated_by_us)
{
	DBusGProxy *proxy;
	GIOChannel *gio;

	gio = g_io_channel_unix_new(fd);
	g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
		       data_received, NULL);

	channel_object *c = get_channel(path);
	if (c) {
		c->fd = fd;
		return 0;
	}

	proxy = dbus_g_proxy_new_for_name(conn, "org.bluez", path,
					  "org.bluez.HealthChannel");

	c = (channel_object *) g_new(channel_object, 1);
	c->path = g_strdup(path);
	c->device = g_strdup(device);
	c->proxy = proxy;
	c->fd = fd;
	c->initiated_by_us = initiated_by_us;

	llist_add(channels(), c);

	device_object *dev = get_device_object(device);
	if (dev) {
		c->first = (++dev->channels == 1);
		if (c->first) {
			c->handle = ++last_handle;
			dev->first_handle = c->handle;
			return c->handle;
		} else {
			c->handle = dev->first_handle;
			return 0;
		}
	} else {
		ERROR("unknown dev %s", device);
	}

	return 0;
}
Example #4
0
int init(int32_t title_number,char *device_path){
	int intRetVal=ERR_FATAL;
	dd_disc=get_device_object();

	/* open device*/
	intRetVal=open_disc(dd_disc,device_path);
	if(ERR_OK!=intRetVal){
		return intRetVal;
	}

	/* set title */
	if(title_number>0){
		intRetVal=set_titleset(dd_disc,title_number);
		return intRetVal;
	}

	/* directory listing update title list*/
	intRetVal=update_title_list(dd_disc);
	return intRetVal;
	
}
Example #5
0
/**
 * Takes care of channel closure, when initiative is remote
 */
static void channel_closed(const char *path)
{
	channel_object *c = get_channel(path);
	device_object *d;

	if (!c)
		return;

	d = get_device_object(c->device);

	if (c->first) {
		// notifies higher layers
		if (d) {
			device_disconnected(c->handle, d->addr);
		} else {
			ERROR("Unknown device: %s", c->device);
			device_disconnected(c->handle, c->device);
		}
	}

	disconnect_channel(c->handle, 1);
}
Example #6
0
/**
 * Remove channel path from channel proxy list
 */
static void remove_channel(const char *path, int passive)
{
	channel_object *c = get_channel(path);

	if (c) {
		GError *error = NULL;
		device_object *d = get_device_object(c->device);

		if (d) {
			d->channels--;
		}

		if (d && !passive) {
			DEBUG("Destroying channel %s", path);
			if (!dbus_g_proxy_call(d->proxy, "DestroyChannel",
						&error,
						DBUS_TYPE_G_OBJECT_PATH,
						path,
						G_TYPE_INVALID,
						G_TYPE_INVALID)) {
				if (error) {
					DEBUG("Err destroying HDP channel %s",
								error->message);
					g_error_free(error);
				}
			}
		}

		g_free(c->path);
		g_free(c->device);
		g_object_unref(c->proxy);
		shutdown(c->fd, SHUT_RDWR);
		close(c->fd);
		c->fd = -1;
		llist_remove(channels(), c);
		g_free(c);
	}
}
Example #7
0
/* initialization */
NTSTATUS
DriverEntry(IN PDRIVER_OBJECT theDriverObject,
            IN PUNICODE_STRING theRegistryPath)
{
    NTSTATUS status = STATUS_SUCCESS;
	int i;
	UNICODE_STRING name, linkname;

	memtrack_init();
	KeInitializeSpinLock(&g_traffic_guard);

#ifdef USE_TDI_HOOKING
	KdPrint(("[tdi_fw] WARNING! Using unstable working mode: TDI hooking!\n"));
#endif

	status = ot_init();
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: ot_init: 0x%x\n", status));
		goto done;
	}

	status = filter_init();
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: filter_init: 0x%x\n", status));
		goto done;
	}

	status = conn_state_init();
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: conn_state_init: 0x%x\n", status));
		goto done;
	}
	
	for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
		theDriverObject->MajorFunction[i] = DeviceDispatch;

#if DBG
	// register UnLoad procedure
	theDriverObject->DriverUnload = OnUnload;
#endif

	/* create control device and symbolic link */

	RtlInitUnicodeString(&name, L"\\Device\\tdifw");

	status = IoCreateDevice(theDriverObject,
							0,
							&name,
							0,
							0,
							TRUE,		// exclusive!
							&g_devcontrol);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateDevice(control): 0x%x!\n", status));
		goto done;
	}

	RtlInitUnicodeString(&linkname, L"\\??\\tdifw");

	status = IoCreateSymbolicLink(&linkname, &name);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateSymbolicLink: 0x%x!\n", status));
		goto done;
	}

	RtlInitUnicodeString(&name, L"\\Device\\tdifw_nfo");

	status = IoCreateDevice(theDriverObject,
							0,
							&name,
							0,
							0,
							FALSE,		// not exclusive!
							&g_devnfo);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateDevice(nfo): 0x%x!\n", status));
		goto done;
	}

	RtlInitUnicodeString(&linkname, L"\\??\\tdifw_nfo");

	status = IoCreateSymbolicLink(&linkname, &name);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateSymbolicLink: 0x%x!\n", status));
		goto done;
	}

#ifndef USE_TDI_HOOKING

	status = c_n_a_device(theDriverObject, &g_tcpfltobj, &g_tcpoldobj, L"\\Device\\Tcp");
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: c_n_a_device: 0x%x\n", status));
		goto done;
	}

	status = c_n_a_device(theDriverObject, &g_udpfltobj, &g_udpoldobj, L"\\Device\\Udp");
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: c_n_a_device: 0x%x\n", status));
		goto done;
	}

	status = c_n_a_device(theDriverObject, &g_ipfltobj, &g_ipoldobj, L"\\Device\\RawIp");
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: c_n_a_device: 0x%x\n", status));
		goto done;
	}

#else	/* USE_TDI_HOOKING */

	/* get device objects for tcp/udp/ip */

	status = get_device_object(L"\\Device\\Tcp", &g_tcpfltobj);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: get_device_object(tcp): 0x%x\n", status));
		goto done;
	}
	
	status = get_device_object(L"\\Device\\Udp", &g_udpfltobj);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: get_device_object(udp): 0x%x\n", status));
		goto done;
	}
	
	status = get_device_object(L"\\Device\\RawIp", &g_ipfltobj);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: get_device_object(ip): 0x%x\n", status));
		goto done;
	}

	/* hook tcpip */

	status = hook_tcpip(&g_old_DriverObject, TRUE);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: hook_driver: 0x%x\n", status));
		goto done;
	}
	g_hooked = TRUE;

#endif	/* USE_TDI_HOOKING */

	status = STATUS_SUCCESS;

done:
	if (status != STATUS_SUCCESS) {
		// cleanup
		OnUnload(theDriverObject);
	}

    return status;
}
Example #8
0
/**
 * Callback for org.bluez.HealthDevice.ChannelConnected signal
 * Reused by CreateChannel callback (channel initiation)
 */
static void channel_connected(DBusGProxy *proxy, const char *path, gpointer user_data)
{
	int fd;
	guint64 handle;
	device_object *dev;
	const char *device_path;

	channel_object *c = get_channel(path);
	if (c) {
		if (c->initiated_by_us && c->fd >= 0) {
			DEBUG("initiated channel already connected: %s", path);
			return;
		}
	}

	DEBUG("channel connected: %s", path);

	// Need to use non-GLib code here because GLib still does not have
	// the UNIX FD type.

	DBusMessage *msg, *reply;
	DBusError err;

	msg = dbus_message_new_method_call("org.bluez", path,
					   "org.bluez.HealthChannel", "Acquire");

	if (!msg) {
		ERROR(" network:dbus Can't allocate new method call");
		return;
	}

	dbus_error_init(&err);

	reply = dbus_connection_send_with_reply_and_block(
			dbus_g_connection_get_connection(conn),
			msg, -1, &err);

	dbus_message_unref(msg);

	if (!reply) {
		DEBUG(" network:dbus Can't acquire FD");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
			return;
		}
	}

	if (!dbus_message_get_args(reply, &err,
				   DBUS_TYPE_UNIX_FD, &fd,
				   DBUS_TYPE_INVALID)) {
		DEBUG(" network:dbus Can't get reply arguments");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
			dbus_message_unref(reply);
			return;
		}
	}

	dbus_message_unref(reply);

	// dbus_connection_flush(dbus_g_connection_get_connection(conn));
	DEBUG("File descriptor: %d", fd);

	device_path = dbus_g_proxy_get_path(proxy);
	handle = add_channel(path, device_path, fd, user_data != NULL);

	if (!handle) {
		// channel already known, reconnected
		// or channel is secondary
		return;
	}

	dev = get_device_object(device_path);

	if (dev) {
		device_connected(handle, dev->addr);
	} else {
		ERROR("Channel from unknown device: %s", device_path);
		device_connected(handle, device_path);
	}
}