monitor.h File Reference

#include <values.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include "mn.h"
#include "owntypes.h"
#include <linux/if_ether.h>

Include dependency graph for monitor.h:

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

Go to the source code of this file.

Data Structures

struct  monitor_address
struct  monitor_global_data
struct  monitor_interface
struct  monitor_conf_vars

Defines

#define DEFAULT_THRESHOLD   90
#define DEFAULT_WORST_MIN_TIME   10
#define DEFAULT_WORST_MAX_TIME   20
#define DEFAULT_MIN_BALANCE   10
#define DEFAULT_EARLY_EXPIRE_TIME   50
#define DEFAULT_AVG_LEN   3
#define MAX_MONITOR   20
#define MAX_KERNEL   IW_MAX_SPY
#define OLD_FA_FACTOR   50
#define DEFAULT_WIRELESS_PRIO   1.0
#define DEFAULT_DEV_PRIO_PERCENT   0
#define MAXPRIORITY   MAXINT
#define GET_MONCONF   1
#define GET_MONCONF_VAR   2
#define SET_MONCONF_VAR   3

Functions

void MONITOR_register_module (void)
int MONITOR_unregister_module (void)
void monitor_poll_ap_addresses (struct mn_data *mn)
int monitor_api_get_ch (unsigned char *buffer, __u16 *length)
int monitor_api_set_ch (char *ifname, int channel)
int monitor_api_mon_conf (char *buffer, int len, int type)
int next (int p)
int prev (int p)
int drop_worst (struct timeval *tstamp, struct monitor_interface *dev)
int get_free_slot (struct timeval *tstamp, struct monitor_interface *dev)
monitor_interfacemonitor_get_dev (char *ifname)
void print_entries (void)
int find_current_fa_iter (struct node *nod, void *data)


Define Documentation

#define DEFAULT_AVG_LEN   3

Definition at line 51 of file monitor.h.

Referenced by MONITOR_register_module().

#define DEFAULT_DEV_PRIO_PERCENT   0

Definition at line 60 of file monitor.h.

Referenced by MONITOR_register_module().

#define DEFAULT_EARLY_EXPIRE_TIME   50

Definition at line 50 of file monitor.h.

Referenced by MONITOR_register_module().

#define DEFAULT_MIN_BALANCE   10

Definition at line 49 of file monitor.h.

Referenced by MONITOR_register_module().

#define DEFAULT_THRESHOLD   90

Definition at line 35 of file monitor.h.

Referenced by MONITOR_register_module().

#define DEFAULT_WIRELESS_PRIO   1.0

Definition at line 59 of file monitor.h.

#define DEFAULT_WORST_MAX_TIME   20

Definition at line 48 of file monitor.h.

Referenced by MONITOR_register_module().

#define DEFAULT_WORST_MIN_TIME   10

Definition at line 47 of file monitor.h.

Referenced by MONITOR_register_module().

#define GET_MONCONF   1

Definition at line 65 of file monitor.h.

Referenced by handle_api(), and monitor_api_mon_conf().

#define GET_MONCONF_VAR   2

Definition at line 66 of file monitor.h.

Referenced by handle_api(), and monitor_api_mon_conf().

#define MAX_KERNEL   IW_MAX_SPY

Definition at line 53 of file monitor.h.

#define MAX_MONITOR   20

Definition at line 52 of file monitor.h.

Referenced by drop_worst(), get_free_slot(), and print_entries().

#define MAXPRIORITY   MAXINT

Definition at line 62 of file monitor.h.

#define OLD_FA_FACTOR   50

Definition at line 56 of file monitor.h.

Referenced by MONITOR_register_module().

#define SET_MONCONF_VAR   3

Definition at line 67 of file monitor.h.

Referenced by handle_api(), and monitor_api_mon_conf().


Function Documentation

int drop_worst ( struct timeval *  tstamp,
struct monitor_interface dev 
)

Definition at line 52 of file monitor_util.c.

