forked from Mr-jinfa/iwtools4wifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_wifi.c
147 lines (128 loc) · 3.41 KB
/
main_wifi.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
#include <stdio.h>
#include "iwlib.h"
#define PERIPHERAL_MAGIC 0x40
#define WIFIPOWERON_CMD _IOW(PERIPHERAL_MAGIC,0x01,unsigned long)
#define WIFIPOWERDOWN_CMD _IOW(PERIPHERAL_MAGIC,0x02,unsigned long)
#define GPRSRESET_CMD _IOW(PERIPHERAL_MAGIC,0x03,unsigned long)
#define GPRSPOWERON_CMD _IOW(PERIPHERAL_MAGIC,0x04,unsigned long)
#define GPRSPOWERDOWN_CMD _IOW(PERIPHERAL_MAGIC,0x05,unsigned long)
#define WITHNO_ACCOUNT 0
#define WITH_ACCOUNT 1
void show_list();
#define wifi_script "/etc/wpa_wpa2.conf"
void usage(void)
{
printf("*********************************\n");
printf("\t1.link .\n");
printf("\t2.unlink .\n");
// printf("\t3.get dynamic ip .\n");
printf("\t4.exit .\n");
printf("*********************************\n");
printf("input:");
}
int main(int argc, char const *argv[])
{
struct p_connect *con_wifi;
struct p_curwifi *cur_wifi;
struct p_wifi_list *wifi_list_head;
int fd_wifi_script=0, pperipheral_fd;
int operstate_fd;
struct p_wifi_list *q;
if((fd_wifi_script =open(wifi_script, O_RDONLY)) <0)
{
printf("please prepare a wpa_supplicant run script\n");
return -1;
}
close(fd_wifi_script);
con_wifi = malloc(sizeof(struct p_connect));
cur_wifi = malloc(sizeof(struct p_curwifi));
wifi_list_head = malloc(sizeof(struct p_wifi_list));
wifi_list_head->next = NULL;
operstate_fd =open("/sys/class/net/wlan0/operstate", O_RDONLY);
if(operstate_fd <0)
{
printf("open operstate fd fail\n");
return -1;
}
bzero(cur_wifi, sizeof(struct p_curwifi));
get_curwifi_info(cur_wifi, operstate_fd);
printf("[test] curwifi ssid:%s\n", cur_wifi->ESSID);
printf("[test] curwifi Singal:%d\n", cur_wifi->Singal);
printf("[test] curwifi link:%d\n", cur_wifi->link);
close(operstate_fd);
bzero(wifi_list_head, sizeof(struct p_wifi_list));
// get_wifi_list(wifi_list_head);
// show_list(wifi_list_head);
int flag=0,run=1, mode=0;
char *IP;
#if 0
ioctl(pperipheral_fd,WIFIPOWERON_CMD,0);
ioctl(pperipheral_fd,GPRSPOWERDOWN_CMD,0);
unlink_wifi();
close_udhcpc();
sleep(1);
link_wifi(con_wifi, 0);
sleep(1);
open_udhcpc();
bzero(cur_wifi, sizeof(struct p_curwifi));
get_curwifi_info(cur_wifi);
printf("[test] curwifi ssid:%s\n", cur_wifi->ESSID);
printf("[test] curwifi Singal:%d\n", cur_wifi->Singal);
printf("[test] curwifi link:%d\n", cur_wifi->link);
#endif
#if 0
usage();
while(run)
{
scanf("%d", &flag);
switch (flag)
{
case 1:
#if 0
printf("please input mode & account & password\n");
printf("flag:");
scanf("%d", &mode);
if(mode == WITH_ACCOUNT)
{
printf("account:");
scanf("%s", con_wifi->essid);
printf("password:");
scanf("%s", con_wifi->password_wifi);
}
#endif
printf("go...\n");
link_wifi(con_wifi, mode); //在链接之前先做unlink清除上下文
break;
case 2:
unlink_wifi();
break;
case 4:
run = 0;
break;
default :
break;
}
}
free(con_wifi);
free(cur_wifi);
q = wifi_list_head;
while(q !=NULL)
{
free(q);
q = q->next;
}
#endif
return 0;
}
void show_list(struct p_wifi_list *wifi_list_head)
{
struct p_wifi_list *q = wifi_list_head->next;
printf("\n========================================================================\n");
while(q !=NULL)
{
printf("\t[test] list ssid:%s\n", q->ESSID);
printf("\t[test] list Singal:%d\n", q->Singal);
q = q->next;
}
printf("========================================================================\n");
}