#include <malloc.h>
#include <unistd.h>
#include <stdio.h>
#include <getopt.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/wireless.h>
#include "dyn_wireless.h"
#include "debug.h"
#include "util.h"
Include dependency graph for iwspy-sim.c:
Go to the source code of this file.
Defines | |
#define | DEBUG_FLAG '4' |
#define | USAGE |
#define | MAX_LINE 80 |
#define | MAX_FILES 64 |
Functions | |
int | free_nodes (struct quality_values *q) |
quality_values * | read_quals (FILE *f, int *ival, int *filetype) |
FILE * | get_file (char *name) |
int | close_file (FILE *f) |
int | parse_hw_address (char *string, char *hw) |
void | print_quals (struct quality_values *q) |
int | parse_pairs (int oindex, int const argc, char **argv, char *hw, FILE *qfile[], int *qfile_index) |
int | main (int argc, char **argv) |
Variables | |
char * | optarg |
int | optind |
int | opterr |
int | optopt |
int | opt_debug |
#define DEBUG_FLAG '4' |
Definition at line 34 of file iwspy-sim.c.
#define MAX_FILES 64 |
#define MAX_LINE 80 |
#define USAGE |
Value:
"iwspy_sim -d <device> [-h] {[<mac_address> "\ "<qualities_file>] .. | -m <mac_address>}\n"
Definition at line 36 of file iwspy-sim.c.
int close_file | ( | FILE * | f | ) |
int free_nodes | ( | struct quality_values * | q | ) |
Definition at line 50 of file iwspy-sim.c.
References quality_values::next.
Referenced by main().
00051 { 00052 struct quality_values *t; 00053 00054 while (q != NULL) { 00055 t = q; 00056 q = q->next; 00057 free(t); 00058 } 00059 00060 return 0; 00061 }
FILE* get_file | ( | char * | name | ) |
Definition at line 124 of file iwspy-sim.c.
Referenced by parse_pairs().
00125 { 00126 FILE *fd; 00127 00128 fd = fopen(name, "r"); 00129 if (fd) 00130 return fd; 00131 fprintf(stderr, "get_file - %s: %s\n", name, strerror(errno)); 00132 00133 return NULL; 00134 }
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 288 of file iwspy-sim.c.
References close_file(), DEBUG(), DEBUG_FLAG, dyn_wireless_create_socket(), dyn_wireless_get_ifname(), dyn_wireless_get_simulator(), free_nodes(), IFNAMSIZ, MAX_FILES, opt_debug, optarg, optind, parse_hw_address(), parse_pairs(), print_quals(), and USAGE.
00289 { 00290 int oindex = 0, ret = 1, ret2 = 0; 00291 char hw[MAX_FILES*ETH_ALEN]; 00292 char get_hw[ETH_ALEN]; 00293 FILE *qfile[MAX_FILES]; 00294 int qfile_index = 0; 00295 struct quality_values *quals = NULL; 00296 char ifname[IFNAMSIZ+1]; 00297 signed char c; 00298 int sock, i; 00299 00300 memset(qfile, 0, sizeof(qfile)); 00301 while ((c = getopt_long(argc, argv, "+d:hm:v", long_options, &oindex)) 00302 != EOF) { 00303 switch (c) { 00304 case 'd': 00305 DEBUG(DEBUG_FLAG, "option d (Device) with value " 00306 "'%s'\n", optarg); 00307 ret = dyn_wireless_get_ifname(optarg, ifname); 00308 break; 00309 case 'm': 00310 DEBUG(DEBUG_FLAG, "option m (Mac address) with value " 00311 "'%s'\n", optarg); 00312 ret2 = parse_hw_address(optarg, get_hw); 00313 break; 00314 case 'h': 00315 printf(USAGE); 00316 return 0; 00317 break; 00318 case 'v': 00319 opt_debug = 1; 00320 break; 00321 default: 00322 fprintf(stderr, "Unknown option %c\n", c); 00323 printf(USAGE); 00324 break; 00325 } 00326 } 00327 00328 00329 if (ret) { 00330 printf("Couldn't parse device name!\n"); 00331 printf(USAGE); 00332 return 1; 00333 } 00334 00335 00336 /* initialize socket */ 00337 sock = dyn_wireless_create_socket(); 00338 if (sock < 0) { 00339 fprintf(stderr, "Socket creation failed (%s)\n", 00340 strerror(errno)); 00341 return 1; 00342 } 00343 00344 if (ret2) { 00345 /* GET_SIMULATOR */ 00346 DEBUG(DEBUG_FLAG, "GET\n"); 00347 quals = dyn_wireless_get_simulator(sock, ifname, get_hw); 00348 print_quals(quals); 00349 free_nodes(quals); 00350 } else { 00351 /* SET_SIMULATOR */ 00352 /* parse hw address and qualities file pairs */ 00353 DEBUG(DEBUG_FLAG, "SET\n"); 00354 if (parse_pairs(optind, argc, argv, hw, qfile, &qfile_index)) { 00355 fprintf(stderr, "Command line parsing failed!\n"); 00356 return 1; 00357 } 00358 feed_quality_values(sock, ifname, hw, qfile, qfile_index); 00359 } 00360 00361 for (i = 0; qfile[i] != NULL; i++) 00362 close_file(qfile[i]); 00363 return 0; 00364 }
Here is the call graph for this function:
int parse_hw_address | ( | char * | string, | |
char * | hw | |||
) |
Definition at line 142 of file iwspy-sim.c.
Referenced by main(), and parse_pairs().
00143 { 00144 int ret; 00145 00146 ret = sscanf(string, "%02x:%02x:%02x:%02x:%02x:%02x", 00147 (unsigned int *)&hw[0], (unsigned int *)&hw[1], 00148 (unsigned int *)&hw[2], (unsigned int *)&hw[3], 00149 (unsigned int *)&hw[4], (unsigned int *)&hw[5]); 00150 if (ret == 6) 00151 return 1; /* TRUE */ 00152 00153 return 0; /* FALSE */ 00154 }
int parse_pairs | ( | int | oindex, | |
int const | argc, | |||
char ** | argv, | |||
char * | hw, | |||
FILE * | qfile[], | |||
int * | qfile_index | |||
) |
Definition at line 173 of file iwspy-sim.c.
References get_file(), MAX_FILES, parse_hw_address(), and USAGE.
Referenced by main().
00175 { 00176 int ret; 00177 00178 *qfile_index = 0; 00179 while (oindex < argc-1) { 00180 printf("oindex = %d, argc = %d, qfile_index = %d\n", 00181 oindex, argc, *qfile_index ); 00182 ret = parse_hw_address(argv[oindex], 00183 &hw[(*qfile_index)*ETH_ALEN]); 00184 if (!ret) { 00185 fprintf(stderr, "Couldn't parse hw address!\n"); 00186 printf(USAGE); 00187 return 1; 00188 } 00189 qfile[*qfile_index] = get_file(argv[oindex+1]); 00190 if (qfile[*qfile_index] == NULL) 00191 return 1; 00192 (*qfile_index)++; 00193 if (*qfile_index >= MAX_FILES) 00194 return 2; 00195 oindex += 2; 00196 } 00197 00198 return 0; 00199 }
Here is the call graph for this function:
void print_quals | ( | struct quality_values * | q | ) |
Definition at line 156 of file iwspy-sim.c.
References quality_values::next, quality_values::num_of_quals, quality_values::sim_quals, and quality_values::sim_timestamps.
Referenced by main().
00157 { 00158 unsigned long i, j; 00159 00160 j = 0; 00161 while (q != NULL) { 00162 for (i = 0; i < q->num_of_quals; i++) 00163 if (q->sim_timestamps[i] > 0) 00164 printf("%-4lu %3d\n", q->sim_timestamps[i], 00165 q->sim_quals[i]); 00166 else 00167 printf("%-4ld %3d\n", i + j, q->sim_quals[i]); 00168 j += q->num_of_quals; 00169 q = q->next; 00170 } 00171 }
struct quality_values* read_quals | ( | FILE * | f, | |
int * | ival, | |||
int * | filetype | |||
) |
Definition at line 68 of file iwspy-sim.c.
References dyn_wireless_get_quals_node(), MAX_LINE, MAX_NUM_QUALS, quality_values::num_of_quals, quality_values::sim_quals, and quality_values::sim_timestamps.
00069 { 00070 struct quality_values *q, *t; 00071 char buf[MAX_LINE], hw[ETH_ALEN+1], addr[20]; 00072 int ret, qual; 00073 unsigned long tstamp; 00074 00075 00076 q = t = dyn_wireless_get_quals_node(NULL); 00077 00078 /* Read the interval from the first line */ 00079 *ival = 0; 00080 fgets(buf, MAX_LINE, f); 00081 ret = sscanf(buf, "# %d %d", ival, filetype); 00082 if (ret != 2) { 00083 fprintf(stderr, "Header not found! ´# <ival(in msec)> " 00084 "<filetype (0:no timestamps, 1:timestamps in seconds" 00085 ", 2:timestamps in tens of milli seconds>'. " 00086 "buf: '%s'\n", buf); 00087 return NULL; 00088 } 00089 fgets(buf, MAX_LINE, f); 00090 ret = sscanf(buf, "# %19s %6s", addr, hw); 00091 if (ret != 2) { 00092 fprintf(stderr, "Addresses not found. Should be: " 00093 "'# <ip-addr> <hw-addr>'. buf: '%s'\n", buf); 00094 return NULL; 00095 } 00096 /* Read values into structure */ 00097 while (fgets(buf, MAX_LINE, f)) { 00098 if (*filetype == 0) /* no timestamps */ 00099 sscanf(buf, "%d", &qual); 00100 /* timestamps in seconds OR in milliseconds/10 */ 00101 else if (*filetype == 1 || *filetype == 2 || *filetype == 3) 00102 sscanf(buf, "%lu %d", &tstamp, &qual); 00103 else { 00104 fprintf(stderr, "Unknown filetype! (%d)\n", *filetype); 00105 return NULL; 00106 } 00107 if (qual < 0 || qual > 100) { /* FIX: Exact range */ 00108 fprintf(stderr, "Invalid quality value! (%lu) " 00109 "(%d) '%s'\n", 00110 tstamp, qual, buf); 00111 return NULL; 00112 } 00113 if (t->num_of_quals >= MAX_NUM_QUALS) 00114 t = dyn_wireless_get_quals_node(t); 00115 /* store value */ 00116 t->sim_quals[t->num_of_quals] = qual; 00117 t->sim_timestamps[t->num_of_quals] = tstamp; 00118 t->num_of_quals++; 00119 } 00120 00121 return q; 00122 }
Here is the call graph for this function:
int opt_debug |
char* optarg |
Referenced by main(), and mn_parse_command_line().
int opterr |
int optopt |