@@ -103,7 +103,6 @@ struct bt_att_chan {
103
103
ATOMIC_DEFINE (flags , ATT_NUM_FLAGS );
104
104
struct bt_att_req * req ;
105
105
struct k_fifo tx_queue ;
106
- struct net_buf * rsp_buf ;
107
106
struct bt_att_tx_meta_data rsp_meta ;
108
107
struct k_work_delayable timeout_work ;
109
108
sys_snode_t node ;
@@ -660,7 +659,7 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t
660
659
struct net_buf * buf ;
661
660
struct bt_att_tx_meta_data * data ;
662
661
k_timeout_t timeout ;
663
- bool re_use = false;
662
+ bool is_rsp = false;
664
663
665
664
if (len + sizeof (op ) > bt_att_mtu (chan )) {
666
665
LOG_WRN ("ATT MTU exceeded, max %u, wanted %zu" , bt_att_mtu (chan ),
@@ -673,23 +672,19 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t
673
672
case ATT_CONFIRMATION :
674
673
/* Use a timeout only when responding/confirming */
675
674
timeout = BT_ATT_TIMEOUT ;
676
- re_use = true;
675
+ is_rsp = true;
677
676
break ;
678
677
default :
679
678
timeout = K_FOREVER ;
680
679
}
681
680
682
- if (IS_ENABLED (CONFIG_BT_GATT_READ_MULTIPLE ) &&
683
- (op == BT_ATT_OP_READ_MULT_RSP ||
684
- op == BT_ATT_OP_READ_MULT_VL_RSP )) {
685
- /* We can't re-use the REQ buffer (see below) for these two
686
- * opcodes, as the handler will read from it _after_ allocating
687
- * the RSP buffer.
688
- */
689
- re_use = false;
681
+ buf = bt_l2cap_create_pdu_timeout (NULL , 0 , timeout );
682
+ if (!buf ) {
683
+ LOG_ERR ("Unable to allocate buffer for op 0x%02x" , op );
684
+ return NULL ;
690
685
}
691
686
692
- if (re_use ) {
687
+ if (is_rsp ) {
693
688
/* There can only ever be one transaction at a time on a
694
689
* bearer/channel. Use a dedicated channel meta-data to ensure
695
690
* we can always queue an (error) RSP for each REQ. The ATT
@@ -706,27 +701,8 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t
706
701
return NULL ;
707
702
}
708
703
data = & chan -> rsp_meta ;
709
-
710
- /* Re-use REQ buf to avoid dropping the REQ and timing out.
711
- * This only works if the bearer used to RX REQs is the same as
712
- * for sending the RSP. That should always be the case
713
- * (per-spec).
714
- */
715
- __ASSERT_NO_MSG (chan -> rsp_buf );
716
- buf = net_buf_ref (chan -> rsp_buf );
717
-
718
- net_buf_reset (buf );
719
- net_buf_reserve (buf , BT_L2CAP_BUF_SIZE (0 ));
720
-
721
- LOG_DBG ("re-using REQ buf %p for RSP" , buf );
704
+ LOG_INF ("alloc rsp meta" );
722
705
} else {
723
- LOG_DBG ("alloc buf & meta from global pools" );
724
- buf = bt_l2cap_create_pdu_timeout (NULL , 0 , timeout );
725
- if (!buf ) {
726
- LOG_ERR ("Unable to allocate buffer for op 0x%02x" , op );
727
- return NULL ;
728
- }
729
-
730
706
data = tx_meta_data_alloc (timeout );
731
707
if (!data ) {
732
708
LOG_WRN ("Unable to allocate ATT TX meta" );
@@ -810,7 +786,6 @@ static void send_err_rsp(struct bt_att_chan *chan, uint8_t req, uint16_t handle,
810
786
811
787
buf = bt_att_chan_create_pdu (chan , BT_ATT_OP_ERROR_RSP , sizeof (* rsp ));
812
788
if (!buf ) {
813
- LOG_ERR ("unable to allocate buf for error response" );
814
789
return ;
815
790
}
816
791
@@ -2894,40 +2869,26 @@ static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
2894
2869
}
2895
2870
}
2896
2871
2897
- /* Thread-local variable, shouldn't be used by anything else */
2898
- __ASSERT_NO_MSG (!att_chan -> rsp_buf );
2899
-
2900
- /* Mark buffer free for re-use by the opcode handler.
2901
- *
2902
- * This allows ATT to always be able to send a RSP (or err RSP)
2903
- * to the peer, regardless of the TX buffer usage by other stack
2904
- * users (e.g. GATT notifications, L2CAP using global pool, SMP,
2905
- * etc..), avoiding an ATT timeout due to resource usage.
2906
- *
2907
- * The ref is taken by `bt_att_chan_create_pdu`.
2908
- */
2909
- att_chan -> rsp_buf = net_buf_ref (buf );
2910
-
2911
2872
if (!handler ) {
2912
2873
LOG_WRN ("Unhandled ATT code 0x%02x" , hdr -> code );
2913
2874
if (att_op_get_type (hdr -> code ) != ATT_COMMAND &&
2914
2875
att_op_get_type (hdr -> code ) != ATT_INDICATION ) {
2915
2876
send_err_rsp (att_chan , hdr -> code , 0 ,
2916
2877
BT_ATT_ERR_NOT_SUPPORTED );
2917
2878
}
2918
- goto exit ;
2879
+ return 0 ;
2919
2880
}
2920
2881
2921
2882
if (IS_ENABLED (CONFIG_BT_ATT_ENFORCE_FLOW )) {
2922
2883
if (handler -> type == ATT_REQUEST &&
2923
2884
atomic_test_and_set_bit (att_chan -> flags , ATT_PENDING_RSP )) {
2924
2885
LOG_WRN ("Ignoring unexpected request" );
2925
- goto exit ;
2886
+ return 0 ;
2926
2887
} else if (handler -> type == ATT_INDICATION &&
2927
2888
atomic_test_and_set_bit (att_chan -> flags ,
2928
2889
ATT_PENDING_CFM )) {
2929
2890
LOG_WRN ("Ignoring unexpected indication" );
2930
- goto exit ;
2891
+ return 0 ;
2931
2892
}
2932
2893
}
2933
2894
@@ -2943,10 +2904,6 @@ static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
2943
2904
send_err_rsp (att_chan , hdr -> code , 0 , err );
2944
2905
}
2945
2906
2946
- exit :
2947
- net_buf_unref (att_chan -> rsp_buf );
2948
- att_chan -> rsp_buf = NULL ;
2949
-
2950
2907
return 0 ;
2951
2908
}
2952
2909
0 commit comments