blob: 8d6a88a0ebb26cd6dac61341960d77435f464cf6 [file] [log] [blame]
liuyangf01f2772024-10-18 16:33:46 +08001#include <string.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <pthread.h>
5#include <unistd.h>
6#include <sys/epoll.h>
7#include <errno.h>
8#include <sys/wait.h>
9#include <sys/types.h>
10
11#include "wpa_ctrl.h"
12#include "sta_ctrl.h"
liuyang09c3d7a2024-10-25 10:56:51 +080013#include "mbtk_log.h"
b.liu9e8584b2024-11-06 19:21:28 +080014#include "mbtk_utils.h"
liuyang09c3d7a2024-10-25 10:56:51 +080015
liuyangf01f2772024-10-18 16:33:46 +080016//#include "sta_log.h"
17
18#define WPA_SUPPLICANT_LOG_FILE "/data/wpa_supplicant.log"
19
20static void
21sta_ctrl_wpa_req_cb(char *msg, size_t len);
22
23static void*
24sta_ctrl_event_thread_run( void *arg );
25
26static sta_err_enum
27sta_ctrl_close_connection(void);
28
29static sta_err_enum
30sta_ctrl_open_connection(void);
31
32static sta_err_enum
33sta_ctrl_reconnect(void);
34
35static void
36sta_ctrl_recv_event(void);
37
38static sta_err_enum
39sta_ctrl_conf_file_parse
40(
41 const char *key,
42 char *value
43);
44
b.liu9e8584b2024-11-06 19:21:28 +080045// extern struct wpa_ctrl;
liuyangf01f2772024-10-18 16:33:46 +080046
47static struct wpa_ctrl *sta_ctrl_conn;
48static struct wpa_ctrl *sta_mon_conn;
49static int sta_ctrl_attached = 0;
b.liudeb8e422024-12-14 17:36:56 +080050static pthread_t sta_event_thread_id;
liuyangf01f2772024-10-18 16:33:46 +080051static int sta_event_thread_is_running = 0;
52static char sta_ctrl_conf_file_path[50];
53static char sta_ctrl_ifname[10];
54static sta_ctrl_msg_cb sta_ctrl_msg = NULL;
55static int sta_ctrl_pipe_fd[2];
56
57static void
58sta_ctrl_wpa_req_cb(char *msg, size_t len)
59{
liuyang09c3d7a2024-10-25 10:56:51 +080060 LOGE("%s\n", msg);
liuyangf01f2772024-10-18 16:33:46 +080061}
62
63bool
64sta_ctrl_system
65(
66 const char *command
67)
68{
69 int result = TRUE;
70 FILE *stream = NULL;
71
liuyang09c3d7a2024-10-25 10:56:51 +080072 LOGE("system call: %s\n", command);
liuyangf01f2772024-10-18 16:33:46 +080073
74 stream = popen( command, "w" );
75 if( stream == NULL )
76 {
liuyang09c3d7a2024-10-25 10:56:51 +080077 LOGE("system command failed\n");
liuyangf01f2772024-10-18 16:33:46 +080078 result = FALSE;
79 }
80 else if( 0 > pclose( stream ) )
81 {
liuyang09c3d7a2024-10-25 10:56:51 +080082 LOGE("pclose command failed\n");
liuyangf01f2772024-10-18 16:33:46 +080083 }
84
85 return result;
86}
87
88/*
89* Return TRUE if process <name> is not running after 2 second.
90*/
91bool
92sta_ctrl_kill_check(const char *name)
93{
94#define PROCESS_KILL_RETRY 40
95 bool result;
96 int tmp = 0;
97 FILE *cmd;
98 char pid_s[STA_BUF_SIZE];
99 int pid;
100 tmp = snprintf(pid_s,STA_BUF_SIZE,
101 "pidof %s",name);
102 pid_s[tmp] = '\0';
103 tmp = 0;
104 while (tmp++ < PROCESS_KILL_RETRY)
105 {
106 usleep(50000);/*50 mili second*/
107 cmd = popen(pid_s, "r");
108 pid = 0;
109 bzero(pid_s, STA_BUF_SIZE);
110 if(cmd)
111 {
b.liu9e8584b2024-11-06 19:21:28 +0800112 if(fgets(pid_s, STA_BUF_SIZE, cmd) == NULL) {
113
114 }
liuyangf01f2772024-10-18 16:33:46 +0800115 pclose(cmd);
116 }
b.liu9e8584b2024-11-06 19:21:28 +0800117
liuyangf01f2772024-10-18 16:33:46 +0800118 pid = atoi(pid_s);
liuyang09c3d7a2024-10-25 10:56:51 +0800119 LOGE("%s pid =%d\n", name,pid);
liuyangf01f2772024-10-18 16:33:46 +0800120 /* If pid is zero we break from while*/
121 if(pid == 0)
122 {
123 result = TRUE;
124 goto exit_end;
125 }
126 }
127
liuyang09c3d7a2024-10-25 10:56:51 +0800128 LOGE("PID still running after waiting 2 second.\n");
liuyangf01f2772024-10-18 16:33:46 +0800129 result = FALSE;
130exit_end:
131#undef PROCESS_KILL_RETRY
132 return result;
133}
134
135/*
136* Return TRUE if process <name> is running.
137*/
138bool
139sta_ctrl_process_running(const char *name)
140{
141 char pid_s[STA_BUF_SIZE];
142 int tmp = snprintf(pid_s,STA_BUF_SIZE,
143 "pidof %s",name);
144 pid_s[tmp] = '\0';
145 FILE *cmd = popen(pid_s, "r");
146 bzero(pid_s, STA_BUF_SIZE);
147 if(cmd)
148 {
b.liu9e8584b2024-11-06 19:21:28 +0800149 if(fgets(pid_s, STA_BUF_SIZE, cmd) == NULL) {
150
151 }
liuyangf01f2772024-10-18 16:33:46 +0800152 pclose(cmd);
153 }
154
155 int pid = atoi(pid_s);
liuyang09c3d7a2024-10-25 10:56:51 +0800156 LOGE("%s pid =%d\n", name,pid);
liuyangf01f2772024-10-18 16:33:46 +0800157 /* If pid is zero we break from while*/
158 if(pid == 0)
159 {
liuyang09c3d7a2024-10-25 10:56:51 +0800160 LOGE("%s not runnig.\n",name);
liuyangf01f2772024-10-18 16:33:46 +0800161 return FALSE;
162 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800163 LOGE("%s is runnig.\n",name);
liuyangf01f2772024-10-18 16:33:46 +0800164 return TRUE;
165 }
166}
167
168
169static void*
170sta_ctrl_event_thread_run( void *arg )
171{
liuyang09c3d7a2024-10-25 10:56:51 +0800172 LOGE("Thread[%ld] run().\n",pthread_self());
liuyangf01f2772024-10-18 16:33:46 +0800173
b.liu9e8584b2024-11-06 19:21:28 +0800174 int nready = 0;
liuyangf01f2772024-10-18 16:33:46 +0800175 struct epoll_event ev_sock,ev_pipe,events[20];
176 int epfd = epoll_create(256);
177 ev_sock.data.fd = wpa_ctrl_get_fd(sta_mon_conn);
178 ev_sock.events = EPOLLIN | EPOLLET;
179 epoll_ctl(epfd,EPOLL_CTL_ADD,wpa_ctrl_get_fd(sta_mon_conn),&ev_sock);
180
181 ev_pipe.data.fd = sta_ctrl_pipe_fd[0];
182 ev_pipe.events = EPOLLIN | EPOLLET;
183 epoll_ctl(epfd,EPOLL_CTL_ADD,sta_ctrl_pipe_fd[0],&ev_pipe);
184
185 for ( ; ; ) {
186 if(!sta_event_thread_is_running){
187 break;
188 }
liuyang09c3d7a2024-10-25 10:56:51 +0800189 LOGE("epoll_wait waitting...\n",nready);
liuyangf01f2772024-10-18 16:33:46 +0800190 nready = epoll_wait(epfd,events,20,-1);
liuyang09c3d7a2024-10-25 10:56:51 +0800191 LOGE("epoll_wait return.(count = %d)\n",nready);
liuyangf01f2772024-10-18 16:33:46 +0800192 int i;
193 for(i=0;i<nready;++i) {
194 if (events[i].events & EPOLLIN) {// Read
195 if (events[i].data.fd < 0)
196 continue;
197
198 if(sta_mon_conn // sta_mon_conn can not be NULL
199 && events[i].data.fd == wpa_ctrl_get_fd(sta_mon_conn)){
200 sta_ctrl_recv_event();
201 }else if(events[i].data.fd == sta_ctrl_pipe_fd[0]){
liuyang09c3d7a2024-10-25 10:56:51 +0800202 LOGE("Thread end.[fd = %d]\n",events[i].data.fd);
liuyangf01f2772024-10-18 16:33:46 +0800203 // End thread
204 char buf_end[10] = {0};
205 if(read(sta_ctrl_pipe_fd[0],buf_end,10) > 0
206 && strcmp(buf_end,"0") == 0){
207 sta_event_thread_is_running = 0;
208 break;
209 }
210 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800211 LOGE("No such fd[%d].\n",events[i].data.fd);
liuyangf01f2772024-10-18 16:33:46 +0800212 }
213 } else {
liuyang09c3d7a2024-10-25 10:56:51 +0800214 LOGE("event error.\n");
liuyangf01f2772024-10-18 16:33:46 +0800215 }
216 }
217 }
218
219 close(epfd);
liuyang09c3d7a2024-10-25 10:56:51 +0800220 LOGE("Thread exit.\n");
liuyangf01f2772024-10-18 16:33:46 +0800221 return ((void*)0);
222}
223
224static sta_err_enum
225sta_ctrl_close_connection(void)
226{
liuyang09c3d7a2024-10-25 10:56:51 +0800227 LOGE("start.\n");
liuyangf01f2772024-10-18 16:33:46 +0800228 if (sta_ctrl_conn == NULL)
229 return STA_ERR_UNKNOWN;
230
231 if (sta_ctrl_attached) {
232 wpa_ctrl_detach(sta_mon_conn);
233 sta_ctrl_attached = 0;
234 }
235 wpa_ctrl_close(sta_ctrl_conn);
236 sta_ctrl_conn = NULL;
237 if (sta_mon_conn) {
238 wpa_ctrl_close(sta_mon_conn);
239 sta_mon_conn = NULL;
240 }
241
liuyang09c3d7a2024-10-25 10:56:51 +0800242 LOGE("end.\n");
liuyangf01f2772024-10-18 16:33:46 +0800243 return STA_ERR_SUCCESS;
244}
245
246static sta_err_enum
247sta_ctrl_open_connection(void)
248{
249 sta_err_enum result = STA_ERR_SUCCESS;
250
251 if(sta_ctrl_conn){
252 return STA_ERR_UNKNOWN;
253 }
254
255 char ctrl_path[100] = {0};
256 result = sta_ctrl_conf_file_parse("ctrl_interface", ctrl_path);
257 if(STA_ERR_SUCCESS != result){
liuyang09c3d7a2024-10-25 10:56:51 +0800258 LOGE("sta_ctrl_conf_file_parse() fail(%d).\n",result);
liuyangf01f2772024-10-18 16:33:46 +0800259 return result;
260 }
b.liu9e8584b2024-11-06 19:21:28 +0800261 sprintf(ctrl_path + strlen(ctrl_path),
liuyangf01f2772024-10-18 16:33:46 +0800262 "/%s",
263 sta_ctrl_ifname);
264
liuyang09c3d7a2024-10-25 10:56:51 +0800265 LOGE("ctrl_path = \"%s\"\n",ctrl_path);
liuyangf01f2772024-10-18 16:33:46 +0800266
267 sta_ctrl_conn = wpa_ctrl_open(ctrl_path);
268 if (sta_ctrl_conn == NULL) {
269 sleep(1);
270 return sta_ctrl_open_connection();
271 }
272
273 sta_mon_conn = wpa_ctrl_open(ctrl_path);
274 if (sta_mon_conn == NULL) {
275 return STA_ERR_UNKNOWN;
276 }
277
278 if (wpa_ctrl_attach(sta_mon_conn) == 0) {
279 sta_ctrl_attached = 1;
280 } else {
liuyang09c3d7a2024-10-25 10:56:51 +0800281 LOGE("Warning: Failed to attach to "
liuyangf01f2772024-10-18 16:33:46 +0800282 "wpa_supplicant.\n");
283 sta_ctrl_close_connection();
284 return STA_ERR_UNKNOWN;
285 }
286
287 if(!sta_event_thread_is_running) {
288 sta_event_thread_is_running = 1;
289 int ret = pthread_create(&sta_event_thread_id,
290 NULL,
291 sta_ctrl_event_thread_run,
292 NULL);
293 if( ret != 0 ) {
liuyang09c3d7a2024-10-25 10:56:51 +0800294 LOGE( "Create thread error!\n");
liuyangf01f2772024-10-18 16:33:46 +0800295 }
296 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800297 LOGE("sta_event_thread is running.\n");
liuyangf01f2772024-10-18 16:33:46 +0800298 return STA_ERR_UNKNOWN;
299 }
300 return result;
301}
302
303static sta_err_enum
304sta_ctrl_reconnect(void)
305{
306 if(STA_ERR_SUCCESS == sta_ctrl_close_connection()){
307 return sta_ctrl_open_connection();
308 }else{
309 return STA_ERR_UNKNOWN;
310 }
311}
312
313static void
314sta_ctrl_recv_event(void)
315{
liuyang09c3d7a2024-10-25 10:56:51 +0800316 LOGE("start.\n");
liuyangf01f2772024-10-18 16:33:46 +0800317 if (sta_ctrl_conn == NULL) {
318 sta_ctrl_reconnect();
liuyang09c3d7a2024-10-25 10:56:51 +0800319 LOGE("sta_ctrl_conn == NULL:end.\n");
liuyangf01f2772024-10-18 16:33:46 +0800320 return;
321 }
322
323 while (wpa_ctrl_pending(sta_mon_conn) > 0) {
324 char buf[4096];
325 size_t len = sizeof(buf) - 1;
326 if (wpa_ctrl_recv(sta_mon_conn, buf, &len) == 0) {
327 buf[len] = '\0';
liuyang09c3d7a2024-10-25 10:56:51 +0800328 LOGE("<<%s>>\n",buf);
liuyangf01f2772024-10-18 16:33:46 +0800329 if(sta_ctrl_msg)
330 sta_ctrl_msg(buf);
331 } else {
liuyang09c3d7a2024-10-25 10:56:51 +0800332 LOGE("Could not read pending message.\n");
liuyangf01f2772024-10-18 16:33:46 +0800333 break;
334 }
335 }
336
337 if (wpa_ctrl_pending(sta_mon_conn) < 0) {
liuyang09c3d7a2024-10-25 10:56:51 +0800338 LOGE("Connection to wpa_supplicant lost - trying to "
liuyangf01f2772024-10-18 16:33:46 +0800339 "reconnect\n");
340 sta_ctrl_reconnect();
341 }
342
liuyang09c3d7a2024-10-25 10:56:51 +0800343 LOGE("end.\n");
liuyangf01f2772024-10-18 16:33:46 +0800344}
345
346static sta_err_enum
347sta_ctrl_conf_file_parse
348(
349 const char *key,
350 char *value
351)
352{
353 sta_err_enum result = STA_ERR_UNKNOWN;
354 FILE *fd = fopen(sta_ctrl_conf_file_path,"r");
355 if(!fd){
liuyang09c3d7a2024-10-25 10:56:51 +0800356 LOGE("Open file(%s) fail(%d).\n",sta_ctrl_conf_file_path,errno);
liuyangf01f2772024-10-18 16:33:46 +0800357 return STA_ERR_UNKNOWN;
358 }
359
360 char buf[1024];
361 while(fgets(buf,1024,fd)){
362 char *start = strstr(buf,key);
363 if(start){ // Find key
364 char *tmp = start + strlen(start) -1;
365 while(*tmp){
366 if(*tmp == '\r'
367 || *tmp == '\n'){
368 *tmp = '\0';
369 }else{
370 break;
371 }
b.liu9e8584b2024-11-06 19:21:28 +0800372 tmp--;
liuyangf01f2772024-10-18 16:33:46 +0800373 }
374
375 int size = snprintf(value,100,
376 "%s",
377 start + strlen(key) + 1);
378 value[size] = '\0';
379 result = STA_ERR_SUCCESS;
380 break;
381 }
382 }
383
384 fclose(fd);
385
386 return result;
387}
388
389/***************************************************************/
390/************************ Public Fuction ***********************/
391/***************************************************************/
392sta_err_enum
393sta_ctrl_cmd_process
394(
395 const char *cmd,
396 char *reply,
397 size_t reply_len
398)
399{
400 sta_err_enum result = STA_ERR_SUCCESS;
401 bzero(reply,reply_len);
402 reply_len = reply_len - 1;
403 int ret = wpa_ctrl_request(sta_ctrl_conn,
404 cmd,
405 strlen(cmd),
406 reply,
407 &reply_len,
408 sta_ctrl_wpa_req_cb);
409 if (ret == -2) {
liuyang09c3d7a2024-10-25 10:56:51 +0800410 LOGE("command timed out.\n");
liuyangf01f2772024-10-18 16:33:46 +0800411 result = STA_ERR_TIMEOUT;
412 goto end_fail;
413 } else if (ret < 0) {
liuyang09c3d7a2024-10-25 10:56:51 +0800414 LOGE("command failed.\n");
liuyangf01f2772024-10-18 16:33:46 +0800415 result = STA_ERR_UNKNOWN;
416 goto end_fail;
417 } else {
418 reply[reply_len] = '\0';
liuyang09c3d7a2024-10-25 10:56:51 +0800419 LOGE("1:%s\n", reply);
liuyangf01f2772024-10-18 16:33:46 +0800420
421 if(reply_len > 0 && reply[reply_len - 1] != '\n')
liuyang09c3d7a2024-10-25 10:56:51 +0800422 LOGE("\n");
liuyangf01f2772024-10-18 16:33:46 +0800423 }
424
b.liu9e8584b2024-11-06 19:21:28 +0800425//end_success:
liuyangf01f2772024-10-18 16:33:46 +0800426
427 return result;
428end_fail:
429
430 return result;
431}
432
433/**
434* Open or close wlan driver.
435*/
436sta_err_enum
437sta_ctrl_driver_init(bool open)
438{
439 sta_err_enum result = STA_ERR_SUCCESS;
440
441 FILE *fd_tmp = NULL;
442 if(open){
443 fd_tmp = popen("/etc/wifi/mbtk_wifi_driver.sh sta start","r");
444 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800445 fd_tmp = popen("/etc/wifi/mbtk_wifi_driver.sh sta stop","r");
liuyangf01f2772024-10-18 16:33:46 +0800446 }
447
448 if(fd_tmp){
449 char buf[200] = {0};
b.liu9e8584b2024-11-06 19:21:28 +0800450 if(fgets(buf,200,fd_tmp) == NULL) {
451
452 }
liuyangf01f2772024-10-18 16:33:46 +0800453 pclose(fd_tmp);
454 if(strlen(buf) > 0){
liuyang09c3d7a2024-10-25 10:56:51 +0800455 LOGE("Driver %s fail.(%s)\n",(open?"open":"close"),buf);
liuyangf01f2772024-10-18 16:33:46 +0800456 result = STA_ERR_DRIVER;
457 }else{// Open wpa_supplicant
liuyang09c3d7a2024-10-25 10:56:51 +0800458 LOGE("Driver %s success.\n",(open?"open":"close"));
liuyangf01f2772024-10-18 16:33:46 +0800459 }
460 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800461 LOGE("Driver %s fail.(%s)\n",(open?"open":"close"));
liuyangf01f2772024-10-18 16:33:46 +0800462 result = STA_ERR_DRIVER;
463 }
464
465 return result;
466}
467
468sta_err_enum
469sta_ctrl_wpa_init
470(
471 const char *conf_file,
472 const char *interface,
473 sta_ctrl_msg_cb cb
474)
475{
476 sta_err_enum result = STA_ERR_SUCCESS;
477 if(!conf_file
478 || strlen(conf_file) == 0){
479 result = STA_ERR_UNKNOWN;
480 goto end_fail;
481 }
482
483 if(!interface
484 || strlen(interface) == 0){
485 result = STA_ERR_UNKNOWN;
486 goto end_fail;
487 }
488
489 sta_ctrl_msg = cb;
490
491 int size = snprintf(sta_ctrl_conf_file_path,
492 50,
493 "%s",
494 conf_file);
495 sta_ctrl_conf_file_path[size] = '\0';
496 size = snprintf(sta_ctrl_ifname,
497 10,
498 "%s",
499 interface);
500 sta_ctrl_ifname[size] = '\0';
501
502 if(pipe(sta_ctrl_pipe_fd)){
liuyang09c3d7a2024-10-25 10:56:51 +0800503 LOGE("pipe() fail(%d).\n",errno);
liuyangf01f2772024-10-18 16:33:46 +0800504 result = STA_ERR_UNKNOWN;
505 goto end_fail;
506 }
507
508 FILE *fd_tmp = popen("pidof wpa_supplicant","r");
509 if(fd_tmp){
510 char buf[200] = {0};
b.liu9e8584b2024-11-06 19:21:28 +0800511 if(fgets(buf,200,fd_tmp) == NULL) {
512
513 }
liuyangf01f2772024-10-18 16:33:46 +0800514 pclose(fd_tmp);
515 if(strlen(buf) > 0){
liuyang09c3d7a2024-10-25 10:56:51 +0800516 LOGE("wpa_supplicant is running.(%s)\n",buf);
liuyangf01f2772024-10-18 16:33:46 +0800517 }else{// Open wpa_supplicant
518 bzero(buf,200);
b.liu9e8584b2024-11-06 19:21:28 +0800519
liuyangf01f2772024-10-18 16:33:46 +0800520 snprintf(buf,200,
521 "wpa_supplicant -Dnl80211 -c%s -i%s -f%s -ddd &",
522 conf_file,
523 interface,
524 WPA_SUPPLICANT_LOG_FILE);
b.liu9e8584b2024-11-06 19:21:28 +0800525
liuyangf01f2772024-10-18 16:33:46 +0800526 /*
527 snprintf(buf,200,
528 "wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wifi/wpa_supplicant.conf -B");
529 */
530 if (sta_ctrl_system(buf)){
liuyang09c3d7a2024-10-25 10:56:51 +0800531 LOGE("\"%s\" success.\n",buf);
liuyangf01f2772024-10-18 16:33:46 +0800532 sleep(1);
533 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800534 LOGE("\"%s\" fail.\n",buf);
liuyangf01f2772024-10-18 16:33:46 +0800535 result = STA_ERR_UNKNOWN;
536 goto end_fail;
537 }
538 }
539 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800540 LOGE("\"pidof wpa_supplicant\" fail\n");
liuyangf01f2772024-10-18 16:33:46 +0800541 result = STA_ERR_UNKNOWN;
542 goto end_fail;
543 }
544
545 result = sta_ctrl_open_connection();
546 if(STA_ERR_SUCCESS != result) {
liuyang09c3d7a2024-10-25 10:56:51 +0800547 LOGE("sta_ctrl_open_connection() fail(%d).\n",result);
liuyangf01f2772024-10-18 16:33:46 +0800548 goto end_fail;
549 }
550
b.liu9e8584b2024-11-06 19:21:28 +0800551//end_success:
liuyangf01f2772024-10-18 16:33:46 +0800552
553 return result;
554end_fail:
555
556 return result;
557}
558
559sta_err_enum
560sta_ctrl_wpa_deinit
561(
562 void
563)
564{
565 sta_err_enum result = STA_ERR_SUCCESS;
566 result = sta_ctrl_close_connection();
567 if(STA_ERR_SUCCESS != result){
568 goto end_fail;
569 }
570
571 bzero(sta_ctrl_conf_file_path,50);
572 bzero(sta_ctrl_ifname,10);
573
574 sta_event_thread_is_running = 0;
575 // End thread.
b.liu9e8584b2024-11-06 19:21:28 +0800576 mbtk_write(sta_ctrl_pipe_fd[1],"0",1);
liuyangf01f2772024-10-18 16:33:46 +0800577
578
liuyang09c3d7a2024-10-25 10:56:51 +0800579 LOGE("Waitting for thread(%ld) exit.\n",sta_event_thread_id);
liuyangf01f2772024-10-18 16:33:46 +0800580
581 pthread_join(sta_event_thread_id,NULL);
582
liuyang09c3d7a2024-10-25 10:56:51 +0800583 LOGE("pthread_join() return.\n");
liuyangf01f2772024-10-18 16:33:46 +0800584
585
586 close(sta_ctrl_pipe_fd[0]);
587 close(sta_ctrl_pipe_fd[1]);
588
liuyangf01f2772024-10-18 16:33:46 +0800589 sta_ctrl_msg = NULL;
590
591 // Stop process wpa_supplicant
592 if(sta_ctrl_system("killall -15 wpa_supplicant")
593 && sta_ctrl_kill_check("wpa_supplicant")){
liuyang09c3d7a2024-10-25 10:56:51 +0800594 LOGE("\"killall -15 wpa_supplicant\" success.\n");
liuyangf01f2772024-10-18 16:33:46 +0800595 }else{
596 if(sta_ctrl_system("killall -9 wpa_supplicant")){
liuyang09c3d7a2024-10-25 10:56:51 +0800597 LOGE("\"killall -9 wpa_supplicant\" success.\n");
liuyangf01f2772024-10-18 16:33:46 +0800598 }else{
liuyang09c3d7a2024-10-25 10:56:51 +0800599 LOGE("\"killall -9 wpa_supplicant\" fail.\n");
liuyangf01f2772024-10-18 16:33:46 +0800600 }
601 }
602
b.liu9e8584b2024-11-06 19:21:28 +0800603//end_success:
liuyang09c3d7a2024-10-25 10:56:51 +0800604 LOGE("sta_ctrl_wpa_deinit() end(success).\n");
liuyangf01f2772024-10-18 16:33:46 +0800605 return result;
606end_fail:
liuyang09c3d7a2024-10-25 10:56:51 +0800607 LOGE("sta_ctrl_wpa_deinit() end(fail)[%s].\n",result);
liuyangf01f2772024-10-18 16:33:46 +0800608 return result;
609}
610