From 3635c70249a5ee6f0adb364ab83dde0bedfbffa1 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 21 Jun 2012 18:44:10 +0200 Subject: [PATCH] p2p: Bind and listen only on a specific target Bind and listening are related to a particular adapter, not to a target or device index. --- include/device.h | 3 +-- plugins/p2p.c | 12 ++++++------ src/device.c | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/device.h b/include/device.h index 0aa1950..5785572 100644 --- a/include/device.h +++ b/include/device.h @@ -40,8 +40,7 @@ struct near_ndef_message; struct near_device_driver { int priority; - int (*listen)(uint32_t adapter_idx, uint32_t target_idx, - near_device_io_cb cb); + int (*listen)(uint32_t adapter_idx, near_device_io_cb cb); int (*push)(uint32_t adapter_idx, uint32_t target_idx, struct near_ndef_message *ndef, near_device_io_cb cb); diff --git a/plugins/p2p.c b/plugins/p2p.c index c437776..edfcdbd 100644 --- a/plugins/p2p.c +++ b/plugins/p2p.c @@ -143,6 +143,7 @@ static gboolean p2p_listener_event(GIOChannel *channel, GIOCondition condition, return FALSE; } + client_addr_len = sizeof(client_addr); client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_addr_len); if (client_fd < 0) { @@ -154,6 +155,7 @@ static gboolean p2p_listener_event(GIOChannel *channel, GIOCondition condition, DBG("client dsap %d ssap %d", client_addr.dsap, client_addr.ssap); + DBG("target idx %d", client_addr.target_idx); client_data = g_try_malloc0(sizeof(struct p2p_data)); if (client_data == NULL) { @@ -163,7 +165,7 @@ static gboolean p2p_listener_event(GIOChannel *channel, GIOCondition condition, client_data->driver = server_data->driver; client_data->adapter_idx = server_data->adapter_idx; - client_data->target_idx = server_data->target_idx; + client_data->target_idx = client_addr.target_idx; client_data->fd = client_fd; client_data->cb = server_data->cb; @@ -181,7 +183,7 @@ static gboolean p2p_listener_event(GIOChannel *channel, GIOCondition condition, } static int p2p_bind(struct near_p2p_driver *driver, uint32_t adapter_idx, - uint32_t target_idx, near_device_io_cb cb) + near_device_io_cb cb) { int err, fd; struct sockaddr_nfc_llcp addr; @@ -226,7 +228,6 @@ static int p2p_bind(struct near_p2p_driver *driver, uint32_t adapter_idx, server_data->driver = driver; server_data->adapter_idx = adapter_idx; - server_data->target_idx = target_idx; server_data->fd = fd; server_data->cb = cb; @@ -241,8 +242,7 @@ static int p2p_bind(struct near_p2p_driver *driver, uint32_t adapter_idx, return 0; } -static int p2p_listen(uint32_t adapter_idx, - uint32_t target_idx, near_device_io_cb cb) +static int p2p_listen(uint32_t adapter_idx, near_device_io_cb cb) { int err = 0; GSList *list; @@ -250,7 +250,7 @@ static int p2p_listen(uint32_t adapter_idx, for (list = driver_list; list != NULL; list = list->next) { struct near_p2p_driver *driver = list->data; - err &= p2p_bind(driver, adapter_idx, target_idx, cb); + err &= p2p_bind(driver, adapter_idx, cb); } return err; diff --git a/src/device.c b/src/device.c index 185da9a..afaba3e 100644 --- a/src/device.c +++ b/src/device.c @@ -360,8 +360,7 @@ int __near_device_listen(struct near_device *device, near_device_io_cb cb) for (list = driver_list; list; list = list->next) { struct near_device_driver *driver = list->data; - return driver->listen(device->adapter_idx, - device->target_idx, cb); + return driver->listen(device->adapter_idx, cb); } return 0; -- 2.7.4