|
@@ -30,12 +30,12 @@
|
|
|
|
|
|
#include <unistd.h>
|
|
|
#include <stdarg.h>
|
|
|
-#include <stdio.h> /*標準輸入輸出定義*/
|
|
|
-#include <stdlib.h> /*標準函數庫定義*/
|
|
|
-#include <unistd.h> /*Unix 標準函數定義*/
|
|
|
-#include <fcntl.h> /*檔控制定義*/
|
|
|
-#include <termios.h> /*PPSIX 終端控制定義*/
|
|
|
-#include <errno.h> /*錯誤號定義*/
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <fcntl.h>
|
|
|
+#include <termios.h>
|
|
|
+#include <errno.h>
|
|
|
#include <errno.h>
|
|
|
#include <string.h>
|
|
|
#include <time.h>
|
|
@@ -44,6 +44,7 @@
|
|
|
#include <sqlite3.h>
|
|
|
#include <json-c/json.h>
|
|
|
#include <signal.h>
|
|
|
+#include <regex.h>
|
|
|
#include "define.h"
|
|
|
|
|
|
#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
@@ -197,7 +198,7 @@ struct interface_info
|
|
|
int authType;
|
|
|
int rssi;
|
|
|
int cnt_InternetFail;
|
|
|
- char *currentInterface;
|
|
|
+ char currentInterface[16];
|
|
|
char currentSSID[256];
|
|
|
char currentPasswd[256];
|
|
|
char currentMAC[24];
|
|
@@ -444,6 +445,31 @@ int InitShareMemory()
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+//==========================================
|
|
|
+// Valid MAC address
|
|
|
+//==========================================
|
|
|
+int isMacValid(char *MacAddress)
|
|
|
+{
|
|
|
+ int result = FALSE;
|
|
|
+ int r,cflags=0;
|
|
|
+ regmatch_t pm[10];
|
|
|
+ const size_t nmatch = 10;
|
|
|
+ regex_t reg;
|
|
|
+
|
|
|
+ r=regcomp(®, "^[0-9A-F]\\([0-9A-F]\\:[0-9A-F]\\)\\{5\\}[0-9A-F]$", cflags);
|
|
|
+ if(r==0)
|
|
|
+ {
|
|
|
+ r=regexec(®, MacAddress, nmatch, pm, cflags);
|
|
|
+ }
|
|
|
+ regfree(®);
|
|
|
+
|
|
|
+ if(r==0)result = TRUE;
|
|
|
+
|
|
|
+ DEBUG_INFO("MAC(%s) format valid result: %d\n", MacAddress, result);
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
//==========================================
|
|
|
// Get parameters from shared memory
|
|
|
//==========================================
|
|
@@ -504,7 +530,7 @@ int isFindInterface()
|
|
|
{
|
|
|
if(mystrcmp(ifa->ifa_name, Support_InterfaceAP[idx]) == PASS)
|
|
|
{
|
|
|
- Wifi.currentInterface = ifa->ifa_name;
|
|
|
+ sprintf(Wifi.currentInterface, "%s", ifa->ifa_name);
|
|
|
result = PASS;
|
|
|
}
|
|
|
}
|
|
@@ -527,7 +553,7 @@ int isFindInterface()
|
|
|
{
|
|
|
if(mystrcmp(ifa->ifa_name, Support_InterfaceSTA[idx]) == PASS)
|
|
|
{
|
|
|
- Wifi.currentInterface = ifa->ifa_name;
|
|
|
+ sprintf(Wifi.currentInterface, "%s", ifa->ifa_name);
|
|
|
result = PASS;
|
|
|
}
|
|
|
}
|
|
@@ -816,7 +842,7 @@ int setWPAconf()
|
|
|
strcat(buffer, "\"\n key_mgmt=WPA-EAP WPA-PSK \n");
|
|
|
strcat(buffer, " bgscan=\"simple:10:-65:3600\" \n");
|
|
|
strcat(buffer, " scan_ssid=1\n");
|
|
|
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0)
|
|
|
+ if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac))
|
|
|
{
|
|
|
strcat(buffer, "\n bssid=");
|
|
|
strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac);
|
|
@@ -838,7 +864,7 @@ int setWPAconf()
|
|
|
strcat(buffer, "\"\n auth_alg=OPEN SHARED\n");
|
|
|
strcat(buffer, " bgscan=\"simple:10:-65:3600\"\n");
|
|
|
strcat(buffer, " scan_ssid=1\n");
|
|
|
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0)
|
|
|
+ if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac))
|
|
|
{
|
|
|
strcat(buffer, "\n bssid=");
|
|
|
strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac);
|
|
@@ -851,7 +877,7 @@ int setWPAconf()
|
|
|
strcat(buffer, "\"\n key_mgmt=NONE");
|
|
|
strcat(buffer, "\n bgscan=\"simple:10:-65:3600\"");
|
|
|
strcat(buffer, "\n scan_ssid=1");
|
|
|
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0)
|
|
|
+ if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac))
|
|
|
{
|
|
|
strcat(buffer, "\n bssid=");
|
|
|
strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac);
|
|
@@ -865,7 +891,7 @@ int setWPAconf()
|
|
|
strcat(buffer, "\"\n key_mgmt=NONE");
|
|
|
strcat(buffer, "\n bgscan=\"simple:10:-65:3600\"");
|
|
|
strcat(buffer, "\n scan_ssid=1");
|
|
|
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0)
|
|
|
+ if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac))
|
|
|
{
|
|
|
strcat(buffer, "\n bssid=");
|
|
|
strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac);
|