L2CAP signaling for AMP channel create/move
Subsystems (2)
cover L2CAP signaling for AMP channel create/move
Here are the changes that process commands on the L2CAP signaling channel for setting up AMP channels. There's still a lot of integration to do as other AMP functionality is implemented. I've marked places that require this integration with "Placeholder" comments (look for that string).
This patch set has some minor conflicts with Andrei's "Create AMP physical link" patch set, and will need to be rebased after that is merged.
Changes:
* RFCv1 - Finished commit messages, fixed formatting/style issues
* RFCv0 - Initial post
Mat Martineau (20):
Bluetooth: Add new l2cap_chan struct members for high speed channels
Bluetooth: Factor out common L2CAP connection code
Bluetooth: Add L2CAP create channel request handling
Bluetooth: Process create response and connect response identically
Bluetooth: Lookup channel structure based on DCID
Bluetooth: Channel move request handling
Bluetooth: Add new ERTM receive states for channel move
Bluetooth: Add move channel confirm handling
Bluetooth: Add state to hci_chan
Bluetooth: Move channel response
Bluetooth: Add logical link confirm
Bluetooth: Add move confirm response handling
Bluetooth: Handle physical link completion
Bluetooth: Flag ACL frames as complete for AMP controllers
Bluetooth: Do not send data during channel move
Bluetooth: Configure appropriate timeouts for AMP controllers
Bluetooth: Ignore BR/EDR packet size constraints when fragmenting for
AMP
Bluetooth: Send create channel request instead of connect for AMP
Bluetooth: Do not retransmit data during a channel move
Bluetooth: Start channel move when socket option is changed
include/net/bluetooth/hci.h | 1 + include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/l2cap.h | 32 ++ net/bluetooth/hci_conn.c | 1 + net/bluetooth/l2cap_core.c | 1019 ++++++++++++++++++++++++++++++++++++-- net/bluetooth/l2cap_sock.c | 5 + 6 files changed, 1010 insertions(+), 49 deletions(-)
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 1/20 Bluetooth: Add new l2cap_chan struct members for high speed channels
An L2CAP channel using high speed continues to be associated with a BR/EDR l2cap_conn, while also tracking an additional hci_conn (representing a physical link on a high speed controller) and hci_chan (representing a logical link). There may only be one physical link between two high speed controllers. Each physical link may contain several logical links, with each logical link representing a channel with specific quality of service.
During a channel move, the destination channel id, current move state, and role (initiator vs. responder) are tracked and used by the channel move state machine. The ident value associated with a move request must also be stored in order to use it in later move responses.
The active channel is stored in local_amp_id.
--- include/net/bluetooth/l2cap.h | 29 +++++++++++++++++++++++++++++ net/bluetooth/l2cap_core.c | 5 +++++ 2 files changed, 34 insertions(+)
include/net/bluetooth/l2cap.h +29 -0
@@ -433,6 +433,8 @@ struct l2cap_chan {struct sock *sk;struct l2cap_conn *conn; +struct hci_conn *hs_hcon; +struct hci_chan *hs_hchan;struct kref kref;__u8 state;
@@ -476,6 +478,11 @@ struct l2cap_chan {unsigned long conn_state;unsigned long flags; +__u8 local_amp_id; +__u8 move_id; +__u8 move_state; +__u8 move_role; +__u16 next_tx_seq;__u16 expected_ack_seq;__u16 expected_tx_seq;
@@ -640,6 +647,9 @@ enum {enum {L2CAP_RX_STATE_RECV ,L2CAP_RX_STATE_SREJ_SENT , +L2CAP_RX_STATE_MOVE , +L2CAP_RX_STATE_WAIT_P , +L2CAP_RX_STATE_WAIT_F , };enum {
@@ -670,6 +680,25 @@ enum { L2CAP_EV_RECV_FRAME, }; +enum { +L2CAP_MOVE_ROLE_NONE , +L2CAP_MOVE_ROLE_INITIATOR , +L2CAP_MOVE_ROLE_RESPONDER , +}; + +enum { +L2CAP_MOVE_STABLE , +L2CAP_MOVE_WAIT_REQ , +L2CAP_MOVE_WAIT_RSP , +L2CAP_MOVE_WAIT_RSP_SUCCESS , +L2CAP_MOVE_WAIT_CONFIRM , +L2CAP_MOVE_WAIT_CONFIRM_RSP , +L2CAP_MOVE_WAIT_LOGICAL_COMP , +L2CAP_MOVE_WAIT_LOGICAL_CFM , +L2CAP_MOVE_WAIT_LOCAL_BUSY , +L2CAP_MOVE_WAIT_PREPARE , +}; +void l2cap_chan_hold (struct l2cap_chan *c);void l2cap_chan_put (struct l2cap_chan *c);
net/bluetooth/l2cap_core.c +5 -0
@@ -2747,6 +2747,11 @@ int l2cap_ertm_init(struct l2cap_chan *chan)skb_queue_head_init (&chan->tx_q); + chan->local_amp_id =0 ; + chan->move_id =0 ; + chan->move_state =L2CAP_MOVE_STABLE ; + chan->move_role =L2CAP_MOVE_ROLE_NONE ; +if (chan->mode !=L2CAP_MODE_ERTM )return 0 ;
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [RFCv1 01/20] Bluetooth: Add new l2cap_chan struct members for high speed channels
Hi Mat,
Quoted 26 lines · Mat Martineau
An L2CAP channel using high speed continues to be associated with a BR/EDR
l2cap_conn, while also tracking an additionalhci_conn(representing a physical link on a high speed controller) andhci_chan(representing a logical link). There may only be one physical link between two high speed controllers. Each physical link may contain several logical links, with each logical link representing a channel with specific quality of service.During a channel move, the destination channel id, current move state, and role (initiator vs. responder) are tracked and used by the channel move state machine. The ident value associated with a move request must also be stored in order to use it in later move responses.
The active channel is stored in
local_amp_id.Signed-off-by Mat Martineau <[email protected]>--- include/net/bluetooth/l2cap.h | 29 +++++++++++++++++++++++++++++ net/bluetooth/l2cap_core.c | 5 +++++ 2 files changed, 34 insertions(+)include/net/bluetooth/l2cap.h +0
-0
include/net/bluetooth/l2cap.h struct l2cap_chan { · line 436
Quoted 4 lines
include/net/bluetooth/l2cap.h +1
-0@@ -433,6 +433,8 @@ struct l2cap_chan {struct sock *sk;struct l2cap_conn *conn; +struct hci_conn *hs_hcon;
Do we need hs_hcon if we have hs_hchan ?
include/net/bluetooth/l2cap.h struct l2cap_chan { · line 482
Quoted 10 lines
include/net/bluetooth/l2cap.h +3
-0+struct hci_chan *hs_hchan;struct kref kref;__u8 state;@@ -476,6 +478,11 @@ struct l2cap_chan {unsigned long conn_state;unsigned long flags; +__u8 local_amp_id; +__u8 move_id;
So this is Destination AMP ctrl id, would this be better to name it like move_dst_amp_id or dst_amp_id;
...
Best regards
Andrei Emeltchenko
Re: [RFCv1 01/20] Bluetooth: Add new l2cap_chan struct members for high speed channels
In reply to Mat MartineauHi,
Quoted 8 lines · Mat Martineau
An L2CAP channel using high speed continues to be associated with a BR/EDR
l2cap_conn, while also tracking an additionalhci_conn(representing a physical link on a high speed controller) andhci_chan(representing a logical link). There may only be one physical link between two high speed controllers. Each physical link may contain several logical links, with each logical link representing a channel with specific quality of service.
Quoted 8 lines
During a channel move, the destination channel id, current move state, and role (initiator vs. responder) are tracked and used by the channel move state machine. The ident value associated with a move request must also be stored in order to use it in later move responses.
The active channel is stored in
local_amp_id.Signed-off-by Mat Martineau <[email protected]>
Best regards
Andrei Emeltchenko
RFC 2/20 Bluetooth: Factor out common L2CAP connection code
In reply to Mat MartineauL2CAP connect requests and create channel requests share a significant amount of code. This change moves common code to a new function.
--- net/bluetooth/l2cap_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +8 -2
@@ -3362,7 +3362,8 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdreturn 0 ; } -static inline int l2cap_connect_req (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd,u8 *data) +static void __l2cap_connect (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd, +u8 *data,u8 rsp_code,u8 amp_id) {struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;struct l2cap_conn_rsp rsp;
@@ -3456,7 +3457,7 @@ sendresp: rsp.dcid =cpu_to_le16 (dcid); rsp.result =cpu_to_le16 (result); rsp.status =cpu_to_le16 (status); -l2cap_send_cmd (conn, cmd->ident,L2CAP_CONN_RSP ,sizeof (rsp), &rsp); +l2cap_send_cmd (conn, cmd->ident, rsp_code,sizeof (rsp), &rsp);if (result ==L2CAP_CR_PEND && status ==L2CAP_CS_NO_INFO ) {struct l2cap_info_req info;
@@ -3479,7 +3480,12 @@ sendresp: l2cap_build_conf_req(chan, buf), buf); chan->num_conf_req++; } +} +static int l2cap_connect_req (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd,u8 *data) +{ +__l2cap_connect (conn, cmd, data,L2CAP_CONN_RSP ,0 );return 0 ; }
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [RFCv1 02/20] Bluetooth: Factor out common L2CAP connection code
Hi,
Quoted 4 lines · Mat Martineau
L2CAP connect requests and create channel requests share a significant amount of code. This change moves common code to a new function.
Signed-off-by Mat Martineau <[email protected]>
Best regards
Andrei Emeltchenko
RFC 3/20 Bluetooth: Add L2CAP create channel request handling
In reply to Mat MartineauThe L2CAP create channel request is very similar to an L2CAP connect request, but it has an additional parameter for the controller ID. If the controller id is 0, the channel is set up on the BR/EDR controller (just like a connect request). Using a valid high speed controller ID will cause the channel to be initially created on that high speed controller. While the L2CAP data will be initially routed over the AMP controller, the L2CAP fixed signaling channel only uses BR/EDR.
When a create channel request is received for a high speed controller, a pending response is always sent first. After the high speed physical and logical links are complete a success response will be sent.
--- net/bluetooth/l2cap_core.c | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-)
net/bluetooth/l2cap_core.c +54 -16
@@ -3362,8 +3362,9 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdreturn 0 ; } -static void __l2cap_connect (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd, -u8 *data,u8 rsp_code,u8 amp_id) +static struct l2cap_chan *__l2cap_connect (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd, +u8 *data,u8 rsp_code,u8 amp_id) {struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;struct l2cap_conn_rsp rsp;
@@ -3390,7 +3391,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,/* Check if the ACL is secure enough (if not SDP) */ if (psm !=__constant_cpu_to_le16 (L2CAP_PSM_SDP ) && - !hci_conn_check_link_mode (conn->hcon)) { + !hci_conn_check_link_mode (conn->hcon)) { conn->disc_reason =HCI_ERROR_AUTH_FAILURE ; result =L2CAP_CR_SEC_BLOCK ; goto response;
@@ -3414,6 +3415,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,bacpy (&bt_sk (sk)->dst, conn->dst); chan->psm = psm; chan->dcid = scid; + chan->local_amp_id = amp_id;bt_accept_enqueue (parent, sk);
@@ -3433,8 +3435,16 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, status =L2CAP_CS_AUTHOR_PEND ; parent->sk_data_ready (parent,0 ); }else { -__l2cap_state_change (chan,BT_CONFIG ); - result =L2CAP_CR_SUCCESS ; +/* Force pending result for AMP controllers. +* The connection will succeed after the +* physical link is up. */ +if (amp_id) { +__l2cap_state_change (chan,BT_CONNECT2 ); + result =L2CAP_CR_PEND ; + }else { +__l2cap_state_change (chan,BT_CONFIG ); + result =L2CAP_CR_SUCCESS ; + } status =L2CAP_CS_NO_INFO ; } }else {
@@ -3480,6 +3490,8 @@ sendresp: l2cap_build_conf_req(chan, buf), buf); chan->num_conf_req++; } + +return chan; } static int l2cap_connect_req(struct l2cap_conn *conn,
@@ -3970,12 +3982,12 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cmreturn 0 ; } -static inline int l2cap_create_channel_req (struct l2cap_conn *conn, -struct l2cap_cmd_hdr *cmd,u16 cmd_len, -void *data) +static int l2cap_create_channel_req (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd,u16 cmd_len, +void *data) {struct l2cap_create_chan_req *req = data; -struct l2cap_create_chan_rsp rsp; +struct l2cap_chan *chan;u16 psm, scid;if (cmd_len !=sizeof (*req))
@@ -3989,14 +4001,40 @@ static inline int l2cap_create_channel_req(struct l2cap_conn *conn,BT_DBG ("psm 0x%2.2x, scid 0x%4.4x, amp_id %d" , psm, scid, req->amp_id); -/* Placeholder: Always reject */ - rsp.dcid =0 ; - rsp.scid =cpu_to_le16 (scid); - rsp.result =__constant_cpu_to_le16 (L2CAP_CR_NO_MEM ); - rsp.status =__constant_cpu_to_le16 (L2CAP_CS_NO_INFO ); +if (req->amp_id) { +struct hci_dev *hdev; -l2cap_send_cmd (conn, cmd->ident,L2CAP_CREATE_CHAN_RSP , -sizeof (rsp), &rsp); +/* Validate AMP controller id */ + hdev =hci_dev_get (req->amp_id); +if (!hdev || hdev->dev_type !=HCI_AMP || + !test_bit (HCI_UP , &hdev->flags)) { +struct l2cap_create_chan_rsp rsp; + + rsp.dcid =0 ; + rsp.scid =cpu_to_le16 (scid); + rsp.result =L2CAP_CR_BAD_AMP ; + rsp.status =L2CAP_CS_NO_INFO ; + +l2cap_send_cmd (conn, cmd->ident,L2CAP_CREATE_CHAN_RSP , +sizeof (rsp), &rsp); + +if (hdev) +hci_dev_put (hdev); + +return 0 ; + } + +hci_dev_put (hdev); + } + + chan =__l2cap_connect (conn, cmd, data,L2CAP_CREATE_CHAN_RSP , + req->amp_id); + +/* Placeholder - uncomment when amp functions are available +if (chan && req->amp_id && +(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) +amp_accept_physical(conn, req->amp_id, chan); +*/ return 0 ; }
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [RFCv1 03/20] Bluetooth: Add L2CAP create channel request handling
Hi Mat,
Quoted 110 lines · Mat Martineau
The L2CAP create channel request is very similar to an L2CAP connect request, but it has an additional parameter for the controller ID. If the controller id is 0, the channel is set up on the BR/EDR controller (just like a connect request). Using a valid high speed controller ID will cause the channel to be initially created on that high speed controller. While the L2CAP data will be initially routed over the AMP controller, the L2CAP fixed signaling channel only uses BR/EDR.
When a create channel request is received for a high speed controller, a pending response is always sent first. After the high speed physical and logical links are complete a success response will be sent.
Signed-off-by Mat Martineau <[email protected]>--- net/bluetooth/l2cap_core.c | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-)net/bluetooth/l2cap_core.c +23
-16@@ -3362,8 +3362,9 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdreturn 0 ; } -static void __l2cap_connect (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd, -u8 *data,u8 rsp_code,u8 amp_id) +static struct l2cap_chan *__l2cap_connect (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd, +u8 *data,u8 rsp_code,u8 amp_id) {struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;struct l2cap_conn_rsp rsp;@@ -3390,7 +3391,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,/* Check if the ACL is secure enough (if not SDP) */ if (psm !=__constant_cpu_to_le16 (L2CAP_PSM_SDP ) && - !hci_conn_check_link_mode (conn->hcon)) { + !hci_conn_check_link_mode (conn->hcon)) { conn->disc_reason =HCI_ERROR_AUTH_FAILURE ; result =L2CAP_CR_SEC_BLOCK ; goto response;@@ -3414,6 +3415,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,bacpy (&bt_sk (sk)->dst, conn->dst); chan->psm = psm; chan->dcid = scid; + chan->local_amp_id = amp_id;bt_accept_enqueue (parent, sk);@@ -3433,8 +3435,16 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, status =L2CAP_CS_AUTHOR_PEND ; parent->sk_data_ready (parent,0 ); }else { -__l2cap_state_change (chan,BT_CONFIG ); - result =L2CAP_CR_SUCCESS ; +/* Force pending result for AMP controllers. +* The connection will succeed after the +* physical link is up. */ +if (amp_id) { +__l2cap_state_change (chan,BT_CONNECT2 ); + result =L2CAP_CR_PEND ; + }else { +__l2cap_state_change (chan,BT_CONFIG ); + result =L2CAP_CR_SUCCESS ; + } status =L2CAP_CS_NO_INFO ; } }else {@@ -3480,6 +3490,8 @@ sendresp: l2cap_build_conf_req(chan, buf), buf); chan->num_conf_req++; } + +return chan; } static int l2cap_connect_req(struct l2cap_conn *conn,@@ -3970,12 +3982,12 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cmreturn 0 ; } -static inline int l2cap_create_channel_req (struct l2cap_conn *conn, -struct l2cap_cmd_hdr *cmd,u16 cmd_len, -void *data) +static int l2cap_create_channel_req (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd,u16 cmd_len, +void *data) {struct l2cap_create_chan_req *req = data; -struct l2cap_create_chan_rsp rsp; +struct l2cap_chan *chan;u16 psm, scid;if (cmd_len !=sizeof (*req))@@ -3989,14 +4001,40 @@ static inline int l2cap_create_channel_req(struct l2cap_conn *conn,BT_DBG ("psm 0x%2.2x, scid 0x%4.4x, amp_id %d" , psm, scid, req->amp_id); -/* Placeholder: Always reject */ - rsp.dcid =0 ; - rsp.scid =cpu_to_le16 (scid); - rsp.result =__constant_cpu_to_le16 (L2CAP_CR_NO_MEM ); - rsp.status =__constant_cpu_to_le16 (L2CAP_CS_NO_INFO ); +if (req->amp_id) { +struct hci_dev *hdev; -l2cap_send_cmd (conn, cmd->ident,L2CAP_CREATE_CHAN_RSP , -sizeof (rsp), &rsp);
net/bluetooth/l2cap_core.c static inline int l2cap_create_channel_req(struct l2cap_conn *conn, · line 4016
Quoted 10 lines
net/bluetooth/l2cap_core.c +10
-0+/* Validate AMP controller id */ + hdev =hci_dev_get (req->amp_id); +if (!hdev || hdev->dev_type !=HCI_AMP || + !test_bit (HCI_UP , &hdev->flags)) { +struct l2cap_create_chan_rsp rsp; + + rsp.dcid =0 ; + rsp.scid =cpu_to_le16 (scid); + rsp.result =L2CAP_CR_BAD_AMP ; + rsp.status =L2CAP_CS_NO_INFO ;
Please consider this:
- rsp.result = L2CAP_CR_BAD_AMP; - rsp.status = L2CAP_CS_NO_INFO; + rsp.result = __constant_cpu_to_le16(L2CAP_CR_BAD_AMP); + rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
Best regards
Andrei Emeltchenko
Re: [RFCv1 03/20] Bluetooth: Add L2CAP create channel request handling
Andrei -
Quoted 127 lines · Andrei Emeltchenko
Hi Mat,
Quoted 110 lines · Mat Martineau
The L2CAP create channel request is very similar to an L2CAP connect request, but it has an additional parameter for the controller ID. If the controller id is 0, the channel is set up on the BR/EDR controller (just like a connect request). Using a valid high speed controller ID will cause the channel to be initially created on that high speed controller. While the L2CAP data will be initially routed over the AMP controller, the L2CAP fixed signaling channel only uses BR/EDR.
When a create channel request is received for a high speed controller, a pending response is always sent first. After the high speed physical and logical links are complete a success response will be sent.
Signed-off-by Mat Martineau <[email protected]>--- net/bluetooth/l2cap_core.c | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-)net/bluetooth/l2cap_core.c +23
-16@@ -3362,8 +3362,9 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdreturn 0 ; } -static void __l2cap_connect (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd, -u8 *data,u8 rsp_code,u8 amp_id) +static struct l2cap_chan *__l2cap_connect (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd, +u8 *data,u8 rsp_code,u8 amp_id) {struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;struct l2cap_conn_rsp rsp;@@ -3390,7 +3391,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,/* Check if the ACL is secure enough (if not SDP) */ if (psm !=__constant_cpu_to_le16 (L2CAP_PSM_SDP ) && - !hci_conn_check_link_mode (conn->hcon)) { + !hci_conn_check_link_mode (conn->hcon)) { conn->disc_reason =HCI_ERROR_AUTH_FAILURE ; result =L2CAP_CR_SEC_BLOCK ; goto response;@@ -3414,6 +3415,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,bacpy (&bt_sk (sk)->dst, conn->dst); chan->psm = psm; chan->dcid = scid; + chan->local_amp_id = amp_id;bt_accept_enqueue (parent, sk);@@ -3433,8 +3435,16 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, status =L2CAP_CS_AUTHOR_PEND ; parent->sk_data_ready (parent,0 ); }else { -__l2cap_state_change (chan,BT_CONFIG ); - result =L2CAP_CR_SUCCESS ; +/* Force pending result for AMP controllers. +* The connection will succeed after the +* physical link is up. */ +if (amp_id) { +__l2cap_state_change (chan,BT_CONNECT2 ); + result =L2CAP_CR_PEND ; + }else { +__l2cap_state_change (chan,BT_CONFIG ); + result =L2CAP_CR_SUCCESS ; + } status =L2CAP_CS_NO_INFO ; } }else {@@ -3480,6 +3490,8 @@ sendresp: l2cap_build_conf_req(chan, buf), buf); chan->num_conf_req++; } + +return chan; } static int l2cap_connect_req(struct l2cap_conn *conn,@@ -3970,12 +3982,12 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cmreturn 0 ; } -static inline int l2cap_create_channel_req (struct l2cap_conn *conn, -struct l2cap_cmd_hdr *cmd,u16 cmd_len, -void *data) +static int l2cap_create_channel_req (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd,u16 cmd_len, +void *data) {struct l2cap_create_chan_req *req = data; -struct l2cap_create_chan_rsp rsp; +struct l2cap_chan *chan;u16 psm, scid;if (cmd_len !=sizeof (*req))@@ -3989,14 +4001,40 @@ static inline int l2cap_create_channel_req(struct l2cap_conn *conn,BT_DBG ("psm 0x%2.2x, scid 0x%4.4x, amp_id %d" , psm, scid, req->amp_id); -/* Placeholder: Always reject */ - rsp.dcid =0 ; - rsp.scid =cpu_to_le16 (scid); - rsp.result =__constant_cpu_to_le16 (L2CAP_CR_NO_MEM ); - rsp.status =__constant_cpu_to_le16 (L2CAP_CS_NO_INFO ); +if (req->amp_id) { +struct hci_dev *hdev; -l2cap_send_cmd (conn, cmd->ident,L2CAP_CREATE_CHAN_RSP , -sizeof (rsp), &rsp);net/bluetooth/l2cap_core.c static inline int l2cap_create_channel_req(struct l2cap_conn *conn, · line 4016
Quoted 10 lines
net/bluetooth/l2cap_core.c +10
-0+/* Validate AMP controller id */ + hdev =hci_dev_get (req->amp_id); +if (!hdev || hdev->dev_type !=HCI_AMP || + !test_bit (HCI_UP , &hdev->flags)) { +struct l2cap_create_chan_rsp rsp; + + rsp.dcid =0 ; + rsp.scid =cpu_to_le16 (scid); + rsp.result =L2CAP_CR_BAD_AMP ; + rsp.status =L2CAP_CS_NO_INFO ;Please consider this:
Review
Quoted 4 lines
(quoted diff) +2
-2- rsp.result = L2CAP_CR_BAD_AMP; - rsp.status = L2CAP_CS_NO_INFO; + rsp.result = __constant_cpu_to_le16(L2CAP_CR_BAD_AMP); + rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
Ok, I'll fix that and look for similar issues.
--
Mat Martineau
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [RFCv1 03/20] Bluetooth: Add L2CAP create channel request handling
In reply to Mat MartineauHi Mat,
Quoted 131 lines · Mat Martineau
The L2CAP create channel request is very similar to an L2CAP connect request, but it has an additional parameter for the controller ID. If the controller id is 0, the channel is set up on the BR/EDR controller (just like a connect request). Using a valid high speed controller ID will cause the channel to be initially created on that high speed controller. While the L2CAP data will be initially routed over the AMP controller, the L2CAP fixed signaling channel only uses BR/EDR.
When a create channel request is received for a high speed controller, a pending response is always sent first. After the high speed physical and logical links are complete a success response will be sent.
Signed-off-by Mat Martineau <[email protected]>--- net/bluetooth/l2cap_core.c | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-)net/bluetooth/l2cap_core.c +44
-16@@ -3362,8 +3362,9 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdreturn 0 ; } -static void __l2cap_connect (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd, -u8 *data,u8 rsp_code,u8 amp_id) +static struct l2cap_chan *__l2cap_connect (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd, +u8 *data,u8 rsp_code,u8 amp_id) {struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;struct l2cap_conn_rsp rsp;@@ -3390,7 +3391,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,/* Check if the ACL is secure enough (if not SDP) */ if (psm !=__constant_cpu_to_le16 (L2CAP_PSM_SDP ) && - !hci_conn_check_link_mode (conn->hcon)) { + !hci_conn_check_link_mode (conn->hcon)) { conn->disc_reason =HCI_ERROR_AUTH_FAILURE ; result =L2CAP_CR_SEC_BLOCK ; goto response;@@ -3414,6 +3415,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,bacpy (&bt_sk (sk)->dst, conn->dst); chan->psm = psm; chan->dcid = scid; + chan->local_amp_id = amp_id;bt_accept_enqueue (parent, sk);@@ -3433,8 +3435,16 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, status =L2CAP_CS_AUTHOR_PEND ; parent->sk_data_ready (parent,0 ); }else { -__l2cap_state_change (chan,BT_CONFIG ); - result =L2CAP_CR_SUCCESS ; +/* Force pending result for AMP controllers. +* The connection will succeed after the +* physical link is up. */ +if (amp_id) { +__l2cap_state_change (chan,BT_CONNECT2 ); + result =L2CAP_CR_PEND ; + }else { +__l2cap_state_change (chan,BT_CONFIG ); + result =L2CAP_CR_SUCCESS ; + } status =L2CAP_CS_NO_INFO ; } }else {@@ -3480,6 +3490,8 @@ sendresp: l2cap_build_conf_req(chan, buf), buf); chan->num_conf_req++; } + +return chan; } static int l2cap_connect_req(struct l2cap_conn *conn,@@ -3970,12 +3982,12 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cmreturn 0 ; } -static inline int l2cap_create_channel_req (struct l2cap_conn *conn, -struct l2cap_cmd_hdr *cmd,u16 cmd_len, -void *data) +static int l2cap_create_channel_req (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd,u16 cmd_len, +void *data) {struct l2cap_create_chan_req *req = data; -struct l2cap_create_chan_rsp rsp; +struct l2cap_chan *chan;u16 psm, scid;if (cmd_len !=sizeof (*req))@@ -3989,14 +4001,40 @@ static inline int l2cap_create_channel_req(struct l2cap_conn *conn,BT_DBG ("psm 0x%2.2x, scid 0x%4.4x, amp_id %d" , psm, scid, req->amp_id); -/* Placeholder: Always reject */ - rsp.dcid =0 ; - rsp.scid =cpu_to_le16 (scid); - rsp.result =__constant_cpu_to_le16 (L2CAP_CR_NO_MEM ); - rsp.status =__constant_cpu_to_le16 (L2CAP_CS_NO_INFO ); +if (req->amp_id) { +struct hci_dev *hdev; -l2cap_send_cmd (conn, cmd->ident,L2CAP_CREATE_CHAN_RSP , -sizeof (rsp), &rsp); +/* Validate AMP controller id */ + hdev =hci_dev_get (req->amp_id); +if (!hdev || hdev->dev_type !=HCI_AMP || + !test_bit (HCI_UP , &hdev->flags)) { +struct l2cap_create_chan_rsp rsp; + + rsp.dcid =0 ; + rsp.scid =cpu_to_le16 (scid); + rsp.result =L2CAP_CR_BAD_AMP ; + rsp.status =L2CAP_CS_NO_INFO ; + +l2cap_send_cmd (conn, cmd->ident,L2CAP_CREATE_CHAN_RSP , +sizeof (rsp), &rsp); + +if (hdev) +hci_dev_put (hdev); + +return 0 ; + } + +hci_dev_put (hdev);
net/bluetooth/l2cap_core.c static inline int l2cap_create_channel_req(struct l2cap_conn *conn, · line 4037
Quoted 10 lines
net/bluetooth/l2cap_core.c +10
-0+ } + + chan =__l2cap_connect (conn, cmd, data,L2CAP_CREATE_CHAN_RSP , + req->amp_id); + +/* Placeholder - uncomment when amp functions are available +if (chan && req->amp_id && +(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) +amp_accept_physical(conn, req->amp_id, chan); +*/
I believe this comment shall be deleted, we accept physical link long time ago before this sequence.
Best regards
Andrei Emeltchenko
RFC 4/20 Bluetooth: Process create response and connect response identically
In reply to Mat MartineauThis removes an intermediate function for sending a create response which added no functionality.
--- net/bluetooth/l2cap_core.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
net/bluetooth/l2cap_core.c +4 -14
@@ -3501,7 +3501,8 @@ static int l2cap_connect_req(struct l2cap_conn *conn,return 0 ; } -static inline int l2cap_connect_rsp (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd,u8 *data) +static inline int l2cap_connect_create_rsp (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd,u8 *data) {struct l2cap_conn_rsp *rsp = (struct l2cap_conn_rsp *) data;u16 scid, dcid, result, status;
@@ -4039,14 +4040,6 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,return 0 ; } -static inline int l2cap_create_channel_rsp (struct l2cap_conn *conn, -struct l2cap_cmd_hdr *cmd,void *data) -{ -BT_DBG ("conn %p" , conn); - -return l2cap_connect_rsp (conn, cmd, data); -} -static void l2cap_send_move_chan_rsp (struct l2cap_conn *conn,u8 ident,u16 icid,u16 result) {
@@ -4250,7 +4243,8 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,break ;case L2CAP_CONN_RSP : - err =l2cap_connect_rsp (conn, cmd, data); +case L2CAP_CREATE_CHAN_RSP : + err =l2cap_connect_create_rsp (conn, cmd, data);break ;case L2CAP_CONF_REQ :
@@ -4288,10 +4282,6 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn, err =l2cap_create_channel_req (conn, cmd, cmd_len, data);break ; -case L2CAP_CREATE_CHAN_RSP : - err =l2cap_create_channel_rsp (conn, cmd, data); -break ; -case L2CAP_MOVE_CHAN_REQ : err =l2cap_move_channel_req (conn, cmd, cmd_len, data);break ;
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [RFCv1 04/20] Bluetooth: Process create response and connect response identically
Hi,
Quoted 4 lines · Mat Martineau
This removes an intermediate function for sending a create response which added no functionality.
Signed-off-by Mat Martineau <[email protected]>
Best regards
Andrei Emeltchenko
RFC 5/20 Bluetooth: Lookup channel structure based on DCID
In reply to Mat MartineauProcessing a move channel request involves getting the channel structure using the destination channel ID. Previous code could only look up using the source channel ID.
--- net/bluetooth/l2cap_core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
net/bluetooth/l2cap_core.c +22 -0
@@ -97,6 +97,22 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cireturn c; } +/* Find channel with given DCID. +* Returns locked channel. */ +static struct l2cap_chan *l2cap_get_chan_by_dcid (struct l2cap_conn *conn, +u16 cid) +{ +struct l2cap_chan *c; + +mutex_lock (&conn->chan_lock); + c =__l2cap_get_chan_by_dcid (conn, cid); +if (c) +l2cap_chan_lock (c); +mutex_unlock (&conn->chan_lock); + +return c; +} +static struct l2cap_chan *__l2cap_get_chan_by_ident (struct l2cap_conn *conn,u8 ident) {struct l2cap_chan *c;
@@ -4088,6 +4104,7 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn, u16 cmd_len, void *data) { struct l2cap_move_chan_req *req = data; +struct l2cap_chan *chan;u16 icid =0 ;u16 result =L2CAP_MR_NOT_ALLOWED ;
@@ -4101,9 +4118,14 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn,if (!enable_hs)return -EINVAL ; + chan =l2cap_get_chan_by_dcid (conn, icid); +/* Placeholder: Always refuse */ l2cap_send_move_chan_rsp (conn, cmd->ident, icid, result); +if (chan) +l2cap_chan_unlock (chan); +return 0 ; }
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 6/20 Bluetooth: Channel move request handling
In reply to Mat MartineauOn receipt of a channel move request, the request must be validated based on the L2CAP mode, connection state, and controller capabilities. ERTM channels must have their state machines cleared and transmission paused while the channel move takes place.
If the channel is being moved to an AMP controller then an AMP physical link must be prepared. Moving the channel back to BR/EDR proceeds immediately.
--- net/bluetooth/l2cap_core.c | 98 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +97 -1
@@ -977,6 +977,41 @@ static void l2cap_send_conn_req(struct l2cap_chan *chan)l2cap_send_cmd (conn, chan->ident,L2CAP_CONN_REQ ,sizeof (req), &req); } +static void l2cap_move_setup (struct l2cap_chan *chan) +{ +struct sk_buff *skb; + +BT_DBG ("chan %p" , chan); + +if (chan->mode !=L2CAP_MODE_ERTM ) +return ; + +__clear_retrans_timer (chan); +__clear_monitor_timer (chan); +__clear_ack_timer (chan); + + chan->retry_count =0 ; + skb_queue_walk(&chan->tx_q, skb) { +if (bt_cb (skb)->control.retries) +bt_cb (skb)->control.retries =1 ; +else +break ; + } + + chan->expected_tx_seq = chan->buffer_seq; + +clear_bit (CONN_REJ_ACT , &chan->conn_state); +clear_bit (CONN_SREJ_ACT , &chan->conn_state); +l2cap_seq_list_clear (&chan->retrans_list); +l2cap_seq_list_clear (&chan->srej_list); +skb_queue_purge (&chan->srej_q); + + chan->tx_state =L2CAP_TX_STATE_XMIT ; + chan->rx_state =L2CAP_RX_STATE_MOVE ; + +set_bit (CONN_REMOTE_BUSY , &chan->conn_state); +} +static void l2cap_chan_ready (struct l2cap_chan *chan) {/* This clears all conf flags, including CONF_NOT_COMPLETE */
@@ -4120,7 +4155,68 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn, chan =l2cap_get_chan_by_dcid (conn, icid); -/* Placeholder: Always refuse */ +if (!chan || chan->scid <L2CAP_CID_DYN_START || + (chan->mode !=L2CAP_MODE_ERTM && + chan->mode !=L2CAP_MODE_STREAMING )) { + result =L2CAP_MR_NOT_ALLOWED ; + goto send_move_response; + } + +if (chan->local_amp_id == req->dest_amp_id) { + result =L2CAP_MR_SAME_ID ; + goto send_move_response; + } + +if (req->dest_amp_id) { +struct hci_dev *hdev; + hdev =hci_dev_get (req->dest_amp_id); +if (!hdev || hdev->dev_type !=HCI_AMP || + !test_bit (HCI_UP , &hdev->flags)) { +if (hdev) +hci_dev_put (hdev); + + result =L2CAP_MR_BAD_ID ; + goto send_move_response; + } +hci_dev_put (hdev); + } + +if (((chan->move_state !=L2CAP_MOVE_STABLE && + chan->move_state !=L2CAP_MOVE_WAIT_PREPARE ) || + chan->move_role !=L2CAP_MOVE_ROLE_NONE ) && +bacmp (conn->src, conn->dst) >0 ) { + result =L2CAP_MR_COLLISION ; + goto send_move_response; + } + +if (chan->chan_policy ==BT_CHANNEL_POLICY_BREDR_ONLY ) { + result =L2CAP_MR_NOT_ALLOWED ; + goto send_move_response; + } + + chan->ident = cmd->ident; + chan->move_role =L2CAP_MOVE_ROLE_RESPONDER ; +l2cap_move_setup (chan); + chan->move_id = req->dest_amp_id; + icid = chan->dcid; + +if (req->dest_amp_id ==0 ) { +/* Moving to BR/EDR */ +if (test_bit (CONN_LOCAL_BUSY , &chan->conn_state)) { + chan->move_state =L2CAP_MOVE_WAIT_LOCAL_BUSY ; + result =L2CAP_MR_PEND ; + }else { + chan->move_state =L2CAP_MOVE_WAIT_CONFIRM ; + result =L2CAP_MR_SUCCESS ; + } + }else { + chan->move_state =L2CAP_MOVE_WAIT_PREPARE ; +/* Placeholder - uncomment when amp functions are available */ +/*amp_accept_physical(chan, req->dest_amp_id);*/ + result =L2CAP_MR_PEND ; + } + +send_move_response:l2cap_send_move_chan_rsp (conn, cmd->ident, icid, result);if (chan)
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 7/20 Bluetooth: Add new ERTM receive states for channel move
In reply to Mat MartineauTwo new states are required to implement channel moves with the ERTM receive state machine.
The "WAIT_P" state is used by a move responder to wait for a "poll" flag after a move is completed (success or failure). "WAIT_F" is similarly used by a move initiator to wait for a "final" flag when the move is completing. In either state, the reqseq value in the poll/final frame tells the state machine exactly which frame should be expected next.
--- net/bluetooth/l2cap_core.c | 106 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
net/bluetooth/l2cap_core.c +106 -0
@@ -5153,6 +5153,106 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,return err; } +static int l2cap_finish_move (struct l2cap_chan *chan) +{ +int err =0 ; + +BT_DBG ("chan %p" , chan); + + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + chan->rx_state =L2CAP_RX_STATE_RECV ; + +if (chan->hs_hcon) + chan->conn->mtu = chan->hs_hcon->hdev->acl_mtu; +else + chan->conn->mtu = chan->conn->hcon->hdev->acl_mtu; + +/* Placeholder - resegment based on new conn->mtu */ +/*err = l2cap_resegment(chan);*/ + +return err; +} + +static int l2cap_rx_state_wait_p (struct l2cap_chan *chan, +struct l2cap_ctrl *control, +struct sk_buff *skb,u8 event) +{ +int err = -EPROTO ; + +BT_DBG ("chan %p, control %p, skb %p, event %d" , chan, control, skb, + event); + +if (!control->poll) +return err; + +l2cap_process_reqseq (chan, control->reqseq); + +if (!skb_queue_empty (&chan->tx_q)) + chan->tx_send_head =skb_peek (&chan->tx_q); +else + chan->tx_send_head =NULL ; + +/* Rewind next_tx_seq to the point expected +* by the receiver. +*/ + chan->next_tx_seq = control->reqseq; + chan->unacked_frames =0 ; + + err =l2cap_finish_move (chan); + +if (err) +return err; + +set_bit (CONN_SEND_FBIT , &chan->conn_state); +l2cap_send_i_or_rr_or_rnr (chan); + +if (event ==L2CAP_EV_RECV_IFRAME ) + err = -EPROTO ; +else + err =l2cap_rx_state_recv (chan, control,NULL , event); + +return err; +} + +static int l2cap_rx_state_wait_f (struct l2cap_chan *chan, +struct l2cap_ctrl *control, +struct sk_buff *skb,u8 event) +{ +int err = -EPROTO ; + +if (control->final) { +clear_bit (CONN_REMOTE_BUSY , &chan->conn_state); + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + + chan->rx_state =L2CAP_RX_STATE_RECV ; +l2cap_process_reqseq (chan, control->reqseq); + +if (!skb_queue_empty (&chan->tx_q)) + chan->tx_send_head =skb_peek (&chan->tx_q); +else + chan->tx_send_head =NULL ; + +/* Rewind next_tx_seq to the point expected +* by the receiver. +*/ + chan->next_tx_seq = control->reqseq; + chan->unacked_frames =0 ; + +if (chan->hs_hcon) + chan->conn->mtu = chan->hs_hcon->hdev->acl_mtu; +else + chan->conn->mtu = chan->conn->hcon->hdev->acl_mtu; + +/* Placeholder - resegment based on new conn->mtu */ +/*err = l2cap_resegment(chan);*/ + +if (!err) + err =l2cap_rx_state_recv (chan, control, skb, event); + } + +return err; +} +static bool __valid_reqseq (struct l2cap_chan *chan,u16 reqseq) {/* Make sure reqseq is for a packet that has been sent but not acked */
@@ -5179,6 +5279,12 @@ static int l2cap_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control, err =l2cap_rx_state_srej_sent (chan, control, skb, event);break ; +case L2CAP_RX_STATE_WAIT_P : + err =l2cap_rx_state_wait_p (chan, control, skb, event); +break ; +case L2CAP_RX_STATE_WAIT_F : + err =l2cap_rx_state_wait_f (chan, control, skb, event); +break ;default :/* shut it down */ break ;
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 8/20 Bluetooth: Add move channel confirm handling
In reply to Mat MartineauAfter sending a move channel response, a move responder waits for a move channel confirm command. If the received command has a "confirmed" result the move is proceeding, and "unconfirmed" means the move has failed and the channel will not change controllers.
--- net/bluetooth/l2cap_core.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-)
net/bluetooth/l2cap_core.c +67 -3
@@ -1012,6 +1012,42 @@ static void l2cap_move_setup(struct l2cap_chan *chan)set_bit (CONN_REMOTE_BUSY , &chan->conn_state); } +static void l2cap_move_success (struct l2cap_chan *chan) +{ +BT_DBG ("chan %p" , chan); + +if (chan->mode !=L2CAP_MODE_ERTM ) +return ; + +switch (chan->move_role) { +case L2CAP_MOVE_ROLE_INITIATOR : +l2cap_tx (chan,NULL ,NULL ,L2CAP_EV_EXPLICIT_POLL ); + chan->rx_state =L2CAP_RX_STATE_WAIT_F ; +break ; +case L2CAP_MOVE_ROLE_RESPONDER : + chan->rx_state =L2CAP_RX_STATE_WAIT_P ; +break ; + } +} + +static void l2cap_move_revert (struct l2cap_chan *chan) +{ +BT_DBG ("chan %p" , chan); + +if (chan->mode !=L2CAP_MODE_ERTM ) +return ; + +switch (chan->move_role) { +case L2CAP_MOVE_ROLE_INITIATOR : +l2cap_tx (chan,NULL ,NULL ,L2CAP_EV_EXPLICIT_POLL ); + chan->rx_state =L2CAP_RX_STATE_WAIT_F ; +break ; +case L2CAP_MOVE_ROLE_RESPONDER : + chan->rx_state =L2CAP_RX_STATE_WAIT_P ; +break ; + } +} +static void l2cap_chan_ready (struct l2cap_chan *chan) {/* This clears all conf flags, including CONF_NOT_COMPLETE */
@@ -4246,11 +4282,12 @@ static inline int l2cap_move_channel_rsp(struct l2cap_conn *conn,return 0 ; } -static inline int l2cap_move_channel_confirm (struct l2cap_conn *conn, -struct l2cap_cmd_hdr *cmd, -u16 cmd_len,void *data) +static int l2cap_move_channel_confirm (struct l2cap_conn *conn, +struct l2cap_cmd_hdr *cmd, +u16 cmd_len,void *data) {struct l2cap_move_chan_cfm *cfm = data; +struct l2cap_chan *chan;u16 icid, result;if (cmd_len !=sizeof (*cfm))
@@ -4261,8 +4298,35 @@ static inline int l2cap_move_channel_confirm(struct l2cap_conn *conn,BT_DBG ("icid 0x%4.4x, result 0x%4.4x" , icid, result); + chan =l2cap_get_chan_by_dcid (conn, icid); +if (!chan) + goto send_move_confirm_response; + +if (chan->move_state ==L2CAP_MOVE_WAIT_CONFIRM ) { + chan->move_state =L2CAP_MOVE_STABLE ; +if (result ==L2CAP_MC_CONFIRMED ) { + chan->local_amp_id = chan->move_id; +if (!chan->local_amp_id) { +/* Have moved off of AMP, free the channel */ + chan->hs_hchan =NULL ; + chan->hs_hcon =NULL ; + +/* Placeholder - free the logical link */ + } +l2cap_move_success (chan); + }else { + chan->move_id = chan->local_amp_id; +l2cap_move_revert (chan); + } + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + } + +send_move_confirm_response:l2cap_send_move_chan_cfm_rsp (conn, cmd->ident, icid); +if (chan) +l2cap_chan_unlock (chan); +return 0 ; }
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 9/20 Bluetooth: Add state to hci_chan
In reply to Mat MartineauOn an AMP controller, hci_chan maps to a logical link. When a channel is being moved, the logical link may or may not be connected already. The hci_chan->state is used to determine the existance of a useable logical link so the link can be either used or requested.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_conn.c | 1 + 2 files changed, 2 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
@@ -341,6 +341,7 @@ struct hci_chan {struct hci_conn *conn;struct sk_buff_head data_q;unsigned int sent; +__u8 state; };extern struct list_head hci_dev_list;
net/bluetooth/hci_conn.c +1 -0
@@ -929,6 +929,7 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn) chan->conn = conn;skb_queue_head_init (&chan->data_q); + chan->state =BT_CONNECTED ;list_add_rcu (&chan->list, &conn->chan_list);
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 10/20 Bluetooth: Move channel response
In reply to Mat MartineauThe move response command includes a result code indicationg "pending", "success", or "failure" status. A pending result is received when the remote address is still setting up a physical link, and will be followed by success or failure. On success, logical link setup will proceed. On failure, the move is stopped. The receiver of a move channel response must always follow up by sending a move channel confirm command.
--- include/net/bluetooth/l2cap.h | 2 + net/bluetooth/l2cap_core.c | 137 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 137 insertions(+), 2 deletions(-)
include/net/bluetooth/l2cap.h +2 -0
@@ -51,6 +51,8 @@#define L2CAP_ENC_TIMEOUT msecs_to_jiffies(5000)#define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000)#define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000) +#define L2CAP_MOVE_TIMEOUT msecs_to_jiffies(4000) +#define L2CAP_MOVE_ERTX_TIMEOUT msecs_to_jiffies(60000)#define L2CAP_A2MP_DEFAULT_MTU 670
net/bluetooth/l2cap_core.c +135 -2
155 lines not on this page · raw message
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 11/20 Bluetooth: Add logical link confirm
In reply to Mat MartineauThe logical link confirm callback is executed when the AMP controller completes its logical link setup. During a channel move, a newly formed logical link allows a move responder to send a move channel response. A move initiator will send a move channel confirm. A failed logical link will end the channel move and send an appropriate response or confirm command indicating a failure.
If the channel is being created on an AMP controller, L2CAP configuration is started after the logical link is set up.
--- net/bluetooth/l2cap_core.c | 117 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +115 -2
@@ -3725,6 +3725,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr goto unlock; } + chan->ident = cmd->ident;l2cap_send_cmd (conn, cmd->ident,L2CAP_CONF_RSP , len, rsp); chan->num_conf_rsp++;
@@ -4170,11 +4171,123 @@ static void l2cap_send_move_chan_cfm_rsp(struct l2cap_conn *conn, u8 ident,l2cap_send_cmd (conn, ident,L2CAP_MOVE_CHAN_CFM_RSP ,sizeof (rsp), &rsp); } +/* Call with chan locked */ static void l2cap_logical_cfm (struct l2cap_chan *chan,struct hci_chan *hchan,u8 status) { -/* Placeholder */ -return ; +BT_DBG ("chan %p, hchan %p, status %d" , chan, hchan, status); + +if (chan->state !=BT_CONNECTED && !chan->local_amp_id) +return ; + +if (!status && chan->state !=BT_CONNECTED ) { +struct l2cap_conf_rsp rsp; +u8 code; + +/* Create channel complete */ + chan->hs_hcon = hchan->conn; + chan->hs_hcon->l2cap_data = chan->conn; + + code =l2cap_build_conf_rsp (chan, &rsp, +L2CAP_CONF_SUCCESS ,0 ); +l2cap_send_cmd (chan->conn, chan->ident,L2CAP_CONF_RSP , code, + &rsp); +set_bit (CONF_OUTPUT_DONE , &chan->conf_state); + +if (test_bit (CONF_INPUT_DONE , &chan->conf_state)) { +int err =0 ; + +set_default_fcs (chan); + +if (chan->mode ==L2CAP_MODE_ERTM || + chan->mode ==L2CAP_MODE_STREAMING ) + err =l2cap_ertm_init (chan); + +if (err <0 ) +l2cap_send_disconn_req (chan->conn, chan, -err); +else +l2cap_chan_ready (chan); + } + }else if (chan && !status) { +/* Channel move */ + chan->hs_hcon = hchan->conn; + chan->hs_hcon->l2cap_data = chan->conn; + +BT_DBG ("move_state %d" , chan->move_state); + +if (chan->state !=BT_CONNECTED ) +return ; + +switch (chan->move_state) { +case L2CAP_MOVE_WAIT_LOGICAL_COMP : +/* Move confirm will be sent after a success +* response is received +*/ + chan->move_state =L2CAP_MOVE_WAIT_RSP_SUCCESS ; +break ; +case L2CAP_MOVE_WAIT_LOGICAL_CFM : +if (test_bit (CONN_LOCAL_BUSY , &chan->conn_state)) { + chan->move_state =L2CAP_MOVE_WAIT_LOCAL_BUSY ; + }else if (chan->move_role == +L2CAP_MOVE_ROLE_INITIATOR ) { + chan->move_state =L2CAP_MOVE_WAIT_CONFIRM_RSP ; +l2cap_send_move_chan_cfm (chan->conn, chan, + chan->scid, +L2CAP_MR_SUCCESS ); +__set_chan_timer (chan,L2CAP_MOVE_TIMEOUT ); + }else if (chan->move_role == +L2CAP_MOVE_ROLE_RESPONDER ) { + chan->move_state =L2CAP_MOVE_WAIT_CONFIRM ; +l2cap_send_move_chan_rsp (chan->conn, + chan->ident, + chan->dcid, +L2CAP_MR_SUCCESS ); + } +break ; +default : +/* Move was not in expected state, free the channel */ + chan->hs_hchan =NULL ; + chan->hs_hcon =NULL ; + +/* Placeholder - free the logical link */ + + chan->move_state =L2CAP_MOVE_STABLE ; + } + }else { +/* Logical link setup failed. */ + +if (chan->state !=BT_CONNECTED ) +l2cap_send_disconn_req (chan->conn, chan,ECONNRESET ); +else if (chan->move_role ==L2CAP_MOVE_ROLE_RESPONDER ) { +l2cap_move_revert (chan); + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + chan->move_state =L2CAP_MOVE_STABLE ; +l2cap_send_move_chan_rsp (chan->conn, chan->ident, + chan->dcid,L2CAP_MR_NOT_SUPP ); + }else if (chan->move_role ==L2CAP_MOVE_ROLE_INITIATOR ) { +if (chan->move_state ==L2CAP_MOVE_WAIT_LOGICAL_COMP || + chan->move_state ==L2CAP_MOVE_WAIT_LOGICAL_CFM ) { +/* Remote has only sent pending or +* success responses, clean up +*/ +l2cap_move_revert (chan); + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + chan->move_state =L2CAP_MOVE_STABLE ; + } + +/* Other amp move states imply that the move +* has already aborted +*/ +l2cap_send_move_chan_cfm (chan->conn, chan, chan->scid, +L2CAP_MC_UNCONFIRMED ); +__set_chan_timer (chan,L2CAP_MOVE_TIMEOUT ); + } + + chan->hs_hchan =NULL ; + chan->hs_hcon =NULL ; + +/* Placeholder - free logical link */ + } } static inline int l2cap_move_channel_req(struct l2cap_conn *conn,
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 12/20 Bluetooth: Add move confirm response handling
In reply to Mat MartineauThe move confirm response concludes the channel move command sequence. Receipt of this command indicates that data may begin to flow again.
--- net/bluetooth/l2cap_core.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
net/bluetooth/l2cap_core.c +26 -0
@@ -4581,6 +4581,7 @@ static inline int l2cap_move_channel_confirm_rsp(struct l2cap_conn *conn, u16 cmd_len, void *data) { struct l2cap_move_chan_cfm_rsp *rsp = data; +struct l2cap_chan *chan;u16 icid;if (cmd_len !=sizeof (*rsp))
@@ -4590,6 +4591,31 @@ static inline int l2cap_move_channel_confirm_rsp(struct l2cap_conn *conn,BT_DBG ("icid 0x%4.4x" , icid); + chan =l2cap_get_chan_by_scid (conn, icid); +if (!chan) +return 0 ; + +__clear_chan_timer (chan); + +if (chan->move_state ==L2CAP_MOVE_WAIT_CONFIRM_RSP ) { + chan->move_state =L2CAP_MOVE_STABLE ; + chan->local_amp_id = chan->move_id; + +if (!chan->local_amp_id && chan->hs_hchan) { +/* Have moved off of AMP, free the channel */ + chan->hs_hchan =NULL ; + chan->hs_hcon =NULL ; + +/* Placeholder - free the logical link */ + } + +l2cap_move_success (chan); + + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + } + +l2cap_chan_unlock (chan); +return 0 ; }
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 13/20 Bluetooth: Handle physical link completion
In reply to Mat MartineauSeveral different actions may be taken when an AMP physical link becomes available. A channel being created on an AMP controller must continue the connection process. A channel being moved needs to either send a move request or a move response. A failed physical link will revert to using a BR/EDR controller if possible.
--- net/bluetooth/l2cap_core.c | 166 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+)
net/bluetooth/l2cap_core.c +166 -0
@@ -977,6 +977,19 @@ static void l2cap_send_conn_req(struct l2cap_chan *chan)l2cap_send_cmd (conn, chan->ident,L2CAP_CONN_REQ ,sizeof (req), &req); } +static void l2cap_send_create_chan_req (struct l2cap_chan *chan,u8 amp_id) +{ +struct l2cap_create_chan_req req; + req.scid =cpu_to_le16 (chan->scid); + req.psm = chan->psm; + req.amp_id = amp_id; + + chan->ident =l2cap_get_ident (chan->conn); + +l2cap_send_cmd (chan->conn, chan->ident,L2CAP_CREATE_CHAN_REQ , +sizeof (req), &req); +} +static void l2cap_move_setup (struct l2cap_chan *chan) {struct sk_buff *skb;
@@ -4128,6 +4141,23 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,return 0 ; } +static void l2cap_send_move_chan_req (struct l2cap_chan *chan,u8 dest_amp_id) +{ +struct l2cap_move_chan_req req; +u8 ident; + +BT_DBG ("chan %p, dest_amp_id %d" , chan, dest_amp_id); + + ident =l2cap_get_ident (chan->conn); + chan->ident = ident; + + req.icid =cpu_to_le16 (chan->scid); + req.dest_amp_id = dest_amp_id; + +l2cap_send_cmd (chan->conn, ident,L2CAP_MOVE_CHAN_REQ ,sizeof (req), + &req); +} +static void l2cap_send_move_chan_rsp (struct l2cap_conn *conn,u8 ident,u16 icid,u16 result) {
@@ -4290,6 +4320,142 @@ static void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, } } +static void l2cap_do_create (struct l2cap_chan *chan,int result, +u8 local_amp_id,u8 remote_amp_id) +{ +if (!test_bit (CONF_CONNECT_PEND , &chan->conf_state)) { +struct l2cap_conn_rsp rsp; +char buf[128 ]; + rsp.scid =cpu_to_le16 (chan->dcid); + rsp.dcid =cpu_to_le16 (chan->scid); + +/* Incoming channel on AMP */ +if (result ==L2CAP_CR_SUCCESS ) { +/* Send successful response */ + rsp.result =cpu_to_le16 (L2CAP_CR_SUCCESS ); + rsp.status =cpu_to_le16 (L2CAP_CS_NO_INFO ); + }else { +/* Send negative response */ + rsp.result =cpu_to_le16 (L2CAP_CR_NO_MEM ); + rsp.status =cpu_to_le16 (L2CAP_CS_NO_INFO ); + } + +l2cap_send_cmd (chan->conn, chan->ident,L2CAP_CREATE_CHAN_RSP , +sizeof (rsp), &rsp); + +if (result ==L2CAP_CR_SUCCESS ) { +__l2cap_state_change (chan,BT_CONFIG ); +set_bit (CONF_REQ_SENT , &chan->conf_state); +l2cap_send_cmd (chan->conn,l2cap_get_ident (chan->conn), +L2CAP_CONF_REQ , +l2cap_build_conf_req (chan, buf), buf); + chan->num_conf_req++; + } + }else { +/* Outgoing channel on AMP */ +if (result ==L2CAP_CR_SUCCESS ) { + chan->local_amp_id = local_amp_id; +l2cap_send_create_chan_req (chan, remote_amp_id); + }else { +/* Revert to BR/EDR connect */ +l2cap_send_conn_req (chan); + } + } +} + +static void l2cap_do_move_initiate (struct l2cap_chan *chan,u8 local_amp_id, +u8 remote_amp_id) +{ +l2cap_move_setup (chan); + chan->move_id = local_amp_id; + chan->move_state =L2CAP_MOVE_WAIT_RSP ; + +l2cap_send_move_chan_req (chan, remote_amp_id); +__set_chan_timer (chan,L2CAP_MOVE_TIMEOUT ); +} + +static void l2cap_do_move_respond (struct l2cap_chan *chan,int result) +{ +struct hci_chan *hchan =NULL ; + +/* Placeholder - get hci_chan for logical link */ + +if (hchan) { +if (hchan->state ==BT_CONNECTED ) { +/* Logical link is ready to go */ + chan->hs_hcon = hchan->conn; + chan->hs_hcon->l2cap_data = chan->conn; + chan->move_state =L2CAP_MOVE_WAIT_CONFIRM ; +l2cap_send_move_chan_rsp (chan->conn, chan->ident, + chan->dcid,L2CAP_MR_SUCCESS ); + +l2cap_logical_cfm (chan, hchan,L2CAP_MR_SUCCESS ); + }else { +/* Wait for logical link to be ready */ + chan->move_state =L2CAP_MOVE_WAIT_LOGICAL_CFM ; + } + }else { +/* Logical link not available */ +l2cap_send_move_chan_rsp (chan->conn, chan->ident, chan->dcid, +L2CAP_MR_NOT_ALLOWED ); + } +} + +static void l2cap_do_move_cancel (struct l2cap_chan *chan,int result) +{ +if (chan->move_role ==L2CAP_MOVE_ROLE_RESPONDER ) { +u8 rsp_result; +if (result == -EINVAL ) + rsp_result =L2CAP_MR_BAD_ID ; +else + rsp_result =L2CAP_MR_NOT_ALLOWED ; + +l2cap_send_move_chan_rsp (chan->conn, chan->ident, chan->dcid, + rsp_result); + } + + chan->move_role =L2CAP_MOVE_ROLE_NONE ; + chan->move_state =L2CAP_MOVE_STABLE ; + +/* Restart data transmission */ +l2cap_ertm_send (chan); +} + +void l2cap_physical_cfm (struct l2cap_chan *chan,int result,u8 local_amp_id, +u8 remote_amp_id) +{ +BT_DBG ("chan %p, result %d, local_amp_id %d, remote_amp_id %d" , + chan, result, local_amp_id, remote_amp_id); + +l2cap_chan_lock (chan); + +if (chan->state ==BT_DISCONN || chan->state ==BT_CLOSED ) { +l2cap_chan_unlock (chan); +return ; + } + +if (chan->state !=BT_CONNECTED ) { +l2cap_do_create (chan, result, local_amp_id, remote_amp_id); + }else if (result !=L2CAP_MR_SUCCESS ) { +l2cap_do_move_cancel (chan, result); + }else { +switch (chan->move_role) { +case L2CAP_MOVE_ROLE_INITIATOR : +l2cap_do_move_initiate (chan, local_amp_id, + remote_amp_id); +break ; +case L2CAP_MOVE_ROLE_RESPONDER : +l2cap_do_move_respond (chan, result); +break ; +default : +l2cap_do_move_cancel (chan, result); +break ; + } + } + +l2cap_chan_unlock (chan); +} +static inline int l2cap_move_channel_req (struct l2cap_conn *conn,struct l2cap_cmd_hdr *cmd,u16 cmd_len,void *data)
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 14/20 Bluetooth: Flag ACL frames as complete for AMP controllers
In reply to Mat MartineauAMP controllers expect to transmit only "complete" ACL frames. These frames have both the "start" and "cont" bits set. AMP does not allow fragmented ACLs.
--- include/net/bluetooth/hci.h | 1 + net/bluetooth/l2cap_core.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -196,6 +196,7 @@ enum {#define ACL_START_NO_FLUSH 0x00#define ACL_CONT 0x01#define ACL_START 0x02 +#define ACL_COMPLETE 0x03#define ACL_ACTIVE_BCAST 0x04#define ACL_PICO_BCAST 0x08
net/bluetooth/l2cap_core.c +12 -2
@@ -734,10 +734,20 @@ static void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb)u16 flags;BT_DBG ("chan %p, skb %p len %d priority %u" , chan, skb, skb->len, - skb->priority); + skb->priority); + +if (chan->hs_hcon && (chan->move_state ==L2CAP_MOVE_STABLE || + chan->move_state ==L2CAP_MOVE_WAIT_PREPARE )) { +if (chan->hs_hchan) +hci_send_acl (chan->hs_hchan, skb,ACL_COMPLETE ); +else +kfree_skb (skb); + +return ; + }if (!test_bit (FLAG_FLUSHABLE , &chan->flags) && -lmp_no_flush_capable (hcon->hdev)) +lmp_no_flush_capable (hcon->hdev)) flags =ACL_START_NO_FLUSH ;else flags =ACL_START ;
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 15/20 Bluetooth: Do not send data during channel move
In reply to Mat MartineauOutgoing ERTM data is queued during a channel move. The ERTM state machine is partially reset at the start of a move, and must be resynchronized with the remote state machine at the end of the move. Data is not sent so that there are no state transitions between the partial reset and the resync.
Streaming mode frames are dropped during a move.
--- net/bluetooth/l2cap_core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
net/bluetooth/l2cap_core.c +16 -0
@@ -921,6 +921,10 @@ static void l2cap_send_sframe(struct l2cap_chan *chan,if (!control->sframe)return ; +if (chan->move_state !=L2CAP_MOVE_STABLE && + chan->move_state !=L2CAP_MOVE_WAIT_PREPARE ) +return ; +if (test_and_clear_bit (CONN_SEND_FBIT , &chan->conn_state) && !control->poll) control->final =1 ;
@@ -1765,6 +1769,10 @@ static void l2cap_streaming_send(struct l2cap_chan *chan,BT_DBG ("chan %p, skbs %p" , chan, skbs); +if (chan->move_state !=L2CAP_MOVE_STABLE && + chan->move_state !=L2CAP_MOVE_WAIT_PREPARE ) +return ; +skb_queue_splice_tail_init (skbs, &chan->tx_q);while (!skb_queue_empty (&chan->tx_q)) {
@@ -1807,6 +1815,10 @@ static int l2cap_ertm_send(struct l2cap_chan *chan)if (test_bit (CONN_REMOTE_BUSY , &chan->conn_state))return 0 ; +if (chan->move_state !=L2CAP_MOVE_STABLE && + chan->move_state !=L2CAP_MOVE_WAIT_PREPARE ) +return 0 ; +while (chan->tx_send_head && chan->unacked_frames < chan->remote_tx_win && chan->tx_state ==L2CAP_TX_STATE_XMIT ) {
@@ -1872,6 +1884,10 @@ static void l2cap_ertm_resend(struct l2cap_chan *chan)if (test_bit (CONN_REMOTE_BUSY , &chan->conn_state))return ; +if (chan->move_state !=L2CAP_MOVE_STABLE && + chan->move_state !=L2CAP_MOVE_WAIT_PREPARE ) +return ; +while (chan->retrans_list.head !=L2CAP_SEQ_LIST_CLEAR ) { seq =l2cap_seq_list_pop (&chan->retrans_list);
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 16/20 Bluetooth: Configure appropriate timeouts for AMP controllers
In reply to Mat MartineauThe L2CAP spec recommends specific retransmit and monitor timeouts for ERTM channels that are on AMP controllers. These timeouts are calculated from the AMP controller's best effort flush timeout.
BR/EDR controllers use the default retransmit and monitor timeouts.
--- net/bluetooth/l2cap_core.c | 47 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-)
net/bluetooth/l2cap_core.c +41 -6
@@ -2924,6 +2924,44 @@ static inline bool __l2cap_efs_supported(struct l2cap_chan *chan)return enable_hs && chan->conn->feat_mask &L2CAP_FEAT_EXT_FLOW ; } +static void __l2cap_set_ertm_timeouts (struct l2cap_chan *chan, +struct l2cap_conf_rfc *rfc) +{ +if (chan->local_amp_id && chan->hs_hcon) { +u64 ertm_to = chan->hs_hcon->hdev->amp_be_flush_to; + +/* Class 1 devices have must have ERTM timeouts +* exceeding the Link Supervision Timeout. The +* default Link Supervision Timeout for AMP +* controllers is 10 seconds. +* +* Class 1 devices use 0xffffffff for their +* best-effort flush timeout, so the clamping logic +* will result in a timeout that meets the above +* requirement. ERTM timeouts are 16-bit values, so +* the maximum timeout is 65.535 seconds. +*/ + +/* Convert timeout to milliseconds and round */ + ertm_to =div_u64 (ertm_to +999 ,1000 ); + +/* This is the recommended formula for class 2 devices +* that start ERTM timers when packets are sent to the +* controller. +*/ + ertm_to =3 * ertm_to +500 ; + +if (ertm_to >0xffff ) + ertm_to =0xffff ; + + rfc->retrans_timeout =cpu_to_le16 ((u16 ) ertm_to); + rfc->monitor_timeout = rfc->retrans_timeout; + }else { + rfc->retrans_timeout =__constant_cpu_to_le16 (L2CAP_DEFAULT_RETRANS_TO ); + rfc->monitor_timeout =__constant_cpu_to_le16 (L2CAP_DEFAULT_MONITOR_TO ); + } +} +static inline void l2cap_txwin_setup (struct l2cap_chan *chan) { if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW &&
@@ -2990,8 +3028,8 @@ done:case L2CAP_MODE_ERTM : rfc.mode =L2CAP_MODE_ERTM ; rfc.max_transmit = chan->max_tx; - rfc.retrans_timeout =0 ; - rfc.monitor_timeout =0 ; + +__l2cap_set_ertm_timeouts (chan, &rfc); size = min_t(u16, L2CAP_DEFAULT_MAX_PDU_SIZE, chan->conn->mtu - L2CAP_EXT_HDR_SIZE -
@@ -3223,10 +3261,7 @@ done: rfc.max_pdu_size =cpu_to_le16 (size); chan->remote_mps = size; - rfc.retrans_timeout = -__constant_cpu_to_le16 (L2CAP_DEFAULT_RETRANS_TO ); - rfc.monitor_timeout = -__constant_cpu_to_le16 (L2CAP_DEFAULT_MONITOR_TO ); +__l2cap_set_ertm_timeouts (chan, &rfc);set_bit (CONF_MODE_DONE , &chan->conf_state);
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 17/20 Bluetooth: Ignore BR/EDR packet size constraints when fragmenting for AMP
In reply to Mat MartineauWhen operating over BR/EDR, ERTM accounts for the maximum over-the-air packet size when setting the PDU size. AMP controllers do not use the same over-the-air packets, so the PDU size should only be based on the HCI MTU of the AMP controller.
--- net/bluetooth/l2cap_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +3 -1
@@ -2230,7 +2230,9 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,/* PDU size is derived from the HCI MTU */ pdu_len = chan->conn->mtu; - pdu_len =min_t (size_t, pdu_len,L2CAP_BREDR_MAX_PAYLOAD ); +/* Constrain PDU size for BR/EDR connections */ +if (!chan->hs_hcon) + pdu_len =min_t (size_t, pdu_len,L2CAP_BREDR_MAX_PAYLOAD );/* Adjust for largest possible L2CAP overhead. */ if (chan->fcs)
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [RFCv1 17/20] Bluetooth: Ignore BR/EDR packet size constraints when fragmenting for AMP
Hi,
Quoted 6 lines · Mat Martineau
When operating over BR/EDR, ERTM accounts for the maximum over-the-air packet size when setting the PDU size. AMP controllers do not use the same over-the-air packets, so the PDU size should only be based on the HCI MTU of the AMP controller.
Signed-off-by Mat Martineau <[email protected]>
Best regards
Andrei Emeltchenko
RFC 18/20 Bluetooth: Send create channel request instead of connect for AMP
In reply to Mat MartineauWhen the channel policy is set to prefer AMP, then an L2CAP channel is set up using the "create channel" command rather than the "connect" command. A physical link is also set up before sending "create channel".
Behavior is unchanged if enable_hs is false.
--- net/bluetooth/l2cap_core.c | 84 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-)
net/bluetooth/l2cap_core.c +78 -6
@@ -56,7 +56,10 @@ static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *chan, int err);static void l2cap_tx (struct l2cap_chan *chan,struct l2cap_ctrl *control, -struct sk_buff_head *skbs,u8 event); +struct sk_buff_head *skbs,u8 event); + +static void l2cap_logical_cfm (struct l2cap_chan *chan,struct hci_chan *hchan, +u8 status);/* ---- L2CAP channels ---- */
@@ -554,6 +557,13 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)hci_conn_put (conn->hcon); } +if (chan->hs_hchan) { + chan->hs_hchan =NULL ; + chan->hs_hcon =NULL ; + +/* Placeholder - free logical link */ + } +if (chan->ops->teardown) chan->ops->teardown (chan, err);
@@ -1100,8 +1110,19 @@ static void l2cap_do_start(struct l2cap_chan *chan)return ;if (l2cap_chan_check_security (chan) && -__l2cap_no_conn_pending (chan)) -l2cap_send_conn_req (chan); +__l2cap_no_conn_pending (chan)) { +if (enable_hs && + (conn->fixed_chan_mask &L2CAP_FC_A2MP ) && + chan->chan_policy ==BT_CHANNEL_POLICY_AMP_PREFERRED ) { +set_bit (CONF_CONNECT_PEND , &chan->conf_state); + +/* Placeholder +amp_create_phylink(); +*/ + }else { +l2cap_send_conn_req (chan); + } + } }else {struct l2cap_info_req req; req.type =__constant_cpu_to_le16 (L2CAP_IT_FEAT_MASK );
@@ -1196,8 +1217,17 @@ static void l2cap_conn_start(struct l2cap_conn *conn)continue ; } -l2cap_send_conn_req (chan); +if (enable_hs && + (conn->fixed_chan_mask &L2CAP_FC_A2MP ) && + chan->chan_policy ==BT_CHANNEL_POLICY_AMP_PREFERRED ) { +set_bit (CONF_CONNECT_PEND , &chan->conf_state); +/* Placeholder +amp_create_phylink(); +*/ + }else { +l2cap_send_conn_req (chan); + } }else if (chan->state ==BT_CONNECT2 ) {struct l2cap_conn_rsp rsp;char buf[128 ];
@@ -1225,8 +1255,18 @@ static void l2cap_conn_start(struct l2cap_conn *conn) rsp.status =__constant_cpu_to_le16 (L2CAP_CS_AUTHEN_PEND ); } +if (rsp.result ==__constant_cpu_to_le16 (L2CAP_CR_SUCCESS ) && + chan->local_amp_id) { +/* Placeholder - uncomment when amp functions +* are available +amp_accept_physical(chan, chan->local_amp_id); +*/ +l2cap_chan_unlock (chan); +continue ; + } +l2cap_send_cmd (conn, chan->ident,L2CAP_CONN_RSP , -sizeof (rsp), &rsp); +sizeof (rsp), &rsp);if (test_bit (CONF_REQ_SENT , &chan->conf_state) || rsp.result !=L2CAP_CR_SUCCESS ) {
@@ -3308,6 +3348,18 @@ done: rfc.mode = chan->mode; } +if (test_bit (CONF_LOC_CONF_PEND , &chan->conf_state) && + chan->local_amp_id) { +struct hci_chan *hchan =NULL ; + +/* Placeholder - get hci_chan for logical link */ + +if (hchan && hchan->state ==BT_CONNECTED ) { +l2cap_logical_cfm (chan, hchan, +L2CAP_MR_SUCCESS ); + } + } +if (result ==L2CAP_CONF_SUCCESS )set_bit (CONF_OUTPUT_DONE , &chan->conf_state); }
@@ -6282,7 +6334,18 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)if (chan->state ==BT_CONNECT ) {if (!status) { -l2cap_send_conn_req (chan); +if (enable_hs && + (conn->fixed_chan_mask &L2CAP_FC_A2MP ) && + chan->chan_policy ==BT_CHANNEL_POLICY_AMP_PREFERRED ) { +set_bit (CONF_CONNECT_PEND , + &chan->conf_state); + +/* Placeholder +amp_create_phylink(); +*/ + }else { +l2cap_send_conn_req (chan); + } }else {__set_chan_timer (chan,L2CAP_DISC_TIMEOUT ); }
@@ -6302,6 +6365,15 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)if (parent) parent->sk_data_ready (parent,0 ); }else { +if (chan->local_amp_id) { +/* Placeholder - accept physical +* link +amp_accept_physical(chan, +chan->local_amp_id); +*/ +continue ; + } +__l2cap_state_change (chan,BT_CONFIG ); res =L2CAP_CR_SUCCESS ; stat =L2CAP_CS_NO_INFO ;
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 19/20 Bluetooth: Do not retransmit data during a channel move
In reply to Mat MartineauDo not retransmit previously-sent data when a "receiver ready" s-frame with the "final" flag is received during a move.
The ERTM state machines will resynchronize at the end of a channel move, and the state machine needs to avoid state changes during a move.
--- net/bluetooth/l2cap_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +3 -2
@@ -5580,8 +5580,9 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,if (control->final) {clear_bit (CONN_REMOTE_BUSY , &chan->conn_state); -if (!test_and_clear_bit (CONN_REJ_ACT , - &chan->conn_state)) { +if (!test_and_clear_bit (CONN_REJ_ACT , &chan->conn_state) + && (chan->move_state ==L2CAP_MOVE_STABLE || + chan->move_state ==L2CAP_MOVE_WAIT_PREPARE )) { control->final =0 ;l2cap_retransmit_all (chan, control); }
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
RFC 20/20 Bluetooth: Start channel move when socket option is changed
In reply to Mat MartineauChannel moves are triggered by changes to the BT_CHANNEL_POLICY sockopt when an ERTM or streaming-mode channel is connected.
Moves are only started if enable_hs is true.
--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 20 ++++++++++++++++++++ net/bluetooth/l2cap_sock.c | 5 +++++ 3 files changed, 26 insertions(+)
include/net/bluetooth/l2cap.h +1 -0
@@ -799,5 +799,6 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan);int l2cap_ertm_init (struct l2cap_chan *chan);void l2cap_chan_add (struct l2cap_conn *conn,struct l2cap_chan *chan);void l2cap_chan_del (struct l2cap_chan *chan,int err); +void l2cap_move_start (struct l2cap_chan *chan);#endif /* __L2CAP_H */
net/bluetooth/l2cap_core.c +20 -0
@@ -4435,6 +4435,26 @@ static void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, } } +void l2cap_move_start (struct l2cap_chan *chan) +{ +BT_DBG ("chan %p" , chan); + +if (chan->local_amp_id ==0 ) { +if (chan->chan_policy !=BT_CHANNEL_POLICY_AMP_PREFERRED ) +return ; + chan->move_role =L2CAP_MOVE_ROLE_INITIATOR ; + chan->move_state =L2CAP_MOVE_WAIT_PREPARE ; +/* Placeholder - start physical link setup */ + }else { + chan->move_role =L2CAP_MOVE_ROLE_INITIATOR ; + chan->move_state =L2CAP_MOVE_WAIT_RSP_SUCCESS ; + chan->move_id =0 ; +l2cap_move_start (chan); +l2cap_send_move_chan_req (chan,0 ); +__set_chan_timer (chan,L2CAP_MOVE_TIMEOUT ); + } +} +static void l2cap_do_create (struct l2cap_chan *chan,int result,u8 local_amp_id,u8 remote_amp_id) {
net/bluetooth/l2cap_sock.c +5 -0
@@ -725,6 +725,11 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch } chan->chan_policy = (u8 ) opt; + +if (sk->sk_state ==BT_CONNECTED && + chan->move_role ==L2CAP_MOVE_ROLE_NONE ) +l2cap_move_start (chan); +break ;default :
Signature · 7 lines
1.7.12 -- Mat Martineau The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation