Skip to content

Commit bf8b9a9

Browse files
kolodgrzholtmann
authored andcommitted
Bluetooth: bnep: Add support to extended headers of control frames
Handling extended headers of control frames is required BNEP functionality. This patch refractor bnep rx frame handling function. Extended header for control frames shouldn't be omitted as it was previously done. Every control frame should be checked if it contains extended header and then every extension should be parsed separately. Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 0477e2e commit bf8b9a9

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

‎net/bluetooth/bnep/core.c‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,29 +292,55 @@ static int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb)
292292
{
293293
struct net_device *dev = s->dev;
294294
struct sk_buff *nskb;
295-
u8 type;
295+
u8 type, ctrl_type;
296296

297297
dev->stats.rx_bytes += skb->len;
298298

299299
type = *(u8 *) skb->data;
300300
skb_pull(skb, 1);
301+
ctrl_type = *(u8 *)skb->data;
301302

302303
if ((type & BNEP_TYPE_MASK) >= sizeof(__bnep_rx_hlen))
303304
goto badframe;
304305

305306
if ((type & BNEP_TYPE_MASK) == BNEP_CONTROL) {
306-
bnep_rx_control(s, skb->data, skb->len);
307-
kfree_skb(skb);
308-
return 0;
309-
}
307+
if (bnep_rx_control(s, skb->data, skb->len) < 0) {
308+
dev->stats.tx_errors++;
309+
kfree_skb(skb);
310+
return 0;
311+
}
310312

311-
skb_reset_mac_header(skb);
313+
if (!(type & BNEP_EXT_HEADER)) {
314+
kfree_skb(skb);
315+
return 0;
316+
}
312317

313-
/* Verify and pull out header */
314-
if (!skb_pull(skb, __bnep_rx_hlen[type & BNEP_TYPE_MASK]))
315-
goto badframe;
318+
/* Verify and pull ctrl message since it's already processed */
319+
switch (ctrl_type) {
320+
case BNEP_SETUP_CONN_REQ:
321+
/* Pull: ctrl type (1 b), len (1 b), data (len bytes) */
322+
if (!skb_pull(skb, 2 + *(u8 *)(skb->data + 1) * 2))
323+
goto badframe;
324+
break;
325+
case BNEP_FILTER_MULTI_ADDR_SET:
326+
case BNEP_FILTER_NET_TYPE_SET:
327+
/* Pull: ctrl type (1 b), len (2 b), data (len bytes) */
328+
if (!skb_pull(skb, 3 + *(u16 *)(skb->data + 1) * 2))
329+
goto badframe;
330+
break;
331+
default:
332+
kfree_skb(skb);
333+
return 0;
334+
}
335+
} else {
336+
skb_reset_mac_header(skb);
316337

317-
s->eh.h_proto = get_unaligned((__be16 *) (skb->data - 2));
338+
/* Verify and pull out header */
339+
if (!skb_pull(skb, __bnep_rx_hlen[type & BNEP_TYPE_MASK]))
340+
goto badframe;
341+
342+
s->eh.h_proto = get_unaligned((__be16 *) (skb->data - 2));
343+
}
318344

319345
if (type & BNEP_EXT_HEADER) {
320346
if (bnep_rx_extension(s, skb) < 0)

0 commit comments

Comments
 (0)