Skip to contentSkip to conversation

Problem automatic flush timeout

Bluez-devel In review Jui-Hao Chiang 2 participants 5 messages Aug 22, 2008 – Aug 23, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,
Is there a way to simulate unreliable L2CAP socket in a client-server scenario? (two PCs, each with single adapter; client sends 48 bytes packet to server every 1 second)
After establishing a L2CAP between two adapters, I tried to set the "automatic flush timeout" on the client adapter with timeout to be 2. The hci_send_req is successful, but after 7 to 8 seconds, the server adapter stops to receive any data while client socket is still sending data. If I set it timeout to 4, then everything is fine.

What I am imagining is "some data on client adapter may be flushed, but the later packet should continue to be sent to server adapter".
Am I doing something wrong?

    // build a command packet to send to the bluetooth microcontroller
    cmd_param.handle = connection_handle;
    cmd_param.flush_timeout = htobs(timeout);
    rq.ogf = OGF_HOST_CTL;
    rq.ocf = 0x28;
    rq.cparam = &cmd_param;
    rq.clen = sizeof(cmd_param);
    rq.rparam = &cmd_response;
    rq.rlen = sizeof(cmd_response);
    rq.event = EVT_CMD_COMPLETE;

    // send the command and wait for the response
    err = hci_send_req( dd, &rq, 0 );
    if( err ) goto cleanup;

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw

Hi,
What I found in net/bluetooth/hci_core.c and net/bluetooth/hci_event.c are
(1) the "Flush Occured Event" (ocf 0x11) is not handled in hci_event
(2) while the user socket keeps pushing the data via l2cap_sock_sendmsg->l2cap_do_send->hci_send_acl ->hci_sched_tx->hci_tx_task->hci_sched_acl

Eventually it stops in hci_sched_acl when checking hdev->acl_cnt. I consider that hdev->acl_cnt means: "the number of ACL packet we can push to hci_usb".

Thus, I think the possible way to handle this event is to
(1) add in "include/net/bluetooth/hci.h"
#define HCI_EV_FLUSH_OCCURED 0x11
(2) catch the event in hci_event_packet, and do the following (same as hci_num_comp_pkts_evt)
if ((++ hdev->acl_cnt) > hdev->acl_pkts) hdev->acl_cnt = hdev->acl_pkts;
(3) decrement the conn->sent by
atomic_sub(count, &conn->sent);

Please correct me if I am wrong.

Jui-Hao

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw

PATCH 1/1 Flush Occurred Event

In reply to Jui-Hao Chiang
Quoted 1 line

The following is a patch against 2.6.22 kernel to catch HCI "Flush Occurred" event. (meaningful for ACL; useless for SCO)

One more thing to NOTICE is that the handle in the event packet from my adapter seems to be "Big Endian", so that I use ntohs to convert it. Normally it should be __le16_to_cpu(ev->handle)

diff -r linux-source-2.6.22/include/net/bluetooth/hci_core.h patch-2.6.22/include/net/bluetooth/hci_core.h 27a28

Quoted 1 line

diff -r linux-source-2.6.22/include/net/bluetooth/hci.h patch-2.6.22/include/net/bluetooth/hci.h 587a588,595

Quoted 8 lines

/* Flush Occurred Event JuiHao --*/
#define HCI_EV_FLUSH_OCCURRED 0x11
#define NUM_OF_FLUSH_PKT 0x1

struct hci_ev_flush_occurred {
	__le16   handle;
} __attribute__ ((packed));

/* --Flush Occurred Event JuiHao */

diff -r linux-source-2.6.22/net/bluetooth/hci_event.c patch-2.6.22/net/bluetooth/hci_event.c 854a855,882

Quoted 2 lines

/* Flush Occurred packet JuiHao*/
static inline void hci_flush_occurred_evt(struct hci_dev *hdev, struct sk_buff

*skb)

