blob: fd53f253e58634487952fd5c20b30e708d621795 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <stdbool.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <unistd.h>
8#include <sys/types.h>
9#include <sys/time.h>
10#include <getopt.h>
11#include <time.h>
12#include <wifi_msg.h>
13#include "softap_api.h"
14#include <wifi_util.h>
15
16
17#include "wifi_util.h"
18/*
19static char * g_short_string = "u:b:s:d:h";
20
21static struct option g_long_options[] = {
22 {"upgrade", required_argument, NULL, 'u'},
23 {"boot", required_argument, NULL, 'b'},
24 {"status", required_argument, NULL, 's'},
25 {"debug", required_argument, NULL, 'd'},
26 {"help", no_argument, NULL, 'h'},
27};
28
29static option_handle_t g_option_handle[] = {
30 {'u', excute_command_upgrade},
31 {'b', excute_command_boot},
32 {'s', excute_command_status},
33 {'d', excute_command_debug},
34 {'h', excute_command_help}
35};
36
37*/
38
39int msg_queue_id = 0;
40
41
42void usage (void)
43{
44 printf ("cmd list: "
45 " open open wifi\n"
46 " close close wifi\n"
47 " results display the scan results\n"
48 " mmi display scan list to simulate watch mmi\n"
49 " help dispaly this message\n"
50 " scan send scan cmd\n"
51 " conn connect the ap specified by the index of scan list ,and need input the password\n"
52 " forget disconnect and forget the ap\n"
53 " dump dump the content of the global variable in wlan_manager\n"
54 " cmd you can send a wpa_supplicant cmd directly\n");
55}
56
57wlan_mac_info_list g_mac_list;
58
59static void process_msg(MSG_BUF *pMsg)
60{
61 switch (pMsg->usMsgCmd) {
62 case MSG_CMD_WIFI_SET_ON_RSP:
63 {
64 printf("MSG_CMD_WIFI_SET_ON_RSP\n");
65 break;
66 }
67 case MSG_CMD_WIFI_SET_OFF_RSP:
68 {
69 printf("MSG_CMD_WIFI_SET_OFF_RSP\n");
70 break;
71 }
72
73 case MSG_CMD_WIFI_SET_SECURITY_RSP:
74 {
75 printf("MSG_CMD_WIFI_SET_SECURITY_RSP\n");
76
77 break;
78 }
79
80 case MSG_CMD_WIFI_GET_USER_LIST_RSP:
81 {
82 wlan_mac_info_list *list = (wlan_mac_info_list*)pMsg->aucDataBuf;
83 printf("MSG_CMD_WIFI_GET_USER_LIST_RSP\n");
84 printf("hostname=%s,mac=%s",list->mac_info[0].hostname,list->mac_info[0].mac );
85 memcpy(&g_mac_list, &pMsg->aucDataBuf, sizeof(wlan_mac_info_list));
86 break;
87 }
88
89 case MSG_CMD_WIFI_GET_STATE_RSP:
90 {
91 printf("MSG_CMD_WIFI_GET_STATE_RSP\n");
92 break;
93 }
94 case MSG_CMD_WIFI_GET_INFO_RSP:
95 {
96 printf("MSG_CMD_WIFI_GET_INFO_RSP\n");
97 break;
98 }
99 default:
100 break;
101 }
102
103}
104
105void dump_spot_list()
106{
107 int i = 0;
108 printf("%-8s%-32s%-20s\n","id","hostname","mac");
109 for(i = 0; i< g_mac_list.access_count; i++){
110 wlan_mac_info *info = &g_mac_list.mac_info[i];
111 printf("%-8d%-32s%-20s\n",i, info->hostname, info->mac);
112 }
113}
114
115int mmi_display_loop = 0;
116
117
118
119static void *mmi_loop (void *param)
120{
121 MSG_BUF wlanMsg ={0};
122 char name[32] = {0};
123 int ret = -1;
124
125 strcpy (name, (char*) param);
126 prctl (PR_SET_NAME, name, 0, 0, 0);
127
128 while (1) {
129 if(0 == mmi_display_loop)break;
130 dump_spot_list();
131 sleep(1);
132 printf("\033[2J");//clear screen
133 printf("\033[0;0H");//locate cursor to head
134 }
135
136 return NULL;
137}
138void mmi_display()
139{
140 mmi_display_loop = 1;
141
142 wf_create_thread ("mmi_loop", mmi_loop);
143
144 while(1){
145 char cmd;
146 scanf("%c", &cmd);
147 if(cmd == 'q'){
148 mmi_display_loop = 0;
149 break;
150 }
151 }
152
153 return;
154}
155
156static void *station_loop (void *param)
157{
158 MSG_BUF wlanMsg ={0};
159 char name[32] = {0};
160 int ret = -1;
161
162 strcpy (name, (char*) param);
163 prctl (PR_SET_NAME, name, 0, 0, 0);
164
165 while (1) {
166 memset (&wlanMsg, 0, sizeof (MSG_BUF));
167 ret = msgrcv (msg_queue_id, &wlanMsg, sizeof (MSG_BUF) - sizeof (LONG), 0, 0);
168 if (ret == -1) {
169 continue;
170 }
171 process_msg (&wlanMsg);
172
173 }
174
175 return NULL;
176}
177
178
179int main (int argc, char *argv[])
180{
181 int c=0;
182 int iRet = -1;
183 char cmd[128]={0};
184
185 msg_queue_id = wf_create_msg_qid (MODULE_ID_WLAN_SERVER);
186 wf_create_thread ("ap-mmi", station_loop);
187 printf("rda_ap_mmi v1.0\n"
188 "please use results, conn, disc three cmd to control it\n\n");
189
190 for (;;) {
191
192 printf(">>");
193 scanf("%s", cmd);
194
195 if(!strcmp(cmd, "open")){
196 wf_msg_to_self(MSG_CMD_WIFI_SET_ON_REQ, 0, NULL);
197 }
198 else if(!strcmp(cmd, "close")){
199 wf_msg_to_self(MSG_CMD_WIFI_SET_OFF_REQ, 0, NULL);
200 }
201 else if(!strcmp(cmd, "auth")){
202 wlan_basic_info wbi={0};
203 printf("ssid=");
204 scanf("%s", wbi.ssid);
205 printf("authmode=");
206 scanf("%s", wbi.authmode);
207 printf("pwd=");
208 scanf("%s", wbi.pwd);
209
210 wf_msg_to_self(MSG_CMD_WIFI_SET_SECURITY_REQ, sizeof(wlan_basic_info), &wbi);
211 }
212 else if(!strcmp(cmd, "list")){
213 wf_msg_to_self(MSG_CMD_WIFI_GET_USER_LIST_REQ, 0, NULL);
214 }
215
216 else if(!strcmp(cmd, "mmi")){
217 mmi_display();
218 }
219 else if(!strcmp(cmd, "help")){
220 usage();
221 }
222 else if(!strcmp(cmd, "exit") || !strcmp(cmd, "q")){
223 exit(0);
224 }
225
226 printf("done\n");
227 }
228
229
230 return 0;
231}