153f17a9db278d33517d9888dd77848f554522a38JP Abgrall/*
253f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Copyright (c) 2007
353f17a9db278d33517d9888dd77848f554522a38JP Abgrall *	paolo.abeni@email.it  All rights reserved.
453f17a9db278d33517d9888dd77848f554522a38JP Abgrall *
553f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Redistribution and use in source and binary forms, with or without
653f17a9db278d33517d9888dd77848f554522a38JP Abgrall * modification, are permitted provided that: (1) source code distributions
753f17a9db278d33517d9888dd77848f554522a38JP Abgrall * retain the above copyright notice and this paragraph in its entirety, (2)
853f17a9db278d33517d9888dd77848f554522a38JP Abgrall * distributions including binary code include the above copyright notice and
953f17a9db278d33517d9888dd77848f554522a38JP Abgrall * this paragraph in its entirety in the documentation or other materials
1053f17a9db278d33517d9888dd77848f554522a38JP Abgrall * provided with the distribution, and (3) all advertising materials mentioning
1153f17a9db278d33517d9888dd77848f554522a38JP Abgrall * features or use of this software display the following acknowledgement:
12892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes * ``This product includes software developed by Paolo Abeni.''
13892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes * The name of author may not be used to endorse or promote products derived
1453f17a9db278d33517d9888dd77848f554522a38JP Abgrall * from this software without specific prior written permission.
1553f17a9db278d33517d9888dd77848f554522a38JP Abgrall * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1653f17a9db278d33517d9888dd77848f554522a38JP Abgrall * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1753f17a9db278d33517d9888dd77848f554522a38JP Abgrall * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1853f17a9db278d33517d9888dd77848f554522a38JP Abgrall */
1953f17a9db278d33517d9888dd77848f554522a38JP Abgrall
20892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes#define NETDISSECT_REWORKED
2153f17a9db278d33517d9888dd77848f554522a38JP Abgrall#ifdef HAVE_CONFIG_H
2253f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "config.h"
2353f17a9db278d33517d9888dd77848f554522a38JP Abgrall#endif
2453f17a9db278d33517d9888dd77848f554522a38JP Abgrall
2553f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include <tcpdump-stdinc.h>
2653f17a9db278d33517d9888dd77848f554522a38JP Abgrall
2753f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "interface.h"
2853f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "extract.h"
2953f17a9db278d33517d9888dd77848f554522a38JP Abgrall
3053f17a9db278d33517d9888dd77848f554522a38JP Abgrall#if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
3153f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include <pcap/bluetooth.h>
3253f17a9db278d33517d9888dd77848f554522a38JP Abgrall
3353f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define	BT_HDRLEN sizeof(pcap_bluetooth_h4_header)
3453f17a9db278d33517d9888dd77848f554522a38JP Abgrall/*
3553f17a9db278d33517d9888dd77848f554522a38JP Abgrall * This is the top level routine of the printer.  'p' points
3653f17a9db278d33517d9888dd77848f554522a38JP Abgrall * to the bluetooth header of the packet, 'h->ts' is the timestamp,
3753f17a9db278d33517d9888dd77848f554522a38JP Abgrall * 'h->len' is the length of the packet off the wire, and 'h->caplen'
3853f17a9db278d33517d9888dd77848f554522a38JP Abgrall * is the number of bytes actually captured.
3953f17a9db278d33517d9888dd77848f554522a38JP Abgrall */
4053f17a9db278d33517d9888dd77848f554522a38JP Abgrallu_int
41892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughesbt_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
4253f17a9db278d33517d9888dd77848f554522a38JP Abgrall{
4353f17a9db278d33517d9888dd77848f554522a38JP Abgrall	u_int length = h->len;
4453f17a9db278d33517d9888dd77848f554522a38JP Abgrall	u_int caplen = h->caplen;
4553f17a9db278d33517d9888dd77848f554522a38JP Abgrall	const pcap_bluetooth_h4_header* hdr = (const pcap_bluetooth_h4_header*)p;
4653f17a9db278d33517d9888dd77848f554522a38JP Abgrall
4753f17a9db278d33517d9888dd77848f554522a38JP Abgrall	if (caplen < BT_HDRLEN) {
48892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes		ND_PRINT((ndo, "[|bt]"));
4953f17a9db278d33517d9888dd77848f554522a38JP Abgrall		return (BT_HDRLEN);
5053f17a9db278d33517d9888dd77848f554522a38JP Abgrall	}
5153f17a9db278d33517d9888dd77848f554522a38JP Abgrall	caplen -= BT_HDRLEN;
5253f17a9db278d33517d9888dd77848f554522a38JP Abgrall	length -= BT_HDRLEN;
5353f17a9db278d33517d9888dd77848f554522a38JP Abgrall	p += BT_HDRLEN;
54892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes	if (ndo->ndo_eflag)
55892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes		ND_PRINT((ndo, "hci length %d, direction %s, ", length, (EXTRACT_32BITS(&hdr->direction)&0x1)?"in":"out"));
5653f17a9db278d33517d9888dd77848f554522a38JP Abgrall
57892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes	if (!ndo->ndo_suppress_default_print)
58892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes		ND_DEFAULTPRINT(p, caplen);
5953f17a9db278d33517d9888dd77848f554522a38JP Abgrall
6053f17a9db278d33517d9888dd77848f554522a38JP Abgrall	return (BT_HDRLEN);
6153f17a9db278d33517d9888dd77848f554522a38JP Abgrall}
6253f17a9db278d33517d9888dd77848f554522a38JP Abgrall#endif
6353f17a9db278d33517d9888dd77848f554522a38JP Abgrall
6453f17a9db278d33517d9888dd77848f554522a38JP Abgrall
6553f17a9db278d33517d9888dd77848f554522a38JP Abgrall/*
6653f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Local Variables:
6753f17a9db278d33517d9888dd77848f554522a38JP Abgrall * c-style: whitesmith
6853f17a9db278d33517d9888dd77848f554522a38JP Abgrall * c-basic-offset: 8
6953f17a9db278d33517d9888dd77848f554522a38JP Abgrall * End:
7053f17a9db278d33517d9888dd77848f554522a38JP Abgrall */
71