Quoted 9 lines
{
	struct hci_ev_flush_occurred *ev = (struct hci_ev_flush_occurred *) skb->data;
	struct hci_conn *conn;
	
	tasklet_disable(&hdev->tx_task);

	BT_DBG("handle is %x, skb->len %d\n", ev->handle, skb->len);	

	/* The handle returned is probably Big Endian such that  __le16_to_cpu is

useless*/

Quoted 8 lines
	conn = hci_conn_hash_lookup_handle(hdev, ntohs(ev->handle));

	if (conn) {
		atomic_sub(NUM_OF_FLUSH_PKT, &conn->sent);

		if (conn->type == ACL_LINK) {
			if ((hdev->acl_cnt += NUM_OF_FLUSH_PKT) > hdev->acl_pkts)
				hdev->acl_cnt = hdev->acl_pkts;
Quoted 9 lines
		}
		BT_DBG("conn %p type %d hdev->acl_cnt %d conn->sent %d",
			conn, conn->type, hdev->acl_cnt, atomic_read(&conn->sent));
	}
	hci_sched_tx(hdev);

	tasklet_enable(&hdev->tx_task);
}

1289a1318,1322

Quoted 5 lines
	/* handle Flush Occurred Event JuiHao --*/
	case HCI_EV_FLUSH_OCCURRED:
		hci_flush_occurred_evt(hdev, skb);
		break;	
	/* -- handle Flush Occurred Event JuiHao */

Bests,
Jui-Hao

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#3 lore raw

Re: [Bluez-devel] [Patch] Flush Occurred Event

Hi,

Quoted 6 lines

The following is a patch against 2.6.22 kernel to catch HCI "Flush Occurred" event. (meaningful for ACL; useless for SCO)

One more thing to NOTICE is that the handle in the event packet from my adapter seems to be "Big Endian", so that I use ntohs to convert it. Normally it should be __le16_to_cpu(ev->handle)

against 2.6.27-rc4 please and in unified diff format. I am not even going to bother reading context diffs.

Regards

Marcel

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw

Re: [Bluez-devel] [Patch] Flush Occurred Event

Hi, Marcel, please see if it is ok

Quoted 7 lines · Marcel Holtmann <marcel <at> holtmann.org> writes:

against 2.6.27-rc4 please and in unified diff format. I am not even going to bother reading context diffs.

Regards

Marcel

include/net/bluetooth/hci.h +6 -0
diff -ru orig/include/net/bluetooth/hci.h new/include/net/bluetooth/hci.h
@@ -682,6 +682,12 @@
 	__le16   opcode;
 } __attribute__ ((packed));
 
+#define HCI_EV_FLUSH_OCCURRED   0x11
+#define NUM_OF_FLUSH_PKT        0x1
+struct hci_ev_flush_occurred {
+        __le16   handle;
+} __attribute__ ((packed));
+
 #define HCI_EV_ROLE_CHANGE		0x12
 struct hci_ev_role_change {
 	__u8     status;
net/bluetooth/hci_event.c +1 -0
diff -ru orig/net/bluetooth/hci_event.c new/net/bluetooth/hci_event.c
@@ -1398,6 +1398,32 @@
 	hci_dev_unlock(hdev);
 }
 
+static inline void hci_flush_occurred_evt(struct hci_dev *hdev, struct sk_buff

*skb)
+{
+ struct hci_ev_flush_occurred *ev = (struct hci_ev_flush_occurred *) skb->data;
+ struct hci_conn *conn;
+
+ tasklet_disable(&hdev->tx_task);
+
+ BT_DBG("handle is %x, skb->len %d\n", ev->handle, skb->len);
+
+ conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
+
+ if (conn) {
+ atomic_sub(NUM_OF_FLUSH_PKT, &conn->sent);
+
+ if (conn->type == ACL_LINK) {
+ if ((hdev->acl_cnt += NUM_OF_FLUSH_PKT) > hdev->acl_pkts)
+ hdev->acl_cnt = hdev->acl_pkts;
+ }
+ BT_DBG("conn %p type %d hdev->acl_cnt %d conn->sent %d",
+ conn, conn->type, hdev->acl_cnt, atomic_read(&conn->sent));
+ }
+ hci_sched_tx(hdev);
+
+ tasklet_enable(&hdev->tx_task);
+}
+
static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) {
struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
@@ -1894,6 +1920,10 @@
hci_remote_host_features_evt(hdev, skb);
break;

+ case HCI_EV_FLUSH_OCCURRED:
+ hci_flush_occurred_evt(hdev, skb);
+ break;
+
default:
BT_DBG("%s event 0x%x", hdev->name, event); break;

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel