]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/fwp/fwp/demo/fake_wifi_agent.c
fwp: fake_wifi_agent: Input correction
[frescor/frsh-forb.git] / src / fwp / fwp / demo / fake_wifi_agent.c
1 /*
2  *      @brief fake wifi agent - creates a station manually and send data to frm
3  *
4  */
5
6 #include <forb.h>
7 #include <stdio.h>
8 #include "wifi_agent_idl.h"
9 #include "wifi_agent.h"
10
11 int atoint(char a)
12 {
13         if( (a >= '0') && (a <= '9') )
14                 return a - '0';
15         else if ( (a >= 'A') && (a <= 'F') ) 
16                 return a - 'A' + 10;
17         else if ( (a >= 'a') && (a <= 'f') ) 
18                 return a - 'a' + 10;
19         return 0;
20 }
21
22 long long mac_addr_string_to_number(char * mac)
23 {
24         long long number;
25         long long help;
26         int ix;
27         int ix2;
28         char mac_num[12];
29
30         mac_num[0] = mac[0];
31         mac_num[1] = mac[1];
32         mac_num[2] = mac[3];
33         mac_num[3] = mac[4];
34         mac_num[4] = mac[6];
35         mac_num[5] = mac[7];
36         mac_num[6] = mac[9];
37         mac_num[7] = mac[10];
38         mac_num[8] = mac[12];
39         mac_num[9] = mac[13];
40         mac_num[10] = mac[15];
41         mac_num[11] = mac[16];
42
43         number = 0;
44
45         for(ix = 0; ix <= 12 ; ix++)
46         {       
47                 help = 1;
48                 for(ix2 = 1; ix2 < 12 - ix; ix2++)
49                         help *= 16;  
50                 number += atoint(mac_num[ix]) * help;
51
52         }
53         
54         printf("%llu \n", number);
55         return number;
56 }
57
58 int main(int argc, char **argv)
59 {
60         forb_orb fwp_orb;
61         wifi_agent_idl wai;
62         CORBA_Environment env;
63         int rate;
64         char mac_addr[20];
65         int opt;
66         bool opt_daemon = false;
67         char *opt_pidfile = NULL;
68
69         rate = 1;
70         opterr = 0;
71         while ((opt = getopt (argc, argv, "d:a:r:")) != -1) {
72
73                 switch (opt) {
74                         case 'e':
75                                 opt_daemon = true;
76                                 opt_pidfile = optarg;
77                                 break;
78                         case 'a':
79                                 strcpy(mac_addr, optarg);
80                                 break;
81                         case 'r':
82                                 rate = atoi(optarg);
83                                 break;
84                         case '?':
85                                 printf("Usage: %s -a mac_addr -r rate (Mbit/s)\n",
86                                                 argv[0]);
87                 }
88         }
89
90         if (opt_daemon)
91                 forb_daemon_prepare(opt_pidfile);
92
93         fwp_orb = forb_init(&argc, &argv, NULL); /* FORB initialization */
94
95         if (opt_daemon)
96                 forb_daemon_ready();
97         
98         /* Find our implementation */
99         wai = forb_resolve_reference(fwp_orb, "net.sourceforge.frsh-forb.wai");
100         if(wai == NULL)
101                 fprintf(stderr, "failed to create connection\n");       
102         else
103         {       printf("%d \n", rate);
104                 wifi_agent_idl_add(wai, rate, mac_addr_string_to_number(mac_addr), &env);
105
106                 //TODO: Print state is just for testing purposes - delete                       
107                 wifi_agent_idl_print_state(wai, &env);
108         }
109
110         return 0;
111 }
112