@@ -93,24 +93,70 @@ static bool is_hci_event_discardable(const uint8_t *evt_data)
93
93
}
94
94
}
95
95
96
- static struct net_buf * get_rx (const uint8_t * buf )
96
+ static struct net_buf * get_rx_evt (const uint8_t * data )
97
97
{
98
- bool discardable = false;
99
- k_timeout_t timeout = K_FOREVER ;
98
+ bool discardable = is_hci_event_discardable (data );
99
+ struct net_buf * buf ;
100
+
101
+ do {
102
+ buf = bt_buf_get_evt (data [1 ], discardable , discardable ? K_NO_WAIT : K_SECONDS (1 ));
103
+ if (buf == NULL ) {
104
+ if (discardable ) {
105
+ LOG_DBG ("Discardable buffer pool full, ignoring event" );
106
+ return buf ;
107
+ }
108
+ LOG_WRN ("Couldn't allocate a buffer after waiting 1 second." );
109
+ }
110
+ } while (!buf );
100
111
101
- switch (buf [0 ]) {
102
- case BT_HCI_H4_EVT :
103
- if (is_hci_event_discardable (buf )) {
104
- discardable = true;
105
- timeout = K_NO_WAIT ;
112
+ return buf ;
113
+ }
114
+
115
+ static struct net_buf * get_rx_acl (const uint8_t * data )
116
+ {
117
+ struct net_buf * buf ;
118
+
119
+ buf = bt_buf_get_rx (BT_BUF_ACL_IN , K_NO_WAIT );
120
+ if (buf == NULL ) {
121
+ LOG_ERR ("No available ACL buffers!" );
122
+ }
123
+
124
+ return buf ;
125
+ }
126
+
127
+ static struct net_buf * get_rx_iso (const uint8_t * data )
128
+ {
129
+ static unsigned int fail_cnt ;
130
+ struct net_buf * buf ;
131
+
132
+ buf = bt_buf_get_rx (BT_BUF_ISO_IN , K_NO_WAIT );
133
+ if (buf == NULL ) {
134
+ if (fail_cnt == 0 ) {
135
+ LOG_ERR ("No available ISO buffers!" );
106
136
}
107
137
108
- return bt_buf_get_evt (buf [1 ], discardable , timeout );
138
+ fail_cnt ++ ;
139
+ } else {
140
+ if (fail_cnt ) {
141
+ LOG_INF ("ISO buffer available (%u dropped)!" , fail_cnt );
142
+ }
143
+
144
+ fail_cnt = 0 ;
145
+ }
146
+
147
+ return buf ;
148
+ }
149
+
150
+ static struct net_buf * get_rx (const uint8_t * buf )
151
+ {
152
+ switch (buf [0 ]) {
153
+ case BT_HCI_H4_EVT :
154
+ return get_rx_evt (buf );
109
155
case BT_HCI_H4_ACL :
110
- return bt_buf_get_rx ( BT_BUF_ACL_IN , K_FOREVER );
156
+ return get_rx_acl ( buf );
111
157
case BT_HCI_H4_ISO :
112
158
if (IS_ENABLED (CONFIG_BT_ISO )) {
113
- return bt_buf_get_rx ( BT_BUF_ISO_IN , K_FOREVER );
159
+ return get_rx_iso ( buf );
114
160
}
115
161
__fallthrough ;
116
162
default :
@@ -281,7 +327,6 @@ static void rx_thread(void *p1, void *p2, void *p3)
281
327
frame_start += decoded_len ;
282
328
283
329
if (!buf ) {
284
- LOG_DBG ("Discard adv report due to insufficient buf" );
285
330
continue ;
286
331
}
287
332
0 commit comments