References monitor_address::added, monitor_address::avg, MAX_MONITOR, monitor_interface::mon, mon_conf, monitor_global_data::worst_max_time, and monitor_global_data::worst_min_time.

Referenced by get_free_slot().

00053 {
00054         int worst_avg = 1000; /* theoretical max quality is below */
00055         int worst_index = -2, i;
00056 
00057         /* (POLICY) */
00058         /* Find old entries */
00059         for (i = 0; i < MAX_MONITOR; i++) {
00060                 /* old ghost. If MAX_TIME has passed
00061                  * for this entry and it still doesn't
00062                  * have decent values, just drop it */
00063                 if (dev->mon[i].added.tv_sec + 
00064                     mon_conf.worst_max_time < tstamp->tv_sec &&
00065                     dev->mon[i].avg == 0)
00066                         return i;
00067         }
00068 
00069         /* No old entries found. Find the worst entry */
00070         for (i = 0; i < MAX_MONITOR; i++) {
00071                 if ((dev->mon[i].added.tv_sec + 
00072                      mon_conf.worst_min_time) > tstamp->tv_sec)
00073                         return -1; /* new entry. Don't update faster than
00074                                     * in MIN_TIME interval */
00075                 if (dev->mon[i].avg < worst_avg) {
00076                         worst_avg = dev->mon[i].avg;
00077                         worst_index = i;
00078                 }
00079         }
00080 
00081         if (worst_index >= 0 && worst_index != mon_conf.current_fa)
00082                 return worst_index;
00083 
00084         /* worst one is current FA :( */
00085         return -1;
00086 }

int find_current_fa_iter ( struct node *  nod,
void *  data 
)

int get_free_slot ( struct timeval *  tstamp,
struct monitor_interface dev 
)

Definition at line 89 of file monitor_util.c.

References monitor_address::active, agentadv_data::addr, monitor_address::adv, DEBUG(), DEBUG_FLAG, drop_worst(), MAX_MONITOR, and monitor_interface::mon.

00090 {
00091         int i, ph;
00092 
00093         for (i = 0; i < MAX_MONITOR; i++) {
00094                 if (dev->mon[i].active != 1)
00095                         return i;
00096         }
00097 
00098         /* no non-active entries found */
00099         ph = drop_worst(tstamp, dev);
00100         if (ph < 0) {
00101                 DEBUG(DEBUG_FLAG, "get_free_slot: Working set is full, "
00102                       "worst entry just changed. Not dropped.\n");
00103                 return -1;
00104         }
00105 
00106         DEBUG(DEBUG_FLAG, "get_free_slot: Working set is full, "
00107               "worst entry dropped (%s).\n",
00108               inet_ntoa(dev->mon[ph].adv->addr));
00109         return ph;
00110 }

Here is the call graph for this function:

int monitor_api_get_ch ( unsigned char *  buffer,
__u16 *  length 
)

Definition at line 31 of file monitor_api.c.

References monitor_interface::channel, DEBUG(), DEBUG_FLAG, dyn_wireless_get_ap_address(), dyn_wireless_get_channel(), ifname, IFNAMSIZ, MAX_INTERFACES, mon_devs, and sock.

