xref: /dflybsd-src/contrib/tcpdump/print-bt.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
127bfbee1SPeter Avalos /*
227bfbee1SPeter Avalos  * Copyright (c) 2007
327bfbee1SPeter Avalos  *	paolo.abeni@email.it  All rights reserved.
427bfbee1SPeter Avalos  *
527bfbee1SPeter Avalos  * Redistribution and use in source and binary forms, with or without
627bfbee1SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
727bfbee1SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
827bfbee1SPeter Avalos  * distributions including binary code include the above copyright notice and
927bfbee1SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1027bfbee1SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1127bfbee1SPeter Avalos  * features or use of this software display the following acknowledgement:
1227bfbee1SPeter Avalos  * ``This product includes software developed by Paolo Abeni.''
1327bfbee1SPeter Avalos  * The name of author may not be used to endorse or promote products derived
1427bfbee1SPeter Avalos  * from this software without specific prior written permission.
1527bfbee1SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1627bfbee1SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1727bfbee1SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1827bfbee1SPeter Avalos  */
1927bfbee1SPeter Avalos 
20411677aeSAaron LI /* \summary: Bluetooth printer */
2127bfbee1SPeter Avalos 
2227bfbee1SPeter Avalos #ifdef HAVE_CONFIG_H
23*ed775ee7SAntonio Huete Jimenez #include <config.h>
2427bfbee1SPeter Avalos #endif
2527bfbee1SPeter Avalos 
26*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
2727bfbee1SPeter Avalos 
28*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
29411677aeSAaron LI #include "netdissect.h"
3027bfbee1SPeter Avalos #include "extract.h"
3127bfbee1SPeter Avalos 
32*ed775ee7SAntonio Huete Jimenez #ifdef DLT_BLUETOOTH_HCI_H4_WITH_PHDR
3327bfbee1SPeter Avalos 
34*ed775ee7SAntonio Huete Jimenez /*
35*ed775ee7SAntonio Huete Jimenez  * Header prepended by libpcap to each bluetooth h4 frame;
36*ed775ee7SAntonio Huete Jimenez  * the direction field is in network byte order.
37*ed775ee7SAntonio Huete Jimenez  */
38*ed775ee7SAntonio Huete Jimenez typedef struct _bluetooth_h4_header {
39*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t direction; /* if first bit is set direction is incoming */
40*ed775ee7SAntonio Huete Jimenez } bluetooth_h4_header;
41*ed775ee7SAntonio Huete Jimenez 
42*ed775ee7SAntonio Huete Jimenez #define	BT_HDRLEN sizeof(bluetooth_h4_header)
43*ed775ee7SAntonio Huete Jimenez 
4427bfbee1SPeter Avalos /*
4527bfbee1SPeter Avalos  * This is the top level routine of the printer.  'p' points
4627bfbee1SPeter Avalos  * to the bluetooth header of the packet, 'h->ts' is the timestamp,
4727bfbee1SPeter Avalos  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
4827bfbee1SPeter Avalos  * is the number of bytes actually captured.
4927bfbee1SPeter Avalos  */
50*ed775ee7SAntonio Huete Jimenez void
bt_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)51411677aeSAaron LI bt_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
5227bfbee1SPeter Avalos {
5327bfbee1SPeter Avalos 	u_int length = h->len;
5427bfbee1SPeter Avalos 	u_int caplen = h->caplen;
55*ed775ee7SAntonio Huete Jimenez 	const bluetooth_h4_header* hdr = (const bluetooth_h4_header*)p;
5627bfbee1SPeter Avalos 
57*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "bluetooth";
58*ed775ee7SAntonio Huete Jimenez 	nd_print_protocol(ndo);
59*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_LEN(p, BT_HDRLEN);
60*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_ll_hdr_len += BT_HDRLEN;
6127bfbee1SPeter Avalos 	caplen -= BT_HDRLEN;
6227bfbee1SPeter Avalos 	length -= BT_HDRLEN;
6327bfbee1SPeter Avalos 	p += BT_HDRLEN;
64411677aeSAaron LI 	if (ndo->ndo_eflag)
65*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", hci length %u, direction %s", length,
66*ed775ee7SAntonio Huete Jimenez 			 (GET_BE_U_4(hdr->direction)&0x1) ? "in" : "out");
6727bfbee1SPeter Avalos 
68411677aeSAaron LI 	if (!ndo->ndo_suppress_default_print)
69411677aeSAaron LI 		ND_DEFAULTPRINT(p, caplen);
7027bfbee1SPeter Avalos }
7127bfbee1SPeter Avalos #endif
72