L2CAP Flow Control - 2nd stage
Subsystems (2)
Hello together,
I worked on some Flow Control mechanisms on the L2CAP layer for the past few weeks/months and want to give everybody who is interested in this work the opportunity to review the code, add comments or get an overview.
The current status is that I can obtain all necessary information from incoming information requests and responses as well as configuration requests and responses. A valid configuration request is parsed and a reasonable configuration response will be created.
The next step will include to create information requests by ourself and (especially from the corresponding information responses) to create configuration requests with all flow control options set. After that real Flow Control needs to take place and all the logic behind it will be implemented according to the procedures specified in Section 8 of the current specification.
Some notes on the current patch:
In my last patch I already created the new function »l2cap_get_conf_opt« which is only called from within l2cap_parse_conf_opt. This function checks a parsed option for validity and returns the corresponding result code (Success or Unacceptable Parameters). This will be the return code for this specific option, say result[L2CAP_CONF_MTU] for the MTU or equivalent. Refer to my mail from Feb 13 for more information about the result codes.
The function »l2cap_parse_conf_opt« didn't change in logic but became smaller as parts of the response building process is moved to the function »l2cap_build_conf_rsp« which makes the data flow appear more logically (the parse function should really only parse and not build anything). Therefore the build_conf_rsp function is now much bigger as we have to very specific about which option is to be included in our response (see specification). Whenever we build a response option that has to be put into a response packet, we call »l2cap_add_conf_opt« with the appropriate data.
The function »l2cap_build_conf_req« is not done yet but should already work for an MTU option as expected.
At the end I worked on the two functions »l2cap_information_req« and »l2cap_information_rsp«. Both should be able to handle Flow Control options, but couldn't be tested yet as I lack devices that make use of this functionality :-/ The latter function sets the flow control bits in the extended features mask (see section 4.12 in the spec). The next step would be to use this information in the configuration request building process (first send an information request, read the response and create an appropriate configuration request).
That's it for now.
Martin
include/net/bluetooth/l2cap.h +60 -7
@@ -27,7 +27,10 @@/* L2CAP defaults */ #define L2CAP_DEFAULT_MTU 672 +#define L2CAP_MIN_MTU 48#define L2CAP_DEFAULT_FLUSH_TO 0xFFFF +#define L2CAP_MIN_TXW 1 +#define L2CAP_MAX_TXW 32#define L2CAP_CONN_TIMEOUT (HZ * 40)
@@ -47,6 +50,10 @@__u8 mode; }; +#define L2CAP_MODE_BASIC 0x00 +#define L2CAP_MODE_RET 0x01 +#define L2CAP_MODE_FLOW 0x02 +#define L2CAP_CONNINFO 0x02struct l2cap_conninfo {__u16 hci_handle;
@@ -129,8 +136,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 0x0003struct l2cap_conf_opt {__u8 type;
@@ -144,8 +153,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; +u16 ret_to; +u16 mon_to; +u16 mps; +} __attribute__ ((packed)); +struct l2cap_disconn_req {__le16 dcid;__le16 scid;
@@ -158,7 +179,6 @@struct l2cap_info_req {__le16 type; -__u8 data[0 ]; } __attribute__ ((packed));struct l2cap_info_rsp {
@@ -168,12 +188,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 */ +#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 +240,39 @@__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;__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;
net/bluetooth/l2cap.c +354 -95
618 lines not on this page · raw message