Skip to contentSkip to conversation

L2CAP Flow Control - 3rd stage

Bluez-devel Martin Röhricht 1 participant 1 message May 4, 2006

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

Hello together,

it took me some time since my last post to fix some annoying bugs regarding my implementation of flow control features in BlueZ. Currently I have only three test devices: a Siemens S55 mobile phone, a Siemens S75 mobile phone and another Acer laptop with the Windows XP Bluetooth stack. I hope to get another USB adaptor with a Toshiba stack within the next few days which may even work with the Apple Bluetooth stack at my iMac G4.

I will go over some investigations and implementation specific things now.
First of all I extended l2cap.h to provide some global constants for Flow Control. The reject command (struct l2cap_cmd_rej) offers some information data for two of the three possible reject reasons so I figured out it might be interesting to see why this rejection applied and added the variable length array »data« as well as the three possible reject reasons as constants.
The different configuration states (conf_states) have been extended, too. All the other stuff should already be covered by one of my earlier mails.

Secondly I worked on l2cap.c for most of the time.
Most of these functions didn't change since my last post. I fixed some bugs in l2cap_config_rsp() and this is one function that might be still erroneous (I couldn't validate the L2CAP_CONF_UNKNOWN and the default cases), but it works with those three devices mentioned above. l2cap_build_conf_rsp() was one of the trouble makers, which was basically my fault. I removed the l2cap_conf_output() function and put its functionality into l2cap_build_conf_rsp().
The reject command is now really handled by its own function l2cap_command_rej() and corresponding debug messages are printed. One major issue about my implementation (and the long delay) is the »new technique« that applies now: Instead of sending a configuration request first, we start with an information request and do not send a configuration request before we got an answer in form of an information response. We can trust this model as it is stated in the specification:
»Information requests are used to request implementation specific information from a remote L2CAP entity. L2CAP implementations _shall_ respond to a valid Information Request with an Information Response [...]« (section 4.10)
This assumption is rather hard, but we must send an information request before we try to make use of flow control options in configuration requests ... So the downside is now, that if the remote peer is not able to send a simple information response (which is really simple) we do not come into the stage of any configuration process.
The main problem was now to send a configuration request right after getting (and parsing) the information response. This was problematic because I was not able to retrieve the working socket from within our l2cap_information_rsp() function. This took me some weeks but finally I seem to have this issue solved. To retrieve the socket I use the function l2cap_get_chan_by_ident(&conn->chan_list, cmd->ident) which didn't work with the Windows stack but with my Siemens mobile phones. I had to set the socket's identificator to the next available connection's identificator instead of starting from 0, and use this socket's ident in our l2cap_connect_rsp() function as the command code for our information request.

Okay, so that's basically it. The current patch makes the configuration process to work with my three devices. Unfortunately none of those three devices wants to »flow control« with me :-( The nearest one is the Siemens S75 which claims to support all the extended features, including flow control (explicitly) but when I start a configuration request trying to use flow control, it responds with »unacceptable parameters« and states it wants to use the Basic L2CAP Mode ... Damn. Windows and the S55 do not offer the extended features in an information response. I hope to have more luck with the Toshiba and the Apple stack. This patch does only set the flow control parameters and does not do anything regarding the flow control process itself. If somebody has devices with newer Bluetooth stacks (Widcomm for example) he is welcomed to compile this patch and just initiate a send and receive action to see if it still works.

Martin

include/net/bluetooth/l2cap.h +86 -12
diff -urN linux-2.6.15-mh2/include/net/bluetooth/l2cap.h linux-2.6.15-mr/include/net/bluetooth/l2cap.h
@@ -27,7 +27,19 @@
 
 /* L2CAP defaults */
 #define L2CAP_DEFAULT_MTU	672
+#define L2CAP_MIN_MTU		48
 #define L2CAP_DEFAULT_FLUSH_TO	0xFFFF
+#define L2CAP_DEFAULT_TXW 	32
+#define L2CAP_MIN_TXW		1
+#define L2CAP_MAX_TXW		32
+#define L2CAP_DEFAULT_MAXT 	32
+#define L2CAP_DEFAULT_RETTO 	1000
+#define L2CAP_DEFAULT_MONTO 	1000
+#define L2CAP_DEFAULT_MPS 	0xFFFF
+#define L2CAP_MAX_MPS		0xFFFF
+
+/* maximum possible options for one request/response */
+#define L2CAP_MAX_OPTS 		128
 
 #define L2CAP_CONN_TIMEOUT	(HZ * 40)
 
@@ -47,6 +59,10 @@
 	__u8  mode;
 };
 
