* [PATCH 2/5] Bluetooth: Refactor ACL connection into its own function
2012-05-31 0:20 [PATCH 1/5] Bluetooth: Refactor LE connection into its own function Vinicius Costa Gomes
@ 2012-05-31 0:20 ` Vinicius Costa Gomes
2012-05-31 0:20 ` [PATCH 3/5] Bluetooth: Refactor SCO " Vinicius Costa Gomes
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2012-05-31 0:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
The hci_connect() function was starting to get too complicated to be
quickly understood. We can separated the creation of a new ACL
connection into its own function.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
---
net/bluetooth/hci_conn.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index a7bfc27..ac12cbd 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -492,18 +492,10 @@ static struct hci_conn *add_le_conn(struct hci_dev *hdev, bdaddr_t *dst,
return le;
}
-/* Create SCO, ACL or LE connection.
- * Device _must_ be locked */
-struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
- __u8 dst_type, __u8 sec_level, __u8 auth_type)
+static struct hci_conn *add_acl_conn(struct hci_dev *hdev, bdaddr_t *dst,
+ u8 sec_level, u8 auth_type)
{
struct hci_conn *acl;
- struct hci_conn *sco;
-
- BT_DBG("%s dst %s", hdev->name, batostr(dst));
-
- if (type == LE_LINK)
- return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
if (!acl) {
@@ -521,6 +513,26 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
hci_acl_connect(acl);
}
+ return acl;
+}
+
+/* Create SCO, ACL or LE connection.
+ * Device _must_ be locked */
+struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
+ __u8 dst_type, __u8 sec_level, __u8 auth_type)
+{
+ struct hci_conn *acl;
+ struct hci_conn *sco;
+
+ BT_DBG("%s dst %s", hdev->name, batostr(dst));
+
+ if (type == LE_LINK)
+ return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
+
+ acl = add_acl_conn(hdev, dst, sec_level, auth_type);
+ if (IS_ERR(acl))
+ return acl;
+
if (type == ACL_LINK)
return acl;
--
1.7.10.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/5] Bluetooth: Refactor SCO connection into its own function
2012-05-31 0:20 [PATCH 1/5] Bluetooth: Refactor LE connection into its own function Vinicius Costa Gomes
2012-05-31 0:20 ` [PATCH 2/5] Bluetooth: Refactor ACL " Vinicius Costa Gomes
@ 2012-05-31 0:20 ` Vinicius Costa Gomes
2012-05-31 0:20 ` [PATCH 4/5] Bluetooth: Simplify a the connection type handling Vinicius Costa Gomes
2012-05-31 0:20 ` [PATCH 5/5] Bluetooth: Add type information to the hci_connect() debug statement Vinicius Costa Gomes
3 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2012-05-31 0:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
We can do the same that we did for the other link types, for SCO
connections. The only thing that's worth noting is that as SCO
links need an ACL link, this functions uses the function that adds
an ACL link.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
---
net/bluetooth/hci_conn.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index ac12cbd..320cc5d 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -516,29 +516,19 @@ static struct hci_conn *add_acl_conn(struct hci_dev *hdev, bdaddr_t *dst,
return acl;
}
-/* Create SCO, ACL or LE connection.
- * Device _must_ be locked */
-struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
- __u8 dst_type, __u8 sec_level, __u8 auth_type)
+static struct hci_conn *add_sco_conn(struct hci_dev *hdev, bdaddr_t *dst,
+ u8 sec_level, u8 auth_type)
{
struct hci_conn *acl;
struct hci_conn *sco;
- BT_DBG("%s dst %s", hdev->name, batostr(dst));
-
- if (type == LE_LINK)
- return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
-
acl = add_acl_conn(hdev, dst, sec_level, auth_type);
if (IS_ERR(acl))
return acl;
- if (type == ACL_LINK)
- return acl;
-
- sco = hci_conn_hash_lookup_ba(hdev, type, dst);
+ sco = hci_conn_hash_lookup_ba(hdev, SCO_LINK, dst);
if (!sco) {
- sco = hci_conn_add(hdev, type, dst);
+ sco = hci_conn_add(hdev, SCO_LINK, dst);
if (!sco) {
hci_conn_put(acl);
return ERR_PTR(-ENOMEM);
@@ -567,6 +557,21 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
return sco;
}
+/* Create SCO, ACL or LE connection. */
+struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
+ __u8 dst_type, __u8 sec_level, __u8 auth_type)
+{
+ BT_DBG("%s dst %s", hdev->name, batostr(dst));
+
+ if (type == LE_LINK)
+ return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
+
+ if (type == ACL_LINK)
+ return add_acl_conn(hdev, dst, sec_level, auth_type);
+
+ return add_sco_conn(hdev, dst, sec_level, auth_type);
+}
+
/* Check link security requirement */
int hci_conn_check_link_mode(struct hci_conn *conn)
{
--
1.7.10.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/5] Bluetooth: Simplify a the connection type handling
2012-05-31 0:20 [PATCH 1/5] Bluetooth: Refactor LE connection into its own function Vinicius Costa Gomes
2012-05-31 0:20 ` [PATCH 2/5] Bluetooth: Refactor ACL " Vinicius Costa Gomes
2012-05-31 0:20 ` [PATCH 3/5] Bluetooth: Refactor SCO " Vinicius Costa Gomes
@ 2012-05-31 0:20 ` Vinicius Costa Gomes
2012-05-31 7:39 ` Andrei Emeltchenko
2012-05-31 7:43 ` Andrei Emeltchenko
2012-05-31 0:20 ` [PATCH 5/5] Bluetooth: Add type information to the hci_connect() debug statement Vinicius Costa Gomes
3 siblings, 2 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2012-05-31 0:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
Now that we have separate ways of doing connections for each link type,
we can do better than an "if" statement to handle each link type.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
---
net/bluetooth/hci_conn.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 320cc5d..8848a1e 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -563,13 +563,16 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
{
BT_DBG("%s dst %s", hdev->name, batostr(dst));
- if (type == LE_LINK)
+ switch (type) {
+ case LE_LINK:
return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
-
- if (type == ACL_LINK)
+ case ACL_LINK:
return add_acl_conn(hdev, dst, sec_level, auth_type);
+ case SCO_LINK:
+ return add_sco_conn(hdev, dst, sec_level, auth_type);
+ }
- return add_sco_conn(hdev, dst, sec_level, auth_type);
+ return ERR_PTR(-EINVAL);
}
/* Check link security requirement */
--
1.7.10.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 4/5] Bluetooth: Simplify a the connection type handling
2012-05-31 0:20 ` [PATCH 4/5] Bluetooth: Simplify a the connection type handling Vinicius Costa Gomes
@ 2012-05-31 7:39 ` Andrei Emeltchenko
2012-05-31 13:22 ` Gustavo Padovan
2012-05-31 7:43 ` Andrei Emeltchenko
1 sibling, 1 reply; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-31 7:39 UTC (permalink / raw)
To: Vinicius Costa Gomes; +Cc: linux-bluetooth
Hi Vinicius,
On Wed, May 30, 2012 at 09:20:19PM -0300, Vinicius Costa Gomes wrote:
> Now that we have separate ways of doing connections for each link type,
> we can do better than an "if" statement to handle each link type.
>
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
> ---
> net/bluetooth/hci_conn.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 320cc5d..8848a1e 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -563,13 +563,16 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> {
> BT_DBG("%s dst %s", hdev->name, batostr(dst));
>
> - if (type == LE_LINK)
> + switch (type) {
> + case LE_LINK:
> return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
> -
> - if (type == ACL_LINK)
> + case ACL_LINK:
> return add_acl_conn(hdev, dst, sec_level, auth_type);
> + case SCO_LINK:
> + return add_sco_conn(hdev, dst, sec_level, auth_type);
The patches looks OK but somehow I do not like much returns in switch.
Some parsers will notice missing breaks which are not needed here...
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 4/5] Bluetooth: Simplify a the connection type handling
2012-05-31 7:39 ` Andrei Emeltchenko
@ 2012-05-31 13:22 ` Gustavo Padovan
2012-05-31 17:27 ` Vinicius Costa Gomes
0 siblings, 1 reply; 9+ messages in thread
From: Gustavo Padovan @ 2012-05-31 13:22 UTC (permalink / raw)
To: Andrei Emeltchenko, Vinicius Costa Gomes, linux-bluetooth
Hi Andrei,
* Andrei Emeltchenko <andrei.emeltchenko.news@gmail.com> [2012-05-31 10:39:16 +0300]:
> Hi Vinicius,
>
> On Wed, May 30, 2012 at 09:20:19PM -0300, Vinicius Costa Gomes wrote:
> > Now that we have separate ways of doing connections for each link type,
> > we can do better than an "if" statement to handle each link type.
> >
> > Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
> > ---
> > net/bluetooth/hci_conn.c | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> > index 320cc5d..8848a1e 100644
> > --- a/net/bluetooth/hci_conn.c
> > +++ b/net/bluetooth/hci_conn.c
> > @@ -563,13 +563,16 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> > {
> > BT_DBG("%s dst %s", hdev->name, batostr(dst));
> >
> > - if (type == LE_LINK)
> > + switch (type) {
> > + case LE_LINK:
> > return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
> > -
> > - if (type == ACL_LINK)
> > + case ACL_LINK:
> > return add_acl_conn(hdev, dst, sec_level, auth_type);
> > + case SCO_LINK:
> > + return add_sco_conn(hdev, dst, sec_level, auth_type);
>
> The patches looks OK but somehow I do not like much returns in switch.
> Some parsers will notice missing breaks which are not needed here...
Use return here seems ok to me, I just want that these functions gets a hci_
prefix.
Gustavo
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 4/5] Bluetooth: Simplify a the connection type handling
2012-05-31 13:22 ` Gustavo Padovan
@ 2012-05-31 17:27 ` Vinicius Costa Gomes
0 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2012-05-31 17:27 UTC (permalink / raw)
To: Gustavo Padovan, Andrei Emeltchenko, linux-bluetooth
Hi,
On 10:22 Thu 31 May, Gustavo Padovan wrote:
> Hi Andrei,
>
> * Andrei Emeltchenko <andrei.emeltchenko.news@gmail.com> [2012-05-31 10:39:16 +0300]:
>
> > Hi Vinicius,
> >
> > On Wed, May 30, 2012 at 09:20:19PM -0300, Vinicius Costa Gomes wrote:
> > > Now that we have separate ways of doing connections for each link type,
> > > we can do better than an "if" statement to handle each link type.
> > >
> > > Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
> > > ---
> > > net/bluetooth/hci_conn.c | 11 +++++++----
> > > 1 file changed, 7 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> > > index 320cc5d..8848a1e 100644
> > > --- a/net/bluetooth/hci_conn.c
> > > +++ b/net/bluetooth/hci_conn.c
> > > @@ -563,13 +563,16 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> > > {
> > > BT_DBG("%s dst %s", hdev->name, batostr(dst));
> > >
> > > - if (type == LE_LINK)
> > > + switch (type) {
> > > + case LE_LINK:
> > > return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
> > > -
> > > - if (type == ACL_LINK)
> > > + case ACL_LINK:
> > > return add_acl_conn(hdev, dst, sec_level, auth_type);
> > > + case SCO_LINK:
> > > + return add_sco_conn(hdev, dst, sec_level, auth_type);
> >
> > The patches looks OK but somehow I do not like much returns in switch.
> > Some parsers will notice missing breaks which are not needed here...
>
> Use return here seems ok to me, I just want that these functions gets a hci_
> prefix.
Fair enough. So I am going with hci_add_{acl,sco,le}.
>
> Gustavo
Cheers,
--
Vinicius
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/5] Bluetooth: Simplify a the connection type handling
2012-05-31 0:20 ` [PATCH 4/5] Bluetooth: Simplify a the connection type handling Vinicius Costa Gomes
2012-05-31 7:39 ` Andrei Emeltchenko
@ 2012-05-31 7:43 ` Andrei Emeltchenko
1 sibling, 0 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-31 7:43 UTC (permalink / raw)
To: Vinicius Costa Gomes; +Cc: linux-bluetooth
Hi Vinicius,
On Wed, May 30, 2012 at 09:20:19PM -0300, Vinicius Costa Gomes wrote:
> return add_le_conn(hdev, dst, dst_type, sec_level, auth_type);
> return add_acl_conn(hdev, dst, sec_level, auth_type);
> + return add_sco_conn(hdev, dst, sec_level, auth_type);
Those new functions are only ones missing hci prefix in that file? Maybe
names like hci_add_acl or hci_connect_acl would be better?
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5/5] Bluetooth: Add type information to the hci_connect() debug statement
2012-05-31 0:20 [PATCH 1/5] Bluetooth: Refactor LE connection into its own function Vinicius Costa Gomes
` (2 preceding siblings ...)
2012-05-31 0:20 ` [PATCH 4/5] Bluetooth: Simplify a the connection type handling Vinicius Costa Gomes
@ 2012-05-31 0:20 ` Vinicius Costa Gomes
3 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2012-05-31 0:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
Now that we have a "connect" function for each link type, we should be
able to indentify which function is going to be called.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
---
net/bluetooth/hci_conn.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 8848a1e..d875c68 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -561,7 +561,7 @@ static struct hci_conn *add_sco_conn(struct hci_dev *hdev, bdaddr_t *dst,
struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
__u8 dst_type, __u8 sec_level, __u8 auth_type)
{
- BT_DBG("%s dst %s", hdev->name, batostr(dst));
+ BT_DBG("%s dst %s type 0x%x", hdev->name, batostr(dst), type);
switch (type) {
case LE_LINK:
--
1.7.10.3
^ permalink raw reply related [flat|nested] 9+ messages in thread