2 * pcap-septel.c: Packet capture interface for Intel/Septel card.
4 * The functionality of this code attempts to mimic that of pcap-linux as much
5 * as possible. This code is compiled in several different ways depending on
6 * whether SEPTEL_ONLY and HAVE_SEPTEL_API are defined. If HAVE_SEPTEL_API is
7 * not defined it should not get compiled in, otherwise if SEPTEL_ONLY is
8 * defined then the 'septel_' function calls are renamed to 'pcap_'
9 * equivalents. If SEPTEL_ONLY is not defined then nothing is altered - the
10 * septel_ functions will be called as required from their
11 * pcap-linux/equivalents.
13 * Authors: Gilbert HOYEK (gil_hoyek@hotmail.com), Elias M. KHOURY
18 static const char rcsid[] _U_ =
19 "@(#) $Header: /tcpdump/master/libpcap/pcap-septel.c,v 1.4 2008-04-14 20:40:58 guy Exp $";
26 #include <sys/param.h>
35 #include <netinet/in.h>
37 #include <sys/socket.h>
38 #include <sys/types.h>
41 #ifdef HAVE_SEPTEL_API
47 #endif /* HAVE_SEPTEL_API */
50 /* This code is required when compiling for a Septel device only. */
51 #include "pcap-septel.h"
53 /* Replace septel function names with pcap equivalent. */
54 #define septel_create pcap_create
55 #define septel_platform_finddevs pcap_platform_finddevs
56 #endif /* SEPTEL_ONLY */
58 static int septel_setfilter(pcap_t *p, struct bpf_program *fp);
59 static int septel_stats(pcap_t *p, struct pcap_stat *ps);
60 static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf);
63 * Read at most max_packets from the capture queue and call the callback
64 * for each of them. Returns the number of packets handled, -1 if an
65 * error occured, or -2 if we were told to break out of the loop.
67 static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) {
74 /* identifier for the message queue of the module(upe) from which we are capturing
75 * packets.These IDs are defined in system.txt . By default it is set to 0x2d
76 * so change it to 0xdd for technical reason and therefore the module id for upe becomes:
77 * LOCAL 0xdd * upe - Example user part task */
78 unsigned int id = 0xdd;
80 /* process the packets */
83 unsigned short packet_len = 0;
86 struct pcap_pkthdr pcap_header;
90 * Has "pcap_breakloop()" been called?
95 * Yes - clear the flag that indicates that
96 * it has, and return -2 to indicate that
97 * we were told to break out of the loop.
103 /*repeat until a packet is read
104 *a NULL message means :
105 * when no packet is in queue or all packets in queue already read */
107 /* receive packet in non-blocking mode
108 * GCT_grab is defined in the septel library software */
112 /* a couter is added here to avoid an infinite loop
113 * that will cause our capture program GUI to freeze while waiting
118 while ((m == NULL)&& (counter< 100)) ;
124 /* catch only messages with type = 0xcf00 or 0x8f01 corrsponding to ss7 messages*/
125 /* XXX = why not use API_MSG_TX_REQ for 0xcf00 and API_MSG_RX_IND
127 if ((t != 0xcf00) && (t != 0x8f01)) {
132 /* XXX - is API_MSG_RX_IND for an MTP2 or MTP3 message? */
133 dp = get_param(m);/* get pointer to MSG parameter area (m->param) */
135 caplen = p->snapshot ;
138 if (caplen > packet_len) {
142 /* Run the packet filter if there is one. */
143 if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
146 /* get a time stamp , consisting of :
148 * pcap_header.ts.tv_sec:
149 * ----------------------
150 * a UNIX format time-in-seconds when he packet was captured,
151 * i.e. the number of seconds since Epoch time (January 1,1970, 00:00:00 GMT)
153 * pcap_header.ts.tv_usec :
154 * ------------------------
155 * the number of microseconds since that second
156 * when the packet was captured
159 (void)gettimeofday(&pcap_header.ts, NULL);
161 /* Fill in our own header data */
162 pcap_header.caplen = caplen;
163 pcap_header.len = packet_len;
165 /* Count the packet. */
166 p->md.stat.ps_recv++;
168 /* Call the user supplied callback function */
169 callback(user, &pcap_header, dp);
174 /* after being processed the packet must be
175 *released in order to receive another one */
181 while (processed < cnt) ;
188 septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
190 strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards",
196 * Activate a handle for a live capture from the given Septel device. Always pass a NULL device
197 * The promisc flag is ignored because Septel cards have built-in tracing.
198 * The timeout is also ignored as it is not supported in hardware.
202 static pcap_t *septel_activate(pcap_t* handle) {
203 /* Initialize some components of the pcap structure. */
204 handle->linktype = DLT_MTP2;
209 * "select()" and "poll()" don't work on Septel queues
211 handle->selectable_fd = -1;
213 handle->read_op = septel_read;
214 handle->inject_op = septel_inject;
215 handle->setfilter_op = septel_setfilter;
216 handle->set_datalink_op = NULL; /* can't change data link type */
217 handle->getnonblock_op = pcap_getnonblock_fd;
218 handle->setnonblock_op = septel_setnonblock;
219 handle->stats_op = septel_stats;
224 pcap_t *septel_create(const char *device, char *ebuf) {
227 p = pcap_create_common(device, ebuf);
231 p->activate_op = septel_activate;
235 static int septel_stats(pcap_t *p, struct pcap_stat *ps) {
236 /*p->md.stat.ps_recv = 0;*/
237 /*p->md.stat.ps_drop = 0;*/
246 septel_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
249 const char description[512]= "Intel/Septel device";
250 char name[512]="septel" ;
252 pcap_add_if(devlistp,name,0,description,errbuf);
259 * Installs the given bpf filter program in the given pcap structure. There is
260 * no attempt to store the filter in kernel memory as that is not supported
263 static int septel_setfilter(pcap_t *p, struct bpf_program *fp) {
267 strncpy(p->errbuf, "setfilter: No filter specified",
272 /* Make our private copy of the filter */
274 if (install_bpf_program(p, fp) < 0) {
275 snprintf(p->errbuf, sizeof(p->errbuf),
276 "malloc: %s", pcap_strerror(errno));
287 septel_setnonblock(pcap_t *p, int nonblock, char *errbuf)