00032 {
00033         int ch, len, count = 0, i;
00034         struct dynamics_mn_iw_ch_info *info 
00035                 = (struct dynamics_mn_iw_ch_info *)buffer;
00036 
00037         len = sizeof(struct dynamics_mn_iw_ch_info);
00038         for (i = 0; i < MAX_INTERFACES; i++) {
00039                 if (!mon_devs[i].in_use)
00040                         continue;
00041 
00042                 /* get channel */
00043                 ch = dyn_wireless_get_channel(mon_devs[i].sock, 
00044                                               mon_devs[i].ifname);
00045                 if (ch < 0) {
00046                         DEBUG(DEBUG_FLAG, "monitor_api_get_ch: channel "
00047                               "< 0 (%s)\n", mon_devs[i].ifname);
00048                         continue;
00049                 }
00050                 mon_devs[i].channel = ch; /* if changed */
00051 
00052                 /* copy to caller */
00053                 if (*length+len > API_DATA_SIZE) {
00054                         DEBUG(DEBUG_FLAG, "monitor_api_get_ch: Not enough "
00055                               "room for interface name (%d, %d)\n", *length,
00056                               *length+len);
00057                         return 1;
00058                 }
00059 
00060                 memcpy(info[count].ifname, mon_devs[i].ifname, IFNAMSIZ);
00061                 info[count].channel = mon_devs[i].channel;
00062 
00063                 /* get AP hw addr */
00064                 if (dyn_wireless_get_ap_address(mon_devs[i].sock,
00065                                                 mon_devs[i].ifname,
00066                                                 info[count].ap_hwaddr) < 0) {
00067                         DEBUG(DEBUG_FLAG, "monitor_api_get_ch: get AP hw "
00068                               "addr failed\n");
00069                         continue;
00070                 }
00071 
00072                 *length += len;
00073                 DEBUG(DEBUG_FLAG, "monitor_api_get_ch: %s: %d - %s\n",
00074                       info[count].ifname, info[count].channel,
00075                       ether_hwtoa(info[count].ap_hwaddr));
00076         }
00077 
00078         return 0;
00079 }

Here is the call graph for this function:

int monitor_api_mon_conf ( char *  buffer,
int  len,
int  type 
)

Definition at line 202 of file monitor_api.c.

References DEBUG(), DEBUG_FLAG, GET_MONCONF, GET_MONCONF_VAR, and SET_MONCONF_VAR.

00203 {
00204         switch (type) {
00205         case GET_MONCONF:
00206                 DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: get_mon_conf\n");
00207                 return get_mon_conf(buffer, len);
00208         case GET_MONCONF_VAR:
00209                 DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: get_mon_conf_var\n");
00210                 return get_mon_conf_var(buffer, len);
00211         case SET_MONCONF_VAR:
00212                 DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: set_mon_conf_var\n");
00213                 return set_mon_conf_var(buffer, len);
00214         default:
00215                 DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: unknown type\n");
00216                 return API_UNDEFINED;
00217         }
00218 
00219         /* never reached */
00220         return 0;
00221 }

Here is the call graph for this function:

int monitor_api_set_ch ( char *  ifname,
int  channel 
)

Definition at line 82 of file monitor_api.c.

References DEBUG(), DEBUG_FLAG, dyn_wireless_set_channel(), MAX_INTERFACES, mon_devs, and sock.

00083 {
00084         int r, i;
00085 
00086         for (i = 0; i < MAX_INTERFACES; i++) {
00087                 if (!mon_devs[i].in_use || 
00088                     memcmp(ifname, mon_devs[i].ifname, strlen(ifname)))
00089                         continue;
00090                 /* set channel */
00091                 r = dyn_wireless_set_channel(mon_devs[i].sock, 
00092                                              mon_devs[i].ifname, 
00093                                              channel);
00094                 return r;
00095         }
00096 
00097         DEBUG(DEBUG_FLAG, "monitor_set_ch: not wireless interface (%s)\n",
00098               ifname);
00099         return -1;
00100 }

Here is the call graph for this function:

struct monitor_interface* monitor_get_dev ( char *  ifname  ) 

Definition at line 113 of file monitor_util.c.

References DEBUG(), DEBUG_FLAG, IFNAMSIZ, monitor_interface::in_use, monitor_global_data::interfaces, MAX_INTERFACES, mon_conf, and mon_devs.

00114 {
00115         int i;
00116 
00117         DEBUG(DEBUG_FLAG, "monitor_get_dev: %s (len %d), interfaces %d\n",
00118               ifname, strlen(ifname), mon_conf.interfaces);
00119         if (ifname == NULL) {
00120                 DEBUG(DEBUG_FLAG, "monitor_get_dev: ifname == NULL!\n");
00121                 return NULL;
00122         }
00123 
00124         for(i = 0; i< MAX_INTERFACES; i++) {
00125                 if (mon_devs[i].in_use && 
00126                     !strncmp(ifname, mon_devs[i].ifname, IFNAMSIZ)) {
00127                         return &mon_devs[i];
00128                 }
00129         }
00130 
00131         DEBUG(DEBUG_FLAG, "monitor_get_dev: interface %s not found\n",
00132               ifname);
00133         return NULL;
00134 }

