@@ -58,26 +58,24 @@ static unsigned int port;
58
58
static char socket_path [UNIX_ADDR_BUFF_SIZE ];
59
59
static bool arg_found ;
60
60
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 )
62
62
{
63
- uint8_t evt_type = evt_data [0 ];
64
-
65
- switch (evt_type ) {
63
+ switch (ev -> evt ) {
66
64
#if defined(CONFIG_BT_CLASSIC )
67
65
case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI :
68
66
case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT :
69
67
return true;
70
68
#endif
71
69
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 ;
73
71
74
- switch (subevt_type ) {
72
+ switch (ev -> evt ) {
75
73
case BT_HCI_EVT_LE_ADVERTISING_REPORT :
76
74
return true;
77
75
#if defined(CONFIG_BT_EXT_ADV )
78
76
case BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT : {
79
77
const struct bt_hci_evt_le_ext_advertising_report * ext_adv =
80
- (void * )& evt_data [ 3 ] ;
78
+ (const void * )meta_ev -> data ;
81
79
82
80
return (ext_adv -> num_reports == 1 ) &&
83
81
((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)
93
91
}
94
92
}
95
93
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
+
96
139
static struct net_buf * get_rx (const uint8_t * buf )
97
140
{
98
- bool discardable = false;
99
- k_timeout_t timeout = K_FOREVER ;
141
+ uint8_t hci_h4_type = buf [0 ];
100
142
101
- switch (buf [ 0 ] ) {
143
+ switch (hci_h4_type ) {
102
144
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 ]);
109
146
case BT_HCI_H4_ACL :
110
- return bt_buf_get_rx ( BT_BUF_ACL_IN , K_FOREVER );
147
+ return get_rx_acl ( & buf [ 1 ] );
111
148
case BT_HCI_H4_ISO :
112
149
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 ] );
114
151
}
115
152
__fallthrough ;
116
153
default :
117
- LOG_ERR ("Unknown packet type: %u" , buf [ 0 ] );
154
+ LOG_ERR ("Unknown packet type: %u" , hci_h4_type );
118
155
}
119
156
120
157
return NULL ;
@@ -281,7 +318,6 @@ static void rx_thread(void *p1, void *p2, void *p3)
281
318
frame_start += decoded_len ;
282
319
283
320
if (!buf ) {
284
- LOG_DBG ("Discard adv report due to insufficient buf" );
285
321
continue ;
286
322
}
287
323
0 commit comments