dyn_iwspy_rec.c File Reference

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <linux/wireless.h>
#include "util.h"
#include "hashtable.h"
#include "dyn_iwspy_rec.h"
#include "debug.h"

Include dependency graph for dyn_iwspy_rec.c:

Go to the source code of this file.

Defines

#define TRUE   1
#define FALSE   0
#define DEBUG_FLAG   '5'
#define IMG_X   1000
#define IMG_Y   300
#define G_IMG_X   1500
#define G_IMG_Y   400
#define Q_RANGE   100

Functions

int rec_init (void)
int rec_clean (struct node *node, void *data)
void rec_clean_up (void)
int rec_add_qual (char *hw, struct iw_quality *qual, struct timeval *tstamp)
int rec_add (char *hw, struct iw_quality *qual, struct timeval *t, struct in_addr addr)
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_dump (int type, int interval)

Variables

timeval start_time
int new_dump = 1


Define Documentation

#define DEBUG_FLAG   '5'

Definition at line 39 of file dyn_iwspy_rec.c.

Referenced by dyn_wireless_check_simulator(), dyn_wireless_create_socket(), dyn_wireless_get_ap_address(), dyn_wireless_get_channel(), dyn_wireless_get_name(), dyn_wireless_get_range(), dyn_wireless_get_simulator(), dyn_wireless_his_get(), dyn_wireless_his_set(), dyn_wireless_iwspy_get(), dyn_wireless_iwspy_set(), dyn_wireless_set_channel(), dyn_wireless_set_simulator(), get_free_slot(), main(), monitor_api_get_ch(), monitor_api_mon_conf(), monitor_api_set_ch(), monitor_get_dev(), print_entries(), rec_add(), rec_add_long(), rec_add_qual(), rec_clean(), rec_clean_up(), and rec_dump().

#define FALSE   0

Definition at line 36 of file dyn_iwspy_rec.c.

Referenced by check_expired_agent_advs(), and load_mn().

#define G_IMG_X   1500

Definition at line 44 of file dyn_iwspy_rec.c.

Referenced by rec_dump().

#define G_IMG_Y   400

Definition at line 45 of file dyn_iwspy_rec.c.

Referenced by rec_dump().

#define IMG_X   1000

Definition at line 42 of file dyn_iwspy_rec.c.

#define IMG_Y   300

Definition at line 43 of file dyn_iwspy_rec.c.

#define Q_RANGE   100

Definition at line 46 of file dyn_iwspy_rec.c.

Referenced by rec_dump().

#define TRUE   1

Definition at line 32 of file dyn_iwspy_rec.c.

Referenced by clean_agentadv(), load_mn(), and rec_add().


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 *  tstamp 
)

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:

int rec_clean ( struct node *  node,
void *  data 
)

Definition at line 124 of file dyn_iwspy_rec.c.

References DEBUG(), DEBUG_FLAG, new_dump, qual_entry::next, and hw_record::quals.

Referenced by rec_clean_up().

00125 {
00126         struct hw_record *entry = (struct hw_record *) node;
00127         struct qual_entry *list = entry->quals;
00128         struct qual_entry *tmp;
00129 
00130         DEBUG(DEBUG_FLAG, "rec_clean\n");
00131         while (list != NULL) {
00132                 tmp = list;
00133                 list = list->next;
00134                 free(tmp);
00135         }
00136         hashtable_remove(node);
00137         free(entry);
00138         new_dump = 1;
00139         
00140         return 1;
00141 }

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  type,
int  interval 
)

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 }


Variable Documentation

int new_dump = 1

Definition at line 51 of file dyn_iwspy_rec.c.

Referenced by rec_add(), and rec_clean().

struct timeval start_time

Definition at line 50 of file dyn_iwspy_rec.c.

Referenced by rec_add(), and rec_dump().


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