Here is the call graph for this function:

void monitor_poll_ap_addresses ( struct mn_data mn  ) 

Definition at line 1360 of file monitor.c.

References monitor_interface::ap_hwaddr, DEBUG(), interface_data::device, dyn_wireless_get_ap_address(), mn_data::iface, mn, mon_devs, interface_data::s, and sock.

01361 {
01362         int i, j;
01363         char new_addr[ETH_ALEN];
01364 
01365         DEBUG(DEBUG_FLAG, "monitor_poll_ap_addresses()\n");
01366         for (i = 0; i < MAX_INTERFACES; i++) {
01367                 if (!mon_devs[i].in_use || mon_devs[i].sock < 0)
01368                         continue;
01369 
01370                 if (dyn_wireless_get_ap_address(mon_devs[i].sock,
01371                                                 mon_devs[i].ifname,
01372                                                 new_addr) < 0) {
01373                         DEBUG(DEBUG_FLAG, "monitor_poll_ap_addresses: get AP "
01374                               "hw addr failed\n");
01375                         continue;
01376                 }
01377 
01378                 if (memcmp(new_addr, mon_devs[i].ap_hwaddr, ETH_ALEN) != 0) {
01379                         DEBUG(DEBUG_FLAG, "Monitor: AP hw addr changed "
01380                               "(iface=%s): %s => ",
01381                               mon_devs[i].ifname,
01382                               ether_hwtoa((unsigned char *)
01383                                           mon_devs[i].ap_hwaddr));
01384                         DEBUG(DEBUG_FLAG, "%s\n",
01385                               ether_hwtoa((unsigned char *) new_addr));
01386                         /* send agentsol to this interface */
01387                         for (j = 0; j < MAX_INTERFACES; j++) {
01388                                 if (strcmp(mon_devs[i].ifname,
01389                                            mn->iface[j].device) != 0 ||
01390                                     mn->iface[j].s < 0)
01391                                         continue;
01392 
01393                                 send_agent_solicitation(mn->iface[j].s);
01394                         }
01395                         memcpy(mon_devs[i].ap_hwaddr, new_addr, ETH_ALEN);
01396                 }
01397         }
01398 }

Here is the call graph for this function:

void MONITOR_register_module ( void   ) 

Definition at line 1331 of file monitor.c.

References monitor_global_data::average_length, monitor_global_data::current_adv, monitor_global_data::current_fa, DEFAULT_AVG_LEN, monitor_global_data::default_ch, DEFAULT_DEV_PRIO_PERCENT, DEFAULT_EARLY_EXPIRE_TIME, DEFAULT_MIN_BALANCE, DEFAULT_THRESHOLD, DEFAULT_WORST_MAX_TIME, DEFAULT_WORST_MIN_TIME, monitor_global_data::dev_priority_percentage, monitor_global_data::expiretime, handler_register(), INTERFACE_DOWN, INTERFACE_INIT, monitor_global_data::interfaces, monitor_global_data::iwspy_supported, monitor_global_data::min_balance, mon_conf, mon_devs, mon_rec_qual_initialized, OLD_FA_FACTOR, monitor_global_data::old_fa_factor, monitor_global_data::rec_qual, monitor_global_data::reg_send_timer, monitor_global_data::SQ_cache, monitor_global_data::threshold, monitor_global_data::worst_max_time, and monitor_global_data::worst_min_time.

Referenced by mn_init().

