lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /*
|
| 2 | * wlan-station.c -- wifi station mode Deal module
|
| 3 | *
|
| 4 | * Copyright (c) ZTE Corporation All Rights Reserved.
|
| 5 | *
|
| 6 | * $Id: wlan-station.c, v 0.1 2015-03-09 $
|
| 7 | * Authors : XUJIAN - xu.jian5@zte.com.cn>
|
| 8 | */
|
| 9 | #include "wifi_util.h"
|
| 10 | #include "wlan-station.h"
|
| 11 | #include "Vector.h"
|
| 12 | #include "wifi_sta_ctrl.h"
|
| 13 | #include "soft_timer.h"
|
| 14 | #include "rtk_arch.h"
|
| 15 | #include <semaphore.h>
|
| 16 | #include <limits.h>
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 17 | //#include <sys/socket.h>
|
| 18 | //#include <netinet/in.h>
|
| 19 | #include <arpa/inet.h>
|
| 20 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 21 | #define SUCCESS "1"
|
| 22 | #define FAILED "0"
|
| 23 | #define REPLY_BUF_SIZE 4096 // wpa_supplicant's maximum size.
|
| 24 |
|
| 25 | #define UEVENT_BUFFER_SIZE 1024*2
|
| 26 |
|
| 27 | #define WIFI_STATION_CMD_LEN 256
|
| 28 |
|
| 29 | //¶¨Ê±Æ÷Ïà¹Ø
|
| 30 | #define WIFI_STATION_TIMER_CONNECT 109
|
| 31 | #define WIFI_STATION_TIMER_GET_STATUS 110
|
| 32 | #define WIFI_STATION_TIMER_SCAN 111
|
| 33 | //add sim card init status query timer
|
| 34 | #define WIFI_STATION_TIMER_SIM_CARD_STATUS 112
|
| 35 | #define WIFI_STATION_TIMER_GET_SCAN_RESULTS 113
|
| 36 |
|
| 37 | #define WIFI_STATION_TIMER_CONNECT_INTERVAL 1000
|
| 38 | #define WIFI_STATION_TIMER_GET_STATUS_INTERVAL 2000
|
| 39 | #define WIFI_STATION_TIMER_SCAN_INTERVAL 60000 /// 10 ----> 15s nxl
|
| 40 |
|
| 41 | #define WIFI_STATION_TIMER_GET_SCAN_RESULTS_INTERVAL 8000 /// 10 ----> 15s nxl
|
| 42 |
|
| 43 |
|
| 44 | #define WIFI_STATION_TIMER_SIM_CARD_STATUS_INTERVAL 2000
|
| 45 |
|
| 46 | #define WIFI_STATION_TIMER_WAIT_CONNECT_COUNT 20
|
| 47 | #define WIFI_STATION_TIMER_CONNECT_TIME_OUT 116
|
| 48 |
|
| 49 | //ɨÃèÏà¹Ø
|
| 50 | #define WIFI_STATION_SCAN_DURATION 8
|
| 51 | #define WIFI_STATION_SCRIPT_RSP_LINE_LEN 1024
|
| 52 | #define WIFI_STATION_SCAN_RESULT_STR_LEN 1024
|
| 53 | #define WIFI_STATION_SCAN_ONE_RESULT_STR_LEN 256
|
| 54 | #define WIFI_STATION_SCAN_RESULT_LIST_NUM 60//Ò»°ãʵ¼Ê¹Ì¼þÄÜɨ³öÀ´30¼¸¸ö£¬ÏµÍ³ÄÜ´æ´¢µÄɨÃè½á¹û×î¶à²»³¬¹ý2048¸ö×Ö½Ú
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 | #define WIFI_STATION_SIGNAL_LEVEL1 -80
|
| 61 | #define WIFI_STATION_SIGNAL_LEVEL2 -78
|
| 62 | #define WIFI_STATION_SIGNAL_LEVEL3 -75
|
| 63 | #define WIFI_STATION_SIGNAL_LEVEL4 -72
|
| 64 |
|
| 65 | #define WIFI_STATION_CHANNEL1 2412
|
| 66 | #define WIFI_STATION_CHANNEL2 2417
|
| 67 | #define WIFI_STATION_CHANNEL3 2422
|
| 68 | #define WIFI_STATION_CHANNEL4 2427
|
| 69 | #define WIFI_STATION_CHANNEL5 2432
|
| 70 | #define WIFI_STATION_CHANNEL6 2437
|
| 71 | #define WIFI_STATION_CHANNEL7 2442
|
| 72 | #define WIFI_STATION_CHANNEL8 2447
|
| 73 | #define WIFI_STATION_CHANNEL9 2452
|
| 74 | #define WIFI_STATION_CHANNEL10 2457
|
| 75 | #define WIFI_STATION_CHANNEL11 2462
|
| 76 | #define WIFI_STATION_CHANNEL12 2467
|
| 77 | #define WIFI_STATION_CHANNEL13 2472
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 78 |
|
| 79 | #define WIFI_STATION_CHANNEL14 2484
|
| 80 | //5G
|
| 81 | #define WIFI_STATION_CHANNEL36 5180
|
| 82 | #define WIFI_STATION_CHANNEL40 5200
|
| 83 | #define WIFI_STATION_CHANNEL44 5220
|
| 84 | #define WIFI_STATION_CHANNEL48 5240
|
| 85 | #define WIFI_STATION_CHANNEL52 5260
|
| 86 | #define WIFI_STATION_CHANNEL56 5280
|
| 87 | #define WIFI_STATION_CHANNEL60 5300
|
| 88 | #define WIFI_STATION_CHANNEL64 5320
|
| 89 | #define WIFI_STATION_CHANNEL100 5500
|
| 90 | #define WIFI_STATION_CHANNEL104 5520
|
| 91 | #define WIFI_STATION_CHANNEL108 5540
|
| 92 | #define WIFI_STATION_CHANNEL112 5560
|
| 93 | #define WIFI_STATION_CHANNEL116 5580
|
| 94 | #define WIFI_STATION_CHANNEL120 5600
|
| 95 | #define WIFI_STATION_CHANNEL124 5620
|
| 96 | #define WIFI_STATION_CHANNEL128 5640
|
| 97 | #define WIFI_STATION_CHANNEL132 5660
|
| 98 | #define WIFI_STATION_CHANNEL136 5680
|
| 99 | #define WIFI_STATION_CHANNEL140 5700
|
| 100 | #define WIFI_STATION_CHANNEL144 5720
|
| 101 | #define WIFI_STATION_CHANNEL149 5745
|
| 102 | #define WIFI_STATION_CHANNEL153 5765
|
| 103 | #define WIFI_STATION_CHANNEL157 5785
|
| 104 | #define WIFI_STATION_CHANNEL161 5805
|
| 105 | #define WIFI_STATION_CHANNEL165 5825
|
| 106 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 107 | #define WIFI_STATION_FREQ_LEN 16
|
| 108 |
|
| 109 | #define WIFI_STATION_MSG_SOURCE_STR_LEN 15
|
| 110 | #define WIFI_STATION_IP_STATUS_LEN 16
|
| 111 | #define WIFI_CONNECTION_LEN 4
|
| 112 | #define WIFI_ZPBIC_STATUS_LEN 16
|
| 113 | #define WIFI_STATION_WPA_SUPPLICANT_STATUS_LEN 16
|
| 114 |
|
| 115 | #define WIFI_STATION_SCAN_RESULT_PARSE_IGNORE "bssid / frequency /"
|
| 116 |
|
| 117 | #define WIFI_STATION_AUTH_WPA_PSK "WPA-PSK"
|
| 118 | #define WIFI_STATION_AUTH_WPA2_PSK "WPA2-PSK"
|
| 119 | #define WIFI_STATION_AUTH_WPA_EAP "WPA-EAP"
|
| 120 | #define WIFI_STATION_AUTH_WPA2_EAP "WPA2-EAP"
|
| 121 | #define WIFI_STATION_AUTH_SHARED "SHARED"
|
| 122 | #define WIFI_STATION_AUTH_WPA3 "SAE"
|
| 123 |
|
| 124 | #define WIFI_STATION_ENCRYPT_CCMP "CCMP"
|
| 125 | #define WIFI_STATION_ENCRYPT_TKIP "TKIP"
|
| 126 | #define WIFI_STATION_ENCRYPT_WEP "WEP"
|
| 127 |
|
| 128 | #define WIFI_STATION_PROFILE_AUTH_WPA_PSK "WPAPSK"
|
| 129 | #define WIFI_STATION_PROFILE_AUTH_WPA2_PSK "WPA2PSK"
|
| 130 | //#define WIFI_STATION_PROFILE_AUTH_WPA_EAP "WPAEAP"
|
| 131 | //#define WIFI_STATION_PROFILE_AUTH_WPA2_EAP "WPA2EAP"
|
| 132 | #define WIFI_STATION_PROFILE_AUTH_WPA_EAP "EAP-SIM/AKA"
|
| 133 | #define WIFI_STATION_PROFILE_AUTH_SHARED "SHARED"
|
| 134 | #define WIFI_STATION_PROFILE_AUTH_WPA3 "WPA3Personal"
|
| 135 | #define WIFI_STATION_PROFILE_AUTH_WPA2_WPA3 "WPA2WPA3"
|
| 136 |
|
| 137 | #define WIFI_STATION_PROFILE_ENCRYPT_WEP "WEP"
|
| 138 | #define WIFI_STATION_PROFILE_ENCRYPT_CCMP "CCMP"
|
| 139 | #define WIFI_STATION_PROFILE_ENCRYPT_TKIP "TKIP"
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 | #define WIFI_STATION_STATUS_RESULT_PARSE_BSSID "bssid"
|
| 144 | #define WIFI_STATION_STATUS_RESULT_PARSE_SSID "ssid"
|
| 145 | #define WIFI_STATION_STATUS_RESULT_PARSE_WPA_STATUS "wpa_state"
|
| 146 | #define WIFI_STATION_STATUS_RESULT_PARSE_SUPPLICANT_PAE_STATUS "Supplicant PAE state"
|
| 147 | #define WIFI_STATION_STATUS_RESULT_PARSE_SUPPPORT_STATUS "suppPortStatus"
|
| 148 | #define WIFI_STATION_STATUS_RESULT_PARSE_EAP_STATUS "EAP state"
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_OK "COMPLETED"
|
| 154 |
|
| 155 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_INACTIVE "INACTIVE"
|
| 156 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_SCANNING "SCANNING"
|
| 157 | #define WIFI_STATION_TIMER_SCANNING_STATE_COUNT 10
|
| 158 |
|
| 159 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_AUTHENTICATING "AUTHENTICATING"
|
| 160 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_ASSOCIATING "ASSOCIATING"
|
| 161 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_ASSOCIATED "ASSOCIATED"
|
| 162 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_HANDSHAKE "4WAY_HANDSHAKE"
|
| 163 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_HANDSHAKE "GROUP_HANDSHAKE"
|
| 164 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_UNKNOWN "UNKNOWN"
|
| 165 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_DISCONNECTED "DISCONNECTED"
|
| 166 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_INTERFACE_DISABLED "INTERFACE_DISABLED"
|
| 167 |
|
| 168 |
|
| 169 | #define WIFI_STATION_STATUS_RESULT_EAP_STATUS_FAIL "FAILURE"
|
| 170 | #define WIFI_STATION_STATUS_RESULT_EAP_STATUS_SUCCESS "SUCCESS"
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 | #define WIFI_STATION_IP_STATUS_CONNECT "connect"
|
| 175 | #define WIFI_STATION_IP_STATUS_DISCONNECT "disconnect"
|
| 176 | #define WIFI_STATION_IP_STATUS_CONNECTING "connecting"
|
| 177 | #define WIFI_STATION_IP_STATUS_DHCPING "dhcping"
|
| 178 |
|
| 179 | #define INVALID_NETWORK_ID -1
|
| 180 |
|
| 181 | #define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
|
| 182 |
|
| 183 | #define WPA_CLI "wpa_cli -p"ROOT_DIR"/wifi/wpa_supplicant -iwlan0-vxd"
|
| 184 |
|
| 185 | #define WIFI_CARD_MODE_LEN 3
|
| 186 |
|
| 187 | #define WIFI_PIN_STATUS_LEN 3
|
| 188 |
|
| 189 | #define SIMCARD_INIT_SUCCESS "success"
|
| 190 | #define SIMCARD_INIT_UNDEFINED "undefined"
|
| 191 | #define SIMCARD_INIT_NO_CARD "no_card"
|
| 192 | //#define SIMCARD_INIT_LOCKED "locked"
|
| 193 | //#define SIMCARD_INIT_FAIL "fail"
|
| 194 | //#define SIMCARD_INIT_PARTIAL_SUCCESS "partial_success"
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 195 | #if 0
|
| 196 | static const wlan_sta_freq_ch_t g_sta_freq_ch[] =
|
| 197 | {
|
| 198 | {WIFI_STATION_CHANNEL1, 1},
|
| 199 | {WIFI_STATION_CHANNEL2, 2},
|
| 200 | {WIFI_STATION_CHANNEL3, 3},
|
| 201 | {WIFI_STATION_CHANNEL4, 4},
|
| 202 | {WIFI_STATION_CHANNEL5, 5},
|
| 203 | {WIFI_STATION_CHANNEL6, 6},
|
| 204 | {WIFI_STATION_CHANNEL7, 7},
|
| 205 | {WIFI_STATION_CHANNEL8, 8},
|
| 206 | {WIFI_STATION_CHANNEL9, 9},
|
| 207 | {WIFI_STATION_CHANNEL10, 10},
|
| 208 | {WIFI_STATION_CHANNEL11, 11},
|
| 209 | {WIFI_STATION_CHANNEL12, 12},
|
| 210 | {WIFI_STATION_CHANNEL13, 13},
|
| 211 | {WIFI_STATION_CHANNEL14, 14},
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 212 |
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 213 | {WIFI_STATION_CHANNEL36, 36},
|
| 214 | {WIFI_STATION_CHANNEL40, 40},
|
| 215 | {WIFI_STATION_CHANNEL44, 44},
|
| 216 | {WIFI_STATION_CHANNEL48, 48},
|
| 217 | {WIFI_STATION_CHANNEL52, 52},
|
| 218 | {WIFI_STATION_CHANNEL56, 56},
|
| 219 | {WIFI_STATION_CHANNEL60, 60},
|
| 220 | {WIFI_STATION_CHANNEL64, 64},
|
| 221 | {WIFI_STATION_CHANNEL100, 100},
|
| 222 | {WIFI_STATION_CHANNEL104, 104},
|
| 223 | {WIFI_STATION_CHANNEL108, 108},
|
| 224 | {WIFI_STATION_CHANNEL112, 112},
|
| 225 | {WIFI_STATION_CHANNEL116, 116},
|
| 226 | {WIFI_STATION_CHANNEL120, 120},
|
| 227 | {WIFI_STATION_CHANNEL124, 124},
|
| 228 | {WIFI_STATION_CHANNEL128, 128},
|
| 229 | {WIFI_STATION_CHANNEL132, 132},
|
| 230 | {WIFI_STATION_CHANNEL136, 136},
|
| 231 | {WIFI_STATION_CHANNEL140, 140},
|
| 232 | {WIFI_STATION_CHANNEL144, 144},
|
| 233 | {WIFI_STATION_CHANNEL149, 149},
|
| 234 | {WIFI_STATION_CHANNEL153, 153},
|
| 235 | {WIFI_STATION_CHANNEL157, 157},
|
| 236 | {WIFI_STATION_CHANNEL161, 161},
|
| 237 | {WIFI_STATION_CHANNEL165, 165}
|
| 238 | };
|
| 239 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 240 |
|
| 241 | extern struct wlan_sta_manager *sta_manager;
|
| 242 | extern int need_channel_follow;
|
| 243 |
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 244 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 245 | //static int g_timer_sim_init_undefined_status_count = 0;
|
| 246 | //add by zhouti ÔÚeap ÈÏÖ¤¹ý³Ìǰ·¢Ë͵ÄÒì²½ÏûÏ¢Ôڵȴýʱºò£¬Èç¹ûÓû§disconnect£¬ÄÇôÐèÒªÅжϻØÀ´µÄrespÏûÏ¢ÊÇ·ñΪÕâ´ÎµÄ»ØÓ¦£¬Èç¹ûÊǾÍÐèÒª¶ªÆú²»´¦Àí
|
| 247 | static int g_send_count = 0;
|
| 248 | static int g_pre_send_count = 0;
|
| 249 |
|
| 250 | //gebin: Õ⼸¸öµÄÄ¿µÄ¾ÍÊÇΪÁËÔÚÏ̼߳䴫µÝ²ÎÊý°É??? Èç¹ûÕâÑù¾Í²»ÒªÓÃÈ«¾Ö±äÁ¿ÁË£¬ipc¿ÉÒÔ´«²ÎÊý
|
| 251 | char g_linked_ap_mac[WIFI_STATION_MAC_LEN] = {0};
|
| 252 | int g_linked_network_id = -1;
|
| 253 | int g_linked_network_id_last = -1;
|
| 254 | /*±£´æµ±Ç°ÀúÊ·ÁбíAPÄÚÈÝ*/
|
| 255 | static spot_t *g_spot_list_p[WIFI_STATION_SPOT_LIST_NUM] = {NULL};//ÈȵãÁбíÖ¸ÕëÊý×é
|
| 256 |
|
| 257 | static scan_result_t *g_scan_result_list_p[WIFI_STATION_SCAN_RESULT_LIST_NUM] = {NULL};//ɨÃèÈȵãÁбíÖ¸ÕëÊý×é
|
| 258 | static int g_cardmode = 0; //È«¾Ö¼Ç¼sim¿¨ÀàÐÍ
|
| 259 |
|
| 260 | static int g_blc_send_close_apsta = 0; // È«¾Ö¼Ç¼BLC·¢Ë͹رÕÏûÏ¢Ôò²»ÔÙÖ÷¶¯Á¬½Ówifi,Ö±µ½BLC·¢ËÍ´ò¿ª
|
| 261 | int g_wpa_supplicant;
|
| 262 | extern sem_t g_wpa_supplicant_id;
|
| 263 |
|
| 264 | int has_exec_disconnect = 0; //ÊÇ·ñÖ´Ðйý¶Ï¿ª²Ù×÷
|
| 265 | int has_exec_select_network = 0; //ÊÇ·ñÖ´ÐйýÑ¡ÔñÁ¬½Óijһ¸öÈȵã
|
| 266 | int webui_select_network = 0; //¼Ç¼webuiÏ·¢µÄÑ¡Ôñij¸öÈȵãÁ¬½ÓÃüÁî
|
| 267 | int g_disable_other_network = 0; //ÊÇ·ñ½ûÓÃÆäËûµÄÈȵã
|
| 268 |
|
| 269 | int g_connecting_time_out_timer = 0;//È«¾Ö¼Ç¼ÊÇ·ñÒÑ´´½¨Á¬½Ó³¬Ê±¶¨Ê±Æ÷
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 270 |
|
| 271 | #ifdef USE_CAP_SUPPORT
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 272 | extern int g_work_mode;
|
| 273 | extern int g_cap_sta_enable;
|
| 274 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 275 | int g_cap_scan = 0; //½öcap·¢Æðscanʱ,²ÅÉϱ¨½á¹û,ºǫִ́Ðнá¹û²»±¨
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 276 | int send_sta_status_to_cap(int status, int reason);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 277 | #endif
|
| 278 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 279 | static int wifi_station_connect (int from_where);
|
| 280 | static void wifi_station_scan (void);
|
| 281 | static void *wifi_station_query_sim_card_status(void *arg);
|
| 282 | static void sta_connect (int network_id);
|
| 283 | extern void basic_deal_all (int cmd);
|
| 284 | static int find_linked_ap_index(void);
|
| 285 | static void delete_quote (char * str);
|
| 286 | static void wlan_station_deinit(void);
|
| 287 | static void process_tmp_disabled (char *buf);
|
| 288 |
|
| 289 | extern int check_alive(struct wlan_socket *skt);
|
| 290 |
|
| 291 |
|
| 292 | inline char * sta_docmd(const char *cmd)
|
| 293 | {
|
| 294 | return docmd (&sta_manager->sock, cmd);
|
| 295 | }
|
| 296 |
|
| 297 |
|
| 298 | /*
|
| 299 | 0 : not exist
|
| 300 | 1: alive
|
| 301 | */
|
| 302 | int check_supplicant_alive()
|
| 303 | {
|
| 304 | return check_alive(&sta_manager->sock);
|
| 305 |
|
| 306 | }
|
| 307 |
|
| 308 |
|
| 309 | void *send_message_to_handle_connect_timeout(void *arg)
|
| 310 | {
|
| 311 | ipc_send_message (MODULE_ID_WLAN_SERVER, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_CONNECT_TIMEOUT, 0, NULL, 0);
|
| 312 | return NULL;
|
| 313 | }
|
| 314 | void Create_connect_timeout_timer()
|
| 315 | {
|
| 316 | wf_log ("[111]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 317 | if (g_connecting_time_out_timer) {
|
| 318 | wf_log ("[xxx]station connecting timeout softtimer already exists");
|
| 319 | return;
|
| 320 | }
|
| 321 | wf_log ("[222]create station connecting timeout softtimer");
|
| 322 | sc_timer_create (WIFI_STATION_TIMER_CONNECT_TIME_OUT, TIMER_FLAG_ONCE, 60 * 1000, send_message_to_handle_connect_timeout, NULL);
|
| 323 | g_connecting_time_out_timer = 1;
|
| 324 | wf_log ("[333]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 325 | return;
|
| 326 | }
|
| 327 | void Delete_connect_timeout_timer (void)
|
| 328 | {
|
| 329 | wf_log ("[555]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 330 | if (g_connecting_time_out_timer == 0) {
|
| 331 | wf_log ("[xxx]station connecting timeout softtimer was already deleted");
|
| 332 | return;
|
| 333 | }
|
| 334 | wf_log ("[666]delete station connecting timeout softtimer");
|
| 335 | sc_timer_delete (WIFI_STATION_TIMER_CONNECT_TIME_OUT);
|
| 336 | g_connecting_time_out_timer = 0;
|
| 337 | wf_log ("[777]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 338 | return;
|
| 339 | }
|
| 340 |
|
| 341 | //Ö´ÐÐÒ»¸öshellÃüÁÊä³ö½á¹ûÖðÐд洢ÔÚresvecÖУ¬²¢·µ»ØÐÐÊý
|
| 342 | static int32_t convert2vector (const char *str, vector_t* resvec)
|
| 343 | {
|
| 344 | char *tmp = NULL; //ÉèÖÃÒ»¸öºÏÊʵij¤¶È£¬ÒԴ洢ÿһÐÐÊä³ö
|
| 345 | char *ret = NULL;
|
| 346 | FILE *fp = NULL;
|
| 347 | int tmp_len = 0;
|
| 348 |
|
| 349 | if (str == NULL || resvec == NULL) {
|
| 350 | return -1;
|
| 351 | }
|
| 352 |
|
| 353 | fp = fopen ("/tmp/scan_results", "w+"); //½¨Á¢¹ÜµÀ
|
| 354 | if (!fp) {
|
| 355 | wf_log ("fopen errno: %d\n", errno);
|
| 356 | return -1;
|
| 357 | }
|
| 358 | fprintf (fp, "%s", str);
|
| 359 | fseek (fp, 0, SEEK_SET);
|
| 360 | tmp = safe_malloc (WIFI_STATION_SCRIPT_RSP_LINE_LEN, TRUE);
|
| 361 |
|
| 362 | again:
|
| 363 | errno = 0;
|
| 364 | while ((ret=fgets (tmp, WIFI_STATION_SCRIPT_RSP_LINE_LEN, fp)) != NULL) {
|
| 365 | tmp_len = strlen (tmp);
|
| 366 | if (tmp_len > 0) {
|
| 367 | if (tmp[tmp_len - 1] == '\n') {
|
| 368 | tmp[tmp_len - 1] = '\0'; //È¥³ý»»Ðзû
|
| 369 | }
|
| 370 | vector_push_back (resvec, var_string (tmp));
|
| 371 | }
|
| 372 | }
|
| 373 |
|
| 374 | if (EINTR ==errno) { //kw 3
|
| 375 | wf_log("fgets recv EINTR!");
|
| 376 | goto again;
|
| 377 | }
|
| 378 |
|
| 379 | fclose (fp);
|
| 380 | safe_free (tmp);
|
| 381 |
|
| 382 | return vector_size (resvec);
|
| 383 | }
|
| 384 |
|
| 385 |
|
| 386 | //TODO ÍøÂç×éÍø¿ÚDOWN UP·â×°
|
| 387 | static void network_down_up (BOOL is_up)
|
| 388 | {
|
| 389 | if (is_up == TRUE) {
|
| 390 | sc_cfg_set ("WAN_MODE", "WIFI"); //usb,ppp,wifi
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 391 | /*printf("[wlan-station]calling ipv4.sh linkup\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 392 | system("zte_ipv4.sh \"linkup\"");
|
| 393 | printf("[wlan-station]calling internet.sh\n");
|
| 394 | system("internet.sh");
|
| 395 | printf("[wlan-station]calling nat.sh\n");
|
| 396 | system("nat.sh");*/
|
| 397 | netdev_connect_internet (WIFI_WAN_DEV, MODULE_ID_WIFI);
|
| 398 |
|
| 399 | wf_log ("[wlan-station]netdev_connect_internet");
|
| 400 | } else {
|
| 401 | netdev_disconnect_internet (WIFI_WAN_DEV, MODULE_ID_WIFI);
|
| 402 | wf_log ("[wlan-station]netdev_disconnect_internet");
|
| 403 | //system("zte_ipv4.sh \"linkdown\"");
|
| 404 | sc_cfg_set ("WAN_MODE", "PPP"); //usb,ppp,wifi
|
| 405 | }
|
| 406 | }
|
| 407 |
|
| 408 |
|
| 409 | static void update_EX_APLIST_connect_status (BOOL is_connected)
|
| 410 | {
|
| 411 | char *scan_result_str = NULL;
|
| 412 | char *scan_result_str_tmp = NULL;
|
| 413 | int i = 0;
|
| 414 | int found_ap_index = -1;
|
| 415 | char *splited_string = NULL;
|
| 416 | char *splited_string1 = NULL;
|
| 417 | char *save = NULL;
|
| 418 | char *save1 = NULL;
|
| 419 | char *delimiter = ";";
|
| 420 | int found_str_index = 0;
|
| 421 | BOOL is_found = FALSE;
|
| 422 | BOOL is_find_EX_APLIST1 = FALSE;
|
| 423 |
|
| 424 | int index = 0;
|
| 425 | // ²»¹ÜÊÇÁ´½Ó³É¹¦»¹ÊǶϿª£¬¶¼¿ÉÒÔÕÒµ½¶ÔÓ¦µÄÈȵ㣬²»»áΪÎÞЧֵ
|
| 426 | index = find_linked_ap_index();
|
| 427 |
|
| 428 | for (i = 0; i < WIFI_STATION_SCAN_RESULT_LIST_NUM; i++) {
|
| 429 | if (g_scan_result_list_p[i] != NULL && index != -1) {
|
| 430 | if (strcmp (g_scan_result_list_p[i]->mac, g_spot_list_p[index]->mac) == 0) {
|
| 431 | found_ap_index = i;
|
| 432 |
|
| 433 | if (is_connected == TRUE) {
|
| 434 | g_scan_result_list_p[i]->connect_status = 1;
|
| 435 | } else {
|
| 436 | g_scan_result_list_p[i]->connect_status = 0;
|
| 437 | }
|
| 438 |
|
| 439 | break;
|
| 440 | }
|
| 441 | }
|
| 442 |
|
| 443 | }
|
| 444 |
|
| 445 | //ûÕÒµ½APÔòÖ±½ÓÍ˳ö
|
| 446 | if (found_ap_index == -1) {
|
| 447 | return;
|
| 448 | }
|
| 449 |
|
| 450 | scan_result_str = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 451 | scan_result_str_tmp = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 452 | if (scan_result_str == NULL || scan_result_str_tmp == NULL) {
|
| 453 | safe_free (scan_result_str);
|
| 454 | safe_free (scan_result_str_tmp);
|
| 455 | return;
|
| 456 | }
|
| 457 |
|
| 458 | //²éÕÒEX_APLIST
|
| 459 | sc_cfg_get ("EX_APLIST", scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 460 |
|
| 461 | safe_strcpy (scan_result_str_tmp, scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 462 | //ÒԷֺŷָî×Ö·û´®
|
| 463 | i = 0;
|
| 464 | splited_string = strtok_r (scan_result_str_tmp, delimiter, &save);
|
| 465 | while (splited_string) {
|
| 466 | if (i == found_ap_index) {
|
| 467 | //ÕÒµ½connect_statusÔÚ×Ö·û´®ÖеÄË÷Òý
|
| 468 | found_str_index += 2;
|
| 469 |
|
| 470 | is_found = TRUE;
|
| 471 | break;
|
| 472 | }
|
| 473 | found_str_index += strlen (splited_string) + 1; //ÒªÔÙ¼ÓÉϷֺŵÄ1¸ö×Ö·û³¤¶È
|
| 474 |
|
| 475 | i++;
|
| 476 | splited_string = strtok_r (NULL, delimiter, &save);
|
| 477 | }
|
| 478 |
|
| 479 | //²éÕÒEX_APLIST1
|
| 480 | if (is_found == FALSE) {
|
| 481 | is_find_EX_APLIST1 = TRUE;
|
| 482 | found_str_index = 0;
|
| 483 | memset (scan_result_str, 0, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 484 | memset (scan_result_str_tmp, 0, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 485 | sc_cfg_get ("EX_APLIST1", scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 486 |
|
| 487 | safe_strcpy (scan_result_str_tmp, scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 488 |
|
| 489 | splited_string1 = strtok_r (scan_result_str_tmp, delimiter, &save1);
|
| 490 | while (splited_string1) {
|
| 491 | if (i == found_ap_index) {
|
| 492 | //ÕÒµ½connect_statusÔÚ×Ö·û´®ÖеÄË÷Òý
|
| 493 | found_str_index += 2;
|
| 494 |
|
| 495 | is_found = TRUE;
|
| 496 | break;
|
| 497 | }
|
| 498 | found_str_index += strlen (splited_string1) + 1; //ÒªÔÙ¼ÓÉϷֺŵÄ1¸ö×Ö·û³¤¶È
|
| 499 |
|
| 500 | i++;
|
| 501 | splited_string1 = strtok_r (NULL, delimiter, &save1);
|
| 502 | }
|
| 503 | }
|
| 504 |
|
| 505 | if (is_found == TRUE
|
| 506 | && found_str_index > 0 && found_str_index < strlen (scan_result_str)) {
|
| 507 | if (is_connected == TRUE) {
|
| 508 | scan_result_str[found_str_index] = '1';
|
| 509 | } else {
|
| 510 | scan_result_str[found_str_index] = '0';
|
| 511 | }
|
| 512 |
|
| 513 | if (is_find_EX_APLIST1 == TRUE) {
|
| 514 | sc_cfg_set ("EX_APLIST1", scan_result_str);
|
| 515 | } else {
|
| 516 | sc_cfg_set ("EX_APLIST", scan_result_str);
|
| 517 | }
|
| 518 | }
|
| 519 |
|
| 520 | safe_free (scan_result_str);
|
| 521 | safe_free (scan_result_str_tmp);
|
| 522 | }
|
| 523 |
|
| 524 | static spot_t* parse_spot_string (char *spot_string)
|
| 525 | {
|
| 526 | spot_t *spot = NULL;
|
| 527 | char *splited_string = NULL;
|
| 528 | char *save = NULL;
|
| 529 | const char *delimiter = ",";
|
| 530 | wifi_profile_content_t wifi_profile_content = WIFI_STATION_CONTENT_UNDEFINED;
|
| 531 | char spot_string_tmp[WIFI_STATION_SPOT_LEN] = {0};
|
| 532 |
|
| 533 | if (spot_string == NULL) {
|
| 534 | return NULL;
|
| 535 | }
|
| 536 | //klocwork
|
| 537 | strncpy(spot_string_tmp, spot_string, sizeof(spot_string_tmp)-1);
|
| 538 |
|
| 539 | spot = safe_malloc (sizeof (spot_t), FALSE);
|
| 540 | if (spot == NULL) {
|
| 541 | return NULL;
|
| 542 | }
|
| 543 |
|
| 544 | spot->is_tried_connect = FALSE;
|
| 545 |
|
| 546 | //·Ö¸î×Ö·û´®£¬´æ´¢µ½½á¹¹Ìå
|
| 547 | splited_string = strtok_r (spot_string_tmp, delimiter, &save);
|
| 548 | while (splited_string) {
|
| 549 | wifi_profile_content++;
|
| 550 | switch (wifi_profile_content) {
|
| 551 | case WIFI_STATION_PROFILE_NAME:
|
| 552 | //safe_strcpy (spot->profile_name, splited_string, WIFI_STATION_SPOT_PROFILE_NAME_LEN);
|
| 553 | strncpy (spot->profile_name, splited_string, sizeof(spot->profile_name)-1);
|
| 554 | break;
|
| 555 | case WIFI_STATION_FROM_PROVIDER:
|
| 556 | spot->from_provider = atoi (splited_string);
|
| 557 | break;
|
| 558 | case WIFI_STATION_CONNECT_STATUS:
|
| 559 | spot->connect_status = atoi (splited_string);
|
| 560 | break;
|
| 561 | case WIFI_STATION_SIGNAL:
|
| 562 | spot->signal = atoi (splited_string);
|
| 563 | break;
|
| 564 | case WIFI_STATION_SSID:
|
| 565 | //safe_strcpy (spot->ssid, splited_string, WIFI_STATION_SSID_LEN);
|
| 566 | strncpy (spot->ssid, splited_string, sizeof(spot->ssid)-1);
|
| 567 | break;
|
| 568 | case WIFI_STATION_AUTH_MODE:
|
| 569 | //safe_strcpy (spot->auth_mode, splited_string, WIFI_STATION_AUTH_MODE_LEN);
|
| 570 | strncpy (spot->auth_mode, splited_string, sizeof(spot->auth_mode)-1);
|
| 571 | break;
|
| 572 | case WIFI_STATION_ENCRYPT_TYPE:
|
| 573 | //safe_strcpy (spot->encrypt_type, splited_string, WIFI_STATION_ENCRYPT_TYPE_LEN);
|
| 574 | strncpy (spot->encrypt_type, splited_string, sizeof(spot->encrypt_type)-1);
|
| 575 | break;
|
| 576 | case WIFI_STATION_PASSWORD:
|
| 577 | //safe_strcpy (spot->password, splited_string, WIFI_STATION_SPOT_PASSWORD_LEN);
|
| 578 | strncpy (spot->password, splited_string, sizeof(spot->password)-1);
|
| 579 | break;
|
| 580 | case WIFI_STATION_KEY_ID:
|
| 581 | spot->keyID = atoi (splited_string);
|
| 582 | break;
|
| 583 | case WIFI_STATION_AP_MAC:
|
| 584 | //safe_strcpy (spot->mac, splited_string, WIFI_STATION_MAC_LEN);
|
| 585 | strncpy (spot->mac, splited_string, sizeof(spot->mac)-1);
|
| 586 | break;
|
| 587 | default:
|
| 588 | break;
|
| 589 | }
|
| 590 |
|
| 591 | splited_string = strtok_r (NULL, delimiter, &save);
|
| 592 | }
|
| 593 |
|
| 594 | spot->network_id = -1; // from nv profile , there is no network id property, so ,default set it -1
|
| 595 |
|
| 596 | if (wifi_profile_content != WIFI_STATION_AP_MAC) {
|
| 597 | safe_free (spot);
|
| 598 | return NULL;
|
| 599 | }
|
| 600 |
|
| 601 |
|
| 602 | return spot;
|
| 603 |
|
| 604 | }
|
| 605 |
|
| 606 |
|
| 607 | static void save_config (spot_t *spot)
|
| 608 | {
|
| 609 |
|
| 610 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 611 | char *ptr = NULL;
|
| 612 | char *ptr2 = NULL;
|
| 613 | char *ptr3 = NULL;
|
| 614 | char *ptr_w3 = NULL;
|
| 615 | char *ptr_w23 = NULL;
|
| 616 | char *ptr5 = NULL;
|
| 617 | char *ptr6 = NULL;
|
| 618 | int key_len = 0;
|
| 619 | int id;
|
| 620 |
|
| 621 | if (spot == NULL) {
|
| 622 | return;
|
| 623 | }
|
| 624 |
|
| 625 | if (spot->network_id == -1) {
|
| 626 |
|
| 627 | //id = atoi (sta_docmd ("ADD_NETWORK"));
|
| 628 | //klocwork
|
| 629 | char *reply = NULL;
|
| 630 | reply = sta_docmd("ADD_NETWORK");
|
| 631 | if (reply == NULL) {
|
| 632 | return;
|
| 633 | }
|
| 634 | id = atoi(reply);
|
| 635 |
|
| 636 | spot->network_id = id;
|
| 637 | wf_log ("[sav_config] new spot get new networkid=%d", id);
|
| 638 |
|
| 639 | } else {
|
| 640 | id = spot->network_id ;
|
| 641 | wf_log ("[sav_config] old spot have networkid=%d", id);
|
| 642 |
|
| 643 | }
|
| 644 |
|
| 645 |
|
| 646 | sprintf (cmd, "SET_NETWORK %d ssid \"%s\"", id , spot->ssid);
|
| 647 | sta_docmd (cmd);
|
| 648 |
|
| 649 | memset (cmd, 0, WIFI_STATION_CMD_LEN);
|
| 650 | ptr = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_PSK);
|
| 651 | ptr2 = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_PSK);
|
| 652 | ptr3 = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP);
|
| 653 | ptr_w3 = strstr(spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA3);
|
| 654 | ptr_w23 = strstr(spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_WPA3);
|
| 655 |
|
| 656 | ptr5 = strstr (spot->encrypt_type, WIFI_STATION_PROFILE_ENCRYPT_CCMP);
|
| 657 | ptr6 = strstr (spot->encrypt_type, WIFI_STATION_PROFILE_ENCRYPT_TKIP);
|
| 658 |
|
| 659 | sprintf (cmd, "SET_NETWORK %d priority 1", id);
|
| 660 | sta_docmd (cmd);
|
| 661 |
|
| 662 |
|
| 663 | if (ptr || ptr2) {
|
| 664 | sprintf (cmd, "SET_NETWORK %d key_mgmt WPA-PSK", id);
|
| 665 | sta_docmd (cmd);
|
| 666 |
|
| 667 | if (ptr && !ptr2) {
|
| 668 | sprintf (cmd, "SET_NETWORK %d proto WPA", id);
|
| 669 | sta_docmd (cmd);
|
| 670 | } else if (!ptr && ptr2) {
|
| 671 | sprintf (cmd, "SET_NETWORK %d proto WPA2", id);
|
| 672 | sta_docmd (cmd);
|
| 673 | } else{
|
| 674 | sprintf (cmd, "SET_NETWORK %d proto WPA RSN", id);
|
| 675 | sta_docmd (cmd);
|
| 676 | }
|
| 677 |
|
| 678 | if (ptr5 && !ptr6) {
|
| 679 | sprintf (cmd, "SET_NETWORK %d pairwise CCMP", id);
|
| 680 | sta_docmd (cmd);
|
| 681 | } else if (!ptr5 && ptr6) {
|
| 682 | sprintf (cmd, "SET_NETWORK %d pairwise TKIP", id);
|
| 683 | sta_docmd (cmd);
|
| 684 | } else {
|
| 685 | wf_log ("[save_config]can support both of CCMP TKIP", ptr5, ptr6);
|
| 686 | sprintf (cmd, "SET_NETWORK %d pairwise CCMP TKIP", id);
|
| 687 | sta_docmd (cmd);
|
| 688 | }
|
| 689 |
|
| 690 | sprintf (cmd, "SET_NETWORK %d psk \"%s\" ", id , spot->password);
|
| 691 | sta_docmd (cmd);
|
| 692 | } else if (ptr3) { //|| ptr4)
|
| 693 | sprintf (cmd, "SET_NETWORK %d key_mgmt WPA-EAP", id);
|
| 694 | sta_docmd (cmd);
|
| 695 |
|
| 696 | if (g_cardmode == CARD_MODE_USIM) {
|
| 697 | sprintf (cmd, "SET_NETWORK %d eap AKA", id);
|
| 698 | sta_docmd (cmd);
|
| 699 | } else {
|
| 700 | sprintf (cmd, "SET_NETWORK %d eap SIM", id);
|
| 701 | sta_docmd (cmd);
|
| 702 | }
|
| 703 | sprintf (cmd, "SET_NETWORK %d pcsc '\" \"'", id);
|
| 704 | sta_docmd (cmd);
|
| 705 |
|
| 706 | //ÖØÐ¸²¸ÇÉèÖÃÓÅÏȼ¶Îª×î¸ß
|
| 707 | sprintf (cmd, "SET_NETWORK %d priority 4", id);
|
| 708 | sta_docmd (cmd);
|
| 709 |
|
| 710 | } else if (ptr_w3) {
|
| 711 | sprintf (cmd, "SET_NETWORK %d key_mgmt SAE", id);
|
| 712 | sta_docmd (cmd);
|
| 713 |
|
| 714 | //if set ,other need ieee80211w 0?
|
| 715 | //sprintf (cmd, "SET_NETWORK %d proto RSN", id);
|
| 716 | //sta_docmd (cmd);
|
| 717 |
|
| 718 | //sprintf (cmd, "SET_NETWORK %d pairwise CCMP", id);
|
| 719 | //sta_docmd (cmd);
|
| 720 |
|
| 721 | //sprintf (cmd, "SET_NETWORK %d ieee80211w 2", id);
|
| 722 | //sta_docmd (cmd);
|
| 723 |
|
| 724 |
|
| 725 | sprintf (cmd, "SET_NETWORK %d psk \"%s\"", id , spot->password);
|
| 726 | sta_docmd (cmd);
|
| 727 | } else if (ptr_w23) {
|
| 728 | sprintf (cmd, "SET_NETWORK %d key_mgmt SAE WPA-PSK", id);
|
| 729 | sta_docmd (cmd);
|
| 730 |
|
| 731 | //sprintf (cmd, "SET_NETWORK %d proto RSN", id);
|
| 732 | //sta_docmd (cmd);
|
| 733 |
|
| 734 | //sprintf (cmd, "SET_NETWORK %d pairwise CCMP", id);
|
| 735 | //sta_docmd (cmd);
|
| 736 |
|
| 737 | //sprintf (cmd, "SET_NETWORK %d ieee80211w 1", id);
|
| 738 | //sta_docmd (cmd);
|
| 739 |
|
| 740 |
|
| 741 | sprintf (cmd, "SET_NETWORK %d psk \"%s\"", id , spot->password);
|
| 742 | sta_docmd (cmd);
|
| 743 | } else {
|
| 744 | sprintf (cmd, "SET_NETWORK %d key_mgmt NONE", id);
|
| 745 | sta_docmd (cmd);
|
| 746 | }
|
| 747 |
|
| 748 | ptr = NULL;
|
| 749 | ptr = strstr (spot->encrypt_type, WIFI_STATION_PROFILE_ENCRYPT_WEP);
|
| 750 | if (ptr) {
|
| 751 | sprintf (cmd, "SET_NETWORK %d wep_tx_keyidx %d", id , spot->keyID);
|
| 752 | sta_docmd (cmd);
|
| 753 |
|
| 754 | key_len = strlen (spot->password);
|
| 755 | wf_log ("key_len=%d,password_wep=%s", key_len, spot->password);
|
| 756 | memset (cmd, 0, WIFI_STATION_CMD_LEN);
|
| 757 | if (key_len == 5 || key_len == 13) { //ascii
|
| 758 | sprintf (cmd, "SET_NETWORK %d wep_key%d \"%s\"", id , spot->keyID, spot->password);
|
| 759 | } else if (key_len == 10 || key_len == 26) { //hex
|
| 760 | sprintf (cmd, "SET_NETWORK %d wep_key%d %s", id, spot->keyID, spot->password);
|
| 761 | } else {
|
| 762 | sprintf (cmd, "SET_NETWORK %d wep_key%d \"%s\"", id, spot->keyID, spot->password);
|
| 763 | }
|
| 764 | sta_docmd (cmd);
|
| 765 | }
|
| 766 |
|
| 767 | ptr = NULL;
|
| 768 | ptr = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_SHARED);
|
| 769 | if (ptr) {
|
| 770 | sprintf (cmd, "SET_NETWORK %d auth_alg SHARED", id);
|
| 771 | sta_docmd (cmd);
|
| 772 | }
|
| 773 |
|
| 774 | sprintf (cmd, "SET_NETWORK %d scan_ssid 1", id);
|
| 775 | sta_docmd (cmd);
|
| 776 |
|
| 777 |
|
| 778 | sta_docmd ("SAVE_CONFIG");
|
| 779 | sta_docmd ("LIST_NETWORKS");
|
| 780 | }
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 | static void dump_spot(void)
|
| 785 | {
|
| 786 | int i = 0;
|
| 787 | int spot_num = 0;
|
| 788 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 789 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 790 | spot_num = atoi (wifi_profile_num);
|
| 791 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 792 | return;
|
| 793 |
|
| 794 | //´ËʱµÄ¸öÊýÒѾÊǼõ¹ýµÄÁË£¬ËùÒÔ¸öÊýÒª¼Ó1
|
| 795 | for (i = 0; i < spot_num; i++) {
|
| 796 | if (NULL != g_spot_list_p[i]) {
|
| 797 | wf_log ("spot[%d]%s,%d,%d,%d,%s,%s,%s,%s,%d,%s,%d", i , g_spot_list_p[i]->profile_name,
|
| 798 | g_spot_list_p[i]->from_provider, g_spot_list_p[i]->connect_status, g_spot_list_p[i]->signal,
|
| 799 | g_spot_list_p[i]->ssid, g_spot_list_p[i]->auth_mode, g_spot_list_p[i]->encrypt_type,
|
| 800 | g_spot_list_p[i]->password, g_spot_list_p[i]->keyID, g_spot_list_p[i]->mac, g_spot_list_p[i]->network_id);
|
| 801 | } else {
|
| 802 | wf_log ("ERROR, g_spot_list_p[%d] should not be NULL spot_num = %d\n ", i, spot_num);
|
| 803 | }
|
| 804 | }
|
| 805 | }
|
| 806 |
|
| 807 | static void del_spot (int id)
|
| 808 | {
|
| 809 | int i = 0;
|
| 810 | int spot_num = 0;
|
| 811 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 812 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 813 | spot_num = atoi (wifi_profile_num);
|
| 814 | if (spot_num >= WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)//klocwork
|
| 815 | return;
|
| 816 |
|
| 817 | safe_free (g_spot_list_p[id]);
|
| 818 |
|
| 819 | //´ËʱµÄ¸öÊýÒѾÊǼõ¹ýµÄÁË£¬ËùÒÔ¸öÊýÒª¼Ó1
|
| 820 | for (i = id + 1; i <= spot_num; i++) {
|
| 821 |
|
| 822 | if (g_spot_list_p[i] != NULL) {
|
| 823 | g_spot_list_p[i - 1] = g_spot_list_p[i];
|
| 824 | g_spot_list_p[i] = NULL;
|
| 825 | }
|
| 826 | }
|
| 827 |
|
| 828 |
|
| 829 | //dump_spot();
|
| 830 | }
|
| 831 |
|
| 832 | /*webui ÒѾ½«ÐÂÔöµÄÈÈµã´æÈënv
|
| 833 | ´Ëº¯ÊýÐèÒª½«nvÖÐÐÂÈȵ㠸üе½ÎÒÃÇÓ¦ÓõÄÈ«¾Ö±äÁ¿ÖÐ
|
| 834 | ²¢½«ÐÂÈÈµã´æÈëÅäÖÃÎļþ£¬²¢½«»ñÈ¡µÄnetworkid ´æÈëÈ«¾Ö±äÁ¿
|
| 835 |
|
| 836 | */
|
| 837 | static void webui_update_spot_list (updateinfo_t *info)
|
| 838 | {
|
| 839 | int i = 0;
|
| 840 | spot_t *spot = NULL;
|
| 841 | int spot_num = 0;
|
| 842 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 843 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 844 | int flag = 0;
|
| 845 |
|
| 846 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 847 | spot_num = atoi (wifi_profile_num);
|
| 848 |
|
| 849 | wf_log ("action=%s profile=%s", info->action, info->spot);
|
| 850 |
|
| 851 | //Ìí¼ÓµÄÈȵ㲻¿ÉÄÜÊÇÔËÓªÉÌÈȵ㣬²»¿ÉÄÜÊÇÕýÁ´½ÓµÄÈȵ㣬ËùÒÔ¶¼ÊÇÆÕͨÈȵ㣬ֱ½Ó°´Ë³Ðò¼ÓÔÚºóÃæ
|
| 852 | if (strcmp (info->action, "add") == 0) {
|
| 853 |
|
| 854 | wf_log ("%s processing", info->action);
|
| 855 | if (spot_num < 1 || spot_num > WIFI_STATION_SPOT_LIST_NUM) {//klocwork
|
| 856 | return;
|
| 857 | }
|
| 858 |
|
| 859 | spot = parse_spot_string (info->spot);
|
| 860 | if (spot == NULL) {//klocwork
|
| 861 | return;
|
| 862 | }
|
| 863 | spot->network_id = -1;
|
| 864 | save_config (spot);
|
| 865 | g_spot_list_p[spot_num - 1] = spot;
|
| 866 |
|
| 867 | //Èç¹ûÊǶϿª×´Ì¬£¬Ö±½ÓÁ¬½Ó£¬Èç¹ûÊÇÁ¬½Ó״̬£¬Ö»ÐèÒªenable¾Í¿ÉÒÔÁË
|
| 868 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 869 |
|
| 870 | if (strcmp (sta_ip_status, "disconnect") == 0) {
|
| 871 | sta_connect (spot->network_id);
|
| 872 | }
|
| 873 |
|
| 874 | } else if (strcmp (info->action, "modify") == 0) {
|
| 875 | wf_log ("%s processing", info->action);
|
| 876 | spot = parse_spot_string (info->spot);
|
| 877 | if (spot == NULL) {//klocwork
|
| 878 | return;
|
| 879 | }
|
| 880 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 881 | if (g_spot_list_p[i] != NULL && !strcmp (g_spot_list_p[i]->profile_name, spot->profile_name)) {
|
| 882 | spot->network_id = g_spot_list_p[i]->network_id;
|
| 883 | safe_free (g_spot_list_p[i]);
|
| 884 | g_spot_list_p[i] = spot;
|
| 885 | save_config (spot);
|
| 886 | flag = 1;
|
| 887 | break;
|
| 888 | }
|
| 889 | }
|
| 890 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 891 |
|
| 892 | if (strcmp (sta_ip_status, "disconnect") == 0) {
|
| 893 | sta_connect (spot->network_id);
|
| 894 | }
|
| 895 | if (flag == 0) {//for klocwork,¼Ç¼ȫ¾ÖµÄ²»ÄÜɾ
|
| 896 | safe_free (spot);
|
| 897 | }
|
| 898 | } else if (strcmp (info->action, "delete") == 0) {
|
| 899 | int network_id = -1;;
|
| 900 | int del_id = -1;
|
| 901 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 902 | wf_log ("%s processing", info->action);
|
| 903 |
|
| 904 | dump_spot();
|
| 905 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 906 | if (g_spot_list_p[i] != NULL && !strncmp (g_spot_list_p[i]->profile_name, info->spot, strlen(g_spot_list_p[i]->profile_name))) {
|
| 907 | network_id = g_spot_list_p[i]->network_id;
|
| 908 | del_id = i;
|
| 909 | break;
|
| 910 | }
|
| 911 | }
|
| 912 |
|
| 913 | if (network_id != -1) {
|
| 914 | sprintf (cmd, "REMOVE_NETWORK %d", network_id);
|
| 915 | sta_docmd (cmd);
|
| 916 | sta_docmd ("SAVE_CONFIG");
|
| 917 |
|
| 918 | if (del_id != -1)
|
| 919 | del_spot (del_id);
|
| 920 | } else {
|
| 921 | wf_log ("spot:%s not found", info->spot);
|
| 922 | }
|
| 923 |
|
| 924 | }
|
| 925 | dump_spot();
|
| 926 | }
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 | /*
|
| 931 | ÔÚɾ³ýÈȵã¹ý³ÌÖÐͻȻ¶Ïµç£¬ÎÞ·¨±£´æµ½conf Îļþ£¬ÐèÒªÖØÐÂͬ²½Ò»ÏÂ
|
| 932 |
|
| 933 | */
|
| 934 |
|
| 935 | static int get_spot_info_from_conf (spot_ssid_id_t *info, int num)
|
| 936 | {
|
| 937 |
|
| 938 | int i = 0;
|
| 939 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 940 | char * reply = NULL;
|
| 941 |
|
| 942 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 943 |
|
| 944 | info->id = -1;
|
| 945 | memset (info->ssid, 0 , sizeof (info->ssid));
|
| 946 |
|
| 947 | sprintf (cmd, "GET_NETWORK %d ssid", i);
|
| 948 | reply = sta_docmd (cmd);
|
| 949 | if (reply != NULL) {
|
| 950 | wf_log ("[update networkid from conf]reply SSID=%s", reply);
|
| 951 | strncpy (info->ssid, reply, sizeof (info->ssid)-1);
|
| 952 | } else {
|
| 953 | wf_log ("[update networkid from conf]conf read over!");
|
| 954 | break;
|
| 955 | }
|
| 956 |
|
| 957 | if (strlen (info->ssid) > 0) {
|
| 958 | wf_log ("[update networkid from conf] delete quote");
|
| 959 |
|
| 960 | delete_quote (info->ssid);
|
| 961 | }
|
| 962 |
|
| 963 | info->id = i;
|
| 964 | wf_log ("[update networkid from conf]SSID=%s, network_id=%d", info->ssid, i);
|
| 965 | info += 1;
|
| 966 | }
|
| 967 |
|
| 968 | return i;
|
| 969 | }
|
| 970 |
|
| 971 |
|
| 972 | /**/
|
| 973 | static void delete_quote (char * str)
|
| 974 | {
|
| 975 | int len = 0;
|
| 976 | printf("str=%s\n", str);
|
| 977 | if (*str == '\"') {
|
| 978 | //strcpy (str, str + 1); //cov m
|
| 979 | len = strlen(str + 1);
|
| 980 | memmove(str, str + 1, len + 1);
|
| 981 | *(str + len) = '\0';
|
| 982 | }
|
| 983 | printf("str=%s\n", str);
|
| 984 |
|
| 985 | if (*(str + strlen(str) - 1) == '\"')
|
| 986 | *(str + strlen(str) - 1) = '\0';
|
| 987 |
|
| 988 | printf("str=%s\n", str);
|
| 989 | }
|
| 990 |
|
| 991 |
|
| 992 | //1. ¿ªÆô¹Ø±Õapsta
|
| 993 | /*
|
| 994 |
|
| 995 | ¿ªÆô: conf fileÖØÐ±»wpa_supplicant¶ÁÈ¡£¬ÖØÆô·ÖÅänetwork id£¬ÐèÒªÖØÐÂͬ²½µ½spot list
|
| 996 |
|
| 997 |
|
| 998 | ¹Ø±Õ: ²»Çå¿Õconf file£¬ ΪÁ˺͹ػú±£³ÖÒ»Ö£¬Ò²ÐèÒª½«spot ÄÚÈÝÇå¿Õ
|
| 999 | */
|
| 1000 |
|
| 1001 |
|
| 1002 | //2. ¿ª»ú¹Ø»ú
|
| 1003 | /*
|
| 1004 |
|
| 1005 | ¹Ø»ú: Õý³£¹Ø»úºÍÒì³£¶Ïµç£¬¶¼²»»áÓÐÈκβÙ×÷Á÷³Ì£¬confÎļþ²»»áÐÞ¸Ä
|
| 1006 | ¿ª»ú: Ö±½ÓÖØÐ·ÖÅäspot Äڴ棬´Ónvͬ²½spotÊý¾Ý£¬È»ºó´ÓconfÎļþÖÐͬ²½networkid£¬Èç¹ûûÓжÔÓ¦µÄnetworid
|
| 1007 |
|
| 1008 | ÔòÐèÒªÖØÐÂÌí¼Ó¸ÃÈȵ㵽confÎļþÖУ¬±ÈÈçÊÇÖ±½ÓÔ¤ÖõÄÔËÓªÉÌÈȵã
|
| 1009 |
|
| 1010 | */
|
| 1011 | void sync_nv_spot_list_conf_file()
|
| 1012 | {
|
| 1013 | spot_ssid_id_t g_spot_ssid_id_p[WIFI_STATION_SPOT_LIST_NUM] = {{0}};
|
| 1014 |
|
| 1015 | int i = 0, j = 0;
|
| 1016 | int spot_num = 0;
|
| 1017 | int conf_spot_num = 0;
|
| 1018 |
|
| 1019 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1020 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1021 | spot_num = atoi (wifi_profile_num);
|
| 1022 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 1023 | return;
|
| 1024 |
|
| 1025 | memset (g_spot_ssid_id_p, 0, WIFI_STATION_SPOT_LIST_NUM * sizeof (struct spot_ssid_id));
|
| 1026 | conf_spot_num = get_spot_info_from_conf (g_spot_ssid_id_p, spot_num);
|
| 1027 | wf_log ("spot_num=%d,conf_spot_num=%d", spot_num, conf_spot_num);
|
| 1028 |
|
| 1029 | for (i = 0; i < spot_num; i++) {
|
| 1030 | wf_log ("[sync spot before]SSID:%s, networkid=%d", g_spot_list_p[i]->ssid, g_spot_list_p[i]->network_id);
|
| 1031 | for (j = 0; j < WIFI_STATION_SPOT_LIST_NUM; j ++) {
|
| 1032 | //[sync before]spot SSID:CPE_E3DE4E, conf ssid="CPE_E3DE4E", dubble quote !!!!!!
|
| 1033 | wf_log ("[compare to conf]spot SSID:%s, conf ssid=%s", g_spot_list_p[i]->ssid, g_spot_ssid_id_p[j].ssid);
|
| 1034 | if (strcmp (g_spot_ssid_id_p[j].ssid, g_spot_list_p[i]->ssid) == 0) {
|
| 1035 | g_spot_list_p[i]->network_id = g_spot_ssid_id_p[j].id;
|
| 1036 | break;
|
| 1037 | }
|
| 1038 | }
|
| 1039 |
|
| 1040 | if (-1 == g_spot_list_p[i]->network_id) {
|
| 1041 | save_config (g_spot_list_p[i]); //Èç¹ûconfÖÐûÓУ¬ÔòÐèÒª¼ÓÈ룬update spot networkid
|
| 1042 | }
|
| 1043 | wf_log ("[sync spot after]SSID:%s, networkid=%d", g_spot_list_p[i]->ssid, g_spot_list_p[i]->network_id);
|
| 1044 | }
|
| 1045 |
|
| 1046 | /*ÌÞ³ý confÎļþÖÐûÓÐÕý³£É¾³ýµÄspot*/
|
| 1047 | for (i = 0; i < conf_spot_num; i++) {
|
| 1048 | int conf_spot_in_nv = 0;
|
| 1049 |
|
| 1050 | wf_log ("[sync conf before]SSID:%s, networkid=%d", g_spot_ssid_id_p[i].ssid, g_spot_ssid_id_p[i].id);
|
| 1051 | if (strlen (g_spot_ssid_id_p[i].ssid) > 0) {
|
| 1052 | for (j = 0; j < spot_num; j ++) {
|
| 1053 | wf_log ("[compare to spot]g_spot_list_p[j]->ssid=%s", g_spot_list_p[j]->ssid);
|
| 1054 | if (strcmp (g_spot_ssid_id_p[i].ssid, g_spot_list_p[j]->ssid) == 0) {
|
| 1055 | conf_spot_in_nv = 1;
|
| 1056 | break;
|
| 1057 | }
|
| 1058 | }
|
| 1059 |
|
| 1060 | // Èç¹û²»´æÔÚnvÖУ¬ÐèҪɾ³ý
|
| 1061 | if (0 == conf_spot_in_nv) {
|
| 1062 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 1063 | sprintf (cmd, "REMOVE_NETWORK %d", g_spot_ssid_id_p[i].id);
|
| 1064 | sta_docmd (cmd);
|
| 1065 | }
|
| 1066 | }
|
| 1067 |
|
| 1068 | wf_log ("[sync conf after]SSID:%s, networkid=%d", g_spot_ssid_id_p[i].ssid, g_spot_ssid_id_p[i].id);
|
| 1069 | }
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 | }
|
| 1074 |
|
| 1075 | //»ñÈ¡ÈȵãÁÐ±í£¬·µ»ØÒ»¸öÖ¸ÕëÊý×飬·ÅÈëÈ«¾Ö
|
| 1076 | static void get_spot_list (void)
|
| 1077 | {
|
| 1078 | int i = 0;
|
| 1079 | int j = 0;
|
| 1080 | char spot_string[WIFI_STATION_SPOT_LEN] = {0};
|
| 1081 | char wifi_profile_nv_name[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1082 | spot_t *spot = NULL;
|
| 1083 | int spot_num = 0;
|
| 1084 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1085 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1086 | spot_num = atoi (wifi_profile_num);
|
| 1087 |
|
| 1088 | wf_log ("free [g_spot_list_p] all spot");
|
| 1089 |
|
| 1090 | //ÏÈÊÍ·Å֮ǰ´æ´¢µÄÈȵãÁбíÄÚ´æ
|
| 1091 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1092 | safe_free (g_spot_list_p[i]);
|
| 1093 | //g_spot_list_p[i] = NULL;
|
| 1094 | }
|
| 1095 |
|
| 1096 | if (spot_num > 0 && spot_num <= WIFI_STATION_SPOT_LIST_NUM) {
|
| 1097 | for (i = 0; i < spot_num; i++) {
|
| 1098 | if (i == 0) {
|
| 1099 | sc_cfg_get ("wifi_profile", spot_string, WIFI_STATION_SPOT_LEN);
|
| 1100 | } else {
|
| 1101 | memset (wifi_profile_nv_name, 0, WIFI_STATION_PROFILE_NV_NAME_LEN);
|
| 1102 | snprintf (wifi_profile_nv_name, WIFI_STATION_PROFILE_NV_NAME_LEN, "wifi_profile%d", i);
|
| 1103 | sc_cfg_get (wifi_profile_nv_name, spot_string, WIFI_STATION_SPOT_LEN);
|
| 1104 | }
|
| 1105 |
|
| 1106 | wf_log ("get_spot_list spot_string[%d]= %s", i, spot_string);
|
| 1107 | spot = parse_spot_string (spot_string);
|
| 1108 | if (spot != NULL) {
|
| 1109 | g_spot_list_p[j] = spot;
|
| 1110 | j++;
|
| 1111 | }
|
| 1112 | }
|
| 1113 | }
|
| 1114 |
|
| 1115 | }
|
| 1116 |
|
| 1117 | static void save_spot_list (void)
|
| 1118 | {
|
| 1119 | int i = 0;
|
| 1120 | char spot_string[WIFI_STATION_SPOT_LEN] = {0};
|
| 1121 | char wifi_profile_nv_name[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1122 |
|
| 1123 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1124 | if (g_spot_list_p[i] != NULL) {
|
| 1125 | snprintf (spot_string, WIFI_STATION_SPOT_LEN, "%s,%d,%d,%d,%s,%s,%s,%s,%d,%s", g_spot_list_p[i]->profile_name,
|
| 1126 | g_spot_list_p[i]->from_provider, g_spot_list_p[i]->connect_status, g_spot_list_p[i]->signal,
|
| 1127 | g_spot_list_p[i]->ssid, g_spot_list_p[i]->auth_mode, g_spot_list_p[i]->encrypt_type,
|
| 1128 | g_spot_list_p[i]->password, g_spot_list_p[i]->keyID, g_spot_list_p[i]->mac);
|
| 1129 |
|
| 1130 | wf_log (" g_spot_list_p[%d]=%s, [%d]", i, spot_string, g_spot_list_p[i]->network_id);
|
| 1131 |
|
| 1132 | if (i == 0) {
|
| 1133 | sc_cfg_set ("wifi_profile", spot_string);
|
| 1134 | } else {
|
| 1135 | snprintf (wifi_profile_nv_name, WIFI_STATION_PROFILE_NV_NAME_LEN, "wifi_profile%d", i);
|
| 1136 | sc_cfg_set (wifi_profile_nv_name, spot_string);
|
| 1137 | }
|
| 1138 | }
|
| 1139 | }
|
| 1140 | }
|
| 1141 |
|
| 1142 |
|
| 1143 | /*
|
| 1144 | ½«Á´½Ó³É¹¦µÄÈȵ㣬Åŵ½µÚһλ
|
| 1145 | */
|
| 1146 | static void resort_spot_list (void)
|
| 1147 | {
|
| 1148 |
|
| 1149 | int i = 0, j = 0;
|
| 1150 | int index = 0;
|
| 1151 | spot_t * spot = NULL;
|
| 1152 | // char profile[WIFI_STATION_SPOT_PROFILE_NAME_LEN] = {0};
|
| 1153 |
|
| 1154 | // sc_cfg_get("EX_wifi_profile", profile, WIFI_STATION_SPOT_PROFILE_NAME_LEN);
|
| 1155 |
|
| 1156 |
|
| 1157 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1158 | if (g_spot_list_p[i] != NULL) {
|
| 1159 | if (g_spot_list_p[i]->connect_status == 1) {
|
| 1160 | index = i;
|
| 1161 | spot = g_spot_list_p[i];
|
| 1162 | break;
|
| 1163 | }
|
| 1164 | }
|
| 1165 |
|
| 1166 | }
|
| 1167 |
|
| 1168 | if (index == 0) return;
|
| 1169 |
|
| 1170 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1171 | if (1 == g_spot_list_p[i]->from_provider) {
|
| 1172 | continue;
|
| 1173 | } else {
|
| 1174 | //move other spot
|
| 1175 | for (j = index; j > i; j--) { // ¼Ù¶¨×îºóÒ»¸ö¿Ï¶¨Êǿյ쬲»¿ÉÄÜ10¸öÂúÁË£¬»¹ÔÚÌí¼ÓÈȵ㣬֮ǰÒѾÅжϴíÎó·µ»ØÁË
|
| 1176 | if (g_spot_list_p[j] == NULL) continue;
|
| 1177 | else {
|
| 1178 | g_spot_list_p[j] = g_spot_list_p[j - 1]; //j must greater than 0
|
| 1179 | }
|
| 1180 | }
|
| 1181 | if (i != index) {
|
| 1182 | g_spot_list_p[i] = spot;
|
| 1183 | wf_log ("[%s]SSID=[%s] from %d move to %d", __FILE__, spot->ssid, index, i);
|
| 1184 | } else {
|
| 1185 | wf_log ("[%s]SSID=[%s] do not move", __FILE__, spot->ssid);
|
| 1186 | }
|
| 1187 | break;
|
| 1188 | }
|
| 1189 | }
|
| 1190 |
|
| 1191 | //¸ü¸Ä˳Ðòºó£¬ÐèÒªÖØÐ±¸·Ý signal
|
| 1192 | //reback_up_signal();
|
| 1193 |
|
| 1194 | save_spot_list();
|
| 1195 |
|
| 1196 | }
|
| 1197 |
|
| 1198 |
|
| 1199 | static void update_spot_list_signal_connect_status (short signal, short connect_status)
|
| 1200 | {
|
| 1201 | int i = 0;
|
| 1202 |
|
| 1203 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1204 | if (g_spot_list_p[i] != NULL) {
|
| 1205 | if (signal >= 0) {
|
| 1206 | g_spot_list_p[i]->signal = signal;
|
| 1207 | }
|
| 1208 |
|
| 1209 | if (connect_status >= 0) {
|
| 1210 | g_spot_list_p[i]->connect_status = connect_status;
|
| 1211 | }
|
| 1212 | }
|
| 1213 | }
|
| 1214 |
|
| 1215 | }
|
| 1216 |
|
| 1217 | static void update_spot_connect_status_by_status_result (BOOL is_connected)
|
| 1218 | {
|
| 1219 | int i = 0;
|
| 1220 | char spot_string[WIFI_STATION_SPOT_LEN] = {0};
|
| 1221 | char wifi_profile_nv_name[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1222 |
|
| 1223 | wf_log ("is_connected=%d, g_linked_network_id= %d", is_connected, g_linked_network_id);
|
| 1224 |
|
| 1225 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1226 | if (g_spot_list_p[i] != NULL && g_spot_list_p[i] ->network_id == g_linked_network_id) {
|
| 1227 | if (is_connected == TRUE) {
|
| 1228 | g_spot_list_p[i]->connect_status = 1;
|
| 1229 | } else {
|
| 1230 | g_spot_list_p[i]->connect_status = 0;
|
| 1231 | }
|
| 1232 |
|
| 1233 | if (strcmp (g_spot_list_p[i]->mac, "0F:00:00:00:00:00") == 0) {
|
| 1234 | strcpy (g_spot_list_p[i]->mac, g_linked_ap_mac);
|
| 1235 | }
|
| 1236 | wf_log ("g_spot_list_p[%d]->mac=%s", i, g_spot_list_p[i]->mac);
|
| 1237 | wf_log ("profile[%d]=%d", i, g_spot_list_p[i]->connect_status);
|
| 1238 |
|
| 1239 | snprintf (spot_string, WIFI_STATION_SPOT_LEN, "%s,%d,%d,%d,%s,%s,%s,%s,%d,%s", g_spot_list_p[i]->profile_name,
|
| 1240 | g_spot_list_p[i]->from_provider, g_spot_list_p[i]->connect_status, g_spot_list_p[i]->signal,
|
| 1241 | g_spot_list_p[i]->ssid, g_spot_list_p[i]->auth_mode, g_spot_list_p[i]->encrypt_type,
|
| 1242 | g_spot_list_p[i]->password, g_spot_list_p[i]->keyID, g_spot_list_p[i]->mac);
|
| 1243 |
|
| 1244 | if (i == 0) {
|
| 1245 | sc_cfg_set ("wifi_profile", spot_string);
|
| 1246 | } else {
|
| 1247 | snprintf (wifi_profile_nv_name, WIFI_STATION_PROFILE_NV_NAME_LEN, "wifi_profile%d", i);
|
| 1248 | sc_cfg_set (wifi_profile_nv_name, spot_string);
|
| 1249 | }
|
| 1250 |
|
| 1251 | break;
|
| 1252 | }
|
| 1253 | }
|
| 1254 | }
|
| 1255 |
|
| 1256 | static void update_spot_signal_by_scan_result (scan_result_t *scan_result)
|
| 1257 | {
|
| 1258 | int i = 0;
|
| 1259 |
|
| 1260 | if (scan_result == NULL) {
|
| 1261 | return;
|
| 1262 | }
|
| 1263 |
|
| 1264 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1265 | if (g_spot_list_p[i] != NULL) {
|
| 1266 | if (strcmp (g_spot_list_p[i]->mac, scan_result->mac) == 0 &&
|
| 1267 |
|
| 1268 | strcmp (g_spot_list_p[i]->ssid, scan_result->ssid) == 0
|
| 1269 | // && (strcmp(g_spot_list_p[i]->auth_mode, scan_result->auth_mode) == 0 ||
|
| 1270 | // (strcmp(g_spot_list_p[i]->auth_mode,WIFI_STATION_PROFILE_AUTH_WPA_EAP)==0 && strcmp(scan_result->auth_mode,"802.1X")==0))
|
| 1271 | /*&& strstr(g_spot_list_p[i]->encrypt_type, scan_result->encrypt_type) != NULL*/)
|
| 1272 | // Õë¶ÔÒþ²ØÈȵ㣬ÊÖ¶¯Ìí¼ÓµÄcipherΪauto£¬µ¼ÖÂÎÞ·¨Ê¶±ð¸üÐÂÈȵãÐźÅ
|
| 1273 | //±¾À´ÐèҪʹÓÃmac½øÐÐÆ¥Å䣬Î÷°²²»ÅäºÏ£¬Ö»ÓÐÈ¡ÕâÑùµÄ·±Ëö°ì·¨
|
| 1274 | //webui×Ô¶¯Ê¶±ðtkip aesΪauto£¬±£´æÔÚnv profileÀïÃæÎªTKIPCCMP,µ¼Ö´˴¦ÎÞ·¨Æ¥Å䣬ÎÞ·¨¸üÐÂÈȵãÐźÅ
|
| 1275 | //EAP-SIM/AKA, ÓëÔ±¾Ð´µÄ802.1xÒ²²»Æ¥Å䣬µ¼ÖÂÎÞ·¨¸üÐÂÈȵãÐźÅ
|
| 1276 | //ÐÞ¸ÄΪɨÃèÈȵãµÄ¼ÓÃÜÀàÐÍΪTKIP CCMP,Ö»ÒªÄÜÔÚ±£´æÈȵãÖÐÕÒµ½´Ë×Ö·û£¬ÔòÈÏΪÊÇͬһ¸öÈȵ㣬µ«ÊÇÎÞ·¨½â¾öÕæµÄÓÐÁ½¸öÏàͬµÄÈȵ㣬Õâ¸öÎÞ·¨Ê¶±ð
|
| 1277 | {
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 1278 | #ifdef USE_CAP_SUPPORT
|
| 1279 | g_spot_list_p[i]->signal = scan_result->signal_db;
|
| 1280 | #else
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1281 | g_spot_list_p[i]->signal = scan_result->signal;
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 1282 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1283 | break;
|
| 1284 | }
|
| 1285 | }
|
| 1286 | }
|
| 1287 | }
|
| 1288 |
|
| 1289 |
|
| 1290 | static void sort_scan_result_by_signal (scan_result_t **scan_result, int size)
|
| 1291 | {
|
| 1292 | int i, j = 0;
|
| 1293 | scan_result_t *insertnode = NULL;
|
| 1294 |
|
| 1295 | if (scan_result == NULL) {
|
| 1296 | return;
|
| 1297 | }
|
| 1298 |
|
| 1299 | for (i = 0; i < size; i++) {
|
| 1300 | if (scan_result[i] == NULL) {
|
| 1301 | return;
|
| 1302 | }
|
| 1303 | }
|
| 1304 |
|
| 1305 | //Ö±½Ó²åÈëÅÅÐòËã·¨
|
| 1306 | for (i = 1; i < size; i++) { //ÒÀ´Î²åÈëÊýÖµ
|
| 1307 | insertnode = scan_result[i]; //ÉèÖÃÓû²åÈëµÄÊýÖµ,ÉÚ±ø
|
| 1308 | j = i - 1; //Óû²åÈëÊý×éµÄ¿ªÊ¼Î»ÖÃ
|
| 1309 | while (j >= 0 && insertnode->signal > scan_result[j]->signal) { //ÕÒÊʵ±µÄ²åÈëλÖÃ
|
| 1310 | scan_result[j + 1] = scan_result[j];
|
| 1311 | j--;
|
| 1312 | }
|
| 1313 | scan_result[j + 1] = insertnode;
|
| 1314 | }
|
| 1315 |
|
| 1316 | }
|
| 1317 |
|
| 1318 | /*
|
| 1319 | inputStr: if there is a \, then
|
| 1320 | outputStr: add \\ before, to be \\\
|
| 1321 |
|
| 1322 |
|
| 1323 | */
|
| 1324 |
|
| 1325 | static char* process_backlash (char* inputStr, char* outputStr)
|
| 1326 | {
|
| 1327 | int len = 0;
|
| 1328 | int i, j = 0;
|
| 1329 | if ( (NULL == inputStr) || (NULL == outputStr)) {
|
| 1330 | return NULL;
|
| 1331 | }
|
| 1332 |
|
| 1333 | len = strlen (inputStr);
|
| 1334 | for (i = 0; i < len; i++) { //linux תÒå
|
| 1335 | if ( (inputStr[i] == 0x5c && inputStr[i + 1] == 'x')) {
|
| 1336 | outputStr[j++] = 0x5c;
|
| 1337 | }
|
| 1338 | outputStr[j++] = inputStr[i];
|
| 1339 | }
|
| 1340 | outputStr[j] = '\0';
|
| 1341 | //printf("[process_backlash]inputStr=%s,outputStr=%s",inputStr,outputStr);
|
| 1342 |
|
| 1343 | return outputStr;
|
| 1344 | }
|
| 1345 |
|
| 1346 | static void save_scan_result (scan_result_t* scan_result, char *scan_result_str, char *scan_result_str1)
|
| 1347 | {
|
| 1348 | char *scan_result_str_temp = NULL;
|
| 1349 | char one_scan_result_str[WIFI_STATION_SCAN_ONE_RESULT_STR_LEN] = {0};
|
| 1350 | int one_scan_result_str_len = 0;
|
| 1351 |
|
| 1352 | char ssid[128] = {0};
|
| 1353 | if (scan_result == NULL
|
| 1354 | || scan_result_str == NULL
|
| 1355 | || scan_result_str1 == NULL) {
|
| 1356 | return;
|
| 1357 | }
|
| 1358 |
|
| 1359 | if (strlen (scan_result->ssid) <= 0) {
|
| 1360 | return;
|
| 1361 | }
|
| 1362 |
|
| 1363 | scan_result_str_temp = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, TRUE);
|
| 1364 |
|
| 1365 |
|
| 1366 | process_backlash (scan_result->ssid, ssid);
|
| 1367 |
|
| 1368 | snprintf (one_scan_result_str, WIFI_STATION_SCAN_ONE_RESULT_STR_LEN, "%d,%d,%s,%d,%d,%s,%s,%s", scan_result->from_provider, scan_result->connect_status, ssid,
|
| 1369 | scan_result->signal, scan_result->channel, scan_result->auth_mode, scan_result->encrypt_type, scan_result->mac);
|
| 1370 |
|
| 1371 | one_scan_result_str_len = strlen (one_scan_result_str);
|
| 1372 |
|
| 1373 | //cfg½Ó¿ÚÊÇÒÔ"nv name=nv value\0"·½Ê½À´´æ´¢£¬ÇÒÒ»´Î×Ϊ1024£¬Òò´ËÕâ±ßÊÇ+2
|
| 1374 | if (one_scan_result_str_len + strlen (scan_result_str) + strlen ("EX_APLIST") + 2 > WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1375 | if (one_scan_result_str_len + strlen (scan_result_str1) + strlen ("EX_APLIST1") + 2 > WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1376 | //³¬³ö2048×Ö½ÚÁË£¬Í˳ö
|
| 1377 | safe_free (scan_result_str_temp);
|
| 1378 | return;
|
| 1379 | } else {
|
| 1380 | safe_strcpy (scan_result_str_temp, scan_result_str1, strlen(scan_result_str1) + 1);
|
| 1381 |
|
| 1382 | strncat (scan_result_str_temp, one_scan_result_str, one_scan_result_str_len);
|
| 1383 | strncat (scan_result_str_temp, ";", 1);
|
| 1384 |
|
| 1385 | //¸³Öµ½á¹û
|
| 1386 | safe_strcpy (scan_result_str1, scan_result_str_temp, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 1387 | }
|
| 1388 | } else {
|
| 1389 | safe_strcpy (scan_result_str_temp, scan_result_str, strlen(scan_result_str) + 1);//wlocwork
|
| 1390 |
|
| 1391 | strncat (scan_result_str_temp, one_scan_result_str, one_scan_result_str_len);
|
| 1392 | strncat (scan_result_str_temp, ";", 1);
|
| 1393 |
|
| 1394 | //¸³Öµ½á¹û
|
| 1395 | safe_strcpy (scan_result_str, scan_result_str_temp, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 1396 | }
|
| 1397 |
|
| 1398 | safe_free (scan_result_str_temp);
|
| 1399 |
|
| 1400 | }
|
| 1401 |
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 1402 | static int frequency_to_channel(int freq)
|
| 1403 | {
|
| 1404 | int channel = 0;
|
| 1405 | //channel
|
| 1406 | switch(freq) {
|
| 1407 | case WIFI_STATION_CHANNEL1:
|
| 1408 | channel = 1;
|
| 1409 | break;
|
| 1410 | case WIFI_STATION_CHANNEL2:
|
| 1411 | channel = 2;
|
| 1412 | break;
|
| 1413 | case WIFI_STATION_CHANNEL3:
|
| 1414 | channel = 3;
|
| 1415 | break;
|
| 1416 | case WIFI_STATION_CHANNEL4:
|
| 1417 | channel = 4;
|
| 1418 | break;
|
| 1419 | case WIFI_STATION_CHANNEL5:
|
| 1420 | channel = 5;
|
| 1421 | break;
|
| 1422 | case WIFI_STATION_CHANNEL6:
|
| 1423 | channel = 6;
|
| 1424 | break;
|
| 1425 | case WIFI_STATION_CHANNEL7:
|
| 1426 | channel = 7;
|
| 1427 | break;
|
| 1428 | case WIFI_STATION_CHANNEL8:
|
| 1429 | channel = 8;
|
| 1430 | break;
|
| 1431 | case WIFI_STATION_CHANNEL9:
|
| 1432 | channel = 9;
|
| 1433 | break;
|
| 1434 | case WIFI_STATION_CHANNEL10:
|
| 1435 | channel = 10;
|
| 1436 | break;
|
| 1437 | case WIFI_STATION_CHANNEL11:
|
| 1438 | channel = 11;
|
| 1439 | break;
|
| 1440 | case WIFI_STATION_CHANNEL12:
|
| 1441 | channel = 12;
|
| 1442 | break;
|
| 1443 | case WIFI_STATION_CHANNEL13:
|
| 1444 | channel = 13;
|
| 1445 | break;
|
| 1446 | case WIFI_STATION_CHANNEL14:
|
| 1447 | channel = 14;
|
| 1448 | break;
|
| 1449 | case WIFI_STATION_CHANNEL36:
|
| 1450 | channel = 36;
|
| 1451 | break;
|
| 1452 | case WIFI_STATION_CHANNEL40:
|
| 1453 | channel = 40;
|
| 1454 | break;
|
| 1455 | case WIFI_STATION_CHANNEL44:
|
| 1456 | channel = 44;
|
| 1457 | break;
|
| 1458 | case WIFI_STATION_CHANNEL48:
|
| 1459 | channel = 48;
|
| 1460 | break;
|
| 1461 | case WIFI_STATION_CHANNEL52:
|
| 1462 | channel = 52;
|
| 1463 | break;
|
| 1464 | case WIFI_STATION_CHANNEL56:
|
| 1465 | channel = 56;
|
| 1466 | break;
|
| 1467 | case WIFI_STATION_CHANNEL60:
|
| 1468 | channel = 60;
|
| 1469 | break;
|
| 1470 | case WIFI_STATION_CHANNEL64:
|
| 1471 | channel = 64;
|
| 1472 | break;
|
| 1473 | case WIFI_STATION_CHANNEL100:
|
| 1474 | channel = 100;
|
| 1475 | break;
|
| 1476 | case WIFI_STATION_CHANNEL104:
|
| 1477 | channel = 104;
|
| 1478 | break;
|
| 1479 | case WIFI_STATION_CHANNEL108:
|
| 1480 | channel = 108;
|
| 1481 | break;
|
| 1482 | case WIFI_STATION_CHANNEL112:
|
| 1483 | channel = 112;
|
| 1484 | break;
|
| 1485 | case WIFI_STATION_CHANNEL116:
|
| 1486 | channel = 116;
|
| 1487 | break;
|
| 1488 | case WIFI_STATION_CHANNEL120:
|
| 1489 | channel = 120;
|
| 1490 | break;
|
| 1491 | case WIFI_STATION_CHANNEL124:
|
| 1492 | channel = 124;
|
| 1493 | break;
|
| 1494 | case WIFI_STATION_CHANNEL128:
|
| 1495 | channel = 128;
|
| 1496 | break;
|
| 1497 | case WIFI_STATION_CHANNEL132:
|
| 1498 | channel = 132;
|
| 1499 | break;
|
| 1500 | case WIFI_STATION_CHANNEL136:
|
| 1501 | channel = 136;
|
| 1502 | break;
|
| 1503 | case WIFI_STATION_CHANNEL140:
|
| 1504 | channel = 140;
|
| 1505 | break;
|
| 1506 | case WIFI_STATION_CHANNEL144:
|
| 1507 | channel = 144;
|
| 1508 | break;
|
| 1509 | case WIFI_STATION_CHANNEL149:
|
| 1510 | channel = 149;
|
| 1511 | break;
|
| 1512 | case WIFI_STATION_CHANNEL153:
|
| 1513 | channel = 153;
|
| 1514 | break;
|
| 1515 | case WIFI_STATION_CHANNEL157:
|
| 1516 | channel = 157;
|
| 1517 | break;
|
| 1518 | case WIFI_STATION_CHANNEL161:
|
| 1519 | channel = 161;
|
| 1520 | break;
|
| 1521 | case WIFI_STATION_CHANNEL165:
|
| 1522 | channel = 165;
|
| 1523 | break;
|
| 1524 | default:
|
| 1525 | channel = 0;
|
| 1526 | wf_log("unknow freq[%d]MHz!!!", freq);
|
| 1527 | break;
|
| 1528 | }
|
| 1529 |
|
| 1530 | return channel;
|
| 1531 | }
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1532 |
|
| 1533 | static scan_result_t* parse_scan_result (Var *var)
|
| 1534 | {
|
| 1535 | char *ptr = NULL;
|
| 1536 | char *ptr1 = NULL;
|
| 1537 | char *ptr2 = NULL;
|
| 1538 | char *ptr3 = NULL;
|
| 1539 | char *ptr4 = NULL;
|
| 1540 | char *ptr5 = NULL;
|
| 1541 | scan_result_t *scan_result = NULL;
|
| 1542 | int frequency = 0;
|
| 1543 | int signal = 0;
|
| 1544 | char flags[WIFI_STATION_FLAGS_LEN] = {0};
|
| 1545 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1546 |
|
| 1547 | char operater_ap[32] = {0};
|
| 1548 |
|
| 1549 | if (var == NULL) {
|
| 1550 | return NULL;
|
| 1551 | }
|
| 1552 |
|
| 1553 | //²éÕÒÊÇ·ñÊǿɺöÂÔµÄÒ»ÐÐ
|
| 1554 | ptr = strstr (var->val.str.sval, WIFI_STATION_SCAN_RESULT_PARSE_IGNORE);
|
| 1555 | if (ptr) {
|
| 1556 | return NULL;
|
| 1557 | } else {
|
| 1558 | //·ÖÅäɨÃè½á¹ûÄÚ´æ
|
| 1559 | scan_result = safe_malloc (sizeof (scan_result_t), FALSE);
|
| 1560 | if (scan_result == NULL) {
|
| 1561 | return NULL;
|
| 1562 | }
|
| 1563 |
|
| 1564 | //Æ¥ÅäɨÃè½á¹ûÐÅÏ¢
|
| 1565 | sscanf (var->val.str.sval, "%19[0-9,a-f,A-F,:] %d %d %127s %127[^\n]", scan_result->mac, &frequency, &signal, flags, scan_result->ssid);
|
| 1566 |
|
| 1567 | if (strncmp (scan_result->ssid, "\\x00", 4) == 0) {
|
| 1568 | wf_log ("scan_result->mac=[%s] scan_result->ssid=[%s]is a hidden AP",
|
| 1569 | scan_result->mac, scan_result->ssid);
|
| 1570 | safe_free (scan_result);
|
| 1571 | return NULL;
|
| 1572 | }
|
| 1573 |
|
| 1574 |
|
| 1575 | sc_cfg_get ("operater_ap", operater_ap, sizeof (operater_ap));
|
| 1576 | if (strcmp (scan_result->ssid, operater_ap) == 0) {
|
| 1577 | scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1578 | } else {
|
| 1579 | scan_result->from_provider = 0;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1580 | }
|
| 1581 |
|
| 1582 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1583 | //connectStatus Á¬½Ó״̬
|
| 1584 | if (g_linked_network_id != -1 && strcmp (sta_ip_status, "connect") == 0) {
|
| 1585 | int i = 0;
|
| 1586 | i = find_linked_ap_index();
|
| 1587 | if (i != -1) {
|
| 1588 | wf_log ("g_spot_list_p[i]->ssid=[%s],scan_result->ssid=[%s]",
|
| 1589 | g_spot_list_p[i]->ssid, scan_result->ssid);
|
| 1590 |
|
| 1591 | if (strcmp (g_spot_list_p[i]->mac, scan_result->mac) == 0
|
| 1592 | && strcmp (g_spot_list_p[i]->ssid, scan_result->ssid) == 0) {
|
| 1593 | scan_result->connect_status = 1;
|
| 1594 | } else {
|
| 1595 | scan_result->connect_status = 0;
|
| 1596 |
|
| 1597 | }
|
| 1598 | wf_log ("connect_status = [%d]", scan_result->connect_status);
|
| 1599 | } else {
|
| 1600 | scan_result->connect_status = 0;
|
| 1601 | }
|
| 1602 |
|
| 1603 | } else {
|
| 1604 | scan_result->connect_status = 0;
|
| 1605 | }
|
| 1606 |
|
| 1607 | //signalÐźÅÇ¿¶È
|
| 1608 | if (signal > WIFI_STATION_SIGNAL_LEVEL4) {
|
| 1609 | scan_result->signal = 4;
|
| 1610 | } else if (signal > WIFI_STATION_SIGNAL_LEVEL3) {//kw 3
|
| 1611 | scan_result->signal = 3;
|
| 1612 | } else if (signal > WIFI_STATION_SIGNAL_LEVEL2) {
|
| 1613 | scan_result->signal = 2;
|
| 1614 | } else if (signal > WIFI_STATION_SIGNAL_LEVEL1) {
|
| 1615 | scan_result->signal = 1;
|
| 1616 | } else {
|
| 1617 | scan_result->signal = 0;
|
| 1618 | }
|
| 1619 |
|
| 1620 | //channel
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 1621 | #ifdef USE_CAP_SUPPORT
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 1622 | if (signal <= 0 && signal > -128) {
|
| 1623 | scan_result->signal_db = (signed char)signal;
|
| 1624 | }
|
| 1625 | else {
|
| 1626 | scan_result->signal_db = (signed char)(-128);
|
| 1627 | }
|
| 1628 | //scan_result->ch_freq = frequency;
|
| 1629 |
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 1630 | scan_result->channel = frequency_to_channel(frequency);
|
| 1631 | #else
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1632 | switch (frequency) {
|
| 1633 | case WIFI_STATION_CHANNEL1:
|
| 1634 | scan_result->channel = 1;
|
| 1635 | break;
|
| 1636 | case WIFI_STATION_CHANNEL2:
|
| 1637 | scan_result->channel = 2;
|
| 1638 | break;
|
| 1639 | case WIFI_STATION_CHANNEL3:
|
| 1640 | scan_result->channel = 3;
|
| 1641 | break;
|
| 1642 | case WIFI_STATION_CHANNEL4:
|
| 1643 | scan_result->channel = 4;
|
| 1644 | break;
|
| 1645 | case WIFI_STATION_CHANNEL5:
|
| 1646 | scan_result->channel = 5;
|
| 1647 | break;
|
| 1648 | case WIFI_STATION_CHANNEL6:
|
| 1649 | scan_result->channel = 6;
|
| 1650 | break;
|
| 1651 | case WIFI_STATION_CHANNEL7:
|
| 1652 | scan_result->channel = 7;
|
| 1653 | break;
|
| 1654 | case WIFI_STATION_CHANNEL8:
|
| 1655 | scan_result->channel = 8;
|
| 1656 | break;
|
| 1657 | case WIFI_STATION_CHANNEL9:
|
| 1658 | scan_result->channel = 9;
|
| 1659 | break;
|
| 1660 | case WIFI_STATION_CHANNEL10:
|
| 1661 | scan_result->channel = 10;
|
| 1662 | break;
|
| 1663 | case WIFI_STATION_CHANNEL11:
|
| 1664 | scan_result->channel = 11;
|
| 1665 | break;
|
| 1666 | case WIFI_STATION_CHANNEL12:
|
| 1667 | scan_result->channel = 12;
|
| 1668 | break;
|
| 1669 | case WIFI_STATION_CHANNEL13:
|
| 1670 | scan_result->channel = 13;
|
| 1671 | break;
|
| 1672 | default:
|
| 1673 | scan_result->channel = 0;
|
| 1674 | break;
|
| 1675 | }
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 1676 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1677 | //authMode¼øÈ¨Ä£Ê½
|
| 1678 | ptr = NULL;
|
| 1679 | ptr2 = NULL;
|
| 1680 | ptr3 = NULL;
|
| 1681 | ptr = strstr (flags, WIFI_STATION_AUTH_WPA_PSK);
|
| 1682 | ptr1 = strstr (flags, WIFI_STATION_AUTH_WPA3); //wpa2/wpa3: [WPA2-PSK+SAE-CCMP] wpa3: [WPA2-SAE-CCMP][ESS]
|
| 1683 | ptr2 = strstr (flags, WIFI_STATION_AUTH_WPA2_PSK);
|
| 1684 | ptr3 = strstr (flags, WIFI_STATION_AUTH_SHARED);
|
| 1685 | ptr4 = strstr (flags, WIFI_STATION_AUTH_WPA_EAP);
|
| 1686 | ptr5 = strstr (flags, WIFI_STATION_AUTH_WPA2_EAP);
|
| 1687 | if (ptr && ptr2) {
|
| 1688 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPAPSKWPA2PSK");
|
| 1689 | } else if (ptr1 && ptr2) {
|
| 1690 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPA2WPA3");
|
| 1691 | } else if (ptr) {
|
| 1692 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPAPSK");
|
| 1693 | } else if (ptr2) {
|
| 1694 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPA2PSK");
|
| 1695 | } else if (ptr1) {
|
| 1696 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPA3Personal");
|
| 1697 | } else if (ptr3) {
|
| 1698 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "SHARED");
|
| 1699 | } else if (ptr4 && ptr5) {
|
| 1700 |
|
| 1701 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "802.1X");
|
| 1702 | //TODO scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1703 | } else if (ptr4) {
|
| 1704 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "802.1X");
|
| 1705 |
|
| 1706 | //TODO scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1707 | } else if (ptr5) {
|
| 1708 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "802.1X");
|
| 1709 |
|
| 1710 | //TODO scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1711 | } else {
|
| 1712 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "OPEN");
|
| 1713 | }
|
| 1714 |
|
| 1715 | //encryptType¼ÓÃÜÀàÐÍ
|
| 1716 | ptr = NULL;
|
| 1717 | ptr2 = NULL;
|
| 1718 | ptr3 = NULL;
|
| 1719 | ptr = strstr (flags, WIFI_STATION_ENCRYPT_CCMP);
|
| 1720 | ptr2 = strstr (flags, WIFI_STATION_ENCRYPT_TKIP);
|
| 1721 | ptr3 = strstr (flags, WIFI_STATION_ENCRYPT_WEP);
|
| 1722 | if (ptr && ptr2) {
|
| 1723 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "TKIPCCMP");
|
| 1724 | } else if (ptr) {
|
| 1725 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "CCMP");
|
| 1726 | } else if (ptr2) {
|
| 1727 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "TKIP");
|
| 1728 | } else if (ptr3) {
|
| 1729 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "WEP");
|
| 1730 | } else {
|
| 1731 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "NONE");
|
| 1732 | }
|
| 1733 | }
|
| 1734 |
|
| 1735 | return scan_result;
|
| 1736 |
|
| 1737 | }
|
| 1738 |
|
| 1739 |
|
| 1740 | static void handle_scan_result (vector_t* v)
|
| 1741 | {
|
| 1742 | int i = 0;
|
| 1743 | int j = 0;
|
| 1744 | Var *var = NULL;
|
| 1745 | char *scan_result_str = NULL;
|
| 1746 | char *scan_result_str1 = NULL;
|
| 1747 | int scan_result_str_len = 0;
|
| 1748 | int scan_result_str_len1 = 0;
|
| 1749 | scan_result_t *scan_result = NULL;
|
| 1750 |
|
| 1751 | if (v == NULL) {
|
| 1752 | return;
|
| 1753 | }
|
| 1754 |
|
| 1755 | scan_result_str = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 1756 | scan_result_str1 = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 1757 |
|
| 1758 | if (scan_result_str == NULL || scan_result_str1 == NULL) {
|
| 1759 | safe_free (scan_result_str);
|
| 1760 | safe_free (scan_result_str1);
|
| 1761 | return;
|
| 1762 | }
|
| 1763 |
|
| 1764 | //ÏÈÊÍ·Å֮ǰ´æ´¢µÄɨÃèÈȵãÁбíÄÚ´æ
|
| 1765 | for (i = 0; i < WIFI_STATION_SCAN_RESULT_LIST_NUM; i++) {
|
| 1766 | safe_free (g_scan_result_list_p[i]);
|
| 1767 | //g_scan_result_list_p[i] = NULL;
|
| 1768 | //printf("xujian safe_free g_scan_result_list_p[%d] = %d \n", i, g_scan_result_list_p[i]);
|
| 1769 | }
|
| 1770 |
|
| 1771 | // Ö»ÄÜÊÇÔÚwebui¸üÐÂÁбí²Å»áÈ¥»ñÈ¡ÁÐ±í£¬ÆäËûÇé¿ö²»ÐèÒª
|
| 1772 | // get_spot_list();
|
| 1773 | //Ïȳõʼ»¯ÈȵãÁбíµÄÐźÅΪ0
|
| 1774 | update_spot_list_signal_connect_status (0, -1);
|
| 1775 |
|
| 1776 | for (i = 0; i < vector_size (v); i++) {
|
| 1777 | if (j >= WIFI_STATION_SCAN_RESULT_LIST_NUM) {
|
| 1778 | break;
|
| 1779 | }
|
| 1780 |
|
| 1781 | var = vector_get (v, i);
|
| 1782 | if (var->type == IS_STRING) {
|
| 1783 | scan_result = parse_scan_result (var); // ÀïÃæÓÐ ¸üРɨÃèÁбíµÄ ÈȵãÁ¬½ÓÇé¿ö£¬¸ù¾ÝmacµØÖ·½øÐÐÆ¥Åä
|
| 1784 | if (scan_result != NULL) {
|
| 1785 | g_scan_result_list_p[j] = scan_result;
|
| 1786 |
|
| 1787 | //²éÕÒ¸üжÔÓ¦ÈȵãµÄÐźÅÇ¿¶È
|
| 1788 | update_spot_signal_by_scan_result (g_scan_result_list_p[j]);
|
| 1789 |
|
| 1790 | j++;
|
| 1791 | }
|
| 1792 | }
|
| 1793 | }
|
| 1794 |
|
| 1795 | save_spot_list();
|
| 1796 |
|
| 1797 | sort_scan_result_by_signal (g_scan_result_list_p, j);
|
| 1798 |
|
| 1799 | for (i = 0; i < j; i++) {
|
| 1800 | save_scan_result (g_scan_result_list_p[i], scan_result_str, scan_result_str1);
|
| 1801 | }
|
| 1802 |
|
| 1803 | scan_result_str_len = strlen (scan_result_str);
|
| 1804 | scan_result_str_len1 = strlen (scan_result_str1);
|
| 1805 |
|
| 1806 | wf_log ("scan_result_str_len = %d scan_result_str_len1 = %d j = %d", scan_result_str_len, scan_result_str_len1, j);
|
| 1807 |
|
| 1808 | //ÏÈÇå¿ÕɨÃèÁбíNV£¬ÔÙд
|
| 1809 | sc_cfg_set ("EX_APLIST", "");
|
| 1810 | sc_cfg_set ("EX_APLIST1", "");
|
| 1811 |
|
| 1812 | if (scan_result_str_len > 0 && scan_result_str_len < WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1813 | scan_result_str[scan_result_str_len - 1] = '\0'; //È¥µô×îºóÒ»¸ö·ÖºÅ
|
| 1814 | sc_cfg_set ("EX_APLIST", scan_result_str);
|
| 1815 | }//klocwork
|
| 1816 | if (scan_result_str_len1 > 0 && scan_result_str_len1 < WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1817 | scan_result_str1[scan_result_str_len1 - 1] = '\0'; //È¥µô×îºóÒ»¸ö·ÖºÅ
|
| 1818 | sc_cfg_set ("EX_APLIST1", scan_result_str1);
|
| 1819 | }
|
| 1820 |
|
| 1821 | safe_free (scan_result_str);
|
| 1822 | safe_free (scan_result_str1);
|
| 1823 | }
|
| 1824 |
|
| 1825 |
|
| 1826 | static void ipfail_disconnect_ap()
|
| 1827 | {
|
| 1828 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 1829 | int spot_num = 0;
|
| 1830 | int i = 0;
|
| 1831 |
|
| 1832 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1833 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1834 | spot_num = atoi (wifi_profile_num);
|
| 1835 |
|
| 1836 | for (i = 0; i < spot_num; i++) {
|
| 1837 | if (g_spot_list_p[i]->network_id == g_linked_network_id) {
|
| 1838 | wf_log ("[SSID= %s] ip dhcp failed ,will be disabled, and set priority 0", g_spot_list_p[i]->ssid);
|
| 1839 | sprintf (cmd, "DISABLE_NETWORK %d", g_linked_network_id);
|
| 1840 | sta_docmd (cmd);
|
| 1841 |
|
| 1842 | sprintf (cmd, "SET_NETWORK %d priority 0", g_linked_network_id);
|
| 1843 | sta_docmd (cmd);
|
| 1844 | break;
|
| 1845 | }
|
| 1846 | }
|
| 1847 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1848 | // disable cmd will disconnect the ap , and sta_disconnected will deal the process
|
| 1849 | // i guess wpa_supplicant will connect other enabled spot
|
| 1850 |
|
| 1851 | }
|
| 1852 |
|
| 1853 |
|
| 1854 | static void handle_sim_init_status_timer()
|
| 1855 | {
|
| 1856 | char sim_zpbic_status[WIFI_ZPBIC_STATUS_LEN] = {0};
|
| 1857 |
|
| 1858 | if (g_send_count != g_pre_send_count) {
|
| 1859 | wf_log ("g_send_count is %d -----g_pre_send_count is %d", g_send_count, g_pre_send_count);
|
| 1860 | return;
|
| 1861 | }
|
| 1862 | sc_cfg_get ("sim_zpbic_status", sim_zpbic_status, sizeof (sim_zpbic_status));
|
| 1863 | if (strcmp (sim_zpbic_status, SIMCARD_INIT_NO_CARD) == 0) {
|
| 1864 | //ɾ³ýsim init ״̬¶¨Ê±Æ÷
|
| 1865 | wf_log ("sim_zpbic_status is fail");
|
| 1866 | // g_timer_sim_init_undefined_status_count = 0;
|
| 1867 | //sc_timer_delete(WIFI_STATION_TIMER_SIM_CARD_STATUS);
|
| 1868 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1869 |
|
| 1870 | return;
|
| 1871 | } else if (strcmp (sim_zpbic_status, SIMCARD_INIT_UNDEFINED) == 0) {
|
| 1872 | // printf(" handle_sim_init_status_timer in g_timer_sim_init_undefined_status_count is %d", //g_timer_sim_init_undefined_status_count);
|
| 1873 | #if 0
|
| 1874 | if (g_timer_sim_init_undefined_status_count >= 4) {
|
| 1875 | //ɾ³ýsim init ״̬¶¨Ê±Æ÷
|
| 1876 | //printf(" handle_sim_init_status_timer g_timer_sim_init_undefined_status_count is %d", //g_timer_sim_init_undefined_status_count);
|
| 1877 | //g_timer_sim_init_undefined_status_count = 0;
|
| 1878 | sc_timer_delete (WIFI_STATION_TIMER_SIM_CARD_STATUS);
|
| 1879 | wlan_station_msg_handle_ex();
|
| 1880 | return;
|
| 1881 | }
|
| 1882 | //g_timer_sim_init_undefined_status_count++;
|
| 1883 | #endif
|
| 1884 | sc_timer_create (WIFI_STATION_TIMER_SIM_CARD_STATUS,
|
| 1885 | TIMER_FLAG_ONCE, WIFI_STATION_TIMER_SIM_CARD_STATUS_INTERVAL,
|
| 1886 | wifi_station_query_sim_card_status, NULL);
|
| 1887 | } else if (strcmp (sim_zpbic_status, SIMCARD_INIT_SUCCESS) == 0) {
|
| 1888 | wf_log (" success");
|
| 1889 |
|
| 1890 | //wlan_station_msg_handle_connect();
|
| 1891 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1892 | } else {
|
| 1893 | wf_log ("unknow");
|
| 1894 |
|
| 1895 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1896 |
|
| 1897 | }
|
| 1898 | }
|
| 1899 |
|
| 1900 |
|
| 1901 | static void wpa_supplicant_scan (void)
|
| 1902 | {
|
| 1903 | sta_docmd ("SCAN");
|
| 1904 | }
|
| 1905 |
|
| 1906 | static void wpa_supplicant_get_scan_result (vector_t* v)
|
| 1907 | {
|
| 1908 | char *reply = NULL;
|
| 1909 |
|
| 1910 | if (v == NULL) {
|
| 1911 | return;
|
| 1912 | }
|
| 1913 |
|
| 1914 | //»ñȡɨÃè½á¹û
|
| 1915 | wf_log ("wlan-station get_scan_result");
|
| 1916 | // exec_script(WPA_CLI" scan_results", v);
|
| 1917 | reply = sta_docmd ("SCAN_RESULTS");
|
| 1918 |
|
| 1919 | // wf_log("[scan] scan results:\n %s" , reply);
|
| 1920 | convert2vector (reply, v);
|
| 1921 | }
|
| 1922 |
|
| 1923 |
|
| 1924 | static void *wifi_station_query_sim_card_status(void* arg)
|
| 1925 | {
|
| 1926 | //wlan_station_send_message(MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_SIM_INIT_TIMER_PROCESS, 0, NULL);
|
| 1927 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_SIM_INIT_TIMER_PROCESS, 0, NULL, 0);
|
| 1928 | return NULL;
|
| 1929 | }
|
| 1930 |
|
| 1931 | static void wifi_station_scan (void)
|
| 1932 | {
|
| 1933 | char wifi_sta_connection[WIFI_CONNECTION_LEN] = {0};
|
| 1934 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1935 |
|
| 1936 | sc_cfg_get ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 1937 |
|
| 1938 |
|
| 1939 | wf_log ("wifi_station_scan");
|
| 1940 | //¹¦ÄܹرÕÔòÖ±½ÓÍ˳ö
|
| 1941 | if (strcmp (wifi_sta_connection, "1") != 0) {
|
| 1942 | return;
|
| 1943 | }
|
| 1944 |
|
| 1945 | //ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö
|
| 1946 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1947 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0 ||
|
| 1948 | strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 1949 | wf_log ("sta_ip_status=connecting,set scan_finish=2========");
|
| 1950 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 1951 | return;
|
| 1952 | }
|
| 1953 |
|
| 1954 | //wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤
|
| 1955 | if (check_supplicant_alive() ==0) {
|
| 1956 | wf_log ("wpa supplicant is not running!xx");
|
| 1957 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ã³öÎÊÌâÁË
|
| 1958 |
|
| 1959 | return;
|
| 1960 | }
|
| 1961 | // sc_cfg_set("scan_finish", "0");
|
| 1962 |
|
| 1963 | //ɨÃè
|
| 1964 | wpa_supplicant_scan();
|
| 1965 |
|
| 1966 | }
|
| 1967 |
|
| 1968 | static void wifi_station_get_scan_results (void)
|
| 1969 | {
|
| 1970 | vector_t *v = NULL;
|
| 1971 | char wifi_sta_connection[WIFI_CONNECTION_LEN] = {0};
|
| 1972 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1973 | sc_cfg_get ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 1974 |
|
| 1975 | wf_log ("wifi_station_get_scan_results");
|
| 1976 |
|
| 1977 | //¹¦ÄܹرÕÔòÖ±½ÓÍ˳ö
|
| 1978 | if (strcmp (wifi_sta_connection, "1") != 0) {
|
| 1979 | wf_log ("wifi_sta_connection isn't 1,abormal!!!========");
|
| 1980 | return;
|
| 1981 | }
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 1982 | #ifndef USE_CAP_SUPPORT
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1983 | //ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö
|
| 1984 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1985 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0 ||
|
| 1986 | strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 1987 | wf_log ("sta_ip_status=connecting,set scan_finish=2========");
|
| 1988 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 1989 | return;
|
| 1990 | }
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 1991 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1992 | //wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤
|
| 1993 | if (check_supplicant_alive() ==0) {
|
| 1994 | wf_log ("detect wpa_supplicant isnot running========");
|
| 1995 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ã³öÎÊÌâÁË
|
| 1996 | return;
|
| 1997 | }
|
| 1998 |
|
| 1999 | v = vector_init();
|
| 2000 | wf_log ("starting scan result");
|
| 2001 |
|
| 2002 | //»ñȡɨÃè½á¹û
|
| 2003 | wpa_supplicant_get_scan_result (v);
|
| 2004 |
|
| 2005 | //´¦ÀíɨÃè½á¹û
|
| 2006 | handle_scan_result (v);
|
| 2007 |
|
| 2008 | sc_cfg_set ("scan_finish", "1");
|
| 2009 |
|
| 2010 | wf_log ("set scan finish 1");
|
| 2011 |
|
| 2012 | vector_free (v);
|
| 2013 | }
|
| 2014 |
|
| 2015 | static void wifi_station_open_apsta(void)
|
| 2016 | {
|
| 2017 | wf_log ("restart apsta");
|
| 2018 | basic_deal_all (WIFI_CFG_RESTART_APSTATION); //ÐèÒª½«µ¥¶ÀAPģʽÇл»Îªapsta ģʽ
|
| 2019 | }
|
| 2020 |
|
| 2021 | static void sta_enable_all_networks (void)
|
| 2022 | {
|
| 2023 | wf_log (" webui_select_network= %d, g_disable_other_network=%d ",
|
| 2024 | webui_select_network, g_disable_other_network);
|
| 2025 |
|
| 2026 | #if 0
|
| 2027 | // µ¥¶À´¦Àíwebui ÔÚÁ´½Ó״̬£¬Ñ¡ÔñÆäËûÈÈµã½øÐÐÁ´½ÓÇé¿ö
|
| 2028 | if (webui_select_network == 1) {
|
| 2029 | webui_select_network = 0; // ½ö½öΪÁ˱ÜÃâselectÃüÁîÒýÆðµÄÉϸöÈȵãµÄ¶Ï¿ªÊ¼þ
|
| 2030 | return;
|
| 2031 | }
|
| 2032 | #endif
|
| 2033 |
|
| 2034 | if (g_disable_other_network == 1) {
|
| 2035 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECTING);
|
| 2036 | sta_docmd ("ENABLE_NETWORK all");
|
| 2037 | // reconnect , willl connect last one ???
|
| 2038 | sta_docmd ("RECONNECT");
|
| 2039 | //has_exec_select_network =0;
|
| 2040 | g_disable_other_network = 0; // select will disable others networks, so enable all , then reset it
|
| 2041 | }
|
| 2042 | }
|
| 2043 |
|
| 2044 | static void sta_disconnected (void)
|
| 2045 | {
|
| 2046 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2047 |
|
| 2048 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2049 |
|
| 2050 | if (strcmp (sta_ip_status, "disconnect") != 0) { // ÓпÉÄÜÊǹرÕapsta£¬ÒѾ×öÁËdeinit£¬ËùÒÔÏÂÃæÁ÷³Ì¾Í²»ÐèÒªÁË
|
| 2051 | write_status (STASTATUS, "F"); //F ±íʾ ¶Ï¿ª×´Ì¬£¬0~4 ±íʾÐźÅÇ¿¶È 5¸ö¼¶±ð
|
| 2052 | //¸üÐÂEX_APLISTÖеÄÁ¬½Ó״̬Ϊ0
|
| 2053 | update_EX_APLIST_connect_status (FALSE);
|
| 2054 | //¸üÐÂÈȵãÁбíÖжÔÓ¦ÈȵãµÄÁ¬½Ó״̬Ϊfalse
|
| 2055 | update_spot_connect_status_by_status_result (FALSE);
|
| 2056 |
|
| 2057 | network_down_up (FALSE);
|
| 2058 |
|
| 2059 | g_linked_network_id_last = g_linked_network_id;
|
| 2060 |
|
| 2061 | if (0 ==webui_select_network) {
|
| 2062 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2063 | }else if(1 == webui_select_network){
|
| 2064 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECTING);
|
| 2065 | webui_select_network =0;
|
| 2066 | }
|
| 2067 |
|
| 2068 | }
|
| 2069 | }
|
| 2070 |
|
| 2071 | static void sta_disconnect (void)
|
| 2072 | {
|
| 2073 | int i = 0;
|
| 2074 | int network_id = -1;
|
| 2075 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2076 | int spot_num = 0;
|
| 2077 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2078 |
|
| 2079 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2080 | spot_num = atoi (wifi_profile_num);
|
| 2081 |
|
| 2082 | dump_spot();
|
| 2083 | for (i = 0; i < spot_num; i++) {
|
| 2084 | if (NULL != g_spot_list_p[i] && g_spot_list_p[i]->connect_status == 1) {
|
| 2085 | network_id = g_spot_list_p[i]->network_id;
|
| 2086 | break;
|
| 2087 | }
|
| 2088 | }
|
| 2089 |
|
| 2090 | if (network_id != -1) {
|
| 2091 | sprintf (cmd, "DISCONNECT");
|
| 2092 | sta_docmd (cmd);
|
| 2093 | has_exec_disconnect = 1;
|
| 2094 | // sprintf(cmd, "DISABLE_NETWORK %d", network_id);
|
| 2095 | // sta_docmd(cmd);
|
| 2096 | } else {
|
| 2097 | wf_log ("All SSID AP already disconnect, do not disconnect again");
|
| 2098 | }
|
| 2099 | }
|
| 2100 |
|
| 2101 | static void sta_connect (int network_id)
|
| 2102 | {
|
| 2103 | int i = 0;
|
| 2104 | // int network_id = -1;
|
| 2105 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2106 | int spot_num = 0;
|
| 2107 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2108 | char ssid[WIFI_STATION_SSID_LEN] = {0};
|
| 2109 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2110 | char manual_d_wifi[8] = {0};
|
| 2111 | char blc_wan_mode[32] = {0};
|
| 2112 |
|
| 2113 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2114 | spot_num = atoi (wifi_profile_num);
|
| 2115 |
|
| 2116 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2117 | sc_cfg_get ("manual_d_wifi", manual_d_wifi, sizeof (manual_d_wifi));
|
| 2118 | sc_cfg_get ("blc_wan_mode", blc_wan_mode, sizeof (blc_wan_mode));
|
| 2119 |
|
| 2120 | if ((strcmp (manual_d_wifi, "1") == 0) || (strcmp ("PPPOE", blc_wan_mode) == 0)) {
|
| 2121 | wf_log ("connect failed manual_d_wifi=%s,blc_wan_mode=%s",
|
| 2122 | manual_d_wifi, blc_wan_mode);
|
| 2123 | return;
|
| 2124 | }
|
| 2125 |
|
| 2126 | if (network_id == INVALID_NETWORK_ID) {
|
| 2127 | // set sta_ip_status, for webui
|
| 2128 | sc_cfg_get ("EX_SSID1", ssid, WIFI_STATION_SSID_LEN);
|
| 2129 | // sc_cfg_get("EX_mac", mac, WIFI_STATION_MAC_LEN);
|
| 2130 |
|
| 2131 | for (i = 0; i < spot_num; i++) {
|
| 2132 | wf_log ("g_spot_list_p[%d] = 0x%p", i , g_spot_list_p[i]);//cov m
|
| 2133 | if (g_spot_list_p[i] != NULL && !strcmp (g_spot_list_p[i]->ssid, ssid)) {
|
| 2134 |
|
| 2135 | //protect not to connect twice
|
| 2136 | if(1 == g_spot_list_p[i]->connect_status ){
|
| 2137 | wf_log ("[%s] is connect ,do not need connect again,[sta_ip_status=%s]", ssid, sta_ip_status);
|
| 2138 | return;
|
| 2139 | }
|
| 2140 | network_id = g_spot_list_p[i]->network_id;
|
| 2141 | //select¶¯×÷»áÒýÆðÁ¬×ŵÄÈȵã¶Ï¿ª£¬¶Ï¿ªÊ±ºòÒª¼Ç¼´Ë¶¯×÷£¬²»ÐèÒªÔÙÈ¥enable all
|
| 2142 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECT) == 0 )
|
| 2143 | webui_select_network = 1;
|
| 2144 | break;
|
| 2145 | }
|
| 2146 | }
|
| 2147 | }
|
| 2148 |
|
| 2149 | if (network_id == -1) {
|
| 2150 | wf_log ("got the wrong network id");
|
| 2151 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2152 | return;
|
| 2153 | } else {
|
| 2154 | // if(strcmp(sta_ip_status, WIFI_STATION_IP_STATUS_DISCONNECT) != 0)
|
| 2155 | {
|
| 2156 | sprintf (cmd, "SELECT_NETWORK %d", network_id);
|
| 2157 | sta_docmd (cmd);
|
| 2158 | g_disable_other_network = 1;
|
| 2159 | }
|
| 2160 | sprintf (cmd, "ENABLE_NETWORK %d", network_id);
|
| 2161 | sta_docmd (cmd);
|
| 2162 |
|
| 2163 | sta_docmd ("SAVE_CONFIG");
|
| 2164 |
|
| 2165 | #if 0
|
| 2166 | if (has_exec_disconnect == 1) {
|
| 2167 | sta_docmd ("RECONNECT");
|
| 2168 | has_exec_disconnect = 0; // reconnect will reset has_exec_disconnect
|
| 2169 | }
|
| 2170 | #endif
|
| 2171 | }
|
| 2172 |
|
| 2173 | // Create_connect_timeout_timer(); //´´½¨Á¬½Ó³¬Ê±¶¨Ê±Æ÷
|
| 2174 | }
|
| 2175 |
|
| 2176 | static void do_dhcp (void)
|
| 2177 | {
|
| 2178 | //Á¬½Ó³É¹¦£¬µ÷ÍøÂç×é½Ó¿Ú½øÐÐDHCPÁ÷³Ì·ÖÅäIPµØÖ·
|
| 2179 | network_down_up (TRUE);
|
| 2180 | }
|
| 2181 |
|
| 2182 | /*
|
| 2183 |
|
| 2184 | µ±¶Ï¿ªÊ±ºò£¬¸üÐÂÈȵãÁ´½Ó״̬£¬g_linked_network_id »¹ÊǼǼµÄÁ´½ÓµÄÈȵã
|
| 2185 |
|
| 2186 | sta_ip_status ¼Ç¼µÄ״̬»¹ÊÇconnect ״̬
|
| 2187 | */
|
| 2188 | static int find_linked_ap_index(void)
|
| 2189 | {
|
| 2190 | int spot_num = 0;
|
| 2191 | int i = 0;
|
| 2192 |
|
| 2193 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2194 |
|
| 2195 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2196 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2197 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2198 |
|
| 2199 | spot_num = atoi (wifi_profile_num);
|
| 2200 |
|
| 2201 | if (-1 == g_linked_network_id) return -1;
|
| 2202 |
|
| 2203 | for (i = 0; i < spot_num; i++) {
|
| 2204 | if (g_spot_list_p[i]->network_id == g_linked_network_id) {
|
| 2205 | wf_log ("find_linked_ap_index = %d", i); // Ò»°ã ¶¼ÊÇ0£¬µ±ÓÐÔËÓªÉÌÈȵãʱºò¿ÉÄܲ»ÊÇ0
|
| 2206 | return i;
|
| 2207 | }
|
| 2208 | }
|
| 2209 |
|
| 2210 | return -1;
|
| 2211 |
|
| 2212 | }
|
| 2213 |
|
| 2214 | static void disable_network (char * ssid)
|
| 2215 | {
|
| 2216 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2217 | int spot_num = 0;
|
| 2218 | int i = 0;
|
| 2219 |
|
| 2220 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2221 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2222 |
|
| 2223 | spot_num = atoi (wifi_profile_num);
|
| 2224 |
|
| 2225 | for (i = 0; i < spot_num; i++) {
|
| 2226 | if (strcmp (g_spot_list_p[i]->ssid, ssid) == 0) {
|
| 2227 | if (-1 != g_spot_list_p[i]->network_id) {
|
| 2228 | sprintf (cmd, "DISABLE_NETWORK %d", g_spot_list_p[i]->network_id);
|
| 2229 | sta_docmd (cmd);
|
| 2230 | sta_docmd ("SAVE_CONFIG");
|
| 2231 | break;
|
| 2232 | } else {
|
| 2233 | wf_log ("Error !! ssid =%s, networkid = %d\n ", g_spot_list_p[i]->ssid, g_spot_list_p[i]->network_id);
|
| 2234 | }
|
| 2235 | }
|
| 2236 | }
|
| 2237 | }
|
| 2238 |
|
| 2239 | static void update_current_EX (char * ssid, char * mac)
|
| 2240 | {
|
| 2241 | char buf[WIFI_STATION_SPOT_KEY_ID_LEN] = {0};
|
| 2242 | int spot_num = 0;
|
| 2243 | int i = 0;
|
| 2244 |
|
| 2245 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2246 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2247 |
|
| 2248 | spot_num = atoi (wifi_profile_num);
|
| 2249 |
|
| 2250 | for (i = 0; i < spot_num; i++) {
|
| 2251 | if (strcmp (g_spot_list_p[i]->ssid, ssid) == 0) {
|
| 2252 | sc_cfg_set ("EX_wifi_profile", g_spot_list_p[i]->profile_name);
|
| 2253 | sc_cfg_set ("EX_SSID1", ssid);
|
| 2254 | sc_cfg_set ("EX_AuthMode", g_spot_list_p[i]->auth_mode);
|
| 2255 | sc_cfg_set ("EX_EncrypType", g_spot_list_p[i]->encrypt_type);
|
| 2256 |
|
| 2257 | sprintf (buf, "%d", g_spot_list_p[i]->keyID);
|
| 2258 | sc_cfg_set ("EX_DefaultKeyID", buf);
|
| 2259 |
|
| 2260 | sc_cfg_set ("EX_WPAPSK1", g_spot_list_p[i]->password);
|
| 2261 | sc_cfg_set ("EX_WEPKEY", g_spot_list_p[i]->password);
|
| 2262 | sc_cfg_set ("EX_mac", mac);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2263 | #ifdef USE_CAP_SUPPORT
|
| 2264 | memset(buf, 0, sizeof(buf));
|
| 2265 | snprintf(buf, sizeof(buf), "%d", g_spot_list_p[i]->signal);
|
| 2266 | sc_cfg_set ("EX_signal", buf);
|
| 2267 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2268 | break;
|
| 2269 | }
|
| 2270 | }
|
| 2271 | }
|
| 2272 |
|
| 2273 | static void disable_other_network (int network_id)
|
| 2274 | {
|
| 2275 |
|
| 2276 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2277 | int spot_num = 0;
|
| 2278 | int i = 0;
|
| 2279 |
|
| 2280 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2281 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2282 |
|
| 2283 | spot_num = atoi (wifi_profile_num);
|
| 2284 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 2285 | return;
|
| 2286 |
|
| 2287 | for (i = 0; i < spot_num; i++) {
|
| 2288 | if (g_spot_list_p[i]->network_id == network_id) {
|
| 2289 | continue;
|
| 2290 | }
|
| 2291 |
|
| 2292 | sprintf (cmd, "DISABLE_NETWORK %d", g_spot_list_p[i]->network_id);
|
| 2293 | sta_docmd (cmd);
|
| 2294 | }
|
| 2295 |
|
| 2296 | g_disable_other_network = 1;
|
| 2297 |
|
| 2298 | }
|
| 2299 |
|
| 2300 | static void sta_connected()
|
| 2301 | {
|
| 2302 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2303 |
|
| 2304 | write_status (STASTATUS, "4"); //F ±íʾ ¶Ï¿ª×´Ì¬£¬0~4 ±íʾÐźÅÇ¿¶È 5¸ö¼¶±ð ÔÝʱÐźÅдÂú¸ñ
|
| 2305 |
|
| 2306 | //¸üÐÂÈȵãÁбíÖжÔÓ¦ÈȵãµÄÁ¬½Ó״̬Ϊtrue
|
| 2307 | update_spot_connect_status_by_status_result (TRUE);
|
| 2308 |
|
| 2309 | //¸üÐÂËùÓÐÈȵãÁбíÖеÄis_tried_connectΪfalse
|
| 2310 | //update_spot_list_is_tried_connect(FALSE);
|
| 2311 |
|
| 2312 | resort_spot_list();
|
| 2313 |
|
| 2314 | //¸üÐÂEX_APLISTÖеÄÁ¬½Ó״̬Ϊ1
|
| 2315 | update_EX_APLIST_connect_status (TRUE);
|
| 2316 |
|
| 2317 | // set the success AP to EX_SSID1
|
| 2318 | // update_current_EX();
|
| 2319 |
|
| 2320 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECT);
|
| 2321 | // Delete_connect_timeout_timer();
|
| 2322 |
|
| 2323 | wf_log ("g_linked_network_id_last = %d, g_linked_network_id= %d", g_linked_network_id_last, g_linked_network_id);
|
| 2324 |
|
| 2325 | // ²»ÊÇÎÞЧid£¬ÇÒÉÏÒ»¸öÁ´½ÓµÄºÍÕâ´ÎÁ´½ÓµÄ²»ÊÇͬһ¸öÈȵã
|
| 2326 | if (g_linked_network_id_last != -1 && g_linked_network_id_last != g_linked_network_id) { // thr first time, there's no the last id
|
| 2327 | sprintf (cmd, "SET_NETWORK %d priority 2", g_linked_network_id_last);
|
| 2328 | sta_docmd (cmd);
|
| 2329 | }
|
| 2330 | sprintf (cmd, "SET_NETWORK %d priority 3", g_linked_network_id);
|
| 2331 | sta_docmd (cmd);
|
| 2332 |
|
| 2333 | wf_log ("g_disable_other_network= %d", g_disable_other_network);
|
| 2334 |
|
| 2335 | //Èç¹û²»ÊÇselect ÃüÁîÖ®ºóÍê³ÉµÄÁ´½Ó£¬¾Í²»»ádisableÆäËûÈȵ㣬Ӧ¸ÃÊÇwpa_supplicant ÔÚenable allºó×ÔÐÐÑ¡ÔñÈÈµã½øÐÐÁ´½Ó
|
| 2336 | if (g_disable_other_network == 0) {
|
| 2337 | disable_other_network (g_linked_network_id);
|
| 2338 | // g_disable_other_network =1;
|
| 2339 | }
|
| 2340 |
|
| 2341 | sta_docmd ("SAVE_CONFIG");
|
| 2342 |
|
| 2343 | }
|
| 2344 |
|
| 2345 | static void update_eapsim_spot(void)
|
| 2346 | {
|
| 2347 | int i = 0;
|
| 2348 | int spot_num = 0;
|
| 2349 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2350 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2351 |
|
| 2352 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2353 | spot_num = atoi (wifi_profile_num);
|
| 2354 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 2355 | return;
|
| 2356 |
|
| 2357 | for (i = 0; i < spot_num; i++) {
|
| 2358 | if (strstr (g_spot_list_p[i]->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP)) { //|| strstr(auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_EAP))
|
| 2359 | if (g_cardmode == CARD_MODE_USIM) {
|
| 2360 | sprintf (cmd, "SET_NETWORK %d eap AKA", g_spot_list_p[i]->network_id);
|
| 2361 | sta_docmd (cmd);
|
| 2362 | } else {
|
| 2363 | sprintf (cmd, " SET_NETWORK %d eap SIM", g_spot_list_p[i]->network_id);
|
| 2364 | sta_docmd (cmd);
|
| 2365 | }
|
| 2366 | }
|
| 2367 | }
|
| 2368 | }
|
| 2369 |
|
| 2370 | /*
|
| 2371 | * just enable all networks let supplicant to connect automaticly
|
| 2372 | */
|
| 2373 | static int wifi_station_connect (int from_where)
|
| 2374 | {
|
| 2375 | char wifi_profile_num[8] = {0};
|
| 2376 | char manual_d_wifi[8] = {0};
|
| 2377 | char wifi_cur_state[8] = {0};
|
| 2378 | char blc_wan_mode[16] = {0};
|
| 2379 |
|
| 2380 | wf_log ("enter from %d blc_close_apsta= %d", from_where, g_blc_send_close_apsta);
|
| 2381 |
|
| 2382 | if (g_blc_send_close_apsta == 1) {
|
| 2383 | wf_log ("blc send close wifi,so only blc can open wifi again.");
|
| 2384 | return -1;
|
| 2385 | }
|
| 2386 |
|
| 2387 | //Èç¹ûûÓпÉÒÔÓõÄÈȵ㣬ֱ½Ó·µ»ØÊ§°Ü
|
| 2388 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2389 | sc_cfg_get ("manual_d_wifi", manual_d_wifi, sizeof (manual_d_wifi));
|
| 2390 | sc_cfg_get ("blc_wan_mode", blc_wan_mode, sizeof (blc_wan_mode));
|
| 2391 | sc_cfg_get ("wifi_cur_state", wifi_cur_state, sizeof (wifi_cur_state));
|
| 2392 |
|
| 2393 | //ÊÖ¶¯¶Ï¿ªwifi£¬¼´Ê¹Ö÷¿ØÔÙÈÃÁ¬½Ó£¬Ò²²»»áÔÙÁ¬½ÓÁË
|
| 2394 | if ( (strcmp (wifi_cur_state, WIFI_CLOSED) == 0) || (strcmp (wifi_profile_num, "0") == 0)
|
| 2395 | || (strcmp (manual_d_wifi, "1") == 0) || (strcmp ("PPPOE", blc_wan_mode) == 0)) {
|
| 2396 | wf_log ("connect failed wifi_cur_state=%s, wifi_profile_num=%s,manual_d_wifi=%s,blc_wan_mode=%s",
|
| 2397 | wifi_cur_state, wifi_profile_num, manual_d_wifi, blc_wan_mode);
|
| 2398 | return -1;
|
| 2399 | }
|
| 2400 |
|
| 2401 | sta_enable_all_networks();
|
| 2402 | // Create_connect_timeout_timer(); //´´½¨Á¬½Ó³¬Ê±¶¨Ê±Æ÷
|
| 2403 | return 0;
|
| 2404 | }
|
| 2405 |
|
| 2406 | static void wifi_station_nv_init (void)
|
| 2407 | {
|
| 2408 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2409 | sc_cfg_set ("scan_finish", "0");
|
| 2410 | //sc_cfg_set("EX_APLIST", "");
|
| 2411 | //sc_cfg_set("EX_APLIST1", "");
|
| 2412 | sc_cfg_set ("manual_d_wifi", "0");
|
| 2413 |
|
| 2414 | memset (g_linked_ap_mac, 0, WIFI_STATION_MAC_LEN);
|
| 2415 | g_linked_network_id = -1;
|
| 2416 | g_linked_network_id_last = -1;
|
| 2417 |
|
| 2418 | has_exec_disconnect = 0;
|
| 2419 | webui_select_network = 0;
|
| 2420 | g_disable_other_network = 1;
|
| 2421 |
|
| 2422 | get_spot_list();
|
| 2423 | sync_nv_spot_list_conf_file();
|
| 2424 | update_spot_list_signal_connect_status (0, 0);
|
| 2425 | save_spot_list();
|
| 2426 | }
|
| 2427 |
|
| 2428 | static int exist_eap_simaka_spot()
|
| 2429 | {
|
| 2430 | int i = 0;
|
| 2431 | int spot_num = 0;
|
| 2432 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2433 |
|
| 2434 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2435 | spot_num = atoi (wifi_profile_num);
|
| 2436 |
|
| 2437 | for (i = 0; i < spot_num; i++) {
|
| 2438 | if (strstr (g_spot_list_p[i]->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP)) //|| strstr(auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_EAP))
|
| 2439 | return g_spot_list_p[i]->network_id;
|
| 2440 | }
|
| 2441 | return -1;
|
| 2442 | }
|
| 2443 |
|
| 2444 |
|
| 2445 | void wlan_station_init (void)
|
| 2446 | {
|
| 2447 | if(1 == g_wpa_supplicant)return ;
|
| 2448 |
|
| 2449 | wf_log ("time=%d", time(NULL));
|
| 2450 | if (sta_manager->start_supplicant(sta_manager) == 0) {
|
| 2451 | wf_log ("time=%d", time(NULL));
|
| 2452 | wf_log (" wpa_supplicant run success");
|
| 2453 |
|
| 2454 | if (0 == wifi_connect_to_supplicant(&sta_manager->sock)) {
|
| 2455 | wf_log (" socket connect success");
|
| 2456 | sem_post (&g_wpa_supplicant_id);
|
| 2457 | g_wpa_supplicant = 1;
|
| 2458 | } else {
|
| 2459 | wlan_station_deinit();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2460 | #ifdef USE_CAP_SUPPORT
|
| 2461 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_NONE);
|
| 2462 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2463 | return;
|
| 2464 | }
|
| 2465 | }else {
|
| 2466 | wf_log ("wpa_supplicant start failed");
|
| 2467 | wlan_station_deinit();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2468 | #ifdef USE_CAP_SUPPORT
|
| 2469 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_NONE);
|
| 2470 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2471 | return;
|
| 2472 | }
|
| 2473 |
|
| 2474 |
|
| 2475 | wifi_station_nv_init();
|
| 2476 | sta_docmd ("SCAN_INTERVAL 15");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2477 |
|
| 2478 | #ifdef USE_CAP_SUPPORT
|
| 2479 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_IDLE, IN_WIFI_REASON_CODE_NONE);
|
| 2480 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2481 |
|
| 2482 | //Èç¹ûÓÐEAP-SIMÈȵ㣬ÔòÐèÒªÏÈ×߸òéѯSIM¿¨ÐÅÏ¢Á÷³Ì
|
| 2483 |
|
| 2484 | if (-1 != exist_eap_simaka_spot()) { // ²»ÊÇ-1£¬ Ôò´æÔÚsimaka spot
|
| 2485 | //eap send msg for card type
|
| 2486 | /*if((0 == strcmp(ssid, "CMCC-SIM-test1")) || (0 == strcmp(ssid, "CMCC-SIM-test2")))
|
| 2487 | {
|
| 2488 | strcpy(auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP);
|
| 2489 | }*/
|
| 2490 |
|
| 2491 | //if(0 == wlan_station_send_message(ZUFI_MODULE_ID_AT_MAIN, MODULE_ID_CARD_MODE_REQ, 0, NULL))
|
| 2492 | if (0 == ipc_send_message (MODULE_ID_WIFI, MODULE_ID_AT_CTL, MSG_CMD_CARD_MODE_REQ, 0, NULL, 0)) {
|
| 2493 | //·¢ËÍ ²éѯ¿¨Ä£Ê½ÏûÏ¢£¬µÈ´ýÒì²½·µ»Ø
|
| 2494 | g_pre_send_count = g_send_count;
|
| 2495 | return;
|
| 2496 | } else {
|
| 2497 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2498 | }
|
| 2499 | } else {
|
| 2500 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2501 | }
|
| 2502 | }
|
| 2503 |
|
| 2504 | static void clear_conf_file(void)
|
| 2505 | {
|
| 2506 | sta_docmd ("REMOVE_NETWORK all");
|
| 2507 | sta_docmd ("SAVE_CONFIG");
|
| 2508 | }
|
| 2509 |
|
| 2510 | static void clear_spot_list(void)
|
| 2511 | {
|
| 2512 | int i = 0;
|
| 2513 | wf_log ("[clear_spot_list]");
|
| 2514 |
|
| 2515 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 2516 | if (g_spot_list_p[i] != NULL) {
|
| 2517 | safe_free (g_spot_list_p[i]);
|
| 2518 | }
|
| 2519 |
|
| 2520 | }
|
| 2521 |
|
| 2522 | }
|
| 2523 | static void wlan_station_deinit(void)
|
| 2524 | {
|
| 2525 | int count = 50;
|
| 2526 |
|
| 2527 | wf_log ("enter");
|
| 2528 |
|
| 2529 | sta_docmd ("DISABLE_NETWORK all");
|
| 2530 | sta_docmd ("SAVE_CONFIG");
|
| 2531 | #if !defined(__REALTEK_8192_CHIP__)
|
| 2532 | sta_docmd ("TERMINATE");
|
| 2533 | usleep (150000);
|
| 2534 |
|
| 2535 | while (count-- > 0) {
|
| 2536 | if (check_alive(&sta_manager->sock) == 0) {
|
| 2537 | wf_log ("TERMINATE over\n");
|
| 2538 | break;
|
| 2539 | }
|
| 2540 | usleep (100000);
|
| 2541 | }
|
| 2542 | #endif
|
| 2543 |
|
| 2544 | g_disable_other_network = 1;
|
| 2545 | sta_manager->close_connection(sta_manager);
|
| 2546 |
|
| 2547 | g_wpa_supplicant = 0;
|
| 2548 |
|
| 2549 | clear_spot_list();
|
| 2550 | memset (g_linked_ap_mac, 0, WIFI_STATION_MAC_LEN);
|
| 2551 | g_linked_network_id = -1;
|
| 2552 | g_linked_network_id_last = -1;
|
| 2553 | has_exec_disconnect = 0;
|
| 2554 | webui_select_network = 0;
|
| 2555 | sc_cfg_set ("scan_finish", "0");
|
| 2556 | sc_cfg_set ("EX_APLIST", "");
|
| 2557 | sc_cfg_set ("EX_APLIST1", "");
|
| 2558 |
|
| 2559 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2560 |
|
| 2561 | }
|
| 2562 |
|
| 2563 |
|
| 2564 | void wifi_station_close()
|
| 2565 | {
|
| 2566 | sta_disconnected();
|
| 2567 | wlan_station_deinit();
|
| 2568 | }
|
| 2569 |
|
| 2570 |
|
| 2571 | BOOL wlan_station_is_station_msg (unsigned short msg)
|
| 2572 | {
|
| 2573 | if (msg >= MSG_CMD_WIFI_STATION_OPEN && msg <= MSG_CMD_WIFI_STATION_END) {
|
| 2574 | return TRUE;
|
| 2575 | } else if(msg == MSG_CMD_NET_WAN_DIAL_FAIL ||
|
| 2576 | msg == MSG_CMD_CARD_MODE_RSP ||
|
| 2577 | msg == MSG_CMD_PIN_STATUS_RSP){
|
| 2578 | return TRUE;
|
| 2579 | }
|
| 2580 | else{
|
| 2581 | return FALSE;
|
| 2582 | }
|
| 2583 | }
|
| 2584 |
|
| 2585 | static void wlan_station_msg_handle_card_mode_for_eap (MSG_BUF *pMsg)
|
| 2586 | {
|
| 2587 | #if 0
|
| 2588 | spot_t *p = NULL;
|
| 2589 | char profile_name[WIFI_STATION_SPOT_PROFILE_NAME_LEN] = {0};
|
| 2590 | char *ssid = NULL;
|
| 2591 | char auth_mode[WIFI_STATION_AUTH_MODE_LEN] = {0};
|
| 2592 | char encrypt_type[WIFI_STATION_ENCRYPT_TYPE_LEN] = {0};
|
| 2593 | char *password_wpa = NULL;
|
| 2594 | char *password_wep = NULL;
|
| 2595 | #endif
|
| 2596 | char cardmodestr[WIFI_CARD_MODE_LEN+1] = {0};
|
| 2597 | int cardmode = 0;
|
| 2598 |
|
| 2599 | if (g_send_count != g_pre_send_count) {
|
| 2600 | wf_log ("------------wlan_station_msg_handle_card_mode-----g_send_count is %d -----g_pre_send_count is %d", g_send_count, g_pre_send_count);
|
| 2601 | return;
|
| 2602 | }
|
| 2603 | wf_log ("------------wlan_station_msg_handle_card_mode------------++++++++++++++++++++++++++++++");
|
| 2604 | if (pMsg != NULL) {
|
| 2605 | //kw 3
|
| 2606 | memcpy (cardmodestr, pMsg->aucDataBuf, WIFI_CARD_MODE_LEN);
|
| 2607 |
|
| 2608 | wf_log ("------------wlan_station_msg_handle_card_mode--------333----++++++++++++++++++++++++++++++");
|
| 2609 | cardmode = atoi (cardmodestr);
|
| 2610 | wf_log ("------------wlan_station_msg_handle_card_mode--------cardmode is %d----++++++++++++++++++++++++++++++", cardmode);
|
| 2611 | if (cardmode < 0 || cardmode > INT_MAX-1) //kw 3, cardmode 0-2
|
| 2612 | cardmode = 0;
|
| 2613 | }
|
| 2614 |
|
| 2615 | g_cardmode = cardmode;
|
| 2616 |
|
| 2617 | if (cardmode != CARD_MODE_USIM && cardmode != CARD_MODE_SIM) {
|
| 2618 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2619 | } else {
|
| 2620 | //eap send msg for pin status
|
| 2621 | if (0 == ipc_send_message (MODULE_ID_WIFI, MODULE_ID_AT_CTL, MSG_CMD_PIN_STATUS_REQ, 0, NULL, 0)) {
|
| 2622 | wf_log ("------------ipc_send_message-------MSG_CMD_PIN_STATUSREQ-----++++++++++++++++++++++++++++++");
|
| 2623 | g_pre_send_count = g_send_count;
|
| 2624 | return;
|
| 2625 | } else {
|
| 2626 | wf_log ("------------ipc_send_message-------MODULE_ID_PIN_STATUS_REQ--ex---++++++++++++++++++++++++++++++");
|
| 2627 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2628 |
|
| 2629 | }
|
| 2630 |
|
| 2631 | //wlan_station_msg_handle_connect();
|
| 2632 | }
|
| 2633 | }
|
| 2634 |
|
| 2635 | static void wlan_station_msg_handle_pin_status_for_eap (MSG_BUF *pMsg)
|
| 2636 | {
|
| 2637 | char pinstatusstr[WIFI_PIN_STATUS_LEN+1] = {0};
|
| 2638 | int pinstatus = 0;
|
| 2639 | char sim_zpbic_status[WIFI_ZPBIC_STATUS_LEN] = {0};
|
| 2640 |
|
| 2641 | if (g_send_count != g_pre_send_count) {
|
| 2642 | wf_log ("------------wlan_station_msg_handle_pin_status_for_eap-----g_send_count is %d -----g_pre_send_count is %d", g_send_count, g_pre_send_count);
|
| 2643 | return;
|
| 2644 | }
|
| 2645 | wf_log ("------------wlan_station_msg_handle_pin_status_for_eap------------++++++++++++++++++++++++++++++");
|
| 2646 | if (pMsg != NULL) {
|
| 2647 | //kw 3
|
| 2648 | memcpy (pinstatusstr, pMsg->aucDataBuf, WIFI_PIN_STATUS_LEN);
|
| 2649 |
|
| 2650 | pinstatus = atoi (pinstatusstr);
|
| 2651 |
|
| 2652 | if (PIN_STATUS_NO_PIN != pinstatus) {
|
| 2653 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2654 |
|
| 2655 | } else {
|
| 2656 | //Ôö¼Ó¶Ô¿¨³õʼ»¯ÊÇ·ñÍê³ÉµÄÅжÏ
|
| 2657 | sc_cfg_get ("sim_zpbic_status", sim_zpbic_status, sizeof (sim_zpbic_status));
|
| 2658 | if (0 == strcmp (sim_zpbic_status, SIMCARD_INIT_SUCCESS)) {
|
| 2659 | wf_log ("--------------------sim_zpbic_status-----SIMCARD_INIT_SUCCESS ++++++++++++++-------------");
|
| 2660 | update_eapsim_spot();
|
| 2661 | // wlan_station_msg_handle_connect();
|
| 2662 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2663 | } else if (0 == strcmp (sim_zpbic_status, SIMCARD_INIT_UNDEFINED)) {
|
| 2664 | wf_log ("--------------------sim_zpbic_status-----SIMCARD_INIT_UNDEFINED ++++++++++++++-------------");
|
| 2665 | //g_timer_sim_init_undefined_status_count = 0;
|
| 2666 | g_pre_send_count = g_send_count;
|
| 2667 | //δÍê³É¿¨ÎļþµÄ³õʼ»¯ÎÞ·¨½øÐÐeapÈÏÖ¤£¬ÐèÒª´´½¨¶¨Ê±Æ÷ÂÖѯsim¿¨³õʼ»¯×´Ì¬
|
| 2668 | sc_timer_create (WIFI_STATION_TIMER_SIM_CARD_STATUS,
|
| 2669 | TIMER_FLAG_ONCE, WIFI_STATION_TIMER_SIM_CARD_STATUS_INTERVAL,
|
| 2670 | wifi_station_query_sim_card_status, NULL);
|
| 2671 | } else {
|
| 2672 | wf_log ("--------------------sim_zpbic_status-----wlan_station_msg_handle_ex ++++++++++++++-------------");
|
| 2673 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2674 | }
|
| 2675 | }
|
| 2676 | }
|
| 2677 | }
|
| 2678 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2679 | #ifdef USE_CAP_SUPPORT
|
| 2680 | static void cap_update_spot_param(wlan_sta_param_t *param)
|
| 2681 | {
|
| 2682 | updateinfo_t info = {0};
|
| 2683 | int spot_num = 0;
|
| 2684 | char spot_tmp[WIFI_STATION_SPOT_LEN] = {0};
|
| 2685 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2686 |
|
| 2687 | snprintf(spot_tmp, sizeof(spot_tmp), "123456789123456789,0,0,0,%s,%s,%s,%s,0,0F:00:00:00:00:00",
|
| 2688 | param->ssid, param->authmode, param->encrypt, param->pwd);
|
| 2689 | if (g_wpa_supplicant == 1) {
|
| 2690 | /*request disconnection from the currently connected
|
| 2691 | * network. This will stop any ongoing scans and initiate deauthentication.
|
| 2692 | */
|
| 2693 | sta_docmd("DISCONNECT");
|
| 2694 |
|
| 2695 | sc_cfg_get("wifi_profile_num", wifi_profile_num, sizeof(wifi_profile_num));
|
| 2696 | spot_num = atoi(wifi_profile_num);
|
| 2697 | if (spot_num > 0) {
|
| 2698 | strncpy(info.action, "delete", sizeof(info.action)-1);
|
| 2699 | //strncpy(info.spot, wifi_update_profile, sizeof(info.spot)-1);
|
| 2700 | sc_cfg_get("wifi_profile", info.spot, sizeof(info.spot));
|
| 2701 | webui_update_spot_list(&info);
|
| 2702 | //usleep(100);
|
| 2703 | sc_cfg_set("sta_ip_status", "disconnect");
|
| 2704 | }
|
| 2705 |
|
| 2706 |
|
| 2707 | sc_cfg_set("wifi_profile_num", "1");
|
| 2708 | sc_cfg_set("wifi_profile", spot_tmp);
|
| 2709 | memset(&info, 0, sizeof(info));
|
| 2710 | strncpy(info.action, "add", sizeof(info.action)-1);
|
| 2711 | strncpy(info.spot, spot_tmp, sizeof(info.spot)-1);
|
| 2712 | webui_update_spot_list(&info);
|
| 2713 | }
|
| 2714 | else {
|
| 2715 | //ûÓгõʼ»¯µÄʱºò
|
| 2716 | sc_cfg_set("wifi_profile_num", "1");
|
| 2717 | sc_cfg_set("wifi_profile", spot_tmp);
|
| 2718 | //wpa_suplicantµÄÅäÖÿ´ÊÇ·ñÐèÒª¸Ä£¬Èç¹ûÒѳõʼ»¯ÁË£¬Ó¦¸ÃÒª¸Ä
|
| 2719 | }
|
| 2720 |
|
| 2721 | }
|
| 2722 |
|
xf.li | df7f8ba | 2024-09-12 23:53:34 -0700 | [diff] [blame^] | 2723 | /* Started by AICoder, pid:17c05ab2631ba551484608a0f093f11de3c5165e */
|
| 2724 | void cap_close_station(void)
|
| 2725 | {
|
| 2726 | g_cap_sta_enable = 0;
|
| 2727 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_NONE, IN_WIFI_REASON_CODE_NONE);
|
| 2728 | //sc_cfg_set("wifi_sta_connection", "0");
|
| 2729 |
|
| 2730 | if (0 == g_wpa_supplicant) {
|
| 2731 | wf_log("station has closed");
|
| 2732 | return;
|
| 2733 | }
|
| 2734 | //MSG_CMD_WIFI_STATION_CLOSE;
|
| 2735 | sta_disconnected();
|
| 2736 | wlan_station_deinit();
|
| 2737 | if (g_work_mode == IN_WIFI_WORK_MODE_AP0 || g_work_mode == IN_WIFI_WORK_MODE_AP1) {
|
| 2738 | //no mssid, not need
|
| 2739 | //basic_deal_all (WIFI_CFG_RESTART_AP);
|
| 2740 | }
|
| 2741 | else {
|
| 2742 | sc_cfg_set ("wifi_cur_state", WIFI_CLOSED);
|
| 2743 | }
|
| 2744 |
|
| 2745 | }
|
| 2746 | /* Ended by AICoder, pid:17c05ab2631ba551484608a0f093f11de3c5165e */
|
| 2747 |
|
| 2748 | /* Started by AICoder, pid:ife7a60485s530a149930907308c8b1b9099759f */
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2749 | static void cap_station_enable(wlan_sta_enable_t *sta_ena)
|
| 2750 | {
|
| 2751 | if (sta_ena->enable == 1) {
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 2752 | g_cap_sta_enable = 1;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2753 | if (1 == g_wpa_supplicant) {
|
| 2754 | wf_log("station has opened");
|
| 2755 | return;
|
| 2756 | }
|
| 2757 | //MSG_CMD_WIFI_STATION_OPEN;
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 2758 | if (g_work_mode == IN_WIFI_WORK_MODE_AP0 || g_work_mode == IN_WIFI_WORK_MODE_AP1) {
|
| 2759 | wifi_station_open_apsta();
|
| 2760 | //wifi_station_connect(MODULE_ID_WEB_CGI);//´ò¿ªµÄʱºòÒѾÁ¬ÁËÒ»´Î£¬Ã»ÓбØÒªÔÙ´ÎÁ¬½Ó
|
| 2761 | }
|
| 2762 | else {
|
| 2763 | wf_log("-MSG_CMD_WIFI_STATION_OPEN-");
|
xf.li | df7f8ba | 2024-09-12 23:53:34 -0700 | [diff] [blame^] | 2764 | sc_cfg_set ("wifi_cur_state", WIFI_OPENED);
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 2765 | wlan_station_init();
|
| 2766 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2767 | }
|
| 2768 | else {
|
xf.li | df7f8ba | 2024-09-12 23:53:34 -0700 | [diff] [blame^] | 2769 | cap_close_station();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2770 | }
|
| 2771 |
|
| 2772 | }
|
xf.li | df7f8ba | 2024-09-12 23:53:34 -0700 | [diff] [blame^] | 2773 | /* Ended by AICoder, pid:ife7a60485s530a149930907308c8b1b9099759f */
|
| 2774 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2775 |
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 2776 | static int get_cur_ap_rssi(void)
|
| 2777 | {
|
| 2778 | char *reply = NULL;
|
| 2779 | int rssi = 0;
|
| 2780 | char *start = NULL;
|
| 2781 | char *end = NULL;
|
| 2782 |
|
| 2783 | reply = sta_docmd("SIGNAL_POLL");
|
| 2784 | if (reply == NULL) {
|
| 2785 | wf_log("SIGNAL_POLL failed\n");
|
| 2786 | return 0;
|
| 2787 | }
|
| 2788 |
|
| 2789 | start = strstr(reply, "RSSI=");
|
| 2790 | if (start != NULL) {
|
| 2791 | start += strlen("RSSI="); // skip "RSSI="
|
| 2792 | rssi = strtol(start, &end, 10);
|
| 2793 | if (start == end) {
|
| 2794 | wf_log("Failed to convert RSSI\n");
|
| 2795 | return 0;
|
| 2796 | }
|
| 2797 | } else {
|
| 2798 | wf_log("Could not find RSSI\n");
|
| 2799 | return 0;
|
| 2800 | }
|
| 2801 | return rssi;
|
| 2802 | }
|
| 2803 |
|
| 2804 | static int get_cur_ap_signal(char *mac)
|
| 2805 | {
|
| 2806 | int rssi = 0;
|
| 2807 |
|
| 2808 | int spot_num = 0;
|
| 2809 | int i = 0;
|
| 2810 |
|
| 2811 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2812 | sc_cfg_get("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2813 |
|
| 2814 | spot_num = atoi(wifi_profile_num);
|
| 2815 |
|
| 2816 | for (i = 0; i < spot_num; i++) {
|
| 2817 | if (strcmp(g_spot_list_p[i]->mac, mac) == 0) {
|
| 2818 | rssi = (int)g_spot_list_p[i]->signal;
|
| 2819 | break;
|
| 2820 | }
|
| 2821 | }
|
| 2822 |
|
| 2823 | return rssi;
|
| 2824 | }
|
| 2825 |
|
| 2826 | static unsigned char single_db_to_level(int rssi)
|
| 2827 | {
|
| 2828 | unsigned char level = 0;
|
| 2829 |
|
| 2830 | if (rssi > WIFI_STATION_SIGNAL_LEVEL4) {
|
| 2831 | level = 4;
|
| 2832 | } else if (rssi > WIFI_STATION_SIGNAL_LEVEL3) {//kw 3
|
| 2833 | level = 3;
|
| 2834 | } else if (rssi > WIFI_STATION_SIGNAL_LEVEL2) {
|
| 2835 | level = 2;
|
| 2836 | } else if (rssi > WIFI_STATION_SIGNAL_LEVEL1) {
|
| 2837 | level = 1;
|
| 2838 | } else {
|
| 2839 | level = 0;
|
| 2840 | }
|
| 2841 |
|
| 2842 | return level;
|
| 2843 | }
|
| 2844 |
|
| 2845 | static int netmask_length(const char *netmask)
|
| 2846 | {
|
| 2847 | struct in_addr addr;
|
| 2848 | int count = 0;
|
| 2849 | int i = 0;
|
| 2850 |
|
| 2851 | inet_pton(AF_INET, netmask, &addr);
|
| 2852 | for (i = 0; i < 32; i++) {
|
| 2853 | if ((addr.s_addr >> i) & 1) {
|
| 2854 | count++;
|
| 2855 | }
|
| 2856 | }
|
| 2857 | return count;
|
| 2858 | }
|
| 2859 |
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 2860 | int send_sta_status_to_cap(int status, int reason)
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2861 | {
|
| 2862 | int ret = 0;
|
| 2863 | wlan_sta_status_t sta_stat = {0};
|
| 2864 |
|
| 2865 | sta_stat.status = status;
|
| 2866 | //2.4 5G¶ÀÁ¢Íø¿ÚʱÐèÐÞ¸Ä
|
| 2867 | strncpy(sta_stat.ifname, sta_manager->drv_proxy.iface_name, sizeof(sta_stat.ifname) - 1);
|
| 2868 |
|
| 2869 | if (sta_stat.status == IN_WIFI_STA_STATUS_CONNECTING
|
| 2870 | || sta_stat.status == IN_WIFI_STA_STATUS_ASSOCIATED
|
| 2871 | || sta_stat.status == IN_WIFI_STA_STATUS_CONNECTED) {
|
| 2872 | char wifi_mac[20] = {0};
|
| 2873 | char wifi_signal[20] = {0};
|
| 2874 | sc_cfg_get("EX_mac", wifi_mac, sizeof(wifi_mac));
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 2875 | //sc_cfg_get("EX_signal", wifi_signal, sizeof(wifi_signal));
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2876 |
|
| 2877 | strncpy(sta_stat.ap_bssid, wifi_mac, sizeof(sta_stat.ap_bssid) - 1);
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 2878 | //sta_stat.rssi = get_cur_ap_signal(wifi_mac);
|
| 2879 | sta_stat.rssi = get_cur_ap_rssi();
|
| 2880 | sta_stat.signal_level = single_db_to_level(sta_stat.rssi);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2881 | }
|
| 2882 |
|
| 2883 | if (sta_stat.status == IN_WIFI_STA_STATUS_ERROR) {
|
| 2884 | sta_stat.reason_code = reason;
|
| 2885 | }
|
| 2886 |
|
| 2887 | if (sta_stat.status == IN_WIFI_STA_STATUS_CONNECTED) {
|
| 2888 | char wbwanv6_enable[20] = {0};
|
| 2889 | char wifiwan_ip[64] = {0};
|
| 2890 | char wifiwan_ipv6[64] = {0};
|
| 2891 | char nv_wifiwan[20] = {0};
|
| 2892 | char nv_wifiwan_ip[32] = {0};
|
| 2893 | char nv_wifiwan_ipv6[32] = {0};
|
| 2894 |
|
| 2895 | //wlan
|
| 2896 | sc_cfg_get("wifiwan", nv_wifiwan, sizeof(nv_wifiwan));
|
| 2897 | //ipv4
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 2898 | sta_stat.has_addr = 1;
|
| 2899 | //ip
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2900 | snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_ip", nv_wifiwan);
|
| 2901 | sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 2902 | strncpy(sta_stat.addr.addr, wifiwan_ip, sizeof(sta_stat.addr.addr) - 1);
|
| 2903 | //netmask
|
| 2904 | memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));
|
| 2905 | memset(wifiwan_ip, 0, sizeof(wifiwan_ip));
|
| 2906 | snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_nm", nv_wifiwan);
|
| 2907 | sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));
|
| 2908 | strncpy(sta_stat.addr.netmask, wifiwan_ip, sizeof(sta_stat.addr.netmask) - 1);
|
| 2909 | sta_stat.addr.subnet_bits = netmask_length(sta_stat.addr.netmask);
|
| 2910 | //gateway
|
| 2911 | memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));
|
| 2912 | memset(wifiwan_ip, 0, sizeof(wifiwan_ip));
|
| 2913 | snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_gw", nv_wifiwan);
|
| 2914 | sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));
|
| 2915 | strncpy(sta_stat.addr.gateway, wifiwan_ip, sizeof(sta_stat.addr.gateway) - 1);
|
| 2916 | //pdns
|
| 2917 | memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));
|
| 2918 | memset(wifiwan_ip, 0, sizeof(wifiwan_ip));
|
| 2919 | snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_pridns", nv_wifiwan);
|
| 2920 | sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));
|
| 2921 | strncpy(sta_stat.addr.dnsp, wifiwan_ip, sizeof(sta_stat.addr.dnsp) - 1);
|
| 2922 | //sdns
|
| 2923 | memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));
|
| 2924 | memset(wifiwan_ip, 0, sizeof(wifiwan_ip));
|
| 2925 | snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_secdns", nv_wifiwan);
|
| 2926 | sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));
|
| 2927 | strncpy(sta_stat.addr.dnss, wifiwan_ip, sizeof(sta_stat.addr.dnss) - 1);
|
| 2928 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2929 | //ipv6
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2930 | sc_cfg_get("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
|
| 2931 | if (atoi(wbwanv6_enable) == 1) {
|
| 2932 | sta_stat.has_addr6 = 1;
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 2933 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_ip", nv_wifiwan);
|
| 2934 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2935 | strncpy(sta_stat.addr6.addr, wifiwan_ipv6, sizeof(sta_stat.addr6.addr) - 1);
|
| 2936 | //prefix
|
| 2937 | memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));
|
| 2938 | memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));
|
| 2939 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_prefix_info", nv_wifiwan);
|
| 2940 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2941 | strncpy(sta_stat.addr6.prefix, wifiwan_ipv6, sizeof(sta_stat.addr6.prefix) - 1);
|
| 2942 | //len
|
| 2943 | memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));
|
| 2944 | memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));
|
| 2945 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_prefix_len", nv_wifiwan);
|
| 2946 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2947 | sta_stat.addr6.prefix_bits = atoi(wifiwan_ipv6);
|
| 2948 | //gateway
|
| 2949 | memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));
|
| 2950 | memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));
|
| 2951 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_gw", nv_wifiwan);
|
| 2952 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2953 | strncpy(sta_stat.addr6.gateway, wifiwan_ipv6, sizeof(sta_stat.addr6.gateway) - 1);
|
| 2954 | //pdns
|
| 2955 | memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));
|
| 2956 | memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));
|
| 2957 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_pridns_auto", nv_wifiwan);
|
| 2958 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2959 | strncpy(sta_stat.addr6.dnsp, wifiwan_ipv6, sizeof(sta_stat.addr6.dnsp) - 1);
|
| 2960 | //sdns
|
| 2961 | memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));
|
| 2962 | memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));
|
| 2963 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_secdns_auto", nv_wifiwan);
|
| 2964 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2965 | strncpy(sta_stat.addr6.dnss, wifiwan_ipv6, sizeof(sta_stat.addr6.dnss) - 1);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2966 | }
|
| 2967 | }
|
| 2968 |
|
| 2969 | ret = send_soc_msg(FAR_PS, MODULE_ID_WIFI, MSG_CMD_CAP_STA_STATUS, sizeof(sta_stat), &sta_stat);
|
| 2970 | if (ret != 0) {
|
| 2971 | wf_log("send_soc_msg fail, ret:%d\n", ret);
|
| 2972 | }
|
| 2973 |
|
| 2974 | return ret;
|
| 2975 | }
|
| 2976 |
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 2977 | static void cap_station_info(MSG_BUF *pMsg)
|
| 2978 | {
|
| 2979 | wlan_sta_stat_sync_t sta_stat = {0};
|
| 2980 | sta_stat.rssi = get_cur_ap_rssi();
|
| 2981 | ipc_send_message(MODULE_ID_WIFI, pMsg->src_id, MSG_CMD_CAP_WIFI_STA_STAT_RSP, sizeof(sta_stat), &sta_stat, 0);
|
| 2982 | }
|
| 2983 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2984 | static void cap_station_scan(void)
|
| 2985 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2986 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 2987 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2988 | wf_log("cap_station_scan");
|
| 2989 | //¹¦ÄܹرÕÔòÖ±½ÓÍ˳ö
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2990 | //wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤
|
| 2991 | if (check_supplicant_alive() == 0) {
|
| 2992 | wf_log("wpa supplicant is not running!xx");
|
| 2993 | //Õânv¿ÉÒÔ¿¼ÂÇcap¸´ÓÃ
|
| 2994 | sc_cfg_set("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ã³öÎÊÌâÁË
|
| 2995 | return;
|
| 2996 | }
|
| 2997 |
|
| 2998 | //ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö Á¬½ÓʱÄÚ²¿ÓÐɨÃè ½á¹û²»Ò»¶¨ÊÇÉϲãÏëÒªµÄ
|
| 2999 | sc_cfg_get("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3000 | if (strcmp(sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 3001 | wf_log("sta_ip_status=connecting,set scan_finish=2========");
|
| 3002 | //sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 3003 | //return;
|
| 3004 | }
|
| 3005 |
|
| 3006 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 3007 | wf_log ("sta_ip_status=dhcping,set scan_finish=2========");
|
| 3008 | //¼ÌÐøÉ¨Ãè¿´¿´
|
| 3009 | //sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 3010 | //return;
|
| 3011 | }
|
| 3012 |
|
| 3013 | //ɨÃè
|
| 3014 | g_cap_scan = 1;
|
| 3015 | wpa_supplicant_scan();
|
| 3016 |
|
| 3017 |
|
| 3018 | }
|
| 3019 |
|
| 3020 | static int transe_sta_auth_mode(char *authmode)
|
| 3021 | {
|
| 3022 | int sc_auth = CAP_WIFI_AUTH_UNSUP;
|
| 3023 |
|
| 3024 | if (strcmp(authmode, "OPEN") == 0) {
|
| 3025 | sc_auth = CAP_WIFI_AUTH_OPEN;
|
| 3026 | }
|
| 3027 | else if (strcmp(authmode, "WPA2PSK") == 0) {
|
| 3028 | sc_auth = CAP_WIFI_AUTH_WPA2;
|
| 3029 | }
|
| 3030 | else if (strcmp(authmode, "WPA3Personal") == 0) {
|
| 3031 | sc_auth = CAP_WIFI_AUTH_WPA3;
|
| 3032 | }
|
| 3033 | else if (strcmp(authmode, "WPAPSKWPA2PSK") == 0) {
|
| 3034 | sc_auth = CAP_WIFI_AUTH_WPA12;
|
| 3035 | }
|
| 3036 | else if (strcmp(authmode, "WPA2WPA3") == 0) {
|
| 3037 | sc_auth = CAP_WIFI_AUTH_WPA23;
|
| 3038 | }
|
| 3039 | else {
|
| 3040 | wf_log("unsuport authmode:%s\n", authmode);
|
| 3041 | }
|
| 3042 | return sc_auth;
|
| 3043 | }
|
| 3044 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 3045 | static int transe_sta_encrypt_type(char *etype)
|
| 3046 | {
|
| 3047 | int sc_type = CAP_WIFI_ENCRYPT_UNSUP;
|
| 3048 |
|
| 3049 | if (strcmp(etype, "TKIPCCMP") == 0) {
|
| 3050 | sc_type = CAP_WIFI_ENCRYPT_AUTO;
|
| 3051 | }
|
| 3052 | else if (strcmp(etype, "TKIP") == 0) {
|
| 3053 | sc_type = CAP_WIFI_ENCRYPT_TKIP;
|
| 3054 | }
|
| 3055 | else if (strcmp(etype, "CCMP") == 0) {
|
| 3056 | sc_type = CAP_WIFI_ENCRYPT_AES;
|
| 3057 | }
|
| 3058 | else {
|
| 3059 | wf_log("unsuport encrypttype:%s\n", etype);
|
| 3060 | }
|
| 3061 | return sc_type;
|
| 3062 | }
|
| 3063 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3064 | //ÅÅÐòÁË È¡ÐźźõÄǰ30
|
| 3065 | static int send_scan_result_to_cap(void)
|
| 3066 | {
|
| 3067 | wlan_sta_scan_list_t scan_list = {0};
|
| 3068 | int ret = 0;
|
| 3069 |
|
| 3070 | int i = 0;
|
| 3071 | for (i = 0; i < WIFI_STATION_SCAN_RESULT_LIST_NUM && i < CAP_WIFI_MAX_SCAN_CNT; i++) {
|
| 3072 | if (g_scan_result_list_p[i] == NULL) {
|
| 3073 | break;
|
| 3074 | }
|
| 3075 |
|
| 3076 | scan_list.info[i].auth = transe_sta_auth_mode(g_scan_result_list_p[i]->auth_mode);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 3077 | scan_list.info[i].cipher = transe_sta_encrypt_type(g_scan_result_list_p[i]->encrypt_type);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3078 | scan_list.info[i].channel = g_scan_result_list_p[i]->channel;
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 3079 | //scan_list.info[i].frequency = g_scan_result_list_p[i]->ch_freq;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3080 | scan_list.info[i].signal_level = g_scan_result_list_p[i]->signal;
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 3081 | scan_list.info[i].signal = g_scan_result_list_p[i]->signal_db;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3082 | strncpy(scan_list.info[i].essid, g_scan_result_list_p[i]->ssid, sizeof(scan_list.info[i].essid)-1);
|
| 3083 | strncpy(scan_list.info[i].bssid, g_scan_result_list_p[i]->mac, sizeof(scan_list.info[i].bssid)-1);
|
| 3084 | scan_list.cnt++;
|
| 3085 | }
|
| 3086 | //Ŀǰ30¸ö,¶àÁ˺˼äat´«²»¹ýÈ¡,×î´ó´«3500/2B,Òòhex2str
|
| 3087 | ret = send_soc_msg(FAR_PS, MODULE_ID_WIFI, MSG_CMD_CAP_STA_SCAN_RES, sizeof(scan_list), &scan_list);
|
| 3088 | if (ret != 0) {
|
| 3089 | wf_log("send_soc_msg fail, ret:%d\n", ret);
|
| 3090 | }
|
| 3091 |
|
| 3092 | return ret;
|
| 3093 | }
|
| 3094 |
|
| 3095 | static void scan_result_to_cap(void)
|
| 3096 | {
|
| 3097 | int ret = 0;
|
| 3098 |
|
| 3099 | if (g_cap_scan == 1) {
|
| 3100 | ret = send_scan_result_to_cap();
|
| 3101 | if (ret == 0) {
|
| 3102 | g_cap_scan = 0;
|
| 3103 | }
|
| 3104 | }
|
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 3105 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3106 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3107 | #endif
|
| 3108 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3109 | //wifi station´¦Àíº¯Êý
|
| 3110 | int wlan_sta_parse_msg (MSG_BUF *pMsg)
|
| 3111 | {
|
| 3112 |
|
| 3113 | int ret = 0;
|
| 3114 | switch (pMsg->usMsgCmd) {
|
| 3115 | case MSG_CMD_WIFI_STATION_OPEN: {
|
| 3116 | #if defined(__REALTEK_8192_CHIP__) || defined(__AIC_8800DW_CHIP__)
|
| 3117 | wifi_station_open_apsta();
|
| 3118 | //wifi_station_connect(MODULE_ID_WEB_CGI);//´ò¿ªµÄʱºòÒѾÁ¬ÁËÒ»´Î£¬Ã»ÓбØÒªÔÙ´ÎÁ¬½Ó
|
| 3119 | #else
|
| 3120 | wf_log("-MSG_CMD_WIFI_STATION_OPEN-");
|
| 3121 | wlan_station_init();
|
| 3122 | #endif
|
| 3123 | break;
|
| 3124 | }
|
| 3125 | case MSG_CMD_WIFI_STATION_CLOSE: {
|
| 3126 | sta_disconnected();
|
| 3127 | wlan_station_deinit();
|
| 3128 | #if defined(__REALTEK_8192_CHIP__)|| defined(__AIC_8800DW_CHIP__)
|
| 3129 | basic_deal_all (WIFI_CFG_RESTART_AP);
|
| 3130 | #endif
|
| 3131 | break;
|
| 3132 | }
|
| 3133 | case MSG_CMD_WIFI_STATION_CLOSE_OPEN_MSSID: {
|
| 3134 | sta_disconnected();
|
| 3135 | wlan_station_deinit();
|
| 3136 | basic_deal_all (WIFI_CFG_CLOSESTA_OPENMSSID);
|
| 3137 | break;
|
| 3138 | }
|
| 3139 | case MSG_CMD_WIFI_STATION_SPOT_UPDATE: {
|
| 3140 | webui_update_spot_list ( (updateinfo_t*) (pMsg->aucDataBuf));
|
| 3141 |
|
| 3142 | //ÿ´ÎÓû§¸üÐÂÈȵãºó£¬²»ÐèÒª¸üб£´æsignalµÄÈ«¾Ö±äÁ¿£¬¶øÊÇÔÚɨÃèµÄʱºò£¬À´¼ì²âÊÇ·ñÓб仯
|
| 3143 | //ËùÒÔÔÚÈȵã±ä»¯ºó£¬ÐèҪͨ¹ýscanÀ´¾¡¿ì¸üÐÂÈȵã״̬
|
| 3144 | break;
|
| 3145 | }
|
| 3146 | case MSG_CMD_WIFI_STATION_SCAN: {
|
| 3147 | wifi_station_scan();
|
| 3148 | break;
|
| 3149 | }
|
| 3150 | case MSG_CMD_WIFI_STATION_CONNECT: {
|
| 3151 | sta_connect (INVALID_NETWORK_ID);
|
| 3152 | break;
|
| 3153 | }
|
| 3154 | case MSG_CMD_WIFI_STATION_DISCONNECT: {
|
| 3155 | sta_disconnect();
|
| 3156 | break;
|
| 3157 | }
|
| 3158 | case MSG_CMD_WIFI_STATION_GET_SCAN_RESULTS: {
|
| 3159 | wifi_station_get_scan_results();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3160 | #ifdef USE_CAP_SUPPORT
|
| 3161 | scan_result_to_cap();
|
| 3162 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3163 | break;
|
| 3164 | }
|
| 3165 | case MSG_CMD_WIFI_STATION_SIM_INIT_TIMER_PROCESS: {
|
| 3166 | handle_sim_init_status_timer();
|
| 3167 | break;
|
| 3168 | }
|
| 3169 | case MSG_CMD_WIFI_STATION_EVENT_CONNECTED: {
|
| 3170 | wf_log ("[wifi event connected , goto dhcp]");
|
| 3171 | sc_cfg_set ("sta_ip_status", "dhcping");
|
| 3172 | do_dhcp();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3173 | #ifdef USE_CAP_SUPPORT
|
| 3174 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ASSOCIATED, IN_WIFI_REASON_CODE_NONE);
|
| 3175 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3176 | break;
|
| 3177 | }
|
| 3178 | case MSG_CMD_WIFI_STATION_EVENT_DISCONNECTED: {
|
| 3179 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3180 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3181 |
|
| 3182 | if (strcmp (sta_ip_status, "connect") == 0 || strcmp (sta_ip_status, "dhcping") == 0) {
|
| 3183 | sta_disconnected();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3184 | #ifdef USE_CAP_SUPPORT
|
xf.li | df7f8ba | 2024-09-12 23:53:34 -0700 | [diff] [blame^] | 3185 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_DISCONNECTED, IN_WIFI_REASON_CODE_NONE);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3186 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3187 | }
|
| 3188 | else{
|
| 3189 | wf_log ("The Spot connect failed, just set sta_ip_status disconnect");
|
| 3190 | sc_cfg_set ("sta_ip_status", "disconnect");
|
| 3191 | }
|
| 3192 | break;
|
| 3193 | }
|
| 3194 | case MSG_CMD_WIFI_STATION_EVENT_CONNECTING: {
|
| 3195 | sc_cfg_set("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECTING);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3196 | #ifdef USE_CAP_SUPPORT
|
| 3197 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_CONNECTING, IN_WIFI_REASON_CODE_NONE);
|
| 3198 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3199 | break;
|
| 3200 | }
|
| 3201 |
|
| 3202 | case MSG_CMD_BLC_OPEN_WIFISTATION_ACCESS: { // you can connect
|
| 3203 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3204 |
|
| 3205 | g_blc_send_close_apsta = 0;
|
| 3206 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3207 |
|
| 3208 | wf_log ("sta_ip_status=%s", sta_ip_status);
|
| 3209 |
|
| 3210 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DISCONNECT) == 0) {
|
| 3211 | wifi_station_connect (MODULE_ID_MAIN_CTRL);
|
| 3212 | } else {
|
| 3213 | wf_log ("do not deal connect cmd, sta_ip_status=%s", sta_ip_status);
|
| 3214 | }
|
| 3215 | break;
|
| 3216 | }
|
| 3217 | case MSG_CMD_BLC_CLOSE_WIFISTATION_ACCESS: {
|
| 3218 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3219 |
|
| 3220 | g_blc_send_close_apsta = 1;
|
| 3221 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3222 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DISCONNECT) != 0) {
|
| 3223 | sta_disconnect();// if wifi not connect ok , then if there is disconnect event??
|
| 3224 | } else {
|
| 3225 | wf_log ("do not deal disconnect cmd, sta_ip_status=%s", sta_ip_status);
|
| 3226 |
|
| 3227 | }
|
| 3228 | break;
|
| 3229 | }
|
| 3230 |
|
| 3231 | case MSG_CMD_WIFI_STATION_BLC_CONNECTED: {
|
| 3232 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3233 |
|
| 3234 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3235 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 3236 | wf_log ("[wlan-station] wlan0-vxd get ip success");
|
| 3237 | sta_connected();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3238 | #ifdef USE_CAP_SUPPORT
|
| 3239 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_CONNECTED, IN_WIFI_REASON_CODE_NONE);
|
| 3240 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3241 | }
|
| 3242 | else{
|
| 3243 | wf_log (" DO not deal , sta_ip_status=%s", sta_ip_status);
|
| 3244 | }
|
| 3245 | break;
|
| 3246 | }
|
| 3247 |
|
| 3248 | case MSG_CMD_NET_WAN_DIAL_FAIL: {
|
| 3249 | wf_log ("wlan0-vxd dhcp ip failed");
|
| 3250 | ipfail_disconnect_ap();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3251 | #ifdef USE_CAP_SUPPORT
|
| 3252 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_DHCP_FAILED);
|
| 3253 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3254 | break;
|
| 3255 | }
|
| 3256 | case MSG_CMD_CARD_MODE_RSP: {
|
| 3257 | wlan_station_msg_handle_card_mode_for_eap (pMsg);
|
| 3258 | break;
|
| 3259 | }
|
| 3260 | case MSG_CMD_PIN_STATUS_RSP: {
|
| 3261 | wlan_station_msg_handle_pin_status_for_eap (pMsg);
|
| 3262 | break;
|
| 3263 | }
|
| 3264 | case MSG_CMD_WIFI_STATION_CONNECT_TIMEOUT: {
|
| 3265 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3266 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3267 | wf_log ("handle connect timeout msg,sta_ip_status=%s", sta_ip_status);
|
| 3268 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 3269 | sta_disconnect();
|
| 3270 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 3271 | g_connecting_time_out_timer = 0;
|
| 3272 | }
|
| 3273 | break;
|
| 3274 | }
|
| 3275 |
|
| 3276 | case MSG_CMD_WIFI_STATION_NO_AVAILABLE_AP:{
|
| 3277 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3278 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3279 | wf_log ("handle no available ap, sta_ip_status=%s", sta_ip_status);
|
| 3280 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 3281 | sc_cfg_set ("sta_ip_status", "disconnect");
|
| 3282 | if(1 == g_disable_other_network){
|
| 3283 | sta_docmd ("ENABLE_NETWORK all");// the connecting status will be set by assocating event, if no assoc , just be disconnect
|
| 3284 | g_disable_other_network = 0;
|
| 3285 | }
|
| 3286 | }
|
| 3287 | break;
|
| 3288 | }
|
| 3289 | case MSG_CMD_WIFI_STATION_TEMP_DISABLED: {
|
| 3290 | if (g_wpa_supplicant == 1) {
|
| 3291 | //wf_log ("MSG_CMD_WIFI_STATION_TEMP_DISABLED=%s", (char *)(pMsg->aucDataBuf));
|
| 3292 |
|
| 3293 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 3294 | process_tmp_disabled((char *)(pMsg->aucDataBuf));
|
| 3295 | }
|
| 3296 | break;
|
| 3297 | }
|
| 3298 | case MSG_CMD_WIFI_STATION_FAILED_SET: {
|
| 3299 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 3300 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3301 | wf_log ("handle Failed to set, sta_ip_status=%s", sta_ip_status);
|
| 3302 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 3303 | sc_cfg_set ("sta_ip_status", "disconnect");
|
| 3304 | //if(1 == g_disable_other_network){
|
| 3305 | // sta_docmd ("ENABLE_NETWORK all");// the connecting status will be set by assocating event, if no assoc , just be disconnect
|
| 3306 | // g_disable_other_network = 0;
|
| 3307 | //}
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3308 | #ifdef USE_CAP_SUPPORT
|
| 3309 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_SET_FAILED);
|
| 3310 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3311 | }
|
| 3312 | break;
|
| 3313 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3314 | #ifdef USE_CAP_SUPPORT
|
| 3315 | case MSG_CMD_CAP_STA_SET_PARAM: {
|
| 3316 | cap_update_spot_param((wlan_sta_param_t *)(pMsg->aucDataBuf));
|
| 3317 | break;
|
| 3318 | }
|
| 3319 | case MSG_CMD_CAP_STA_ENABLE: {
|
| 3320 | //ûÓе¥¶À¿ª¹ØstaµÄ¹¦ÄÜ,ÏÈÊÊÅä³Éap´æÔÚµÄÇé¿öÏ¿ª¹Østa
|
| 3321 | cap_station_enable((wlan_sta_enable_t *)(pMsg->aucDataBuf));
|
| 3322 | break;
|
| 3323 | }
|
| 3324 | case MSG_CMD_CAP_STA_SCAN: {
|
| 3325 | cap_station_scan();
|
| 3326 | break;
|
| 3327 | }
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 3328 | case MSG_CMD_CAP_WIFI_STA_STAT_REQ: {
|
| 3329 | cap_station_info(pMsg);
|
| 3330 | break;
|
| 3331 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3332 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3333 | default: {
|
| 3334 | ret = -1;
|
| 3335 | break;
|
| 3336 | }
|
| 3337 | }
|
| 3338 |
|
| 3339 | return ret;
|
| 3340 | }
|
| 3341 |
|
| 3342 |
|
| 3343 | int get_int_from_event (char * buf, char * tag)
|
| 3344 | {
|
| 3345 | int ret = -1;
|
| 3346 | char * pstr = NULL;
|
| 3347 |
|
| 3348 | if(NULL == buf || NULL == tag)
|
| 3349 | return -1;
|
| 3350 |
|
| 3351 | pstr = strstr (buf, tag);
|
| 3352 | if (pstr != NULL) {
|
| 3353 | pstr += strlen (tag);
|
| 3354 | ret = atoi (pstr);
|
| 3355 | }
|
| 3356 |
|
| 3357 | return ret;
|
| 3358 | }
|
| 3359 |
|
| 3360 | /*
|
| 3361 | ÃÀÀö¶³È˵ÄÁù³¯¹Å¶¼ÄÏhh, ÖÐÎÄssid»á±È½Ï³¤
|
| 3362 | \xe7\xbe\x8e\xe4\xb8\xbd\xe5\x86\xbb\xe4\xba\xba\xe7\x9a\x84\xe5\x85\xad\xe6\x9c\x9d\xe5\x8f\xa4\xe9\x83\xbd\xe5\x8d\x97hh
|
| 3363 | */
|
| 3364 | void process_trying_to_assoc (char * buf)
|
| 3365 | {
|
| 3366 | char * start = NULL;
|
| 3367 | char * end = NULL;
|
| 3368 | char ssid[WIFI_STATION_SSID_LEN] = {0};
|
| 3369 | char mac[WIFI_STATION_MAC_LEN] = {0};
|
| 3370 | unsigned int len = 0;//klocwork
|
| 3371 |
|
| 3372 | start = strstr (buf, "SSID=\'") + strlen("SSID=\'");
|
| 3373 | if (start != NULL) {
|
| 3374 | end = strstr (start, "\' ");//klocwork
|
| 3375 | }
|
| 3376 |
|
| 3377 | strncpy (mac, buf + strlen ("Trying to associate with "), 17);
|
| 3378 | wf_log ("Trying to associate with mac=%s", mac);
|
| 3379 | if (end != NULL && start != NULL) {
|
| 3380 | len = end - start;
|
| 3381 | len = MIN(len, WIFI_STATION_SSID_LEN-1);
|
| 3382 | //strncpy (ssid, start, len);
|
| 3383 | //ssid[WIFI_STATION_SSID_LEN-1] = '\0';//klocwork
|
| 3384 | snprintf(ssid,len+1,"%s",start);
|
| 3385 | wf_log ("Trying to associate with ssid= %s", ssid);
|
| 3386 | }
|
| 3387 |
|
| 3388 | update_current_EX (ssid, mac);
|
| 3389 |
|
| 3390 | }
|
| 3391 |
|
| 3392 | //Trying to associate with ca:c2:f1:74:2f:f4 (SSID='D_mi_D' freq=2412 MHz)
|
| 3393 | //SME: Trying to authenticate with 90:1d:27:78:2c:1e (SSID='Ufi_782111' freq=2412 MHz)
|
| 3394 | static void channel_follow(char * buf)
|
| 3395 | {
|
| 3396 | char * start = NULL;
|
| 3397 | char * end = NULL;
|
| 3398 | char freq[WIFI_STATION_FREQ_LEN] = {0};
|
| 3399 | unsigned int len = 0;//klocwork
|
| 3400 | int frequency = 0;
|
| 3401 |
|
zw.wang | c08ce04 | 2024-08-08 18:42:05 +0800 | [diff] [blame] | 3402 | #ifdef USE_CAP_SUPPORT
|
| 3403 | if (g_work_mode == IN_WIFI_WORK_MODE_STA) {
|
| 3404 | wf_log("no ap channel_follow not need");
|
| 3405 | return;
|
| 3406 | }
|
| 3407 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3408 | start = strstr(buf, "freq=") + strlen("freq=");
|
| 3409 | if (start != NULL) {
|
| 3410 | end = strstr (start, " MHz");//klocwork
|
| 3411 | }
|
| 3412 |
|
| 3413 | if (end != NULL && start != NULL) {
|
| 3414 | len = end - start;
|
| 3415 | len = MIN(len, WIFI_STATION_FREQ_LEN-1);
|
| 3416 | snprintf(freq, len+1, "%s", start);
|
| 3417 | frequency = atoi(freq);
|
| 3418 | wf_log("Trying to associate with freq= %s[%d]", freq, frequency);
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 3419 |
|
| 3420 | #ifdef USE_CAP_SUPPORT
|
| 3421 | int i_ch = 0;
|
| 3422 | char s_ch[10] = {0};
|
| 3423 | i_ch = frequency_to_channel(frequency);
|
| 3424 | snprintf(s_ch, sizeof(s_ch), "%d", i_ch);
|
| 3425 | sc_cfg_set("flower_channel", s_ch);
|
| 3426 | #else
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3427 | switch (frequency) {
|
| 3428 | case WIFI_STATION_CHANNEL1:
|
| 3429 | sc_cfg_set("flower_channel", "1");
|
| 3430 | break;
|
| 3431 | case WIFI_STATION_CHANNEL2:
|
| 3432 | sc_cfg_set("flower_channel", "2");
|
| 3433 | break;
|
| 3434 | case WIFI_STATION_CHANNEL3:
|
| 3435 | sc_cfg_set("flower_channel", "3");
|
| 3436 | break;
|
| 3437 | case WIFI_STATION_CHANNEL4:
|
| 3438 | sc_cfg_set("flower_channel", "4");
|
| 3439 | break;
|
| 3440 | case WIFI_STATION_CHANNEL5:
|
| 3441 | sc_cfg_set("flower_channel", "5");
|
| 3442 | break;
|
| 3443 | case WIFI_STATION_CHANNEL6:
|
| 3444 | sc_cfg_set("flower_channel", "6");
|
| 3445 | break;
|
| 3446 | case WIFI_STATION_CHANNEL7:
|
| 3447 | sc_cfg_set("flower_channel", "7");
|
| 3448 | break;
|
| 3449 | case WIFI_STATION_CHANNEL8:
|
| 3450 | sc_cfg_set("flower_channel", "8");
|
| 3451 | break;
|
| 3452 | case WIFI_STATION_CHANNEL9:
|
| 3453 | sc_cfg_set("flower_channel", "9");
|
| 3454 | break;
|
| 3455 | case WIFI_STATION_CHANNEL10:
|
| 3456 | sc_cfg_set("flower_channel", "10");
|
| 3457 | break;
|
| 3458 | case WIFI_STATION_CHANNEL11:
|
| 3459 | sc_cfg_set("flower_channel", "11");
|
| 3460 | break;
|
| 3461 | case WIFI_STATION_CHANNEL12:
|
| 3462 | sc_cfg_set("flower_channel", "12");
|
| 3463 | break;
|
| 3464 | case WIFI_STATION_CHANNEL13:
|
| 3465 | sc_cfg_set("flower_channel", "13");
|
| 3466 | break;
|
| 3467 | default:
|
| 3468 | sc_cfg_set("flower_channel", "0");
|
| 3469 | wf_log("channel_follow with unknow freq = [%d]", frequency);
|
| 3470 | break;
|
| 3471 | }
|
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame] | 3472 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3473 | }
|
| 3474 |
|
| 3475 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_CHANNEL_FOLLOW, 0, NULL, 0);
|
| 3476 |
|
| 3477 | }
|
| 3478 |
|
| 3479 | /*
|
| 3480 | STA: CTRL-EVENT-SSID-TEMP-DISABLED id=7 ssid="ydh" auth_failures=5 duration=60 reason=CONN_FAILED
|
| 3481 |
|
| 3482 | */
|
| 3483 |
|
| 3484 | static void process_tmp_disabled (char *buf)
|
| 3485 | {
|
| 3486 | char *p_WRONG_KEY = NULL;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3487 | char *p_AUTH_FAILED = NULL;
|
| 3488 | char *p_CONN_FAILED = NULL;
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3489 | char wifi_profile_num[8] = {0};
|
| 3490 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 3491 | int network_id = -1;
|
| 3492 | int auth_failures = 0;
|
| 3493 |
|
| 3494 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 3495 | p_WRONG_KEY = strstr (buf, "WRONG_KEY");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3496 | #ifdef USE_CAP_SUPPORT
|
| 3497 | p_AUTH_FAILED = strstr(buf, "AUTH_FAILED");
|
| 3498 | p_CONN_FAILED = strstr(buf, "CONN_FAILED");
|
| 3499 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3500 | /*
|
| 3501 | ¿ÉÒÔÓиüÓÅ»¯µÄËã·¨£¬Ìá¸ßÁ´½ÓЧÂÊ
|
| 3502 | */
|
| 3503 | auth_failures = get_int_from_event (buf, "auth_failures=");
|
| 3504 |
|
| 3505 | if (atoi (wifi_profile_num) > 1 && (p_WRONG_KEY || auth_failures > 1)) {
|
| 3506 | network_id = get_int_from_event (buf, "id=");
|
| 3507 |
|
| 3508 | wf_log ("network_id = %d wrong key or tmp_disabled_times = %d", network_id, auth_failures);
|
| 3509 |
|
| 3510 | sprintf (cmd, "SET_NETWORK %d priority 0", network_id);
|
| 3511 | sta_docmd (cmd);
|
| 3512 | sta_docmd ("SAVE_CONFIG");
|
| 3513 |
|
| 3514 | wifi_station_connect (MODULE_ID_WIFI);
|
| 3515 |
|
| 3516 | if (p_WRONG_KEY) {
|
| 3517 | wf_log ("network_id = %d wrong key to disable it", network_id);
|
| 3518 | sprintf (cmd , "DISABLE_NETWORK %d", network_id);
|
| 3519 | sta_docmd (cmd);
|
| 3520 | sta_docmd ("SAVE_CONFIG");
|
| 3521 | }
|
| 3522 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3523 |
|
| 3524 | #ifdef USE_CAP_SUPPORT
|
| 3525 | if (p_WRONG_KEY) {
|
| 3526 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_WRONG_KEY);
|
| 3527 | }
|
| 3528 | else if (p_AUTH_FAILED) {
|
| 3529 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_AUTH_FAILED);
|
| 3530 | }
|
| 3531 | else if (p_CONN_FAILED) {
|
| 3532 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_CONN_FAILED);
|
| 3533 | }
|
| 3534 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3535 | }
|
| 3536 |
|
| 3537 |
|
| 3538 | void *station_loop (void *param)
|
| 3539 | {
|
| 3540 | char buf[UEVENT_BUFFER_SIZE];
|
| 3541 | char name[32] = {0};
|
| 3542 | static int scan_times = 0;
|
| 3543 | int loop_run = 0;
|
| 3544 |
|
| 3545 | strncpy (name, (char*) param, sizeof(name)-1);
|
| 3546 | prctl (PR_SET_NAME, name, 0, 0, 0);
|
| 3547 |
|
| 3548 | while (1) { //¼àÌýcharging״̬µÄ²å°Î
|
| 3549 | //if wpa_supplicant is stop ,then wait
|
| 3550 | //if recv the sem, g_wpa_supplicant ==1
|
| 3551 | // wf_log("station_loop: g_wpa_supplicant= %d", g_wpa_supplicant);
|
| 3552 | if (g_wpa_supplicant == 0 || 0 == loop_run) {
|
| 3553 | sem_wait (&g_wpa_supplicant_id);
|
| 3554 | }
|
| 3555 | loop_run =1;
|
| 3556 | // ʼþ²Î¿¼wpa_supplantÖÐwpa_ctrl.hÖж¨Òå
|
| 3557 | int nread = wifi_wait_for_event (&sta_manager->sock, buf, sizeof (buf));
|
| 3558 |
|
| 3559 | //wake_sta_lock();
|
| 3560 | if (nread > 0) {
|
| 3561 | wf_log ("STA: %s", buf);
|
| 3562 |
|
| 3563 | if (strstr (buf, "CTRL-EVENT-SCAN-RESULTS")) {
|
| 3564 | char sta_ip_status[16] = {0};
|
| 3565 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3566 |
|
| 3567 | if (strcmp (sta_ip_status, "connecting") != 0) {//disconnect connect dhcping
|
| 3568 | wf_log ("snd msg to get scan results");
|
| 3569 | scan_times = 0; // IF status change to not connecting, then set 0
|
| 3570 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_GET_SCAN_RESULTS, 0, NULL, 0);
|
| 3571 | } else {
|
| 3572 | // 17S ccan interval, 17*12 =204S about, to disconnect, just set the nv value, the wpa_supplicant still scan to connect
|
| 3573 | // the final status ,is enable all network, and scan to connect ,but sta_ip_status is disconnect
|
| 3574 | scan_times ++;
|
| 3575 | if (4 == scan_times) {//12-->4 , decrease the waiting time
|
| 3576 | wf_log ("can not find available spot, just set sta_ip_status disconnect", buf);
|
| 3577 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_NO_AVAILABLE_AP, 0, NULL, 0);
|
| 3578 | scan_times = 0;
|
| 3579 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3580 | #ifdef USE_CAP_SUPPORT
|
| 3581 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_GET_SCAN_RESULTS, 0, NULL, 0);
|
| 3582 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3583 | }
|
| 3584 | }
|
| 3585 | //STA: CTRL-EVENT-CONNECTED - Connection to a6:44:d1:86:c5:d9 completed [id=0 id_str=]
|
| 3586 |
|
| 3587 | else if (strstr (buf, "CTRL-EVENT-CONNECTED")) {
|
| 3588 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_CONNECTED_ENABLE_AP_CMD, 0, NULL, 0);
|
| 3589 |
|
| 3590 | char *p = strstr (buf, "Connection to ");
|
| 3591 |
|
| 3592 | scan_times = 0; // IF status change to not connecting, then set 0
|
| 3593 |
|
| 3594 | if (p != NULL) {//
|
| 3595 | p += strlen ("Connection to ");
|
| 3596 | strncpy (g_linked_ap_mac, p, 17);
|
| 3597 | }
|
| 3598 | g_linked_network_id = get_int_from_event (buf, "[id=");
|
| 3599 | wf_log ("g_linked_network_id_last = %d, g_linked_network_id= %d", g_linked_network_id_last, g_linked_network_id);
|
| 3600 | //wf_send_message( MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTED, 0, NULL);
|
| 3601 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTED, 0, NULL, 0);
|
| 3602 | } else if (strstr (buf, "CTRL-EVENT-DISCONNECTED")) {
|
| 3603 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_DISCONNECTED, 0, NULL, 0);
|
| 3604 | }
|
| 3605 |
|
| 3606 | //STA: CTRL-EVENT-SSID-REENABLED id=0 ssid="ZONG MBB-MF920W+-000012"
|
| 3607 | else if (strstr (buf, "CTRL-EVENT-SSID-REENABLED")) {
|
| 3608 | scan_times = 0; // when reenable , it indicate there is available AP, so set it 0
|
| 3609 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTING, 0, NULL, 0);
|
| 3610 | }
|
| 3611 | //STA: Trying to associate with 00:90:49:58:00:73 (SSID='Wo4G-0073' freq=2412 MHz)
|
| 3612 | else if (strstr (buf, "Trying to associate with")) {
|
| 3613 | #if defined(__AIC_8800DW_CHIP__)
|
| 3614 | channel_follow(buf);
|
| 3615 | #endif
|
| 3616 | scan_times = 0; // when begin to assoc , it indicate there is available AP, so set it 0
|
| 3617 | // CTRL-EVENT-SSID-REENABLED maybe lost
|
| 3618 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTING, 0, NULL, 0);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3619 | process_trying_to_assoc (buf); //·Åipc_send_messageÇ°Ãæ
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3620 | }
|
| 3621 | //SME: Trying to authenticate with 90:1d:27:78:2c:1e (SSID='Ufi_782111' freq=2412 MHz)
|
| 3622 | else if (strstr (buf, "Trying to authenticate with")) {
|
| 3623 | #if defined(__SSV_6X5X_CHIP__)
|
| 3624 | channel_follow(buf);
|
| 3625 | #endif
|
| 3626 | }
|
| 3627 | else if (strstr (buf , "CTRL-EVENT-SIGNAL-CHANGE")) {
|
| 3628 | wf_log ("snd msg to update signal level");
|
| 3629 | }
|
| 3630 | // CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid="CPE_E3DE4E" auth_failures=2 duration=20 reason=WRONG_KEY ¡¢AUTH_FAILED¡¢CONN_FAILED
|
| 3631 | else if (strstr (buf, "CTRL-EVENT-SSID-TEMP-DISABLED")) {
|
| 3632 | //time sequence sc_cfg_set sta_ip_status, process in another thread with other event
|
| 3633 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_TEMP_DISABLED, nread, buf, 0);
|
| 3634 | }
|
| 3635 | //WPA: Failed to select authenticated key management type --- 1
|
| 3636 | //WPA: Failed to set WPA key management and encryption suites --- 2
|
| 3637 | else if (strstr (buf, "WPA: Failed to set")) {
|
| 3638 | //sta auth failed
|
| 3639 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_FAILED_SET, 0, NULL, 0);
|
| 3640 | }
|
| 3641 | else if (strstr (buf, "CTRL-EVENT-TERMINATING")) {
|
| 3642 |
|
| 3643 | loop_run = 0;
|
| 3644 | }
|
| 3645 | } else {
|
| 3646 | wf_log ("Could not read pending message.");
|
| 3647 | }
|
| 3648 | }
|
| 3649 |
|
| 3650 | return NULL;
|
| 3651 | }
|
| 3652 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 3653 | void wifi_station_cancel_scan(void)
|
| 3654 | {
|
| 3655 | sta_docmd("ABORT_SCAN"); //cancel current scan, and remove scan works
|
| 3656 | sta_docmd("SCAN_INTERVAL 15"); //eloop scan timer reset
|
| 3657 | }
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3658 |
|
| 3659 | void wlan_station_open()
|
| 3660 | {
|
| 3661 |
|
| 3662 | }
|
| 3663 |
|
| 3664 | void wlan_statemachine_init()
|
| 3665 | {
|
| 3666 |
|
| 3667 | }
|
| 3668 |
|
| 3669 |
|