Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v3 05/10] profiles/network: Remove unneded bnep_uuid function from bnep code
Date: Thu, 12 Mar 2015 11:02:18 +0100	[thread overview]
Message-ID: <2844331.AvQ85qZQJp@uw000953> (raw)
In-Reply-To: <1425918295-21976-5-git-send-email-grzegorz.kolodziejczyk@tieto.com>

Hi Grzegorz,

On Monday 09 of March 2015 17:24:50 Grzegorz Kolodziejczyk wrote:
> This function is no longer needed since connection and server can handle
> this funcionality by itself.
> ---
>  profiles/network/bnep.c       | 10 ----------
>  profiles/network/bnep.h       |  1 -
>  profiles/network/connection.c | 19 ++++++++++++-------
>  profiles/network/server.c     | 24 +++++++++++++++++++++---
>  4 files changed, 33 insertions(+), 21 deletions(-)
> 
> diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
> index 3fe63f0..a81a260 100644
> --- a/profiles/network/bnep.c
> +++ b/profiles/network/bnep.c
> @@ -85,16 +85,6 @@ struct bnep {
>  	void	*disconn_data;
>  };
>  
> -const char *bnep_uuid(uint16_t id)
> -{
> -	int i;
> -
> -	for (i = 0; __svc[i].uuid128; i++)
> -		if (__svc[i].id == id)
> -			return __svc[i].uuid128;
> -	return NULL;
> -}
> -
>  const char *bnep_name(uint16_t id)
>  {
>  	int i;
> diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h
> index 31579f9..811ea14 100644
> --- a/profiles/network/bnep.h
> +++ b/profiles/network/bnep.h
> @@ -26,7 +26,6 @@ struct bnep;
>  int bnep_init(void);
>  int bnep_cleanup(void);
>  
> -const char *bnep_uuid(uint16_t id);
>  const char *bnep_name(uint16_t id);
>  
>  struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role,
> diff --git a/profiles/network/connection.c b/profiles/network/connection.c
> index 4311cc9..da8b86e 100644
> --- a/profiles/network/connection.c
> +++ b/profiles/network/connection.c
> @@ -284,21 +284,23 @@ static DBusMessage *local_connect(DBusConnection *conn,
>  	struct btd_service *service;
>  	struct network_conn *nc;
>  	const char *svc;
> -	const char *uuid;
>  	uint16_t id;
>  	int err;
> +	char uuid_str[MAX_LEN_UUID_STR];
> +	bt_uuid_t uuid;
>  
>  	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &svc,
>  						DBUS_TYPE_INVALID) == FALSE)
>  		return btd_error_invalid_args(msg);
>  
>  	id = get_pan_srv_id(svc);
> -	uuid = bnep_uuid(id);
> +	bt_uuid16_create(&uuid, id);
> +	bt_uuid_to_uuid128(&uuid, &uuid);
>  
> -	if (uuid == NULL)
> +	if (bt_uuid_to_string(&uuid, uuid_str, MAX_LEN_UUID_STR) < 0)
>  		return btd_error_invalid_args(msg);
>  
> -	service = btd_device_get_service(peer->device, uuid);
> +	service = btd_device_get_service(peer->device, uuid_str);
>  	if (service == NULL)
>  		return btd_error_not_supported(msg);
>  
> @@ -439,15 +441,18 @@ static gboolean network_property_get_uuid(const GDBusPropertyTable *property,
>  {
>  	struct network_peer *peer = data;
>  	struct network_conn *nc;
> -	const char *uuid;
> +	char uuid_str[MAX_LEN_UUID_STR];
> +	bt_uuid_t uuid;
>  
>  	nc = find_connection_by_state(peer->connections, CONNECTED);
>  	if (nc == NULL)
>  		return FALSE;
>  
> -	uuid = bnep_uuid(nc->id);
> +	bt_uuid16_create(&uuid, nc->id);
> +	bt_uuid_to_uuid128(&uuid, &uuid);
> +	bt_uuid_to_string(&uuid, uuid_str, MAX_LEN_UUID_STR);
>  
> -	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid);
> +	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid_str);
>  
>  	return TRUE;
>  }
> diff --git a/profiles/network/server.c b/profiles/network/server.c
> index 9caabb0..e05bc1a 100644
> --- a/profiles/network/server.c
> +++ b/profiles/network/server.c
> @@ -114,14 +114,32 @@ static struct network_server *find_server(GSList *list, uint16_t id)
>  static struct network_server *find_server_by_uuid(GSList *list,
>  							const char *uuid)
>  {
> +	bt_uuid_t srv_uuid, bnep_uuid;
> +
>  	for (; list; list = list->next) {
>  		struct network_server *ns = list->data;
> +		bt_uuid16_create(&bnep_uuid, ns->id);
>  
> -		if (strcasecmp(uuid, bnep_uuid(ns->id)) == 0)
> +		/* UUID value compare */
> +		if (!bt_string_to_uuid(&srv_uuid, uuid) &&
> +					!bt_uuid_cmp(&srv_uuid, &bnep_uuid))
>  			return ns;

Please call bt_string_to_uuid() before loop and based on its result
check if uuid or name compare is needed.

This should make code a bit faster and easier to read.

>  
> -		if (strcasecmp(uuid, bnep_name(ns->id)) == 0)
> -			return ns;
> +		/* String value compare */
> +		switch (ns->id) {
> +		case BNEP_SVC_PANU:
> +			if (!strcasecmp(uuid, "panu"))
> +				return ns;
> +			break;
> +		case BNEP_SVC_NAP:
> +			if (!strcasecmp(uuid, "nap"))
> +				return ns;
> +			break;
> +		case BNEP_SVC_GN:
> +			if (!strcasecmp(uuid, "gn"))
> +				return ns;
> +			break;
> +		}
>  	}
>  
>  	return NULL;
> 

-- 
Best regards, 
Szymon Janc

  reply	other threads:[~2015-03-12 10:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 16:24 [PATCH v3 01/10] profiles/network: Move bnep connection setup logic to bnep Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 02/10] profiles/network: Handle ctrl rsp after conn setup by bnep Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 03/10] profiles/network: Fix sending command responses Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 04/10] profiles/network: Keep interface arguments naming consistent Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 05/10] profiles/network: Remove unneded bnep_uuid function from bnep code Grzegorz Kolodziejczyk
2015-03-12 10:02   ` Szymon Janc [this message]
2015-03-12 10:05     ` Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 06/10] profiles/network: Remove not needed get name by bnep id function Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 07/10] profiles/network: Move disconn cb setting to bnep connect method Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 08/10] tools/bneptest: Add initial support for bneptest tool Grzegorz Kolodziejczyk
2015-03-09 16:24 ` [PATCH v3 09/10] tools/bneptest: Add generic connect/listen funcionality Grzegorz Kolodziejczyk
2015-03-12 10:09   ` Szymon Janc
2015-03-09 16:24 ` [PATCH v3 10/10] android/pts: Add BNEP PTS 6.0 results for android 5.0 Grzegorz Kolodziejczyk
2015-03-12 10:04   ` Szymon Janc
2015-03-12 10:07     ` Grzegorz Kolodziejczyk
2015-03-12 10:07   ` Szymon Janc
2015-03-12 10:32     ` Grzegorz Kolodziejczyk
2015-03-12 10:12 ` [PATCH v3 01/10] profiles/network: Move bnep connection setup logic to bnep Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2844331.AvQ85qZQJp@uw000953 \
    --to=szymon.janc@tieto.com \
    --cc=grzegorz.kolodziejczyk@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox