10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 2007 30f74e101Schristos * paolo.abeni@email.it All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that: (1) source code distributions 70f74e101Schristos * retain the above copyright notice and this paragraph in its entirety, (2) 80f74e101Schristos * distributions including binary code include the above copyright notice and 90f74e101Schristos * this paragraph in its entirety in the documentation or other materials 100f74e101Schristos * provided with the distribution, and (3) all advertising materials mentioning 110f74e101Schristos * features or use of this software display the following acknowledgement: 120f74e101Schristos * ``This product includes software developed by Paolo Abeni.'' 130f74e101Schristos * The name of author may not be used to endorse or promote products derived 140f74e101Schristos * from this software without specific prior written permission. 150f74e101Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 160f74e101Schristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 170f74e101Schristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 180f74e101Schristos */ 190f74e101Schristos 2011b3aaa1Schristos #include <sys/cdefs.h> 210f74e101Schristos #ifndef lint 22*26ba0b50Schristos __RCSID("$NetBSD: print-bt.c,v 1.8 2024/09/02 16:15:30 christos Exp $"); 230f74e101Schristos #endif 240f74e101Schristos 25dc860a36Sspz /* \summary: Bluetooth printer */ 26dc860a36Sspz 27c74ad251Schristos #include <config.h> 280f74e101Schristos 29c74ad251Schristos #include "netdissect-stdinc.h" 300f74e101Schristos 31c74ad251Schristos #define ND_LONGJMP_FROM_TCHECK 32fdccd7e4Schristos #include "netdissect.h" 330f74e101Schristos #include "extract.h" 340f74e101Schristos 35c74ad251Schristos #ifdef DLT_BLUETOOTH_HCI_H4_WITH_PHDR 360f74e101Schristos 37c74ad251Schristos /* 38c74ad251Schristos * Header prepended by libpcap to each bluetooth h4 frame; 39c74ad251Schristos * the direction field is in network byte order. 40c74ad251Schristos */ 41c74ad251Schristos typedef struct _bluetooth_h4_header { 42c74ad251Schristos nd_uint32_t direction; /* if first bit is set direction is incoming */ 43c74ad251Schristos } bluetooth_h4_header; 44c74ad251Schristos 45c74ad251Schristos #define BT_HDRLEN sizeof(bluetooth_h4_header) 46c74ad251Schristos 470f74e101Schristos /* 480f74e101Schristos * This is the top level routine of the printer. 'p' points 490f74e101Schristos * to the bluetooth header of the packet, 'h->ts' is the timestamp, 500f74e101Schristos * 'h->len' is the length of the packet off the wire, and 'h->caplen' 510f74e101Schristos * is the number of bytes actually captured. 520f74e101Schristos */ 53c74ad251Schristos void 54b3a00663Schristos bt_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) 550f74e101Schristos { 560f74e101Schristos u_int length = h->len; 570f74e101Schristos u_int caplen = h->caplen; 58c74ad251Schristos const bluetooth_h4_header *hdr = (const bluetooth_h4_header *)p; 590f74e101Schristos 60c74ad251Schristos ndo->ndo_protocol = "bluetooth"; 61c74ad251Schristos nd_print_protocol(ndo); 62c74ad251Schristos ND_TCHECK_LEN(p, BT_HDRLEN); 63c74ad251Schristos ndo->ndo_ll_hdr_len += BT_HDRLEN; 640f74e101Schristos caplen -= BT_HDRLEN; 650f74e101Schristos length -= BT_HDRLEN; 660f74e101Schristos p += BT_HDRLEN; 67b3a00663Schristos if (ndo->ndo_eflag) 68c74ad251Schristos ND_PRINT(", hci length %u, direction %s", length, 69c74ad251Schristos (GET_BE_U_4(hdr->direction)&0x1) ? "in" : "out"); 700f74e101Schristos 71b3a00663Schristos if (!ndo->ndo_suppress_default_print) 72b3a00663Schristos ND_DEFAULTPRINT(p, caplen); 730f74e101Schristos } 740f74e101Schristos #endif 75