+#define L2CAP_MODE_BASIC	0x00
+#define L2CAP_MODE_RET		0x01
+#define L2CAP_MODE_FLOW		0x02
+
 #define L2CAP_CONNINFO	0x02
 struct l2cap_conninfo {
 	__u16 hci_handle;
@@ -90,8 +106,14 @@
 
 struct l2cap_cmd_rej {
 	__le16     reason;
+	__le16     data[0];
 } __attribute__ ((packed));
 
+/* command reject reasons */
+#define L2CAP_CMD_NOT_UNDERSTOOD 	0x0000
+#define L2CAP_MTU_EXCEEDED 		0x0001
+#define L2CAP_INVALID_CID 		0x0002
+
 struct l2cap_conn_req {
 	__le16     psm;
 	__le16     scid;
@@ -129,8 +151,10 @@
 	__u8       data[0];
 } __attribute__ ((packed));
 
-#define L2CAP_CONF_SUCCESS	0x00
-#define L2CAP_CONF_UNACCEPT	0x01
+#define L2CAP_CONF_SUCCESS	0x0000
+#define L2CAP_CONF_UNACCEPT	0x0001
+#define L2CAP_CONF_REJ		0x0002
+#define L2CAP_CONF_UNKNOWN	0x0003
 
 struct l2cap_conf_opt {
 	__u8       type;
@@ -144,8 +168,20 @@
 #define L2CAP_CONF_QOS		0x03
 #define L2CAP_CONF_RFC		0x04
 
+#define SET_BIT(x, v) ((x) |= 1 << (v))
+#define HAS_BIT(x, v) (((x) & (1 << (v))) != 0)
+
 #define L2CAP_CONF_MAX_SIZE	22
 
+struct l2cap_conf_rfc {
+	__u8	mode;
+	__u8	txw;
+	__u8	maxt;
+	__le16	ret_to;
+	__le16	mon_to;
+	__le16	mps;
+} __attribute__ ((packed));
+
 struct l2cap_disconn_req {
 	__le16     dcid;
 	__le16     scid;
@@ -158,7 +194,6 @@
 
 struct l2cap_info_req {
 	__le16      type;
-	__u8        data[0];
 } __attribute__ ((packed));
 
 struct l2cap_info_rsp {
@@ -168,12 +203,17 @@
 } __attribute__ ((packed));
 
 /* info type */
-#define L2CAP_IT_CL_MTU     0x0001
-#define L2CAP_IT_FEAT_MASK  0x0002
+#define L2CAP_IT_CL_MTU		0x0001
+#define L2CAP_IT_FEAT_MASK	0x0002
+
+/* bits for extended features (no. of bit position) */
+#define L2CAP_EXT_FCM		0
+#define L2CAP_EXT_RTM		1
+#define L2CAP_EXT_QOS		2
 
 /* info result */
-#define L2CAP_IR_SUCCESS    0x0000
-#define L2CAP_IR_NOTSUPP    0x0001
+#define L2CAP_IR_SUCCESS	0x0000
+#define L2CAP_IR_NOTSUPP	0x0001
 
 /* ----- L2CAP connections ----- */
 struct l2cap_chan_list {
@@ -215,11 +255,40 @@
 	__u16		flush_to;
 
 	__u32		link_mode;
+	/* connectionless MTU size from info response */
+	__u16		info_mtu;
+	/* extended feature mask from info response */
+	__u32		info_ext;
 
-	__u8		conf_state;
+	/* bitmask for current config state */
+	__u16		conf_state;
 	__u8		conf_retry;
 	__u16		conf_mtu;
 
+	/* Configuration Request RFC Options */
+	__u8		conf_mode;
+	__u8		conf_txw;
+	__u8		conf_maxt;
+	__u16		conf_ret_to;
+	__u16		conf_mon_to;
+	__u16		conf_mps;
+
+	/* incoming RFC Options */
+	__u8		imode;
+	__u8		itxw;
+	__u8		imaxt;
+	__u16		iret_to;
+	__u16		imon_to;
+	__u16		imps;
+
+	/* outgoing RFC Options */
+	__u8		omode;
+	__u8		otxw;
+	__u8		omaxt;
+	__u16		oret_to;
+	__u16		omon_to;
+	__u16		omps;
+
 	__u8		ident;
 
 	struct l2cap_conn	*conn;
@@ -227,10 +296,15 @@
 	struct sock		*prev_c;
 };
 
-#define L2CAP_CONF_REQ_SENT    0x01
-#define L2CAP_CONF_INPUT_DONE  0x02
-#define L2CAP_CONF_OUTPUT_DONE 0x04
-#define L2CAP_CONF_MAX_RETRIES 2
+#define L2CAP_CONF_MAX_RETRIES	2
+
+/* different conf_states */
+#define L2CAP_INFO_REQ_SENT 	0x01
+#define L2CAP_CONF_REQ_SENT 	0x02
+#define L2CAP_CONF_INPUT_DONE	0x04
+#define L2CAP_CONF_OUTPUT_DONE	0x08
+#define L2CAP_CONF_UNACCEPT_MTU	0x10
+#define L2CAP_CONF_UNACCEPT_RFC	0x20
 
 void l2cap_load(void);
 
net/bluetooth/l2cap.c +537 -124

861 lines not on this page · raw message