source: rtems-libbsd/freebsd/contrib/tcpdump/print-802_15_4.c @ 8440506

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8440506 was 8440506, checked in by Chris Johns <chrisj@…>, on 06/15/15 at 07:42:23

Add tcpdump and libpcap.

  • Update the file builder generator to handle generator specific cflags and includes. The tcpdump and libpcap have localised headers and need specific headers paths to see them. There are also module specific flags and these need to be passed to the lex and yacc generators.
  • Add the tcpdump support.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 2009
5 *      Siemens AG, All rights reserved.
6 *      Dmitry Eremin-Solenikov (dbaryshkov@gmail.com)
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
19 * written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <tcpdump-stdinc.h>
30
31#include <stdio.h>
32#include <pcap.h>
33#include <string.h>
34
35#include "interface.h"
36#include "addrtoname.h"
37
38#include "extract.h"
39
40static const char *ftypes[] = {
41        "Beacon",                       /* 0 */
42        "Data",                         /* 1 */
43        "ACK",                          /* 2 */
44        "Command",                      /* 3 */
45        "Reserved",                     /* 4 */
46        "Reserved",                     /* 5 */
47        "Reserved",                     /* 6 */
48        "Reserved",                     /* 7 */
49};
50
51static int
52extract_header_length(u_int16_t fc)
53{
54        int len = 0;
55
56        switch ((fc >> 10) & 0x3) {
57        case 0x00:
58                if (fc & (1 << 6)) /* intra-PAN with none dest addr */
59                        return -1;
60                break;
61        case 0x01:
62                return -1;
63        case 0x02:
64                len += 4;
65                break;
66        case 0x03:
67                len += 10;
68                break;
69        }
70
71        switch ((fc >> 14) & 0x3) {
72        case 0x00:
73                break;
74        case 0x01:
75                return -1;
76        case 0x02:
77                len += 4;
78                break;
79        case 0x03:
80                len += 10;
81                break;
82        }
83
84        if (fc & (1 << 6)) {
85                if (len < 2)
86                        return -1;
87                len -= 2;
88        }
89
90        return len;
91}
92
93
94u_int
95ieee802_15_4_if_print(struct netdissect_options *ndo,
96                      const struct pcap_pkthdr *h, const u_char *p)
97{
98        u_int caplen = h->caplen;
99        int hdrlen;
100        u_int16_t fc;
101        u_int8_t seq;
102
103        if (caplen < 3) {
104                ND_PRINT((ndo, "[|802.15.4] %x", caplen));
105                return caplen;
106        }
107
108        fc = EXTRACT_LE_16BITS(p);
109        hdrlen = extract_header_length(fc);
110
111        seq = EXTRACT_LE_8BITS(p + 2);
112
113        p += 3;
114        caplen -= 3;
115
116        ND_PRINT((ndo,"IEEE 802.15.4 %s packet ", ftypes[fc & 0x7]));
117        if (vflag)
118                ND_PRINT((ndo,"seq %02x ", seq));
119        if (hdrlen == -1) {
120                ND_PRINT((ndo,"malformed! "));
121                return caplen;
122        }
123
124
125        if (!vflag) {
126                p+= hdrlen;
127                caplen -= hdrlen;
128        } else {
129                u_int16_t panid = 0;
130
131                switch ((fc >> 10) & 0x3) {
132                case 0x00:
133                        ND_PRINT((ndo,"none "));
134                        break;
135                case 0x01:
136                        ND_PRINT((ndo,"reserved destination addressing mode"));
137                        return 0;
138                case 0x02:
139                        panid = EXTRACT_LE_16BITS(p);
140                        p += 2;
141                        ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p)));
142                        p += 2;
143                        break;
144                case 0x03:
145                        panid = EXTRACT_LE_16BITS(p);
146                        p += 2;
147                        ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p)));
148                        p += 8;
149                        break;
150                }
151                ND_PRINT((ndo,"< ");
152
153                switch ((fc >> 14) & 0x3) {
154                case 0x00:
155                        ND_PRINT((ndo,"none "));
156                        break;
157                case 0x01:
158                        ND_PRINT((ndo,"reserved source addressing mode"));
159                        return 0;
160                case 0x02:
161                        if (!(fc & (1 << 6))) {
162                                panid = EXTRACT_LE_16BITS(p);
163                                p += 2;
164                        }
165                        ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p)));
166                        p += 2;
167                        break;
168                case 0x03:
169                        if (!(fc & (1 << 6))) {
170                                panid = EXTRACT_LE_16BITS(p);
171                                p += 2;
172                        }
173                        ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p))));
174                        p += 8;
175                        break;
176                }
177
178                caplen -= hdrlen;
179        }
180
181        if (!suppress_default_print)
182                (ndo->ndo_default_print)(ndo, p, caplen);
183
184        return 0;
185}
Note: See TracBrowser for help on using the repository browser.