00025 {
00026
00027
int i, j, l, err;
00028
struct mac_ifinfo *ifinfo_ptr = NULL;
00029
struct mac_ifinfo_list *temp;
00030
struct mac_params *params_ptr = NULL;
00031
struct mac_params_flags *flags_ptr = NULL;
00032
unsigned char *frame_ptr = NULL;
00033
unsigned short len = 0;
00034
unsigned char *send_parameter_info = NULL, *recv_parameter_info = NULL;
00035
00036
unsigned short hdrlen = 0, type_msb, type_lsb;
00037
00038
if (argc < 2) {
00039 printf(
"Usage: ./monitor name_of_interface.\n");
00040
return(-1);
00041 }
00042
00043
00044
00045
00046
if ( (err =
mac_get_ifinfo(&ifinfo_ptr)) )
00047 {
00048
#ifdef DEBUG_ERR
00049
printf(
"Error, error code: %d, %s\n\n", err, strerror(err));
00050
#endif
00051
return err;
00052 }
00053
00054
00055
if ( (err =
mac_init_params(¶ms_ptr, &flags_ptr)) )
00056 {
00057
#ifdef DEBUG_ERR
00058
printf(
"Error, error code: %d, %s\n\n", err, strerror(err));
00059
#endif
00060
return err;
00061 }
00062
00063
00064
#ifdef DEBUG_BASIC
00065
00066 temp = ifinfo_ptr->mac_list;
00067
while (temp != NULL)
00068 {
00069
00070
if ( !(strcmp(temp->if_name, argv[1])) )
00071 {
00072 printf(
"----------- FOR INTERFACE %s -----------\n", temp->if_name);
00073
00074
00075
00076
if ( (err =
mac_get_params(params_ptr, temp, 4, mac_rssi,
00077 mac_txpower, mac_noise,
00078 mac_currentXmitRate)) )
00079 {
00080
#ifdef DEBUG_ERR
00081
printf(
"Error, error code: %d, %s\n\n", err, strerror(err));
00082
#endif
00083
return err;
00084 }
00085
00086
00087 printf(
"----------- VALUES AFTER CALL TO GET ------------------\n");
00088
for (i =
START_PARAMS_KEY; i < 4; i++)
00089 printf(
"Key: %d, Value: %d\n", params_ptr->key[i],
00090 params_ptr->value[i]);
00091
00092
00093
if ( (err =
mac_set_params(params_ptr, temp, 4, mac_noise, 10,
00094 mac_rssi, 88,
00095 mac_currentXmitRate, 2000000)) )
00096 {
00097
#ifdef DEBUG_ERR
00098
printf(
"Error, error code: %d, %s\n\n", err, strerror(err));
00099
#endif
00100
return err;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 printf(
"------------ VALUES AFTER CALL TO SET -----------------\n");
00110
for (i =
START_PARAMS_KEY; i < 4; i++)
00111 printf(
"Key: %d, Value: %d\n", params_ptr->key[i], params_ptr->value[i]);
00112
00113
00114
00115
00116
if ( (err =
mac_append_params(temp, INCOMING, 2, mac_noise,
00117 mac_rssi)) )
00118 {
00119
#ifdef DEBUG_ERR
00120
printf(
"Error, error code: %d, %s\n\n", err, strerror(err));
00121
#endif
00122
return err;
00123 }
00124
00125
00126
while(1)
00127 {
00128 frame_ptr = NULL;
00129 len = 0;
00130 send_parameter_info = NULL;
00131 recv_parameter_info = NULL;
00132 hdrlen = 0;
00133 type_msb = 4;
00134 type_lsb = 4;
00135
00136
if ( (err =
mac_promisc_recv(&frame_ptr, &len,
00137 &send_parameter_info,
00138 &recv_parameter_info, temp)) )
00139 {
00140
#ifdef DEBUG_ERR
00141
printf(
"Error, error code: %d, %s\n\n", err, strerror(err));
00142
#endif
00143
return err;
00144 }
00145
00146
if (frame_ptr != NULL)
00147 {
00148 type_msb = frame_ptr[0] & 16;
00149 type_lsb = frame_ptr[0] & 32;
00150
00151
00152
if ( (type_msb == 0) && (type_lsb == 0) )
00153 {
00154
#ifdef DEBUG_ERR
00155
00156
#endif
00157
hdrlen = 24;
00158 }
00159
else if ( (type_msb == 0) && (type_lsb == 32) )
00160 {
00161
#ifdef DEBUG_ERR
00162
00163
#endif
00164
hdrlen = 10;
00165 }
00166
00167
else if ( (type_msb == 16) && (type_lsb == 0) )
00168 {
00169
#ifdef DEBUG_ADV
00170
fprintf(stdout,
"Data frame.\n");
00171
#endif
00172
hdrlen = 24;
00173
00174 fprintf(stdout,
"=========== 80211 ==============\n");
00175 fprintf(stdout,
"Frame control: %hd\n",
00176 ((
struct ieee_802_11_header *)
00177 frame_ptr)->frame_control);
00178 fprintf(stdout,
"Duration: %hd\n",
00179 ((
struct ieee_802_11_header *)
00180 frame_ptr)->duration);
00181 fprintf(stdout,
"MAC addr 1: %s\n",
00182
pr_ether((
unsigned char *)
00183 (((
struct ieee_802_11_header *)
00184 frame_ptr)->mac1)));
00185 fprintf(stdout,
"MAC addr 2: %s\n",
00186
pr_ether((
unsigned char *)
00187 (((
struct ieee_802_11_header *)
00188 frame_ptr)->mac2)));
00189 fprintf(stdout,
"MAC addr 3: %s\n",
00190
pr_ether((
unsigned char *)
00191 (((
struct ieee_802_11_header *)
00192 frame_ptr)->mac3)));
00193 fprintf(stdout,
"SeqCtl: %hd\n",
00194 ((
struct ieee_802_11_header *)
00195 frame_ptr)->SeqCtl);
00196 fprintf(stdout,
"MAC addr 4: %s\n",
00197
pr_ether((
unsigned char *)
00198 (((
struct ieee_802_11_header *)
00199 frame_ptr)->mac4)));
00200 fprintf(stdout,
"gapLen: %hd\n",
00201 ((
struct ieee_802_11_header *)
00202 frame_ptr)->gapLen);
00203
00204 printf(
"Length of entire frame: %d\n", len);
00205
00206
00207 printf(
"Length of just payload: %d\n", len - hdrlen);
00208
00209
00210
if ( (send_parameter_info) != NULL )
00211 {
00212
00213 params_ptr->number_of_params = *send_parameter_info;
00214
00215
00216
00217 l =
SIZEOF_PARAMS_LIST_LEN +
00218 ( (params_ptr->number_of_params) *
00219 (
SIZEOF_PARAMS_LIST_KEY +
00220
SIZEOF_PARAMS_LIST_VALUE) );
00221
for(j=
SIZEOF_PARAMS_LIST_LEN;j < l;
00222 j=j+
SIZEOF_PARAMS_LIST_VALUE)
00223 {
00224 printf(
"Param key: %d\n",
00225 send_parameter_info[j]);
00226 j = j+
SIZEOF_PARAMS_LIST_KEY;
00227 printf(
"Param value: %hd",
00228 *((
unsigned short *)
00229 (send_parameter_info + j)));
00230 printf(
"\n");
00231 }
00232
00233
00234
if ( (recv_parameter_info) != NULL )
00235 {
00236
00237 params_ptr->number_of_params =
00238 *recv_parameter_info;
00239
00240
00241
00242 l =
SIZEOF_PARAMS_LIST_LEN +
00243 ( (params_ptr->number_of_params) *
00244 (
SIZEOF_PARAMS_LIST_KEY +
00245
SIZEOF_PARAMS_LIST_VALUE) );
00246
for(j=
SIZEOF_PARAMS_LIST_LEN;j < l;
00247 j=j+
SIZEOF_PARAMS_LIST_VALUE)
00248 {
00249 printf(
"Param key: %d\n",
00250 recv_parameter_info[j]);
00251 j = j+
SIZEOF_PARAMS_LIST_KEY;
00252 printf(
"Param value: %hd",
00253 *((
unsigned short *)
00254 (recv_parameter_info + j)));
00255 printf(
"\n");
00256 }
00257 }
00258 }
00259
else
00260 {
00261
if ( (recv_parameter_info) != NULL )
00262 {
00263
00264 params_ptr->number_of_params =
00265 *recv_parameter_info;
00266
00267
00268
00269 l =
SIZEOF_PARAMS_LIST_LEN +
00270 ( (params_ptr->number_of_params) *
00271 (
SIZEOF_PARAMS_LIST_KEY +
00272
SIZEOF_PARAMS_LIST_VALUE) );
00273
for(j=
SIZEOF_PARAMS_LIST_LEN;j < l;
00274 j=j+
SIZEOF_PARAMS_LIST_VALUE)
00275 {
00276 printf(
"Param key: %d\n",
00277 recv_parameter_info[j]);
00278 j = j+
SIZEOF_PARAMS_LIST_KEY;
00279 printf(
"Param value: %hd",
00280 *((
unsigned short *)
00281 (recv_parameter_info + j)));
00282 printf(
"\n");
00283 }
00284 }
00285 }
00286 }
00287
else if ( (type_msb == 16) && (type_lsb == 32) )
00288 {
00289
#ifdef DEBUG_ADV
00290
fprintf(stdout,
"Unrecognized frame type.\n");
00291
#endif
00292
hdrlen = 4;
00293 }
00294 }
00295
else
00296 fprintf(stdout,
"Only ethernet header received.\n");
00297 }
00298 }
00299 temp = temp->next;
00300 }
00301
#endif
00302
00303
00304
00305
00306
mac_free_params(¶ms_ptr, &flags_ptr);
00307
00308
mac_free_ifinfo(&ifinfo_ptr);
00309
00310
00311
00312
return 0;
00313 }