diff options
Diffstat (limited to 'network')
| -rw-r--r-- | network/connection.c | 37 | ||||
| -rw-r--r-- | network/connection.h | 5 | ||||
| -rw-r--r-- | network/manager.c | 48 | 
3 files changed, 50 insertions, 40 deletions
| diff --git a/network/connection.c b/network/connection.c index e4f759aa..c7f22f4b 100644 --- a/network/connection.c +++ b/network/connection.c @@ -28,16 +28,12 @@  #include <stdio.h>  #include <errno.h>  #include <unistd.h> -#include <stdlib.h> -#include <sys/ioctl.h>  #include <netinet/in.h>  #include <bluetooth/bluetooth.h>  #include <bluetooth/l2cap.h>  #include <bluetooth/bnep.h> -#include <bluetooth/sdp.h> -#include <bluetooth/sdp_lib.h>  #include <glib.h> @@ -564,11 +560,10 @@ static const DBusObjectPathVTable connection_table = {  	.unregister_function = connection_unregister,  }; -int connection_register(DBusConnection *conn, const char *path, -			const char *addr, uint16_t id, const sdp_record_t *rec) +int connection_register(DBusConnection *conn, const char *path, bdaddr_t *src, +		bdaddr_t *dst, uint16_t id, const char *name, const char *desc)  {  	struct network_conn *nc; -	sdp_data_t *d;  	if (!conn)  		return -1; @@ -578,39 +573,23 @@ int connection_register(DBusConnection *conn, const char *path,  	/* register path */  	if (!dbus_connection_register_object_path(conn, path,  						&connection_table, nc)) { -		error("D-Bus failed to register %s path", path); -  		connection_free(nc);  		return -1;  	}  	nc->path = g_strdup(path); -	bacpy(&nc->src, BDADDR_ANY); -	str2ba(addr, &nc->dst); +	bacpy(&nc->src, src); +	bacpy(&nc->dst, dst);  	nc->id = id; - -	/* Extract service name from record */ -	d = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY); -	if (d) { -		nc->name = g_new0(char, d->unitSize); -		snprintf(nc->name, d->unitSize, "%.*s", d->unitSize, -				d->val.str); -	} - -	/* Extract service description from record */ -	d = sdp_data_get(rec, SDP_ATTR_SVCDESC_PRIMARY); -	if (d) { -		nc->desc = g_new0(char, d->unitSize); -		snprintf(nc->desc, d->unitSize, "%.*s", d->unitSize, -				d->val.str); -	} - +	nc->name = g_strdup(name); +	nc->desc = g_strdup(desc);  	memset(nc->dev, 0, 16);  	strncpy(nc->dev, netdev, 16); -  	nc->state = DISCONNECTED;  	nc->conn = conn; +  	info("Registered connection path:%s", path); +  	return 0;  } diff --git a/network/connection.h b/network/connection.h index 27bf2f69..1f810060 100644 --- a/network/connection.h +++ b/network/connection.h @@ -21,8 +21,7 @@   *   */ -int connection_register(DBusConnection *conn, const char *path, -			const char *addr, uint16_t id, -			const sdp_record_t *rec); +int connection_register(DBusConnection *conn, const char *path, bdaddr_t *src, +		bdaddr_t *dst, uint16_t id, const char *name, const char *desc);  int connection_find_data(DBusConnection *conn, const char *path,  			const char *pattern); diff --git a/network/manager.c b/network/manager.c index 93f0821d..43bc9b71 100644 --- a/network/manager.c +++ b/network/manager.c @@ -58,10 +58,11 @@  struct pending_reply {  	DBusConnection	*conn;  	DBusMessage	*msg; -	char		*addr; -	char		*path; -	char		*adapter_path; -	uint16_t	id; +	bdaddr_t	src;		/* Source Address */ +	char		*addr;		/* Destination Address*/ +	char		*path;		/* D-Bus object path */ +	char		*adapter_path;	/* Default adapter path */ +	uint16_t	id;		/* Role */  };  static GSList *server_paths	= NULL;	/* Network registered servers paths */ @@ -187,9 +188,12 @@ static void pan_record_reply(DBusPendingCall *call, void *data)  	struct pending_reply *pr = data;  	DBusMessage *reply = dbus_pending_call_steal_reply(call);  	DBusError derr; +	bdaddr_t src, dst;  	int len, scanned;  	uint8_t *rec_bin; +	sdp_data_t *d;  	sdp_record_t *rec = NULL; +	char *name = NULL, *desc = NULL;  	dbus_error_init(&derr);  	if (dbus_set_error_from_message(&derr, reply)) { @@ -220,8 +224,28 @@ static void pan_record_reply(DBusPendingCall *call, void *data)  	rec = sdp_extract_pdu(rec_bin, &scanned); -	if (connection_register(pr->conn, pr->path, pr->addr, pr->id, -				rec) == -1) { +	/* Extract service name from record */ +	d = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY); +	if (d) { +		name = g_new0(char, d->unitSize); +		snprintf(name, d->unitSize, "%.*s", +				d->unitSize, d->val.str); +	} + +	/* Extract service description from record */ +	d = sdp_data_get(rec, SDP_ATTR_SVCDESC_PRIMARY); +	if (d) { +		desc = g_new0(char, d->unitSize); +		snprintf(desc, d->unitSize, "%.*s", +				d->unitSize, d->val.str); +	} + +	/* FIXME: it can' t be hard coded */ +	bacpy(&src, BDADDR_ANY); +	str2ba(pr->addr, &dst); + +	if (connection_register(pr->conn, pr->path, &src, +				&dst, pr->id, name, desc) < 0) {  		err_failed(pr->conn, pr->msg, "D-Bus path registration failed");  		goto fail;  	} @@ -230,6 +254,12 @@ static void pan_record_reply(DBusPendingCall *call, void *data)  	create_path(pr->conn, pr->msg, pr->path, "ConnectionCreated");  fail: + +	if (name) +		g_free(name); +	if (desc) +		g_free(desc); +  	sdp_record_free(rec);  	dbus_error_free(&derr);  	pending_reply_free(pr); @@ -508,6 +538,7 @@ static DBusHandlerResult create_server(DBusConnection *conn,  		return DBUS_HANDLER_RESULT_HANDLED;  	} +	/* FIXME: use hci_get_route */  	if (get_default_adapter(pr, default_adapter_reply) < 0) {  		err_failed(conn, msg, "D-Bus path registration failed");  		pending_reply_free(pr); @@ -600,6 +631,7 @@ static DBusHandlerResult create_connection(DBusConnection *conn,  	snprintf(pr->path, MAX_PATH_LENGTH,  			NETWORK_PATH"/connection%d", net_uid++); +	/* FIXME: use hci_get_route */  	if (get_default_adapter(pr, default_adapter_reply) < 0) {  		err_failed(conn, msg, "D-Bus path registration failed");  		pending_reply_free(pr); @@ -683,7 +715,7 @@ static const DBusObjectPathVTable manager_table = {  static void parse_stored_connection(char *key, char *value, void *data)  { -	bdaddr_t dst; +	bdaddr_t dst, *src = data;  	char path[MAX_PATH_LENGTH];  	char addr[18];  	const char *ptr; @@ -737,7 +769,7 @@ static void parse_stored_connection(char *key, char *value, void *data)  		return;  	} -	/* FIXME: Change the connection_register prototype */ +	connection_register(connection, path, src, &dst, id, name, ptr);  	g_free(name);  } | 