01332 {
01333         /* initialize state and variables */
01334         memset(&mon_conf, 0, sizeof(struct monitor_global_data));
01335         mon_conf.current_fa = -1;    /* not connected yet */
01336         mon_conf.current_adv = NULL;
01337         mon_conf.reg_send_timer = NULL;
01338         mon_conf.interfaces = 0;
01339         mon_conf.iwspy_supported = 0;
01340         mon_conf.threshold = DEFAULT_THRESHOLD;
01341         mon_conf.default_ch = -1;
01342         mon_conf.old_fa_factor = OLD_FA_FACTOR;
01343         mon_conf.expiretime = DEFAULT_EARLY_EXPIRE_TIME;
01344         mon_conf.min_balance = DEFAULT_MIN_BALANCE;
01345         mon_conf.worst_min_time = DEFAULT_WORST_MIN_TIME;
01346         mon_conf.worst_max_time = DEFAULT_WORST_MAX_TIME;
01347         mon_conf.dev_priority_percentage = DEFAULT_DEV_PRIO_PERCENT;
01348         mon_conf.average_length = DEFAULT_AVG_LEN;
01349         mon_conf.rec_qual = 0;
01350         mon_conf.SQ_cache = 0;
01351         mon_rec_qual_initialized = 0;
01352         memset(mon_devs, 0, sizeof(mon_devs));
01353 
01354         /* register event_INTERFACE handlers */
01355         handler_register(INTERFACE_INIT, monitor_interface_up);
01356         handler_register(INTERFACE_DOWN, monitor_interface_down);
01357 }

Here is the call graph for this function:

int MONITOR_unregister_module ( void   ) 

Definition at line 1303 of file monitor.c.

References dyn_wireless_iwspy_set(), mon_conf, mon_devs, mon_rec_qual_initialized, rec_clean_up(), rec_dump(), REC_DUMP_TYPE, monitor_global_data::rec_qual, monitor_interface::sock, sock, and monitor_global_data::SQ_cache.

Referenced by clean_up().

01304 {
01305         int i;
01306 
01307         for (i = 0; i < MAX_INTERFACES; i++) {
01308                 if (!mon_devs[i].in_use)
01309                         continue;
01310                 if (mon_devs[i].iwspy_support && !mon_conf.SQ_cache)
01311                         dyn_wireless_iwspy_set(mon_devs[i].sock, 
01312                                                mon_devs[i].ifname, NULL, 0);
01313 
01314                 if (mon_devs[i].sock >= 0) {
01315                         close(mon_devs[i].sock);
01316                         mon_devs[i].sock = -1;
01317                 }
01318         }
01319 
01320         if (mon_rec_qual_initialized) {
01321                 if (mon_conf.rec_qual)
01322                         rec_dump(REC_DUMP_TYPE, -1);
01323                 rec_clean_up();
01324                 mon_rec_qual_initialized = 0;
01325         }
01326 
01327         return 0;
01328 }

Here is the call graph for this function:

int next ( int  p  ) 

Definition at line 29 of file monitor_util.c.

00030 {
00031         assert(p >= 0);
00032         if (p == 9)
00033                 return 0;
00034         return p + 1;
00035 
00036 }

int prev ( int  p  ) 

Definition at line 39 of file monitor_util.c.

Referenced by main().

00040 {
00041         assert(p >= 0);
00042         if (p == 0)
00043                 return 9;
00044         return p - 1;
00045 }

void print_entries ( void   ) 

Definition at line 137 of file monitor_util.c.

References monitor_address::adv, DEBUG(), DEBUG_FLAG, monitor_interface::in_use, MAX_INTERFACES, MAX_MONITOR, monitor_interface::mon, mon_devs, and agentadv_data::priority.

00138 {
00139         int i, j;
00140 
00141         for (j = 0; j < MAX_INTERFACES; j++) {
00142                 if (!mon_devs[j].in_use)
00143                         continue;
00144                 for (i = 0; i < MAX_MONITOR; i++) {
00145                         if (mon_devs[j].mon[i].active == 1) {
00146                                 DEBUG(DEBUG_FLAG, "%-15s: prio %d\n",
00147                                       inet_ntoa(mon_devs[j].mon[i].adv->addr),
00148                                       mon_devs[j].mon[i].adv->priority);
00149                         }
00150                 }
00151         }
00152 }

Here is the call graph for this function:


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