dyn_iwspy_rec.h File Reference

#include <sys/time.h>
#include <sys/types.h>
#include <asm/types.h>
#include <linux/wireless.h>
#include <sys/socket.h>
#include "hashtable.h"
#include "agentadv.h"

Include dependency graph for dyn_iwspy_rec.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  qual_entry
struct  hw_record
struct  dump

Defines

#define MAX_GROUP_PREFIX_LEN   80
#define PLOT_STR_SIZE   2048
#define REC_NODE_CHUNK   256
#define REC_HASH_SIZE   256

Functions

int rec_dump (int, int)
int rec_init (void)
void rec_clean_up (void)
int rec_add_long (struct sockaddr *hwa, unsigned char *hw, struct in_addr addr, struct iw_quality *qual, struct timeval *t, int monitored)
int rec_add_qual (char *hw, struct iw_quality *qual, struct timeval *t)
int rec_add (char *hw, struct iw_quality *qual, struct timeval *t, struct in_addr addr)


Define Documentation

#define MAX_GROUP_PREFIX_LEN   80

Definition at line 24 of file dyn_iwspy_rec.h.

#define PLOT_STR_SIZE   2048

Definition at line 25 of file dyn_iwspy_rec.h.

#define REC_HASH_SIZE   256

Definition at line 27 of file dyn_iwspy_rec.h.

Referenced by rec_init().

#define REC_NODE_CHUNK   256

Definition at line 26 of file dyn_iwspy_rec.h.


Function Documentation

int rec_add ( char *  hw,
struct iw_quality *  qual,
struct timeval *  t,
struct in_addr  addr 
)

Definition at line 245 of file dyn_iwspy_rec.c.

References DEBUG(), DEBUG_FLAG, hw_record::hashnode, hw_record::hw, hw_record::ip_addr, new_dump, hw_record::quals, start_time, hw_record::tail, and TRUE.

Referenced by rec_add_long().

00247 {
00248         struct hw_record *recs;
00249         int ret;
00250 
00251         if (new_dump) {
00252                 new_dump = 0;
00253                 start_time.tv_sec = t->tv_sec;
00254                 start_time.tv_usec = t->tv_usec;
00255                 DEBUG(DEBUG_FLAG, "rec_add: start time %ld\n",
00256                       start_time.tv_sec);
00257         }
00258 
00259         assert(rec_hash != NULL);
00260         recs = (struct hw_record *) 
00261                 hashtable_fetch(rec_hash, hashfunc, &hw[2], 
00262                                 cmpfunc);
00263 
00264         if (recs) {
00265                 /* old mac found. Add to that */
00266                 ret = qual_add(recs, qual, t);
00267                 if (ret < 0)
00268                         DEBUG(DEBUG_FLAG, "rec_add: qual entry add failed "
00269                               "(old mac)\n");
00270                 return ret;
00271         }
00272 
00273         /* mac not found. Add new one */
00274         recs = (struct hw_record *) malloc(sizeof(struct hw_record));
00275         if (!recs) {
00276                 DEBUG(DEBUG_FLAG, "rec_add: malloc failed\n");
00277                 /* FIX: Add record dumping into files and free
00278                    memory. Then initialize new list and continue
00279                    recording. */
00280                 return -1;
00281         }
00282         memcpy(recs->hw, hw, ETH_ALEN);
00283         recs->ip_addr.s_addr = addr.s_addr;
00284         recs->quals = NULL;
00285         recs->tail = recs->quals;
00286 
00287         /* Add mac entry */
00288         list_init_node(&recs->hashnode);
00289         ret = hashtable_add(rec_hash, hashfunc, &hw[2], &recs->hashnode);
00290         if (ret != TRUE) {
00291                 DEBUG(DEBUG_FLAG, "rec_add: hashtable_add failed\n");
00292                 return -1;
00293         }
00294         rec_num++;
00295 
00296         /* Add new qual node to the mac entry */
00297         ret = qual_add(recs, qual, t);
00298         if (ret < 0) {
00299                 DEBUG(DEBUG_FLAG, "rec_add: qual entry add "
00300                       "failed (new mac)\n");
00301                 return -1;
00302         }
00303 
00304         return ret;
00305 }

Here is the call graph for this function:

int rec_add_long ( struct sockaddr *  hwa,
unsigned char *  hw,
struct in_addr  addr,
struct iw_quality *  qual,
struct timeval *  t,
int  monitored 
)

Definition at line 308 of file dyn_iwspy_rec.c.

References DEBUG(), DEBUG_FLAG, and rec_add().

00311 {
00312         int index = -1, i;
00313         
00314 
00315         DEBUG(DEBUG_FLAG, "rec_add_long (%s)\n",
00316               inet_ntoa(addr));
00317 
00318         for (i = 0 ; i < monitored; i++) {
00319                 if (!(memcmp(hwa[i].sa_data, hw, ETH_ALEN)))
00320                         index = i;
00321         }
00322         if (index < 0) {
00323                 DEBUG(DEBUG_FLAG, "rec_add: MAC address not found\n");
00324                 return -1;
00325         }
00326 
00327         return (rec_add((char *)&(hwa[index].sa_data), &qual[index], t, addr));
00328 }

Here is the call graph for this function:

