All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response
@ 2015-05-14  7:47 Grzegorz Kolodziejczyk
  2015-05-14  7:47 ` [PATCH v4 2/2] profiles/network: Add support for handling extension hdr in ctrl msg Grzegorz Kolodziejczyk
  2015-05-19 14:34 ` [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Szymon Janc
  0 siblings, 2 replies; 5+ messages in thread
From: Grzegorz Kolodziejczyk @ 2015-05-14  7:47 UTC (permalink / raw)
  To: linux-bluetooth

This patch updates bnep header with get bnep supported features ioctl
and bnep setup response flag.
---
 lib/bnep.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/bnep.h b/lib/bnep.h
index aa46852..e7c2c87 100644
--- a/lib/bnep.h
+++ b/lib/bnep.h
@@ -126,6 +126,9 @@ struct bnep_ext_hdr {
 #define BNEPCONNDEL	_IOW('B', 201, int)
 #define BNEPGETCONNLIST	_IOR('B', 210, int)
 #define BNEPGETCONNINFO	_IOR('B', 211, int)
+#define BNEPGETSUPPFEAT	_IOR('B', 212, int)
+
+#define BNEP_SETUP_RESPONSE	0
 
 struct bnep_connadd_req {
 	int      sock;		/* Connected socket */
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] profiles/network: Add support for handling extension hdr in ctrl msg
  2015-05-14  7:47 [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Grzegorz Kolodziejczyk
@ 2015-05-14  7:47 ` Grzegorz Kolodziejczyk
  2015-05-19 14:34 ` [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Szymon Janc
  1 sibling, 0 replies; 5+ messages in thread
From: Grzegorz Kolodziejczyk @ 2015-05-14  7:47 UTC (permalink / raw)
  To: linux-bluetooth

Support for extension headers is mandatory functionality. This patch
add support to it and leave responsibility for processing extension
header and sending setup success response to kernel.

This patch is necessary to pass PTS bnep test TC_CTRL_BV_19_C.
---
 android/pan.c             |   7 +++-
 profiles/network/bnep.c   | 102 ++++++++++++++++++++++++++++++++++++++++------
 profiles/network/server.c |   7 +++-
 tools/bneptest.c          |   2 +-
 4 files changed, 101 insertions(+), 17 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index 6c9815b..0bb576e 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -471,8 +471,11 @@ static gboolean nap_setup_cb(GIOChannel *chan, GIOCondition cond,
 
 	sk = g_io_channel_unix_get_fd(chan);
 
-	/* Reading BNEP_SETUP_CONNECTION_REQUEST_MSG */
-	n = read(sk, packet, sizeof(packet));
+	/*
+	 * BNEP_SETUP_CONNECTION_REQUEST_MSG should be read and left in case
+	 * of kernel setup connection msg handling.
+	 */
+	n = recv(sk, packet, sizeof(packet), MSG_PEEK);
 	if (n  < 0) {
 		error("read(): %s(%d)", strerror(errno), errno);
 		goto failed;
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index e325b72..59599e4 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -124,6 +124,7 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)
 
 	req.sock = sk;
 	req.role = role;
+	req.flags = (1 << BNEP_SETUP_RESPONSE);
 	if (ioctl(ctl, BNEPCONNADD, &req) < 0) {
 		int err = -errno;
 		error("bnep: Failed to add device %s: %s(%d)",
@@ -135,6 +136,18 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)
 	return 0;
 }
 
+static uint32_t bnep_getsuppfeat(void)
+{
+	uint32_t feat;
+
+	if (ioctl(ctl, BNEPGETSUPPFEAT, &feat) < 0)
+		feat = 0;
+
+	DBG("supported features: 0x%x", feat);
+
+	return feat;
+}
+
 static int bnep_if_up(const char *devname)
 {
 	struct ifreq ifr;
@@ -530,7 +543,9 @@ static uint16_t bnep_setup_decode(int sk, struct bnep_setup_conn_req *req,
 	uint8_t *dest, *source;
 	uint32_t val;
 
-	if (req->type != BNEP_CONTROL || req->ctrl != BNEP_SETUP_CONN_REQ)
+	if (((req->type != BNEP_CONTROL) &&
+		(req->type != (BNEP_CONTROL | BNEP_EXT_HEADER)))  ||
+					req->ctrl != BNEP_SETUP_CONN_REQ)
 		return BNEP_CONN_NOT_ALLOWED;
 
 	dest = req->service;
@@ -587,10 +602,55 @@ static uint16_t bnep_setup_decode(int sk, struct bnep_setup_conn_req *req,
 	return BNEP_CONN_INVALID_DST;
 }
 
+static int bnep_server_add_legacy(int sk, uint16_t dst, char *bridge,
+					char *iface, const bdaddr_t *addr,
+					uint8_t *setup_data, int len)
+{
+	int err, n;
+	uint16_t rsp;
+
+	n = read(sk, setup_data, len);
+	if (n != len) {
+		err = -EIO;
+		rsp = BNEP_CONN_NOT_ALLOWED;
+		goto reply;
+	}
+
+	err = bnep_connadd(sk, dst, iface);
+	if (err < 0) {
+		rsp = BNEP_CONN_NOT_ALLOWED;
+		goto reply;
+	}
+
+	err = bnep_add_to_bridge(iface, bridge);
+	if (err < 0) {
+		bnep_conndel(addr);
+		rsp = BNEP_CONN_NOT_ALLOWED;
+		goto reply;
+	}
+
+	err = bnep_if_up(iface);
+	if (err < 0) {
+		bnep_del_from_bridge(iface, bridge);
+		bnep_conndel(addr);
+		rsp = BNEP_CONN_NOT_ALLOWED;
+	}
+
+reply:
+	if (bnep_send_ctrl_rsp(sk, BNEP_SETUP_CONN_RSP, rsp) < 0) {
+		err = -errno;
+		error("bnep: send ctrl rsp error: %s (%d)", strerror(-err),
+									-err);
+	}
+
+	return err;
+}
+
 int bnep_server_add(int sk, char *bridge, char *iface, const bdaddr_t *addr,
 						uint8_t *setup_data, int len)
 {
 	int err;
+	uint32_t feat;
 	uint16_t rsp, dst;
 	struct bnep_setup_conn_req *req = (void *) setup_data;
 
@@ -614,31 +674,49 @@ int bnep_server_add(int sk, char *bridge, char *iface, const bdaddr_t *addr,
 		err = -rsp;
 		error("bnep: error while decoding setup connection request: %d",
 									rsp);
-		goto reply;
+		goto failed;
 	}
 
+	feat = bnep_getsuppfeat();
+
+	/*
+	 * Take out setup data if kernel doesn't support handling it, especially
+	 * setup request. If kernel would have set session flags, they should
+	 * be checked and handled respectively.
+	 */
+	if (!feat || !(feat & (1 << BNEP_SETUP_RESPONSE)))
+		return bnep_server_add_legacy(sk, dst, bridge, iface, addr,
+							setup_data, len);
+
 	err = bnep_connadd(sk, dst, iface);
 	if (err < 0) {
 		rsp = BNEP_CONN_NOT_ALLOWED;
-		goto reply;
+		goto failed;
 	}
 
 	err = bnep_add_to_bridge(iface, bridge);
-	if (err < 0) {
-		bnep_conndel(addr);
-		rsp = BNEP_CONN_NOT_ALLOWED;
-		goto reply;
-	}
+	if (err < 0)
+		goto failed_conn;
 
 	err = bnep_if_up(iface);
 	if (err < 0)
-		rsp = BNEP_CONN_NOT_ALLOWED;
+		goto failed_bridge;
 
-reply:
+	return 0;
+
+failed_bridge:
+	bnep_del_from_bridge(iface, bridge);
+
+failed_conn:
+	bnep_conndel(addr);
+
+	return err;
+
+failed:
 	if (bnep_send_ctrl_rsp(sk, BNEP_SETUP_CONN_RSP, rsp) < 0) {
 		err = -errno;
-		error("bnep: send ctrl rsp error: %s (%d)", strerror(errno),
-									errno);
+		error("bnep: send ctrl rsp error: %s (%d)", strerror(-err),
+									-err);
 	}
 
 	return err;
diff --git a/profiles/network/server.c b/profiles/network/server.c
index 32aafc3..1bff9f8 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -327,8 +327,11 @@ static gboolean bnep_setup(GIOChannel *chan,
 
 	sk = g_io_channel_unix_get_fd(chan);
 
-	/* Reading BNEP_SETUP_CONNECTION_REQUEST_MSG */
-	n = read(sk, packet, sizeof(packet));
+	/*
+	 * BNEP_SETUP_CONNECTION_REQUEST_MSG should be read and left in case
+	 * of kernel setup connection msg handling.
+	 */
+	n = recv(sk, packet, sizeof(packet), MSG_PEEK);
 	if (n < 0) {
 		error("read(): %s(%d)", strerror(errno), errno);
 		return FALSE;
diff --git a/tools/bneptest.c b/tools/bneptest.c
index 98ee9b1..a7d5815 100644
--- a/tools/bneptest.c
+++ b/tools/bneptest.c
@@ -327,7 +327,7 @@ static gboolean setup_bnep_cb(GIOChannel *chan, GIOCondition cond,
 	sk = g_io_channel_unix_get_fd(chan);
 
 	/* Reading BNEP_SETUP_CONNECTION_REQUEST_MSG */
-	n = read(sk, packet, sizeof(packet));
+	n = recv(sk, packet, sizeof(packet), MSG_PEEK);
 	if (n < 0) {
 		error("read(): %s(%d)", strerror(errno), errno);
 		return FALSE;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response
  2015-05-14  7:47 [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Grzegorz Kolodziejczyk
  2015-05-14  7:47 ` [PATCH v4 2/2] profiles/network: Add support for handling extension hdr in ctrl msg Grzegorz Kolodziejczyk
@ 2015-05-19 14:34 ` Szymon Janc
  2015-05-19 17:39   ` Luiz Augusto von Dentz
  1 sibling, 1 reply; 5+ messages in thread
From: Szymon Janc @ 2015-05-19 14:34 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth

Hi Grzegorz,

On Thursday 14 of May 2015 09:47:09 Grzegorz Kolodziejczyk wrote:
> This patch updates bnep header with get bnep supported features ioctl
> and bnep setup response flag.
> ---
>  lib/bnep.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/bnep.h b/lib/bnep.h
> index aa46852..e7c2c87 100644
> --- a/lib/bnep.h
> +++ b/lib/bnep.h
> @@ -126,6 +126,9 @@ struct bnep_ext_hdr {
>  #define BNEPCONNDEL	_IOW('B', 201, int)
>  #define BNEPGETCONNLIST	_IOR('B', 210, int)
>  #define BNEPGETCONNINFO	_IOR('B', 211, int)
> +#define BNEPGETSUPPFEAT	_IOR('B', 212, int)
> +
> +#define BNEP_SETUP_RESPONSE	0
> 
>  struct bnep_connadd_req {
>  	int      sock;		/* Connected socket */

Both patches applied. Thanks.

-- 
BR
Szymon Janc

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response
  2015-05-19 14:34 ` [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Szymon Janc
@ 2015-05-19 17:39   ` Luiz Augusto von Dentz
  2015-05-20  7:28     ` Grzegorz Kolodziejczyk
  0 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2015-05-19 17:39 UTC (permalink / raw)
  To: Szymon Janc; +Cc: Grzegorz Kolodziejczyk, linux-bluetooth

Hi Grzegorz,

On Tue, May 19, 2015 at 5:34 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> Hi Grzegorz,
>
> On Thursday 14 of May 2015 09:47:09 Grzegorz Kolodziejczyk wrote:
>> This patch updates bnep header with get bnep supported features ioctl
>> and bnep setup response flag.
>> ---
>>  lib/bnep.h | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/lib/bnep.h b/lib/bnep.h
>> index aa46852..e7c2c87 100644
>> --- a/lib/bnep.h
>> +++ b/lib/bnep.h
>> @@ -126,6 +126,9 @@ struct bnep_ext_hdr {
>>  #define BNEPCONNDEL  _IOW('B', 201, int)
>>  #define BNEPGETCONNLIST      _IOR('B', 210, int)
>>  #define BNEPGETCONNINFO      _IOR('B', 211, int)
>> +#define BNEPGETSUPPFEAT      _IOR('B', 212, int)
>> +
>> +#define BNEP_SETUP_RESPONSE  0
>>
>>  struct bnep_connadd_req {
>>       int      sock;          /* Connected socket */
>
> Both patches applied. Thanks.

Btw, next time please keep the first line a bit shorter.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response
  2015-05-19 17:39   ` Luiz Augusto von Dentz
@ 2015-05-20  7:28     ` Grzegorz Kolodziejczyk
  0 siblings, 0 replies; 5+ messages in thread
From: Grzegorz Kolodziejczyk @ 2015-05-20  7:28 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Szymon Janc, linux-bluetooth

Hi Luiz,

On 19 May 2015 at 19:39, Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
> Hi Grzegorz,
>
> On Tue, May 19, 2015 at 5:34 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
>> Hi Grzegorz,
>>
>> On Thursday 14 of May 2015 09:47:09 Grzegorz Kolodziejczyk wrote:
>>> This patch updates bnep header with get bnep supported features ioctl
>>> and bnep setup response flag.
>>> ---
>>>  lib/bnep.h | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/lib/bnep.h b/lib/bnep.h
>>> index aa46852..e7c2c87 100644
>>> --- a/lib/bnep.h
>>> +++ b/lib/bnep.h
>>> @@ -126,6 +126,9 @@ struct bnep_ext_hdr {
>>>  #define BNEPCONNDEL  _IOW('B', 201, int)
>>>  #define BNEPGETCONNLIST      _IOR('B', 210, int)
>>>  #define BNEPGETCONNINFO      _IOR('B', 211, int)
>>> +#define BNEPGETSUPPFEAT      _IOR('B', 212, int)
>>> +
>>> +#define BNEP_SETUP_RESPONSE  0
>>>
>>>  struct bnep_connadd_req {
>>>       int      sock;          /* Connected socket */
>>
>> Both patches applied. Thanks.
>
> Btw, next time please keep the first line a bit shorter.
>
Ok, I'll try to remember.
>
> --
> Luiz Augusto von Dentz


BR,
Grzegorz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-20  7:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14  7:47 [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Grzegorz Kolodziejczyk
2015-05-14  7:47 ` [PATCH v4 2/2] profiles/network: Add support for handling extension hdr in ctrl msg Grzegorz Kolodziejczyk
2015-05-19 14:34 ` [PATCH v4 1/2] lib/bnep: Update bnep header with BNEPGETSUPPFEAT and setup response Szymon Janc
2015-05-19 17:39   ` Luiz Augusto von Dentz
2015-05-20  7:28     ` Grzegorz Kolodziejczyk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.