@@ -3982,6 +3982,30 @@ static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,
39823982 struct l2cap_chan * chan = NULL , * pchan = NULL ;
39833983 int result , status = L2CAP_CS_NO_INFO ;
39843984
3985+ /* If encryption is requested, but the key size is not ready yet,
3986+ * we need to wait for the key size to be ready before we can
3987+ * proceed with the connection. We do this by deferring the
3988+ * connection request until the key size is ready. This is done
3989+ * by storing the connection request in the hcon->pending_connect
3990+ * field. The connection request will be retried when the key size
3991+ * is ready.
3992+ */
3993+ if (test_bit (HCI_CONN_ENCRYPT , & conn -> hcon -> flags ) &&
3994+ !test_bit (HCI_CONN_ENC_KEY_READY , & conn -> hcon -> flags )) {
3995+ struct l2cap_pending_connect * pc ;
3996+
3997+ pc = kzalloc (sizeof (* pc ), GFP_KERNEL );
3998+ if (!pc )
3999+ return ;
4000+ pc -> conn = conn ;
4001+ memcpy (& pc -> cmd , cmd , sizeof (* cmd ));
4002+ memcpy (pc -> data , data , sizeof (struct l2cap_conn_req ));
4003+ pc -> rsp_code = rsp_code ;
4004+ BT_DBG ("store request and retried when keysize is ready" );
4005+ conn -> hcon -> pending_connect = pc ;
4006+ return ;
4007+ }
4008+
39854009 u16 dcid = 0 , scid = __le16_to_cpu (req -> scid );
39864010 __le16 psm = req -> psm ;
39874011
@@ -4105,6 +4129,12 @@ static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,
41054129 l2cap_chan_put (pchan );
41064130}
41074131
4132+ void l2cap_process_pending_connect (struct l2cap_conn * conn , struct l2cap_cmd_hdr * cmd ,
4133+ u8 * data , u8 rsp_code )
4134+ {
4135+ l2cap_connect (conn , cmd , data , rsp_code );
4136+ }
4137+
41084138static int l2cap_connect_req (struct l2cap_conn * conn ,
41094139 struct l2cap_cmd_hdr * cmd , u16 cmd_len , u8 * data )
41104140{
0 commit comments