nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #include <string.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <pthread.h>
5  
6 #include "osdep.h"
7  
8 #define MAX_CHAN_COUNT 128
9  
10 int chans [MAX_CHAN_COUNT] = { 1, 7, 13, 2, 8, 3, 14, 9, 4, 10, 5, 11, 6, 12, 0 };
11  
12 pthread_t *hopper = NULL;
13  
14 int hopper_useconds = 0;
15  
16 void channel_hopper()
17 {
18 // A simple thread to hop channels
19 int cclp = 0;
20  
21 while (1) {
22 osdep_set_channel(chans[cclp]);
23 cclp++;
24 if (chans[cclp] == 0) cclp = 0;
25 usleep(hopper_useconds);
26 }
27 }
28  
29 void init_channel_hopper(char *chanlist, int useconds)
30 {
31 // Channel list chans[MAX_CHAN_COUNT] has been initialized with declaration for all b/g channels
32 char *token = NULL;
33 int chan_cur = EOF;
34 int lpos = 0;
35  
36 if (hopper) {
37 printf("There is already a channel hopper running, skipping this one!\n");
38 }
39  
40 if (chanlist == NULL) { // No channel list given - using defaults
41 printf("\nUsing default channels for hopping every %d milliseconds.\n", useconds/1000);
42 } else {
43  
44 while((token = strsep(&chanlist, ",")) != NULL) {
45 if(sscanf(token, "%d", &chan_cur) != EOF) {
46 chans[lpos] = chan_cur;
47 lpos++;
48 if (lpos == MAX_CHAN_COUNT) {
49 fprintf(stderr, "Exceeded max channel list entries, list truncated.\n");
50 break;
51 }
52 }
53 }
54  
55 chans[lpos] = 0;
56 }
57  
58 hopper_useconds = useconds;
59 hopper = malloc(sizeof(pthread_t));
60 pthread_create(hopper, NULL, (void *) channel_hopper, NULL);
61 }