1a5779b6eSRui Paulo /*
2a5779b6eSRui Paulo * Copyright (c) 2007
3a5779b6eSRui Paulo * paolo.abeni@email.it All rights reserved.
4a5779b6eSRui Paulo *
5a5779b6eSRui Paulo * Redistribution and use in source and binary forms, with or without
6a5779b6eSRui Paulo * modification, are permitted provided that: (1) source code distributions
7a5779b6eSRui Paulo * retain the above copyright notice and this paragraph in its entirety, (2)
8a5779b6eSRui Paulo * distributions including binary code include the above copyright notice and
9a5779b6eSRui Paulo * this paragraph in its entirety in the documentation or other materials
10a5779b6eSRui Paulo * provided with the distribution, and (3) all advertising materials mentioning
11a5779b6eSRui Paulo * features or use of this software display the following acknowledgement:
12a5779b6eSRui Paulo * ``This product includes software developed by Paolo Abeni.''
13a5779b6eSRui Paulo * The name of author may not be used to endorse or promote products derived
14a5779b6eSRui Paulo * from this software without specific prior written permission.
15a5779b6eSRui Paulo * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16a5779b6eSRui Paulo * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17a5779b6eSRui Paulo * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18a5779b6eSRui Paulo */
19a5779b6eSRui Paulo
203340d773SGleb Smirnoff /* \summary: Bluetooth printer */
213340d773SGleb Smirnoff
22*ee67461eSJoseph Mingrone #include <config.h>
23a5779b6eSRui Paulo
24*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
25a5779b6eSRui Paulo
26*ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK
273340d773SGleb Smirnoff #include "netdissect.h"
2827df3f5dSRui Paulo #include "extract.h"
29a5779b6eSRui Paulo
30*ee67461eSJoseph Mingrone #ifdef DLT_BLUETOOTH_HCI_H4_WITH_PHDR
31a5779b6eSRui Paulo
32*ee67461eSJoseph Mingrone /*
33*ee67461eSJoseph Mingrone * Header prepended by libpcap to each bluetooth h4 frame;
34*ee67461eSJoseph Mingrone * the direction field is in network byte order.
35*ee67461eSJoseph Mingrone */
36*ee67461eSJoseph Mingrone typedef struct _bluetooth_h4_header {
37*ee67461eSJoseph Mingrone nd_uint32_t direction; /* if first bit is set direction is incoming */
38*ee67461eSJoseph Mingrone } bluetooth_h4_header;
39*ee67461eSJoseph Mingrone
40*ee67461eSJoseph Mingrone #define BT_HDRLEN sizeof(bluetooth_h4_header)
41*ee67461eSJoseph Mingrone
42a5779b6eSRui Paulo /*
43a5779b6eSRui Paulo * This is the top level routine of the printer. 'p' points
44a5779b6eSRui Paulo * to the bluetooth header of the packet, 'h->ts' is the timestamp,
45a5779b6eSRui Paulo * 'h->len' is the length of the packet off the wire, and 'h->caplen'
46a5779b6eSRui Paulo * is the number of bytes actually captured.
47a5779b6eSRui Paulo */
48*ee67461eSJoseph Mingrone void
bt_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)493c602fabSXin LI bt_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
50a5779b6eSRui Paulo {
51a5779b6eSRui Paulo u_int length = h->len;
52a5779b6eSRui Paulo u_int caplen = h->caplen;
53*ee67461eSJoseph Mingrone const bluetooth_h4_header *hdr = (const bluetooth_h4_header *)p;
54a5779b6eSRui Paulo
55*ee67461eSJoseph Mingrone ndo->ndo_protocol = "bluetooth";
56*ee67461eSJoseph Mingrone nd_print_protocol(ndo);
57*ee67461eSJoseph Mingrone ND_TCHECK_LEN(p, BT_HDRLEN);
58*ee67461eSJoseph Mingrone ndo->ndo_ll_hdr_len += BT_HDRLEN;
59a5779b6eSRui Paulo caplen -= BT_HDRLEN;
60a5779b6eSRui Paulo length -= BT_HDRLEN;
61a5779b6eSRui Paulo p += BT_HDRLEN;
623c602fabSXin LI if (ndo->ndo_eflag)
63*ee67461eSJoseph Mingrone ND_PRINT(", hci length %u, direction %s", length,
64*ee67461eSJoseph Mingrone (GET_BE_U_4(hdr->direction)&0x1) ? "in" : "out");
65a5779b6eSRui Paulo
663c602fabSXin LI if (!ndo->ndo_suppress_default_print)
673c602fabSXin LI ND_DEFAULTPRINT(p, caplen);
68a5779b6eSRui Paulo }
69a5779b6eSRui Paulo #endif
70