/* * Private data for capturing on Septel devices. */ struct pcap_septel { struct pcap_stat stat; } /* * Read at most max_packets from the capture queue and call the callback * for each of them. Returns the number of packets handled, -1 if an * error occured, or -2 if we were told to break out of the loop. */ static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) { struct pcap_septel *ps = p->priv; HDR *h; MSG *m; int processed = 0 ; int t = 0 ; /* identifier for the message queue of the module(upe) from which we are capturing * packets.These IDs are defined in system.txt . By default it is set to 0x2d * so change it to 0xdd for technical reason and therefore the module id for upe becomes: * LOCAL 0xdd * upe - Example user part task */ unsigned int id = 0xdd; /* process the packets */ do { unsigned short packet_len = 0; int caplen = 0; int counter = 0; struct pcap_pkthdr pcap_header; u_char *dp ; /* * Has "pcap_breakloop()" been called? */ loop: if (p->break_loop) { /* * Yes - clear the flag that indicates that * it has, and return -2 to indicate that * we were told to break out of the loop. */ p->break_loop = 0; return -2; } /*repeat until a packet is read *a NULL message means : * when no packet is in queue or all packets in queue already read */ do { /* receive packet in non-blocking mode * GCT_grab is defined in the septel library software */ h = GCT_grab(id); m = (MSG*)h; /* a couter is added here to avoid an infinite loop * that will cause our capture program GUI to freeze while waiting * for a packet*/ counter++ ; } while ((m == NULL)&& (counter< 100)) ; if (m != NULL) { t = h->type ; /* catch only messages with type = 0xcf00 or 0x8f01 corrsponding to ss7 messages*/ /* XXX = why not use API_MSG_TX_REQ for 0xcf00 and API_MSG_RX_IND * for 0x8f01? */ if ((t != 0xcf00) && (t != 0x8f01)) { relm(h); goto loop ; } /* XXX - is API_MSG_RX_IND for an MTP2 or MTP3 message? */ dp = get_param(m);/* get pointer to MSG parameter area (m->param) */ packet_len = m->len; caplen = p->snapshot ; if (caplen > packet_len) { caplen = packet_len; } /* Run the packet filter if there is one. */ if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) { /* get a time stamp , consisting of : * * pcap_header.ts.tv_sec: * ---------------------- * a UNIX format time-in-seconds when he packet was captured, * i.e. the number of seconds since Epoch time (January 1,1970, 00:00:00 GMT) * * pcap_header.ts.tv_usec : * ------------------------ * the number of microseconds since that second * when the packet was captured */ (void)gettimeofday(&pcap_header.ts, NULL); /* Fill in our own header data */ pcap_header.caplen = caplen; pcap_header.len = packet_len; /* Count the packet. */ ps->stat.ps_recv++; /* Call the user supplied callback function */ callback(user, &pcap_header, dp); processed++ ; } /* after being processed the packet must be *released in order to receive another one */ relm(h); }else processed++; } while (processed < cnt) ; return processed ; }
/* ******************************************************************************* * * * Main program loop * * * ******************************************************************************* */ int intu_ent() { HDR *h; /* Received message */ DLG_CB *dlg; /* The control block for the dlg id of the received msg */ u16 i; /* loop counter */ u16 min_rev; /* INAP API major revision number */ u16 maj_rev; /* INAP API major revision number */ char *ident_text; /* INAP API name in text */ if (num_dialogues > DEFAULT_NUM_DIALOGUES) { fprintf(stderr, "intu() : Not enough dialogue resources available\n"); fprintf(stderr, " 0x%04x available, 0x%04x requested\n", DEFAULT_NUM_DIALOGUES, num_dialogues); return(0); } /* * Print banner so we know what's running: */ printf( "INTU: Example INAP application (C) Dialogic Corporation 1997-2010. All Rights Reserved.\n"); printf( "=======================================================================================\n\n"); if (IN_version(&maj_rev, &min_rev, &ident_text) == IN_SUCCESS); printf("%s Version %i.%i\n",ident_text, maj_rev, min_rev); printf("INTU module ID - 0x%02x \nINAP module ID - 0x%02x\n", intu_mod_id, inap_mod_id); printf("Number of dialogues - 0x%04x (%i) \nBase dialogue ID - 0x%04x\n", num_dialogues, num_dialogues, base_dialogue_id); printf("Options set - 0x%04x \n\n", intu_options); /* * Initialise the per-dialogue resources: */ for (i=0; i<DEFAULT_NUM_DIALOGUES; i++) { dlg = &dlg_data[i]; dlg->state = INTU_STATE_IDLE; dlg->reply_prepared = INTU_REPLY_NONE; /* * dlg->cpt intialised when we receive the open indication */ } /* * Now enter main loop, receiving messages as * they become available and processing accordingly: */ finished = 0; while (!finished) { /* * GCT_receive will attempt to receive message * from the tasks message queue and block until * a message is ready: */ if ((h = GCT_receive(intu_mod_id)) != 0) { switch (h->type) { case INAP_MSG_SRV_IND : INTU_srv_ind(h); break; case INAP_MSG_DLG_IND : INTU_dlg_ind(h); break; default : INTU_disp_other_msg(h); break; } /* * Once we have finished processing the message * it must be released to the pool of messages. */ relm(h); } } return(0); }