linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set
@ 2015-02-05 15:07 Szymon Janc
  2015-02-05 15:07 ` [PATCH 2/3] shared/hfp: Fix calling io read function directly Szymon Janc
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Szymon Janc @ 2015-02-05 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Always set pending_result before calling command callback.

If response will be send from callback pending_result will be
cleared by either hfp_gw_send_result or hfp_gw_send_error.
---
 src/shared/hfp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 0ce3121..ea6494d 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -183,8 +183,8 @@ static void handle_unknown_at_command(struct hfp_gw *hfp,
 							const char *data)
 {
 	if (hfp->command_callback) {
-		hfp->command_callback(data, hfp->command_data);
 		hfp->result_pending = true;
+		hfp->command_callback(data, hfp->command_data);
 	} else {
 		hfp_gw_send_result(hfp, HFP_RESULT_ERROR);
 	}
@@ -263,6 +263,7 @@ done:
 		return true;
 	}
 
+	hfp->result_pending = true;
 	handler->callback(&context, type, handler->user_data);
 
 	return true;
-- 
1.9.1


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

* [PATCH 2/3] shared/hfp: Fix calling io read function directly
  2015-02-05 15:07 [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc
@ 2015-02-05 15:07 ` Szymon Janc
  2015-02-05 15:07 ` [PATCH 3/3] shared/hfp: Fix not processing input from hfp_gw_send_error Szymon Janc
  2015-02-09 12:29 ` [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2015-02-05 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

can_read_data function should by called only from IO read callback.
can_read_data feeds ringbuffer but don't call process_input() if
there is pending result. So it is enought to just call process_input
cause any pending data are already present in ring_buffer.

This fix blocking read in unit/test-hfp exposed by previous patch.
---
 src/shared/hfp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index ea6494d..90e17c7 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -762,7 +762,7 @@ bool hfp_gw_send_result(struct hfp_gw *hfp, enum hfp_result result)
 	 */
 	if (hfp->result_pending) {
 		hfp->result_pending = false;
-		can_read_data(hfp->io, hfp);
+		process_input(hfp);
 	}
 
 	return true;
-- 
1.9.1


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

* [PATCH 3/3] shared/hfp: Fix not processing input from hfp_gw_send_error
  2015-02-05 15:07 [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc
  2015-02-05 15:07 ` [PATCH 2/3] shared/hfp: Fix calling io read function directly Szymon Janc
@ 2015-02-05 15:07 ` Szymon Janc
  2015-02-09 12:29 ` [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2015-02-05 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

If for some reason there is more than one AT command in the ring
buffer we should make sure that after upper layer sends error, AT
parser gets back to reading data from ring buffer.

Same is already done in hfp_gw_send_result() and we should handle
this in error response as well.
---
 src/shared/hfp.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 90e17c7..74ee979 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -778,7 +778,14 @@ bool hfp_gw_send_error(struct hfp_gw *hfp, enum hfp_error error)
 
 	wakeup_writer(hfp);
 
-	hfp->result_pending = false;
+	/*
+	 * There might be already something to read in the ring buffer.
+	 * If so, let's read it.
+	 */
+	if (hfp->result_pending) {
+		hfp->result_pending = false;
+		process_input(hfp);
+	}
 
 	return true;
 }
-- 
1.9.1


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

* Re: [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set
  2015-02-05 15:07 [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc
  2015-02-05 15:07 ` [PATCH 2/3] shared/hfp: Fix calling io read function directly Szymon Janc
  2015-02-05 15:07 ` [PATCH 3/3] shared/hfp: Fix not processing input from hfp_gw_send_error Szymon Janc
@ 2015-02-09 12:29 ` Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2015-02-09 12:29 UTC (permalink / raw)
  To: linux-bluetooth

On Thursday 05 of February 2015 16:07:09 Szymon Janc wrote:
> Always set pending_result before calling command callback.
> 
> If response will be send from callback pending_result will be
> cleared by either hfp_gw_send_result or hfp_gw_send_error.
> ---
>  src/shared/hfp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 0ce3121..ea6494d 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -183,8 +183,8 @@ static void handle_unknown_at_command(struct hfp_gw
> *hfp, const char *data)
>  {
>  	if (hfp->command_callback) {
> -		hfp->command_callback(data, hfp->command_data);
>  		hfp->result_pending = true;
> +		hfp->command_callback(data, hfp->command_data);
>  	} else {
>  		hfp_gw_send_result(hfp, HFP_RESULT_ERROR);
>  	}
> @@ -263,6 +263,7 @@ done:
>  		return true;
>  	}
> 
> +	hfp->result_pending = true;
>  	handler->callback(&context, type, handler->user_data);
> 
>  	return true;

All patches applied.

-- 
BR
Szymon Janc

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

end of thread, other threads:[~2015-02-09 12:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-05 15:07 [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc
2015-02-05 15:07 ` [PATCH 2/3] shared/hfp: Fix calling io read function directly Szymon Janc
2015-02-05 15:07 ` [PATCH 3/3] shared/hfp: Fix not processing input from hfp_gw_send_error Szymon Janc
2015-02-09 12:29 ` [PATCH 1/3] shared/hfp: Fix calling callback without result_pending set Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).