@@ -58,26 +58,24 @@ static unsigned int port;
5858static char socket_path [UNIX_ADDR_BUFF_SIZE ];
5959static bool arg_found ;
6060
61- static bool is_hci_event_discardable (const uint8_t * evt_data )
61+ static bool is_hci_event_discardable (const struct bt_hci_evt_hdr * ev )
6262{
63- uint8_t evt_type = evt_data [0 ];
64-
65- switch (evt_type ) {
63+ switch (ev -> evt ) {
6664#if defined(CONFIG_BT_CLASSIC )
6765 case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI :
6866 case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT :
6967 return true;
7068#endif
7169 case BT_HCI_EVT_LE_META_EVENT : {
72- uint8_t subevt_type = evt_data [ sizeof ( struct bt_hci_evt_hdr )] ;
70+ const struct bt_hci_evt_le_meta_event * meta_ev = ( const void * ) ev -> data ;
7371
74- switch (subevt_type ) {
72+ switch (meta_ev -> subevent ) {
7573 case BT_HCI_EVT_LE_ADVERTISING_REPORT :
7674 return true;
7775#if defined(CONFIG_BT_EXT_ADV )
7876 case BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT : {
7977 const struct bt_hci_evt_le_ext_advertising_report * ext_adv =
80- (void * )& evt_data [ 3 ] ;
78+ (const void * )meta_ev -> data ;
8179
8280 return (ext_adv -> num_reports == 1 ) &&
8381 ((ext_adv -> adv_info [0 ].evt_type & BT_HCI_LE_ADV_EVT_TYPE_LEGACY ) !=
@@ -93,28 +91,67 @@ static bool is_hci_event_discardable(const uint8_t *evt_data)
9391 }
9492}
9593
94+ static struct net_buf * get_rx_evt (const uint8_t * data )
95+ {
96+ const struct bt_hci_evt_hdr * ev = (const void * )data ;
97+ const bool discardable = is_hci_event_discardable (ev );
98+ const k_timeout_t timeout = discardable ? K_NO_WAIT : K_SECONDS (1 );
99+ struct net_buf * buf ;
100+
101+ do {
102+ buf = bt_buf_get_evt (ev -> evt , discardable , timeout );
103+ if (buf == NULL ) {
104+ if (discardable ) {
105+ LOG_DBG_RATELIMIT ("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 );
111+
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+ struct net_buf * buf ;
130+
131+ buf = bt_buf_get_rx (BT_BUF_ISO_IN , K_NO_WAIT );
132+ if (buf == NULL ) {
133+ LOG_ERR_RATELIMIT ("No available ISO buffers!" );
134+ }
135+
136+ return buf ;
137+ }
138+
96139static struct net_buf * get_rx (const uint8_t * buf )
97140{
98- bool discardable = false;
99- k_timeout_t timeout = K_FOREVER ;
141+ uint8_t hci_h4_type = buf [0 ];
100142
101- switch (buf [ 0 ] ) {
143+ switch (hci_h4_type ) {
102144 case BT_HCI_H4_EVT :
103- if (is_hci_event_discardable (buf )) {
104- discardable = true;
105- timeout = K_NO_WAIT ;
106- }
107-
108- return bt_buf_get_evt (buf [1 ], discardable , timeout );
145+ return get_rx_evt (& buf [1 ]);
109146 case BT_HCI_H4_ACL :
110- return bt_buf_get_rx ( BT_BUF_ACL_IN , K_FOREVER );
147+ return get_rx_acl ( & buf [ 1 ] );
111148 case BT_HCI_H4_ISO :
112149 if (IS_ENABLED (CONFIG_BT_ISO )) {
113- return bt_buf_get_rx ( BT_BUF_ISO_IN , K_FOREVER );
150+ return get_rx_iso ( & buf [ 1 ] );
114151 }
115152 __fallthrough ;
116153 default :
117- LOG_ERR ("Unknown packet type: %u" , buf [ 0 ] );
154+ LOG_ERR ("Unknown packet type: %u" , hci_h4_type );
118155 }
119156
120157 return NULL ;
@@ -281,7 +318,6 @@ static void rx_thread(void *p1, void *p2, void *p3)
281318 frame_start += decoded_len ;
282319
283320 if (!buf ) {
284- LOG_DBG ("Discard adv report due to insufficient buf" );
285321 continue ;
286322 }
287323
0 commit comments