int rec_add_qual ( char *  hw,
struct iw_quality *  qual,
struct timeval *  t 
)

Definition at line 223 of file dyn_iwspy_rec.c.

References DEBUG(), and DEBUG_FLAG.

00224 {
00225         struct hw_record *recs;
00226         int ret;
00227 
00228         assert(rec_hash != NULL);
00229         recs = (struct hw_record *) 
00230                 hashtable_fetch(rec_hash, hashfunc, &hw[2], cmpfunc);
00231 
00232         if (!recs) {
00233                 DEBUG(DEBUG_FLAG, "rec_add_qual: record not found!\n");
00234                 return 1;
00235         }
00236 
00237         ret = qual_add(recs, qual, tstamp);
00238         if (ret < 0)
00239                 DEBUG(DEBUG_FLAG, "rec_add_qual: qual entry add failed\n");
00240 
00241         return ret;
00242 }

Here is the call graph for this function:

void rec_clean_up ( void   ) 

Definition at line 144 of file dyn_iwspy_rec.c.

References DEBUG(), DEBUG_FLAG, and rec_clean().

Referenced by MONITOR_unregister_module().

00145 {
00146         DEBUG(DEBUG_FLAG, "rec_clean_up\n");
00147         if (rec_hash == NULL)
00148                 return;
00149         hashtable_iterator(rec_hash, rec_clean, NULL);
00150         hashtable_destroy(rec_hash);
00151         rec_hash = NULL;
00152 }

Here is the call graph for this function:

int rec_dump ( int  ,
int   
)

Definition at line 487 of file dyn_iwspy_rec.c.

References DEBUG(), DEBUG_FLAG, G_IMG_X, G_IMG_Y, Q_RANGE, and start_time.

Referenced by MONITOR_unregister_module().

00488 {
00489         struct dump info;
00490         char name[FILENAME_MAX];
00491         long range;
00492         int len;
00493         FILE *header;
00494         struct timeval stop_time;
00495 
00496         DEBUG(DEBUG_FLAG, "rec_dump\n");
00497         /* dump the data in specified format (type) */
00498         if (rec_hash == NULL) {
00499                 DEBUG(DEBUG_FLAG, "rec_dump: hashtable NULL\n");
00500                 return -1;
00501         }
00502         memset(&info, 0, sizeof(info));
00503         info.output_type = type;
00504         info.interval = interval;
00505         hashtable_iterator(rec_hash, dump_fa, &info);
00506         len = strlen(info.plot_str);
00507 
00508         if (len <= 0) {
00509                 DEBUG(DEBUG_FLAG, "rec_dump: info plot string < 0\n");
00510                 return 0;
00511         }
00512 
00513         /* Make special group gnuplot file */
00514         snprintf(name, FILENAME_MAX, "group.plot");
00515         header = fopen(name, "w");
00516         if (header == NULL) {
00517                 DEBUG(DEBUG_FLAG, "rec_dump: fopen: %s\n",
00518                       strerror(errno));
00519                 return -1;
00520         }
00521         gettimeofday(&stop_time, NULL);
00522         range = stop_time.tv_sec - start_time.tv_sec;
00523         fprintf(header, "set output \"group.gif\"\n"); 
00524         if (type == 1)
00525                 fprintf(header, "set terminal gif large size %d,%d\n"
00526                         "set xlabel \"Time t/s\"\n"
00527                         "set ylabel \"Quality\"\n"
00528                         "plot [0:%ld] [0:%d] ", G_IMG_X, G_IMG_Y, range,
00529                         Q_RANGE);
00530         else if (type == 2 || type == 4)
00531                 fprintf(header, "set terminal gif large size %d,%d\n"
00532                         "set xlabel \"Time t/10msec\"\n"
00533                         "set ylabel \"Quality\"\n"
00534                         "plot [0:%ld] [0:%d] ", G_IMG_X, G_IMG_Y, range*100,
00535                         Q_RANGE);
00536         
00537         else if (type == 3)
00538                 fprintf(header, "set terminal gif large size %d,%d\n"
00539                         "set xlabel \"Time t/ms\"\n"
00540                         "set ylabel \"Quality\"\n"
00541                         "plot [0:%ld] [0:%d] ", G_IMG_X, G_IMG_Y, range*1000,
00542                         Q_RANGE);
00543         info.plot_str[len - 2] = '\n';
00544         info.plot_str[len - 1] = '\0';
00545         fprintf(header, info.plot_str);
00546         if (fclose(header))
00547                 DEBUG(DEBUG_FLAG, "rec_dump: fclose: %s\n", 
00548                       strerror(errno));
00549 
00550         return 0;
00551 }

Here is the call graph for this function:

int rec_init ( void   ) 

Definition at line 111 of file dyn_iwspy_rec.c.

References REC_HASH_SIZE.

Referenced by main().

00112 {
00113         /* initialize hash */
00114         rec_num = 0;
00115         rec_hash = NULL;
00116         rec_hash = hashtable_init(REC_HASH_SIZE);
00117         if (rec_hash == NULL)
00118                 return -1;
00119         
00120         return 0;
00121 }


Generated on Tue Jan 15 08:50:45 2008 for Virtual foreign agent generator version 0.1 by  doxygen 1.5.1