-
Notifications
You must be signed in to change notification settings - Fork 2
/
rx.c
665 lines (507 loc) · 20.7 KB
/
rx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// (c)2015 befinitiv
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "fec.h"
#include "lib.h"
#include "wifibroadcast.h"
#include "radiotap.h"
#define MAX_PACKET_LENGTH 4192
#define MAX_USER_PACKET_LENGTH 1450
#define MAX_DATA_OR_FEC_PACKETS_PER_BLOCK 32
#define DEBUG 0
#define debug_print(fmt, ...) \
do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
// this is where we store a summary of the
// information from the radiotap header
typedef struct {
int m_nChannel;
int m_nChannelFlags;
int m_nRate;
int m_nAntenna;
int m_nRadiotapFlags;
} __attribute__((packed)) PENUMBRA_RADIOTAP_DATA;
int flagHelp = 0;
int param_port = 0;
int param_data_packets_per_block = 8;
int param_fec_packets_per_block = 4;
int param_block_buffers = 1;
int param_packet_length = MAX_USER_PACKET_LENGTH;
wifibroadcast_rx_status_t *rx_status = NULL;
int max_block_num = -1;
void
usage(void)
{
printf(
"(c)2015 befinitiv. Based on packetspammer by Andy Green. Licensed under GPL2\n"
"\n"
"Usage: rx [options] <interfaces>\n\nOptions\n"
"-p <port> Port number 0-255 (default 0)\n"
"-b <count> Number of data packets in a block (default 8). Needs to match with tx.\n"
"-r <count> Number of FEC packets per block (default 4). Needs to match with tx.\n\n"
"-f <bytes> Number of bytes per packet (default %d. max %d). This is also the FEC block size. Needs to match with tx\n"
"-d <blocks> Number of transmissions blocks that are buffered (default 1). This is needed in case of diversity if one adapter delivers data faster than the other. Note that this increases latency\n"
"Example:\n"
" iwconfig wlan0 down\n"
" iw dev wlan0 set monitor otherbss fcsfail\n"
" ifconfig wlan0 up\n"
" iwconfig wlan0 channel 13\n"
" rx wlan0 Receive raw packets on wlan0 and output the payload to stdout\n"
"\n", MAX_USER_PACKET_LENGTH, MAX_USER_PACKET_LENGTH);
exit(1);
}
typedef struct {
pcap_t *ppcap;
int selectable_fd;
int n80211HeaderLength;
} monitor_interface_t;
typedef struct {
int block_num;
packet_buffer_t *packet_buffer_list;
} block_buffer_t;
void open_and_configure_interface(const char *name, int port, monitor_interface_t *interface) {
struct bpf_program bpfprogram;
char szProgram[512];
char szErrbuf[PCAP_ERRBUF_SIZE];
// open the interface in pcap
szErrbuf[0] = '\0';
interface->ppcap = pcap_open_live(name, 2048, 1, -1, szErrbuf);
if (interface->ppcap == NULL) {
fprintf(stderr, "Unable to open interface %s in pcap: %s\n",
name, szErrbuf);
exit(1);
}
if(pcap_setnonblock(interface->ppcap, 1, szErrbuf) < 0) {
fprintf(stderr, "Error setting %s to nonblocking mode: %s\n", name, szErrbuf);
}
int nLinkEncap = pcap_datalink(interface->ppcap);
switch (nLinkEncap) {
case DLT_PRISM_HEADER:
fprintf(stderr, "DLT_PRISM_HEADER Encap\n");
interface->n80211HeaderLength = 0x20; // ieee80211 comes after this
sprintf(szProgram, "radio[0x4a:4]==0x13223344 && radio[0x4e:2] == 0x55%.2x", port);
break;
case DLT_IEEE802_11_RADIO:
fprintf(stderr, "DLT_IEEE802_11_RADIO Encap\n");
interface->n80211HeaderLength = 0x18; // ieee80211 comes after this
sprintf(szProgram, "ether[0x0a:4]==0x13223344 && ether[0x0e:2] == 0x55%.2x", port);
break;
default:
fprintf(stderr, "!!! unknown encapsulation on %s !\n", name);
exit(1);
}
if (pcap_compile(interface->ppcap, &bpfprogram, szProgram, 1, 0) == -1) {
puts(szProgram);
puts(pcap_geterr(interface->ppcap));
exit(1);
} else {
if (pcap_setfilter(interface->ppcap, &bpfprogram) == -1) {
fprintf(stderr, "%s\n", szProgram);
fprintf(stderr, "%s\n", pcap_geterr(interface->ppcap));
} else {
}
pcap_freecode(&bpfprogram);
}
interface->selectable_fd = pcap_get_selectable_fd(interface->ppcap);
}
void block_buffer_list_reset(block_buffer_t *block_buffer_list, size_t block_buffer_list_len, int block_buffer_len) {
int i;
block_buffer_t *rb = block_buffer_list;
for(i=0; i<block_buffer_list_len; ++i) {
rb->block_num = -1;
int j;
packet_buffer_t *p = rb->packet_buffer_list;
for(j=0; j<param_data_packets_per_block+param_fec_packets_per_block; ++j) {
p->valid = 0;
p->crc_correct = 0;
p->len = 0;
p++;
}
rb++;
}
}
void process_payload(uint8_t *data, size_t data_len, int crc_correct, block_buffer_t *block_buffer_list, int adapter_no)
{
wifi_packet_header_t *wph;
int block_num;
int packet_num;
int i;
wph = (wifi_packet_header_t*)data;
data += sizeof(wifi_packet_header_t);
data_len -= sizeof(wifi_packet_header_t);
block_num = wph->sequence_number / (param_data_packets_per_block+param_fec_packets_per_block);//if aram_data_packets_per_block+param_fec_packets_per_block would be limited to powers of two, this could be replaced by a logical AND operation
//debug_print("adap %d rec %x blk %x crc %d len %d\n", adapter_no, wph->sequence_number, block_num, crc_correct, data_len);
//we have received a block number that exceeds the currently seen ones -> we need to make room for this new block
//or we have received a block_num that is several times smaller than the current window of buffers -> this indicated that either the window is too small or that the transmitter has been restarted
int tx_restart = (block_num + 128*param_block_buffers < max_block_num);
if((block_num > max_block_num || tx_restart) && crc_correct) {
if(tx_restart) {
rx_status->tx_restart_cnt++;
fprintf(stderr, "TX RESTART: Detected blk %x that lies outside of the current retr block buffer window (max_block_num = %x) (if there was no tx restart, increase window size via -d)\n", block_num, max_block_num);
block_buffer_list_reset(block_buffer_list, param_block_buffers, param_data_packets_per_block + param_fec_packets_per_block);
}
//first, find the minimum block num in the buffers list. this will be the block that we replace
int min_block_num = INT_MAX;
int min_block_num_idx;
for(i=0; i<param_block_buffers; ++i) {
if(block_buffer_list[i].block_num < min_block_num) {
min_block_num = block_buffer_list[i].block_num;
min_block_num_idx = i;
}
}
//debug_print("removing block %x at index %i for block %x\n", min_block_num, min_block_num_idx, block_num);
packet_buffer_t *packet_buffer_list = block_buffer_list[min_block_num_idx].packet_buffer_list;
int last_block_num = block_buffer_list[min_block_num_idx].block_num;
if(last_block_num != -1) {
rx_status->received_block_cnt++;
//we have both pointers to the packet buffers (to get information about crc and vadility) and raw data pointers for fec_decode
packet_buffer_t *data_pkgs[MAX_DATA_OR_FEC_PACKETS_PER_BLOCK];
packet_buffer_t *fec_pkgs[MAX_DATA_OR_FEC_PACKETS_PER_BLOCK];
uint8_t *data_blocks[MAX_DATA_OR_FEC_PACKETS_PER_BLOCK];
uint8_t *fec_blocks[MAX_DATA_OR_FEC_PACKETS_PER_BLOCK];
int datas_missing = 0, datas_corrupt = 0, fecs_missing = 0, fecs_corrupt = 0;
int di = 0, fi = 0;
//first, split the received packets into DATA a FEC packets and count the damaged packets
i = 0;
while(di < param_data_packets_per_block || fi < param_fec_packets_per_block) {
if(di < param_data_packets_per_block) {
data_pkgs[di] = packet_buffer_list + i++;
data_blocks[di] = data_pkgs[di]->data;
if(!data_pkgs[di]->valid)
datas_missing++;
if(data_pkgs[di]->valid && !data_pkgs[di]->crc_correct)
datas_corrupt++;
di++;
}
if(fi < param_fec_packets_per_block) {
fec_pkgs[fi] = packet_buffer_list + i++;
if(!fec_pkgs[fi]->valid)
fecs_missing++;
if(fec_pkgs[fi]->valid && !fec_pkgs[fi]->crc_correct)
fecs_corrupt++;
fi++;
}
}
const int good_fecs_c = param_fec_packets_per_block - fecs_missing - fecs_corrupt;
const int datas_missing_c = datas_missing;
const int datas_corrupt_c = datas_corrupt;
const int fecs_missing_c = fecs_missing;
const int fecs_corrupt_c = fecs_corrupt;
int good_fecs = good_fecs_c;
//the following three fields are infos for fec_decode
unsigned int fec_block_nos[MAX_DATA_OR_FEC_PACKETS_PER_BLOCK];
unsigned int erased_blocks[MAX_DATA_OR_FEC_PACKETS_PER_BLOCK];
unsigned int nr_fec_blocks = 0;
#if DEBUG
if(datas_missing_c + datas_corrupt_c > good_fecs_c) {
int x;
for(x=0;x<param_data_packets_per_block; ++x) {
if(data_pkgs[x]->valid) {
if(data_pkgs[x]->crc_correct)
fprintf(stderr, "v");
else
fprintf(stderr, "c");
}
else
fprintf(stderr, "m");
}
fprintf(stderr, " ");
for(x=0;x<param_fec_packets_per_block; ++x) {
if(fec_pkgs[x]->valid) {
if(fec_pkgs[x]->crc_correct)
fprintf(stderr, "v");
else
fprintf(stderr, "c");
}
else
fprintf(stderr, "m");
}
fprintf(stderr, "\n");
}
#endif
fi = 0;
di = 0;
//look for missing DATA and replace them with good FECs
while(di < param_data_packets_per_block && fi < param_fec_packets_per_block) {
//if this data is fine we go to the next
if(data_pkgs[di]->valid && data_pkgs[di]->crc_correct) {
di++;
continue;
}
//if this DATA is corrupt and there are less good fecs than missing datas we cannot do anything for this data
if(data_pkgs[di]->valid && !data_pkgs[di]->crc_correct && good_fecs <= datas_missing) {
di++;
continue;
}
//if this FEC is not received we go on to the next
if(!fec_pkgs[fi]->valid) {
fi++;
continue;
}
//if this FEC is corrupted and there are more lost packages than good fecs we should replace this DATA even with this corrupted FEC
if(!fec_pkgs[fi]->crc_correct && datas_missing > good_fecs) {
fi++;
continue;
}
if(!data_pkgs[di]->valid)
datas_missing--;
else if(!data_pkgs[di]->crc_correct)
datas_corrupt--;
if(fec_pkgs[fi]->crc_correct)
good_fecs--;
//at this point, data is invalid and fec is good -> replace data with fec
erased_blocks[nr_fec_blocks] = di;
fec_block_nos[nr_fec_blocks] = fi;
fec_blocks[nr_fec_blocks] = fec_pkgs[fi]->data;
di++;
fi++;
nr_fec_blocks++;
}
int reconstruction_failed = datas_missing_c + datas_corrupt_c > good_fecs_c;
if(reconstruction_failed) {
//we did not have enough FEC packets to repair this block
rx_status->damaged_block_cnt++;
fprintf(stderr, "Could not fully reconstruct block %x! Damage rate: %f (%d / %d blocks)\n", last_block_num, 1.0 * rx_status->damaged_block_cnt / rx_status->received_block_cnt, rx_status->damaged_block_cnt, rx_status->received_block_cnt);
debug_print("Data mis: %d\tData corr: %d\tFEC mis: %d\tFEC corr: %d\n", datas_missing_c, datas_corrupt_c, fecs_missing_c, fecs_corrupt_c);
}
//decode data and write it to STDOUT
fec_decode((unsigned int) param_packet_length, data_blocks, param_data_packets_per_block, fec_blocks, fec_block_nos, erased_blocks, nr_fec_blocks);
for(i=0; i<param_data_packets_per_block; ++i) {
payload_header_t *ph = (payload_header_t*)data_blocks[i];
if(!reconstruction_failed || data_pkgs[i]->valid) {
//if reconstruction did fail, the data_length value is undefined. better limit it to some sensible value
if(ph->data_length > param_packet_length)
ph->data_length = param_packet_length;
write(STDOUT_FILENO, data_blocks[i] + sizeof(payload_header_t), ph->data_length);
}
}
//reset buffers
for(i=0; i<param_data_packets_per_block + param_fec_packets_per_block; ++i) {
packet_buffer_t *p = packet_buffer_list + i;
p->valid = 0;
p->crc_correct = 0;
p->len = 0;
}
}
block_buffer_list[min_block_num_idx].block_num = block_num;
max_block_num = block_num;
}
//find the buffer into which we have to write this packet
block_buffer_t *rbb = block_buffer_list;
for(i=0; i<param_block_buffers; ++i) {
if(rbb->block_num == block_num) {
break;
}
rbb++;
}
//check if we have actually found the corresponding block. this could not be the case due to a corrupt packet
if(i != param_block_buffers) {
packet_buffer_t *packet_buffer_list = rbb->packet_buffer_list;
packet_num = wph->sequence_number % (param_data_packets_per_block+param_fec_packets_per_block); //if retr_block_size would be limited to powers of two, this could be replace by a locical and operation
//only overwrite packets where the checksum is not yet correct. otherwise the packets are already received correctly
if(packet_buffer_list[packet_num].crc_correct == 0) {
memcpy(packet_buffer_list[packet_num].data, data, data_len);
packet_buffer_list[packet_num].len = data_len;
packet_buffer_list[packet_num].valid = 1;
packet_buffer_list[packet_num].crc_correct = crc_correct;
}
}
}
void process_packet(monitor_interface_t *interface, block_buffer_t *block_buffer_list, int adapter_no) {
struct pcap_pkthdr * ppcapPacketHeader = NULL;
struct ieee80211_radiotap_iterator rti;
PENUMBRA_RADIOTAP_DATA prd;
u8 payloadBuffer[MAX_PACKET_LENGTH];
u8 *pu8Payload = payloadBuffer;
int bytes;
int n;
int retval;
int u16HeaderLen;
// receive
retval = pcap_next_ex(interface->ppcap, &ppcapPacketHeader,
(const u_char**)&pu8Payload);
if (retval < 0) {
fprintf(stderr, "Socket broken\n");
fprintf(stderr, "%s\n", pcap_geterr(interface->ppcap));
exit(1);
}
//if(retval == 0)
// fprintf(stderr, "retval = 0\n");
if (retval != 1)
return;
u16HeaderLen = (pu8Payload[2] + (pu8Payload[3] << 8));
if (ppcapPacketHeader->len <
(u16HeaderLen + interface->n80211HeaderLength))
return;
bytes = ppcapPacketHeader->len -
(u16HeaderLen + interface->n80211HeaderLength);
if (bytes < 0)
return;
if (ieee80211_radiotap_iterator_init(&rti,
(struct ieee80211_radiotap_header *)pu8Payload,
ppcapPacketHeader->len) < 0)
return;
while ((n = ieee80211_radiotap_iterator_next(&rti)) == 0) {
switch (rti.this_arg_index) {
case IEEE80211_RADIOTAP_RATE:
prd.m_nRate = (*rti.this_arg);
break;
case IEEE80211_RADIOTAP_CHANNEL:
prd.m_nChannel =
le16_to_cpu(*((u16 *)rti.this_arg));
prd.m_nChannelFlags =
le16_to_cpu(*((u16 *)(rti.this_arg + 2)));
break;
case IEEE80211_RADIOTAP_ANTENNA:
prd.m_nAntenna = (*rti.this_arg) + 1;
break;
case IEEE80211_RADIOTAP_FLAGS:
prd.m_nRadiotapFlags = *rti.this_arg;
break;
case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
rx_status->adapter[adapter_no].current_signal_dbm = (int8_t)(*rti.this_arg);
break;
}
}
pu8Payload += u16HeaderLen + interface->n80211HeaderLength;
if (prd.m_nRadiotapFlags & IEEE80211_RADIOTAP_F_FCS)
bytes -= 4;
int checksum_correct = (prd.m_nRadiotapFlags & 0x40) == 0;
if(!checksum_correct)
rx_status->adapter[adapter_no].wrong_crc_cnt++;
rx_status->adapter[adapter_no].received_packet_cnt++;
if(rx_status->adapter[adapter_no].received_packet_cnt % 1024 == 0) {
fprintf(stderr, "Signal (card %d): %ddBm\n", adapter_no, rx_status->adapter[adapter_no].current_signal_dbm);
}
rx_status->last_update = time(NULL);
process_payload(pu8Payload, bytes, checksum_correct, block_buffer_list, adapter_no);
}
void status_memory_init(wifibroadcast_rx_status_t *s) {
s->received_block_cnt = 0;
s->damaged_block_cnt = 0;
s->tx_restart_cnt = 0;
s->wifi_adapter_cnt = 0;
int i;
for(i=0; i<MAX_PENUMBRA_INTERFACES; ++i) {
s->adapter[i].received_packet_cnt = 0;
s->adapter[i].wrong_crc_cnt = 0;
s->adapter[i].current_signal_dbm = 0;
}
}
wifibroadcast_rx_status_t *status_memory_open(void) {
char buf[128];
int fd;
sprintf(buf, "/wifibroadcast_rx_status_%d", param_port);
fd = shm_open(buf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if(fd < 0) {
perror("shm_open");
exit(1);
}
if (ftruncate(fd, sizeof(wifibroadcast_rx_status_t)) == -1) {
perror("ftruncate");
exit(1);
}
void *retval = mmap(NULL, sizeof(wifibroadcast_rx_status_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (retval == MAP_FAILED) {
perror("mmap");
exit(1);
}
wifibroadcast_rx_status_t *tretval = (wifibroadcast_rx_status_t*)retval;
status_memory_init(tretval);
return tretval;
}
int
main(int argc, char *argv[])
{
monitor_interface_t interfaces[MAX_PENUMBRA_INTERFACES];
int num_interfaces = 0;
int i;
block_buffer_t *block_buffer_list;
while (1) {
int nOptionIndex;
static const struct option optiona[] = {
{ "help", no_argument, &flagHelp, 1 },
{ 0, 0, 0, 0 }
};
int c = getopt_long(argc, argv, "hp:b:d:r:f:",
optiona, &nOptionIndex);
if (c == -1)
break;
switch (c) {
case 0: // long option
break;
case 'h': // help
usage();
case 'p': //port
param_port = atoi(optarg);
break;
case 'b':
param_data_packets_per_block = atoi(optarg);
break;
case 'r':
param_fec_packets_per_block = atoi(optarg);
break;
case 'd':
param_block_buffers = atoi(optarg);
break;
case 'f': // MTU
param_packet_length = atoi(optarg);
break;
default:
fprintf(stderr, "unknown switch %c\n", c);
usage();
break;
}
}
if (optind >= argc)
usage();
if(param_packet_length > MAX_USER_PACKET_LENGTH) {
printf("Packet length is limited to %d bytes (you requested %d bytes)\n", MAX_USER_PACKET_LENGTH, param_packet_length);
return (1);
}
fec_init();
int x = optind;
while(x < argc && num_interfaces < MAX_PENUMBRA_INTERFACES) {
open_and_configure_interface(argv[x], param_port, interfaces + num_interfaces);
++num_interfaces;
++x;
}
//block buffers contain both the block_num as well as packet buffers for a block.
block_buffer_list = malloc(sizeof(block_buffer_t) * param_block_buffers);
for(i=0; i<param_block_buffers; ++i)
{
block_buffer_list[i].block_num = -1;
block_buffer_list[i].packet_buffer_list = lib_alloc_packet_buffer_list(param_data_packets_per_block+param_fec_packets_per_block, MAX_PACKET_LENGTH);
}
rx_status = status_memory_open();
rx_status->wifi_adapter_cnt = num_interfaces;
for(;;) {
fd_set readset;
struct timeval to;
to.tv_sec = 0;
to.tv_usec = 1e5;
FD_ZERO(&readset);
for(i=0; i<num_interfaces; ++i)
FD_SET(interfaces[i].selectable_fd, &readset);
int n = select(30, &readset, NULL, NULL, &to);
for(i=0; i<num_interfaces; ++i) {
if(n == 0)
break;
if(FD_ISSET(interfaces[i].selectable_fd, &readset)) {
process_packet(interfaces + i, block_buffer_list, i);
}
}
}
return (0);
}