diff --git a/.cproject b/.cproject
new file mode 100644
index 0000000..78585e4
--- /dev/null
+++ b/.cproject
@@ -0,0 +1,973 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ mingw32-make.exe
+ -s -j6
+ all
+ true
+ true
+ false
+
+
+ make
+ -s
+ clean
+ true
+ true
+ false
+
+
+ make
+ -s
+ flashburn
+ true
+ true
+ false
+
+
+ make
+ -s
+ reset
+ true
+ true
+ false
+
+
+ make
+ -s
+ test
+ true
+ true
+ false
+
+
+ mingw32-make.exe
+ -s
+ readfullflash
+ true
+ true
+ false
+
+
+ mingw32-make.exe
+ -s
+ debug
+ true
+ true
+ true
+
+
+ mingw32-make.exe
+ -s
+ flash
+ true
+ true
+ false
+
+
+ mingw32-make.exe
+ -s
+ ramdebug
+ true
+ true
+ true
+
+
+ mingw32-make.exe
+ -s
+ runram
+ true
+ true
+ false
+
+
+ mingw32-make.exe
+ -s
+ mp
+ true
+ true
+ false
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f71af2f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/AutoMake/
diff --git a/.project b/.project
new file mode 100644
index 0000000..f5c3bc0
--- /dev/null
+++ b/.project
@@ -0,0 +1,118 @@
+
+
+ RTL00MP3
+
+
+ RTL00_SDKV35a
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+ RTL00_SDKV35a
+ 2
+ PARENT-1-PROJECT_LOC/RTL00_SDKV35a
+
+
+
+
+ 1477406640799
+ RTL00_SDKV35a
+ 5
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.h
+
+
+
+ 1477406640809
+ RTL00_SDKV35a
+ 5
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.c
+
+
+
+ 1477406640809
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-AutoMake
+
+
+
+ 1477406640809
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-build
+
+
+
+ 1477406640819
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-flasher
+
+
+
+ 1477406640819
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-LibAutoMake
+
+
+
+ 1477406640829
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-project
+
+
+
+ 1477406640829
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-.git
+
+
+
+ 1477406640829
+ RTL00_SDKV35a
+ 10
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-.settings
+
+
+
+
diff --git a/.settings/ilg.gnuarmeclipse.managedbuild.cross.prefs b/.settings/ilg.gnuarmeclipse.managedbuild.cross.prefs
new file mode 100644
index 0000000..ba91ca5
--- /dev/null
+++ b/.settings/ilg.gnuarmeclipse.managedbuild.cross.prefs
@@ -0,0 +1,3 @@
+buildTools.path=D\:\\MCU\\GNU_Tools_ARM_Embedded\\5.4_2016q2\\bin
+eclipse.preferences.version=1
+toolchain.path.1287942917=D\:\\MCU\\GNU_Tools_ARM_Embedded\\5.4_2016q2\\
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
new file mode 100644
index 0000000..a590756
--- /dev/null
+++ b/.settings/language.settings.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.cdt.codan.core.prefs b/.settings/org.eclipse.cdt.codan.core.prefs
new file mode 100644
index 0000000..77386c2
--- /dev/null
+++ b/.settings/org.eclipse.cdt.codan.core.prefs
@@ -0,0 +1,67 @@
+eclipse.preferences.version=1
+org.eclipse.cdt.codan.checkers.errnoreturn=Warning
+org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false}
+org.eclipse.cdt.codan.checkers.errreturnvalue=Error
+org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.checkers.noreturn=Error
+org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false}
+org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error
+org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error
+org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error
+org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false}
+org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning
+org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()}
+org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error
+org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning
+org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true}
+org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error
+org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error
+org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error
+org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error
+org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error
+org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error
+org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error
+org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info
+org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},pattern\=>"^[a-z]",macro\=>true,exceptions\=>()}
+org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error
+org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error
+org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error
+org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning
+org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning
+org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>()}
+org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},paramNot\=>false}
+org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},else\=>false,afterelse\=>false}
+org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error
+org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true}
+org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true}
+org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning
+org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")}
+org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error
+org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs
new file mode 100644
index 0000000..d24cd11
--- /dev/null
+++ b/.settings/org.eclipse.cdt.core.prefs
@@ -0,0 +1,52 @@
+eclipse.preferences.version=1
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/MINGW_HOME/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/MINGW_HOME/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/MINGW_HOME/value=C\:\\MinGW
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/MSYS_HOME/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/MSYS_HOME/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/MSYS_HOME/value=C\:\\MinGW\\msys\\1.0
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/OCD_PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/OCD_PATH/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/OCD_PATH/value=D\:\\MCU\\OpenOCD\\bin
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/PATH/operation=replace
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/PATH/value=${TL_PATH}\\bin;${MINGW_HOME}\\mingw64\\bin;${MINGW_HOME}\\bin;${MSYS_HOME}\\bin;${OCD_PATH};C\:/Program Files (x86)/Java/jre1.8.0_101/bin/client;C\:/Program Files (x86)/Java/jre1.8.0_101/bin;C\:/Program Files (x86)/Java/jre1.8.0_101/lib/i386;C\:\\MinGW\\mingw64\\bin;C\:\\MinGW\\msys\\1.0\\bin;C\:\\MinGW\\bin;D\:\\MCU\\STMicroelectronics\\st_toolset\\asm;C\:\\Python27;C\:\\Utils\\FarUtils;C\:\\Utils\\FarUtils\\HIEW810;C\:\\Windows;C\:\\Windows\\system32;C\:\\Windows\\System32\\Wbem;C\:\\Windows\\System32\\WindowsPowerShell\\v1.0;D\:\\MCU\\Microchip\\xc32\\v1.42\\bin;D\:\\MCU\\Microchip\\mplabc30\\v3.31\\bin;D\:\\MCU\\Microchip\\MPLAB C32 Suite\\bin;D\:\\MCU\\Microchip\\mplabc32\\v1.12\\bin;D\:\\MCU\\Microchip\\mcc18\\mpasm;D\:\\MCU\\Microchip\\mcc18\\bin;D\:\\WRK\\TortoiseGit\\bin;C\:\\Utils\\TortoiseSVN\\binC\:\\Program Files (x86)\\Git\\cmd;C\:\\Program Files (x86)\\Borland\\Delphi7\\Bin;C\:\\Program Files (x86)\\Borland\\Delphi7\\Projects\\Bpl\\;C\:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C\:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C\:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;C\:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit;C\:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0;C\:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;C\:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn;C\:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn;C\:\\Program Files\\Microsoft DNX\\Dnvm;C\:\\Program Files\\IVI Foundation\\VISA\\Win64\\Bin;D\:\\Automation\\Samcoon\\SKWorkshop\\Marco\\HMI\\bin;D\:\\Automation\\Samcoon\\SKWorkshop\\Marco\\X86\\bin;D\:\\Automation\\Samcoon\\SK035AE\\SKWorkshop\\Marco\\HMI\\bin;D\:\\Automation\\Samcoon\\SK035AE\\SKWorkshop\\Marco\\X86\\bin;C\:\\Users\\PVV\\.dnx\\bin;C\:\\ProgramData\\chocolatey\\bin;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\Program Files (x86)\\QuickTime\\QTSystem;C\:\\Program Files\\nodejs;D\:\\WRK\\TortoiseGit\\bin;C\:\\Utils\\TortoiseSVN\\bin;C\:\\Program Files (x86)\\Git\\cmd;D\:\\MentorGraphics\\Sourcery_CodeBench_Lite_for_MIPS_ELF\\bin;C\:\\Eclipse
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/TL_PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/TL_PATH/operation=replace
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/TL_PATH/value=D\:\\MCU\\GNU_Tools_ARM_Embedded\\5.4_2016q2
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/append=true
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/appendContributed=true
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/MINGW_HOME/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/MINGW_HOME/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/MINGW_HOME/value=C\:\\MinGW
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/MSYS_HOME/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/MSYS_HOME/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/MSYS_HOME/value=C\:\\MinGW\\msys\\1.0
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/OCD_PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/OCD_PATH/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/OCD_PATH/value=D\:\\MCU\\OpenOCD\\bin
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/PATH/operation=replace
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/PATH/value=${TL_PATH}\\bin;${MINGW_HOME}\\mingw64\\bin;${MINGW_HOME}\\bin;${MSYS_HOME}\\bin;${OCD_PATH};C\:/Program Files (x86)/Java/jre1.8.0_101/bin/client;C\:/Program Files (x86)/Java/jre1.8.0_101/bin;C\:/Program Files (x86)/Java/jre1.8.0_101/lib/i386;C\:\\MinGW\\mingw64\\bin;C\:\\MinGW\\msys\\1.0\\bin;C\:\\MinGW\\bin;D\:\\MCU\\STMicroelectronics\\st_toolset\\asm;C\:\\Python27;C\:\\Utils\\FarUtils;C\:\\Utils\\FarUtils\\HIEW810;C\:\\Windows;C\:\\Windows\\system32;C\:\\Windows\\System32\\Wbem;C\:\\Windows\\System32\\WindowsPowerShell\\v1.0;D\:\\MCU\\Microchip\\xc32\\v1.42\\bin;D\:\\MCU\\Microchip\\mplabc30\\v3.31\\bin;D\:\\MCU\\Microchip\\MPLAB C32 Suite\\bin;D\:\\MCU\\Microchip\\mplabc32\\v1.12\\bin;D\:\\MCU\\Microchip\\mcc18\\mpasm;D\:\\MCU\\Microchip\\mcc18\\bin;D\:\\WRK\\TortoiseGit\\bin;C\:\\Utils\\TortoiseSVN\\binC\:\\Program Files (x86)\\Git\\cmd;C\:\\Program Files (x86)\\Borland\\Delphi7\\Bin;C\:\\Program Files (x86)\\Borland\\Delphi7\\Projects\\Bpl\\;C\:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C\:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C\:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;C\:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit;C\:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0;C\:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;C\:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn;C\:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn;C\:\\Program Files\\Microsoft DNX\\Dnvm;C\:\\Program Files\\IVI Foundation\\VISA\\Win64\\Bin;D\:\\Automation\\Samcoon\\SKWorkshop\\Marco\\HMI\\bin;D\:\\Automation\\Samcoon\\SKWorkshop\\Marco\\X86\\bin;D\:\\Automation\\Samcoon\\SK035AE\\SKWorkshop\\Marco\\HMI\\bin;D\:\\Automation\\Samcoon\\SK035AE\\SKWorkshop\\Marco\\X86\\bin;C\:\\Users\\PVV\\.dnx\\bin;C\:\\ProgramData\\chocolatey\\bin;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\Program Files (x86)\\QuickTime\\QTSystem;C\:\\Program Files\\nodejs;D\:\\WRK\\TortoiseGit\\bin;C\:\\Utils\\TortoiseSVN\\bin;C\:\\Program Files (x86)\\Git\\cmd;D\:\\MentorGraphics\\Sourcery_CodeBench_Lite_for_MIPS_ELF\\bin;C\:\\Eclipse
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/TL_PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/TL_PATH/operation=replace
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/TL_PATH/value=D\:\\MCU\\GNU_Tools_ARM_Embedded\\5.4_2016q2
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/append=true
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/appendContributed=true
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/MINGW_HOME/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/MINGW_HOME/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/MINGW_HOME/value=C\:\\MinGW
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/MSYS_HOME/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/MSYS_HOME/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/MSYS_HOME/value=C\:\\MinGW\\msys\\1.0
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/OCD_PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/OCD_PATH/operation=append
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/OCD_PATH/value=D\:\\MCU\\OpenOCD\\bin
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/PATH/operation=replace
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/PATH/value=${TL_PATH}\\bin;${MINGW_HOME}\\mingw64\\bin;${MINGW_HOME}\\bin;${MSYS_HOME}\\bin;${OCD_PATH};C\:/Program Files (x86)/Java/jre1.8.0_101/bin/client;C\:/Program Files (x86)/Java/jre1.8.0_101/bin;C\:/Program Files (x86)/Java/jre1.8.0_101/lib/i386;C\:\\MinGW\\mingw64\\bin;C\:\\MinGW\\msys\\1.0\\bin;C\:\\MinGW\\bin;D\:\\MCU\\STMicroelectronics\\st_toolset\\asm;C\:\\Python27;C\:\\Utils\\FarUtils;C\:\\Utils\\FarUtils\\HIEW810;C\:\\Windows;C\:\\Windows\\system32;C\:\\Windows\\System32\\Wbem;C\:\\Windows\\System32\\WindowsPowerShell\\v1.0;D\:\\MCU\\Microchip\\xc32\\v1.42\\bin;D\:\\MCU\\Microchip\\mplabc30\\v3.31\\bin;D\:\\MCU\\Microchip\\MPLAB C32 Suite\\bin;D\:\\MCU\\Microchip\\mplabc32\\v1.12\\bin;D\:\\MCU\\Microchip\\mcc18\\mpasm;D\:\\MCU\\Microchip\\mcc18\\bin;D\:\\WRK\\TortoiseGit\\bin;C\:\\Utils\\TortoiseSVN\\binC\:\\Program Files (x86)\\Git\\cmd;C\:\\Program Files (x86)\\Borland\\Delphi7\\Bin;C\:\\Program Files (x86)\\Borland\\Delphi7\\Projects\\Bpl\\;C\:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C\:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C\:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI;C\:\\Program Files (x86)\\Windows Live\\Shared;C\:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;C\:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit;C\:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0;C\:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;C\:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn;C\:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C\:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn;C\:\\Program Files\\Microsoft DNX\\Dnvm;C\:\\Program Files\\IVI Foundation\\VISA\\Win64\\Bin;D\:\\Automation\\Samcoon\\SKWorkshop\\Marco\\HMI\\bin;D\:\\Automation\\Samcoon\\SKWorkshop\\Marco\\X86\\bin;D\:\\Automation\\Samcoon\\SK035AE\\SKWorkshop\\Marco\\HMI\\bin;D\:\\Automation\\Samcoon\\SK035AE\\SKWorkshop\\Marco\\X86\\bin;C\:\\Users\\PVV\\.dnx\\bin;C\:\\ProgramData\\chocolatey\\bin;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\Program Files (x86)\\QuickTime\\QTSystem;C\:\\Program Files\\nodejs;D\:\\WRK\\TortoiseGit\\bin;C\:\\Utils\\TortoiseSVN\\bin;C\:\\Program Files (x86)\\Git\\cmd;D\:\\MentorGraphics\\Sourcery_CodeBench_Lite_for_MIPS_ELF\\bin;C\:\\Eclipse
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/TL_PATH/delimiter=;
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/TL_PATH/operation=replace
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/TL_PATH/value=D\:\\MCU\\GNU_Tools_ARM_Embedded\\5.4_2016q2
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/append=true
+environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.510381534/appendContributed=true
diff --git a/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/.settings/org.eclipse.cdt.managedbuilder.core.prefs
new file mode 100644
index 0000000..4630071
--- /dev/null
+++ b/.settings/org.eclipse.cdt.managedbuilder.core.prefs
@@ -0,0 +1,25 @@
+eclipse.preferences.version=1
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/CPATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/CPATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/CPLUS_INCLUDE_PATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/CPLUS_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/C_INCLUDE_PATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/C_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/append=true
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/appendContributed=true
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/CPATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/CPATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/CPLUS_INCLUDE_PATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/CPLUS_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/C_INCLUDE_PATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/C_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/append=true
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/appendContributed=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/LIBRARY_PATH/delimiter=;
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/LIBRARY_PATH/operation=remove
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/append=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404.1853483235/appendContributed=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/LIBRARY_PATH/delimiter=;
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/LIBRARY_PATH/operation=remove
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/append=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1273936404/appendContributed=true
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs
new file mode 100644
index 0000000..b196c64
--- /dev/null
+++ b/.settings/org.eclipse.ltk.core.refactoring.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
diff --git a/JLink-RTL00ConsoleROM.bat b/JLink-RTL00ConsoleROM.bat
new file mode 100644
index 0000000..09767bd
--- /dev/null
+++ b/JLink-RTL00ConsoleROM.bat
@@ -0,0 +1,3 @@
+@echo off
+PATH=D:\MCU\SEGGER\JLink_V610a;%PATH%
+start JLink.exe -Device CORTEX-M3 -If SWD -Speed 4000 flasher\RTL00ConsoleROM.JLinkScript
diff --git a/JLink-RdFullFlash.bat b/JLink-RdFullFlash.bat
new file mode 100644
index 0000000..843e924
--- /dev/null
+++ b/JLink-RdFullFlash.bat
@@ -0,0 +1,3 @@
+@echo off
+PATH=D:\MCU\SEGGER\JLink_V610a;%PATH%
+JLink.exe -Device CORTEX-M3 -If SWD -Speed 4000 flasher/RTL_FFlash.JLinkScript
diff --git a/JLink-Reset.bat b/JLink-Reset.bat
new file mode 100644
index 0000000..81c18f2
--- /dev/null
+++ b/JLink-Reset.bat
@@ -0,0 +1,3 @@
+@echo off
+PATH=D:\MCU\SEGGER\JLink_V610a;%PATH%
+JLink.exe -Device CORTEX-M3 -If SWD -Speed 1000 flasher\RTL_Reset.JLinkScript
diff --git a/JLink-RunRAM.bat b/JLink-RunRAM.bat
new file mode 100644
index 0000000..253941d
--- /dev/null
+++ b/JLink-RunRAM.bat
@@ -0,0 +1,3 @@
+@echo off
+PATH=D:\MCU\SEGGER\JLink_V610a;%PATH%
+start JLink.exe -Device CORTEX-M3 -If SWD -Speed 4000 flasher\RTL_RunRAM.JLinkScript
diff --git a/JLinkGDB-RdFullFlash.bat b/JLinkGDB-RdFullFlash.bat
new file mode 100644
index 0000000..7d1edbf
--- /dev/null
+++ b/JLinkGDB-RdFullFlash.bat
@@ -0,0 +1,6 @@
+@echo off
+PATH=D:\MCU\GNU_Tools_ARM_Embedded\5.2_2015q4\bin;D:\MCU\SEGGER\JLink_V610a;%PATH%
+start JLinkGDBServer.exe -device Cortex-M3 -if SWD -ir -endian little -speed 1000
+arm-none-eabi-gdb.exe -x flasher/gdb_rdflash.jlink
+taskkill /F /IM JLinkGDBServer.exe
+
diff --git a/JLinkGDB-RunRAM.bat b/JLinkGDB-RunRAM.bat
new file mode 100644
index 0000000..40333de
--- /dev/null
+++ b/JLinkGDB-RunRAM.bat
@@ -0,0 +1,15 @@
+@echo off
+PATH=D:\MCU\GNU_Tools_ARM_Embedded\5.2_2015q4\bin;D:\MCU\SEGGER\JLink_V610a;%PATH%
+@if exist build\obj\build.axf goto run
+echo File 'build\obj\build.axf' not found!
+echo Build project...
+mingw32-make.exe -f Makefile all
+@if not exist build\obj\build.axf goto err
+:run
+start JLinkGDBServer.exe -device Cortex-M3 -if SWD -ir -endian little -speed 1000
+arm-none-eabi-gdb.exe -x flasher/gdb_run_ram.jlink
+taskkill /F /IM JLinkGDBServer.exe
+goto end
+:err
+echo Error!
+:end
\ No newline at end of file
diff --git a/JLinkGDB-WrFlash.bat b/JLinkGDB-WrFlash.bat
new file mode 100644
index 0000000..bbfb3ae
--- /dev/null
+++ b/JLinkGDB-WrFlash.bat
@@ -0,0 +1,18 @@
+@echo off
+PATH=D:\MCU\GNU_Tools_ARM_Embedded\5.2_2015q4\bin;D:\MCU\SEGGER\JLink_V610a;%PATH%
+@if not %1x==x goto xxx
+set img_file=build/bin/ram_all.bin
+:xxx
+echo define call1>flasher/flash_file.jlink
+echo SetFirwareSize %img_file%>>flasher/flash_file.jlink
+echo end>>flasher/flash_file.jlink
+echo define call2>>flasher/flash_file.jlink
+echo FlasherWrite %img_file% 0 $Image1Size>>flasher/flash_file.jlink
+echo end>>flasher/flash_file.jlink
+echo define call3>>flasher/flash_file.jlink
+echo FlasherWrite %img_file% $Image2Addr $Image2Size>>flasher/flash_file.jlink
+echo end>>flasher/flash_file.jlink
+start JLinkGDBServer.exe -device Cortex-M3 -if SWD -ir -endian little -speed 3500
+arm-none-eabi-gdb.exe -x flasher/gdb_wrflash.jlink build/bin/ram_all.bin
+taskkill /F /IM JLinkGDBServer.exe
+
diff --git a/JLinkGDBServer.bat b/JLinkGDBServer.bat
new file mode 100644
index 0000000..974e29f
--- /dev/null
+++ b/JLinkGDBServer.bat
@@ -0,0 +1,6 @@
+@echo off
+PATH=D:\MCU\GNU_Tools_ARM_Embedded\5.2_2015q4\bin;D:\MCU\SEGGER\JLink_V610a;%PATH%
+start JLinkGDBServer.exe -device Cortex-M3 -if SWD -ir -endian little -speed 1000
+arm-none-eabi-gdb.exe -x flasher/gdb_init.jlink
+taskkill /F /IM JLinkGDBServer.exe
+
diff --git a/JlinkOpenOCD.bat b/JlinkOpenOCD.bat
new file mode 100644
index 0000000..35d397f
--- /dev/null
+++ b/JlinkOpenOCD.bat
@@ -0,0 +1,4 @@
+@echo off
+PATH=D:\MCU\OpenOCD;%PATH%
+taskkill /F /IM openocd.exe
+start openocd -f interface\Jlink.cfg -f flasher\ameba1.cfg
diff --git a/LICENSES b/LICENSES
new file mode 100644
index 0000000..2b4a036
--- /dev/null
+++ b/LICENSES
@@ -0,0 +1,477 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to
+
+License component (LwIP 1.4.1):
+
+Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
+
+This file is part of the lwIP TCP/IP stack.
+
+Author: Adam Dunkels
+
+
+License component (FreeRTOS 8.1.2):
+
+The FreeRTOS source code is licensed by a *modified* GNU General Public
+License (GPL). The modification is provided in the form of an exception.
+
+NOTE: The modification to the GPL is included to allow you to distribute a
+combined work that includes FreeRTOS without being obliged to provide the source
+code for proprietary components outside of the FreeRTOS kernel.
+
+
+
+----------------------------------------------------------------------------
+
+The FreeRTOS GPL Exception Text:
+
+Any FreeRTOS source code, whether modified or in it's original release form,
+or whether in whole or in part, can only be distributed by you under the terms
+of the GNU General Public License plus this exception. An independent module is
+a module which is not derived from or based on FreeRTOS.
+
+Clause 1:
+
+Linking FreeRTOS statically or dynamically with other modules is making a
+combined work based on FreeRTOS. Thus, the terms and conditions of the GNU
+General Public License cover the whole combination.
+
+As a special exception, the copyright holder of FreeRTOS gives you permission
+to link FreeRTOS with independent modules that communicate with FreeRTOS
+solely through the FreeRTOS API interface, regardless of the license terms of
+these independent modules, and to copy and distribute the resulting combined
+work under terms of your choice, provided that
+
+ + Every copy of the combined work is accompanied by a written statement that
+ details to the recipient the version of FreeRTOS used and an offer by yourself
+ to provide the FreeRTOS source code (including any modifications you may have
+ made) should the recipient request it.
+
+ + The combined work is not itself an RTOS, scheduler, kernel or related product.
+
+ + The independent modules add significant and primary functionality to FreeRTOS
+ and do not merely extend the existing functionality already present in FreeRTOS.
+
+Clause 2:
+
+FreeRTOS may not be used for any competitive or comparative purpose, including the
+publication of any form of run time or compile time metric, without the express
+permission of Real Time Engineers Ltd. (this is the norm within the industry and
+is intended to ensure information accuracy).
+
+
+--------------------------------------------------------------------
+
+The standard GPL exception text:
+
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License** as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ , 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
+License component (libmad 8.1.2):
+
+libmad - MPEG audio decoder library
+Copyright (C) 2000-2004 Underbit Technologies, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+License component (SDK Realtek):
+Not found on sdk-ameba-rtl8710af-v3.5a_without_NDA_GCC_V1.0.0.zip
+https://www.pine64.org/?page_id=946 -> Software & SDK
+-> Ameba RTL8710AF SDK ver v3.5a GCC ver 1.0.0- without NDA
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0bde0dc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
+
+all: ram_all
+mp: ram_all_mp
+
+.PHONY: ram_all
+ram_all:
+ @$(MAKE) -f sdkbuild.mk
+ @$(MAKE) -f flasher.mk genbin1 genbin23
+
+.PHONY: ram_all_mp
+ram_all_mp:
+ @$(MAKE) -f sdkbuild.mk mp
+ @$(MAKE) -f flasher.mk mp
+
+.PHONY: clean clean_all
+clean:
+ @$(MAKE) -f sdkbuild.mk clean
+
+clean_all:
+ @$(MAKE) -f sdkbuild.mk clean_all
+
+.PHONY: debug ramdebug
+debug:
+ @$(MAKE) -f application.mk debug
+
+ramdebug:
+ @$(MAKE) -f application.mk ramdebug
+
+.PHONY: flashburn runram reset test readfullflash
+flashburn:
+ JLinkGDB-WrFlash.bat build/bin/ram_all.bin
+ #@$(MAKE) -f flasher.mk flashburn
+
+runram:
+ JLink-RunRAM.bat
+ #@$(MAKE) --f flasher.mk runram
+
+reset:
+ JLink-Reset.bat
+ #@make -f flasher.mk reset
+
+test:
+ @make -f flasher.mk test
+
+readfullflash:
+ JLink-RdFullFlash.bat
+ #@make -f flasher.mk readfullflash
+
+.PHONY: prerequirement
+prerequirement:
+# @$(file >DEPENDENCY_LIST.txt,$(DEPENDENCY_LIST))
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ee50e02
--- /dev/null
+++ b/README.md
@@ -0,0 +1,57 @@
+# RTL00(RTL8710AF) Test MP3 AmebaV3.5a GCC
+---
+
+MP3 stereo player V0004
+RTL00 module (RTL8710AF)
+
+Толко ТеÑÑ‚!
+
+PWM Out GC_2 and PE_2 (2 канала по 96Bit на один иÑходный sample 48 кГц)
+
+Console command (RX/TX GB1/GB0 38400 baud):
+
+ATW0=SSID - задать Ð¸Ð¼Ñ AP
+ATW1=PASSPHRASE - задать пароль AP
+ATWC - Connect to an AES AP
+ATWD - DisConnect AP
+ATWS=URL,PORT - задать канал web-radio или http файл
+. Sample: ATWS=icecast.omroep.nl/3fm-sb-mp3,80
+. ATWS=meuk.spritesserver.nl/Ii.Romanzeandante.mp3,80
+. ATWS=?, ATWS=close, ATWS=save, ATWS=read
+. ATWS=x,0 и ATWS=save - отключить Ñтарт
+ATST - Mem/Task Info
+ATOF - Отключить MP3
+
+ATSD=hexaddr,count - Damp памÑти/региÑтров Ñ Ð°Ð´Ñ€ÐµÑа...
+ATWD=hexaddr,hexdata - ЗапиÑать dword по адреÑу
+
+
+По умолчанию, в качеÑтве JTAG иÑпользуетÑÑ J-Link STLink V2.
+
+ИÑпользуемое ПО
+
+JTAG/SWD Drivers:
+* [ST-Link](http://www.st.com/web/catalog/tools/FM146/CL1984/SC724/SS1677/PF251168?sc=internet/evalboard/product/251168.jsp)
+* [SEEGER J-Link Software and Documentation Pack](https://www.segger.com/downloads/jlink)
+* [Converting ST-LINK on-board into a J-Link](https://www.segger.com/jlink-st-link.html)
+System:
+* [MinGW](https://sourceforge.net/projects/mingw-w64/)
+* [GNU ARM Embedded Toolchain](https://launchpad.net/gcc-arm-embedded/+download)
+* [OpenOCD: Open On-Chip Debugger](https://sourceforge.net/projects/gnuarmeclipse/files/OpenOCD/)
+Eclipse:
+* [Eclipse IDE for C/C++ Developers](https://eclipse.org/downloads/packages/eclipse-ide-cc-developers/lunasr1a)
+* [GNU ARM Eclipse Plug-ins](http://gnuarmeclipse.github.io/downloads/)
+* [GNU ARM Eclipse OpenOCD](http://gnuarmeclipse.github.io/openocd/install/)
+
+Изначальные верÑии Ð´Ð»Ñ Ð´Ð¾Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ð¹ иÑходников и SDK:
+от [PADI IoT Stamp Resources – PINE64](https://www.pine64.org/?page_id=946):
+* [sdk-ameba-rtl8710af-v3.5a_without_NDA_GCC_V1.0.0.zip](https://yadi.sk/d/dfIwqNkZv6m63)
+от [Realtek IoT/Arduino Solution](http://www.amebaiot.com/en/):
+* [sdk-ameba1-v3.4b3_without_NDA.zip](https://yadi.sk/d/Yt7iS1KBvUAV9)
+из GitHub:
+* [Ameba8195/Arduino: This is Arduino SDK for Ameba Arduino board](https://github.com/Ameba8195/Arduino)
++ [rtl_ameba_gcc_sample](https://github.com/eggman/rtl_ameba_gcc_sample)
++ [rebane rtl8710_openocd](https://bitbucket.org/rebane/rtl8710_openocd/src)
+
+Доп.информациÑ: [esp8266.ru/forum](https://esp8266.ru/forum/threads/rtl00-mp3-player.1697/)
+
\ No newline at end of file
diff --git a/RTL00_MP3_SCH.gif b/RTL00_MP3_SCH.gif
new file mode 100644
index 0000000..eb1de36
Binary files /dev/null and b/RTL00_MP3_SCH.gif differ
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_ethernet.c b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_ethernet.c
new file mode 100644
index 0000000..db9c9f0
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_ethernet.c
@@ -0,0 +1,92 @@
+#include
+#include "log_service.h"
+#include "platform_opts.h"
+#include
+#include "cmsis_os.h"
+#include
+#include
+#include
+#include "wifi_conf.h"
+
+
+#define _AT_DHCP_ETHERNET_MII_ "ATE0"
+#define _AT_SET_DEFAULT_INTERFACE "ATE1"
+
+#if CONFIG_ETHERNET
+extern int dhcp_ethernet_mii;
+extern int ethernet_if_default;
+extern struct netif xnetif[NET_IF_NUM];
+
+void fATE0(void *arg)
+{
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+ printf("[ATE0]:DHCP configure for ethernet\n\r");
+ if(!arg){
+ printf("[ATE0]Usage to disable DHCP: ATE0=0\n");
+ printf("[ATE0]Usage to enable DHCP: ATE0=1\n");
+ return;
+ }
+ if('0' == *(char *)arg)
+ {
+ dhcp_ethernet_mii = 0;
+ }
+
+ else if('1' == *(char *)arg)
+ {
+ dhcp_ethernet_mii = 1;
+ LwIP_DHCP(NET_IF_NUM - 1, DHCP_START);
+ }
+
+ else
+ {
+ printf("[ATE0]Usage to disable DHCP: ATE0=0\n");
+ printf("[ATE0]Usage to enable DHCP: ATE0=1\n");
+ }
+}
+
+void fATE1(void *arg)
+{
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+ printf("[ATE1]:Set/check the default interface\n\r");
+ if(!arg){
+ if(ethernet_if_default)
+ printf("Ethernet is the default interface\n");
+ else
+ printf("wlan is the default interface\n");
+ return;
+ }
+ if('0' == *(char *)arg)
+ {
+ ethernet_if_default = 0;
+ printf("wlan is set to the default interface\n");
+ }
+
+ else if('1' == *(char *)arg)
+ {
+ ethernet_if_default = 1;
+ printf("ethernet is set to the default interface\n");
+ }
+
+ else
+ {
+ printf("[ATE0]Usage to check the default interface: ATE1\n");
+ printf("[ATE0]Usage to set ethernet as default interface: ATE1=1\n");
+ printf("[ATE0]Usage to set wlan as default interface: ATE1=0\n");
+ }
+}
+
+log_item_t at_ethernet_items[ ] = {
+ {"ATE0", fATE0,},
+ {"ATE1", fATE1,}
+};
+
+void at_ethernet_init(void)
+{
+ log_service_add_table(at_ethernet_items, sizeof(at_ethernet_items)/sizeof(at_ethernet_items[0]));
+}
+
+log_module_init(at_ethernet_init);
+
+#endif
\ No newline at end of file
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_lwip.c b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_lwip.c
new file mode 100644
index 0000000..ae5c2b3
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_lwip.c
@@ -0,0 +1,2151 @@
+#include
+#include
+
+#ifdef CONFIG_AT_LWIP
+
+#include
+#include "log_service.h"
+#include "atcmd_wifi.h"
+#include "atcmd_lwip.h"
+#include "osdep_service.h"
+#include "osdep_api.h"
+
+
+#ifndef ATCMD_VER
+#define ATVER_1 1
+#define ATVER_2 2
+#define ATCMD_VER ATVER_2
+#if CONFIG_EXAMPLE_UART_ATCMD
+#define ATCMD_VER ATVER_2
+#else
+#define ATCMD_VER ATVER_1
+#endif
+#endif
+
+//#define MAX_BUFFER 256
+#define MAX_BUFFER (LOG_SERVICE_BUFLEN)
+#define ATCP_STACK_SIZE 512//2048
+
+extern char log_buf[LOG_SERVICE_BUFLEN];
+extern struct netif xnetif[NET_IF_NUM];
+
+static unsigned char tx_buffer[MAX_BUFFER];
+static unsigned char rx_buffer[MAX_BUFFER];
+
+#if ATCMD_VER == ATVER_2
+node node_pool[NUM_NS];
+
+node* mainlist;
+
+static int atcmd_lwip_auto_recv = FALSE;
+volatile int atcmd_lwip_tt_mode = FALSE; //transparent transmission mode
+xTaskHandle atcmd_lwip_tt_task = NULL;
+xSemaphoreHandle atcmd_lwip_tt_sema = NULL;
+volatile int atcmd_lwip_tt_datasize = 0;
+volatile int atcmd_lwip_tt_lasttickcnt = 0;
+
+#ifdef ERRNO
+_WEAK int errno = 0; //LWIP errno
+#endif
+
+static void atcmd_lwip_receive_task(void *param);
+int atcmd_lwip_start_autorecv_task(void);
+int atcmd_lwip_is_autorecv_mode(void);
+void atcmd_lwip_set_autorecv_mode(int enable);
+int atcmd_lwip_start_tt_task(void);
+int atcmd_lwip_is_tt_mode(void);
+void atcmd_lwip_set_tt_mode(int enable);
+int atcmd_lwip_write_info_to_flash(struct atcmd_lwip_conn_info *cur_conn, int enable);
+#else //#if ATCMD_VER == ATVER_2
+
+xTaskHandle server_task = NULL;
+xTaskHandle client_task = NULL;
+
+static int mode = 0;
+static int local_port;
+static int remote_port;
+static char remote_addr[16];
+static int packet_size;
+
+static int sockfd, newsockfd;
+static socklen_t client;
+static struct sockaddr_in serv_addr, cli_addr;
+static int opt = 1;
+
+static int type; //TCP SERVER:1, TCP CLIENT: 2, UDP SERVER:3, UDP CLIENT: 4
+
+static void init_transport_struct(void)
+{
+ mode = 0;
+ local_port = 0;
+ remote_port = 0;
+ sockfd = -1;
+ newsockfd = -1;
+ packet_size = 0;
+ _memset(remote_addr, 0, sizeof(remote_addr));
+ _memset(&client, 0, sizeof(client));
+ _memset(&serv_addr, 0, sizeof(serv_addr));
+
+}
+
+void socket_close(void)
+{
+ close(sockfd);
+ if(server_task != NULL)
+ {
+ vTaskDelete(server_task);
+ server_task = NULL;
+ }
+ if(client_task != NULL)
+ {
+ vTaskDelete(client_task);
+ client_task = NULL;
+ }
+ type = 0;
+ init_transport_struct();
+}
+#endif //#if ATCMD_VER == ATVER_2
+
+static void server_start(void *param)
+{
+ int s_mode;
+ int s_sockfd, s_newsockfd;
+ socklen_t s_client;
+ struct sockaddr_in s_serv_addr, s_cli_addr;
+ int s_local_port;
+ int error_no = 0;
+ int s_opt = 1;
+#if ATCMD_VER == ATVER_2
+ node* ServerNodeUsed = (node*)param;
+ if(ServerNodeUsed){
+ s_mode = ServerNodeUsed->protocol;
+ s_local_port = ServerNodeUsed->port;
+ }
+// else
+//#endif
+#else
+ {
+ s_mode = mode;
+ s_local_port = local_port;
+ s_opt = opt;
+ }
+#endif
+
+ if(s_mode == NODE_MODE_UDP)
+ s_sockfd = socket(AF_INET,SOCK_DGRAM,0);
+ else
+ s_sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (s_sockfd == INVALID_SOCKET_ID) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"ERROR opening socket");
+ error_no = 5;
+ goto err_exit;
+ }
+
+ if((setsockopt(s_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&s_opt, sizeof(s_opt))) < 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"ERROR on setting socket option");
+ error_no = 6;
+ goto err_exit;
+ }
+
+ memset((char *)&s_serv_addr, 0, sizeof(s_serv_addr));
+ s_serv_addr.sin_family = AF_INET;
+ s_serv_addr.sin_addr.s_addr = INADDR_ANY;
+ s_serv_addr.sin_port = htons(s_local_port);
+
+ if (bind(s_sockfd, (struct sockaddr *)&s_serv_addr,sizeof(s_serv_addr)) < 0) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"ERROR on binding");
+ error_no = 7;
+ goto err_exit;
+ }
+
+#if ATCMD_VER == ATVER_2
+ if(ServerNodeUsed != NULL) {
+ uint8_t *ip = (uint8_t *)LwIP_GetIP(&xnetif[0]);
+ ServerNodeUsed->sockfd = s_sockfd;
+ ServerNodeUsed->addr = ntohl(*((u32_t *)ip));
+ }
+// else
+//#endif
+#else
+ {
+ sockfd = s_sockfd;
+ memcpy(&serv_addr, &s_serv_addr, sizeof(s_serv_addr));
+ }
+#endif
+
+ if (s_mode == NODE_MODE_TCP){//TCP MODE
+ if(listen(s_sockfd , 5) < 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"ERROR on listening");
+ error_no = 8;
+ goto err_exit;
+ }
+#if ATCMD_VER == ATVER_2
+ if(param != NULL) {
+ if(hang_node(ServerNodeUsed) < 0)
+ {
+ error_no = 9;
+ goto err_exit;
+ }else{
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPS] OK"
+ "\r\n[ATPS] con_id=%d",
+ ServerNodeUsed->con_id);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ }
+ }
+#endif
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"The TCP SERVER START OK!");
+ s_client = sizeof(s_cli_addr);
+ while(1){
+ if((s_newsockfd = accept(s_sockfd,(struct sockaddr *) &s_cli_addr,&s_client)) < 0){
+#if ATCMD_VER == ATVER_2
+ if(param != NULL) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPS] ERROR:ERROR on accept");
+ }
+// else
+//#endif
+#else
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "ERROR on accept");
+ }
+#endif
+ error_no = 10;
+ goto err_exit;
+ }
+ else{
+#if ATCMD_VER == ATVER_2
+ if(param != NULL) {
+ node* seednode = create_node(s_mode, NODE_ROLE_SEED);
+ if(seednode == NULL){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPS]create node failed!");
+ error_no = 11;
+ goto err_exit;
+ }
+ seednode->sockfd = s_newsockfd;
+ seednode->port = ntohs(s_cli_addr.sin_port);
+ seednode->addr = ntohl(s_cli_addr.sin_addr.s_addr);
+ if(hang_seednode(ServerNodeUsed,seednode) < 0){
+ delete_node(seednode);
+ seednode = NULL;
+ }
+ else{
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPS] A client connected to server[%d]\r\n"
+ "con_id:%d,"
+ "seed,"
+ "tcp,"
+ "address:%s,"
+ "port:%d,"
+ "socket:%d",
+ ServerNodeUsed->con_id,
+ seednode->con_id,
+ inet_ntoa(s_cli_addr.sin_addr.s_addr),
+ ntohs(s_cli_addr.sin_port),
+ seednode->sockfd
+ );
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ }
+ }
+// else
+//#endif
+#else
+ {
+ newsockfd = s_newsockfd;
+ memcpy(&cli_addr, &s_cli_addr, sizeof(cli_addr));
+ client = s_client;
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "A client connected to this server :\r\n[PORT]: %d\r\n[IP]:%s",
+ ntohs(cli_addr.sin_port), inet_ntoa(cli_addr.sin_addr.s_addr));
+ }
+#endif
+ }
+ }
+ }
+ else{
+#if ATCMD_VER == ATVER_2
+ if(ServerNodeUsed != NULL) {
+ if(hang_node(ServerNodeUsed) < 0){
+ error_no = 12;
+ goto err_exit;
+ }
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPS] OK"
+ "\r\n[ATPS] con_id=%d",
+ ServerNodeUsed->con_id);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ //task will exit itself
+ ServerNodeUsed->handletask = NULL;
+ }
+#endif
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"The UDP SERVER START OK!");
+ }
+ goto exit;
+err_exit:
+#if ATCMD_VER == ATVER_2
+ if(ServerNodeUsed){
+ //task will exit itself if getting here
+ ServerNodeUsed->handletask = NULL;
+ delete_node(ServerNodeUsed);
+ }
+ //else
+//#endif
+#else
+ {
+ socket_close();
+ }
+#endif
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPS] ERROR:%d", error_no);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+exit:
+ return;
+}
+
+static void client_start(void *param)
+{
+ int c_mode;
+ int c_remote_port;
+ char c_remote_addr[16];
+ int c_sockfd;
+ struct sockaddr_in c_serv_addr;
+ int error_no = 0;
+#if ATCMD_VER == ATVER_2
+ struct in_addr c_addr;
+ node * ClientNodeUsed = (node *)param;
+ if(ClientNodeUsed){
+ c_mode = ClientNodeUsed->protocol;
+ c_remote_port = ClientNodeUsed->port;
+ c_addr.s_addr = htonl(ClientNodeUsed->addr);
+ if(inet_ntoa_r(c_addr, c_remote_addr, sizeof(c_remote_addr))==NULL){
+ error_no = 6;
+ goto err_exit;
+ }
+ }
+ //else
+//#endif
+#else
+ {
+ c_mode = mode;
+ c_remote_port = remote_port;
+ memcpy(c_remote_addr, remote_addr, 16*sizeof(char));
+ }
+#endif
+ if(c_mode == NODE_MODE_UDP)
+ c_sockfd = socket(AF_INET,SOCK_DGRAM,0);
+ else
+ c_sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (c_sockfd == INVALID_SOCKET_ID) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"Failed to create sock_fd!");
+ error_no = 7;
+ goto err_exit;
+ }
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"OK to create sock_fd!");
+ memset(&c_serv_addr, 0, sizeof(c_serv_addr));
+ c_serv_addr.sin_family = AF_INET;
+ c_serv_addr.sin_addr.s_addr = inet_addr(c_remote_addr);
+ c_serv_addr.sin_port = htons(c_remote_port);
+
+#if ATCMD_VER == ATVER_2
+ if(ClientNodeUsed){
+ ClientNodeUsed->sockfd = c_sockfd;
+ }
+ //else
+//#endif
+#else
+ {
+ sockfd = c_sockfd;
+ memcpy(&serv_addr, &c_serv_addr, sizeof(c_serv_addr));
+ }
+#endif
+ if (c_mode == NODE_MODE_TCP){//TCP MODE
+ if(connect(c_sockfd, (struct sockaddr *)&c_serv_addr, sizeof(c_serv_addr)) == 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"Connect to Server successful!");
+#if ATCMD_VER == ATVER_2
+ if(ClientNodeUsed != NULL) {
+ if(hang_node(ClientNodeUsed) < 0){
+ error_no = 8;
+ goto err_exit;
+ }
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPC] OK\r\n[ATPC] con_id=%d",ClientNodeUsed->con_id);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ }
+#endif
+ }else{
+#if ATCMD_VER == ATVER_2
+ if(ClientNodeUsed != NULL) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"[ATPC] ERROR:Connect to Server failed!");
+ }
+ //else
+//#endif
+#else
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"Connect to Server failed!");
+ }
+#endif
+ error_no = 9;
+ goto err_exit;
+ }
+ }
+ else{
+#if ATCMD_VER == ATVER_2
+ if(ClientNodeUsed != NULL) {
+ if(ClientNodeUsed->local_port){
+ struct sockaddr_in addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family=AF_INET;
+ addr.sin_port=htons(ClientNodeUsed->local_port);
+ addr.sin_addr.s_addr=htonl(INADDR_ANY) ;
+ if (bind(ClientNodeUsed->sockfd, (struct sockaddr *)&addr, sizeof(addr))<0) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"bind sock error!");
+ error_no = 12;
+ goto err_exit;
+ }
+ }
+ if(hang_node(ClientNodeUsed) < 0){
+ error_no = 10;
+ goto err_exit;
+ }
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPC] OK\r\n[ATPC] con_id=%d",ClientNodeUsed->con_id);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ }
+#endif
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"UDP client starts successful!");
+ }
+ goto exit;
+err_exit:
+#if ATCMD_VER == ATVER_2
+ if(ClientNodeUsed)
+ {
+ delete_node(ClientNodeUsed);
+ }
+ //else
+//#endif
+#else
+ {
+ socket_close();
+ }
+#endif
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPC] ERROR:%d", error_no);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+exit:
+ return;
+}
+
+static void client_start_task(void *param)
+{
+ vTaskDelay(1000);
+#if ATCMD_VER == ATVER_2
+ if(param){
+ client_start(param);
+ vTaskDelete(NULL);
+ return;
+ }
+//#endif
+#else
+ if(remote_addr == NULL){
+ printf("[ERROR] Please using ATP3 to input an valid remote IP address!\n");
+ vTaskDelete(client_task);
+ client_task = NULL;
+ }
+ else if(remote_port == 0){
+ printf("[ERROR] Please using ATP4 to input an valid remote PORT!\n");
+ vTaskDelete(client_task);
+ client_task = NULL;
+ }
+ else{
+ printf("\tStart Client\n\t[IP]: %s\n\t[PORT]:%d\n", remote_addr, remote_port);
+ client_start(param);
+ }
+#endif
+ vTaskDelete(NULL);
+}
+
+static void server_start_task(void *param)
+{
+ vTaskDelay(1000);
+#if ATCMD_VER == ATVER_2
+ if(param != NULL){
+ server_start(param);
+ vTaskDelete(NULL);
+ return;
+ }
+//#endif
+#else
+ if(local_port == 0){
+ printf("[ERROR] Please using ATP2 to input an valid local PORT!\n");
+ vTaskDelete(server_task);
+ server_task = NULL;
+ }
+ else{
+ uint8_t *ip = (uint8_t *)LwIP_GetIP(&xnetif[0]);
+ printf("Start Server\n\t[IP]: %d.%d.%d.%d\n\t[PORT]:%d\n", ip[0], ip[1], ip[2], ip[3], local_port);
+ server_start(param);
+ }
+#endif
+ vTaskDelete(NULL);
+}
+
+//AT Command function
+#if ATCMD_VER == ATVER_1
+void fATP1(void *arg){
+ if(!arg){
+ printf("[ATP1]Usage: ATP1=MODE\n\r");
+ goto exit;
+ }
+ mode = atoi((char*)arg);
+ printf("[ATP1]: _AT_TRANSPORT_MODE_ [%d]\n\r", mode);
+exit:
+ return;
+}
+
+void fATP2(void *arg){
+ if(!arg){
+ printf("[ATP2]Usage: ATP2=LOCAL_PORT\n\r");
+ goto exit;
+ }
+ local_port = atoi((char*)arg);
+ printf("[ATP2]: _AT_TRANSPORT_LOCAL_PORT_ [%d]\n\r", local_port);
+
+exit:
+ return;
+}
+
+void fATP3(void *arg){
+ if(!arg){
+ printf("[ATP3]Usage: ATP3=REMOTE_IP\n\r");
+ goto exit;
+ }
+ strcpy((char*)remote_addr, (char*)arg);
+ printf("[ATP3]: _AT_TRANSPORT_REMOTE_IP_ [%s]\n\r", remote_addr);
+
+exit:
+ return;
+}
+
+void fATP4(void *arg){
+ if(!arg){
+ printf("[ATP4]Usage: ATP4=REMOTE_PORT\n\r");
+ goto exit;
+ }
+ remote_port = atoi((char*)arg);
+ printf("[ATP4]: _AT_TRANSPORT_REMOTE_PORT_ [%d]\n\r", remote_port);
+
+exit:
+ return;
+}
+
+void fATP5(void *arg){
+ int server_status = 0;
+ if(!arg){
+ printf("[ATP5]Usage: ATP5=0/1(0:server disable; 1: server enable)\n\r");
+ goto exit;
+ }
+ server_status = atoi((char*)arg);
+ printf("[ATP5]: _AT_TRANSPORT_START_SERVER_ [%d]\n\r", server_status);
+ if(mode == 0){
+ if(server_status == 0){
+ socket_close();
+ type = 0;
+ }
+ else if(server_status == 1){
+ if(server_task == NULL)
+ {
+ if(xTaskCreate(server_start_task, ((const char*)"server_start_task"), ATCP_STACK_SIZE, NULL, ATCMD_LWIP_TASK_PRIORITY, &server_task) != pdPASS)
+ printf("[ATP5]ERROR: Create tcp server task failed.\r\n");
+ }
+ type = 1;
+ }
+ else
+ printf("[ATP5]ERROR: Just support two mode : 0 or 1\n\r");
+ }
+ else if(mode == 1){
+ if(server_status == 0){
+ socket_close();
+ type = 0;
+ }
+ else if(server_status == 1){
+ if(server_task == NULL)
+ {
+ if(xTaskCreate(server_start_task, ((const char*)"server_start_task"), ATCP_STACK_SIZE, NULL, ATCMD_LWIP_TASK_PRIORITY, &server_task) != pdPASS)
+ printf("[ATP5]ERROR: Create udp server task failed.\n");
+ }
+ type = 3;
+ }
+ else
+ printf("[ATP5]ERROR: Just support two mode : 0 or 1\n\r");
+ }
+ else
+ printf("[ATP5]Error: mode(TCP/UDP) can't be empty\n\r");
+
+exit:
+ return;
+}
+
+void fATP6(void *arg){
+ int client_status = 0;
+ if(!arg){
+ printf("[ATP6]Usage: ATP6=0/1(0:Client disable; 1: Client enable)\n\r");
+ goto exit;
+ }
+ client_status = atoi((char*)arg);
+ printf("[ATP6]: _AT_TRANSPORT_START_CLIENT_ [%d]\n\r", client_status);
+ if(mode == 0){
+ if(client_status == 0){
+ socket_close();
+ type = 0;
+ }
+ else if(client_status == 1){
+ printf("[ATP6]TCP Client mode will start\n");
+ if(client_task == NULL)
+ {
+ if(xTaskCreate(client_start_task, ((const char*)"client_start_task"), ATCP_STACK_SIZE, NULL, ATCMD_LWIP_TASK_PRIORITY, &client_task) != pdPASS)
+ printf("[ATP6]ERROR: Create tcp client task failed.\n");
+ }
+ type = 2;
+ }
+ else
+ printf("[ATP6]ERROR: Just support two mode : 0 or 1\n\r");
+ }
+ else if(mode == 1){
+ if(client_status == 0){
+ socket_close();
+ type = 0;
+ }
+ else if(client_status == 1){
+ if(client_task == NULL)
+ {
+ if(xTaskCreate(client_start_task, ((const char*)"client_start_task"), ATCP_STACK_SIZE, NULL, ATCMD_LWIP_TASK_PRIORITY, &client_task) != pdPASS)
+ printf("[ATP6]ERROR: Create udp client task failed.\n");
+ }
+ type = 4;
+ }
+ else
+ printf("[ATP6]ERROR: Just support two mode : 0 or 1\n\r");
+ }
+ else
+ printf("[ATP6]Error: mode(TCP/UDP) can't be empty\n\r");
+
+exit:
+ return;
+}
+
+void fATPZ(void *arg){
+ uint8_t *ip;
+ printf("\nThe current Transport settings:\n");
+ printf("==============================\n");
+ if(mode == 0)
+ printf(" Protocol: TCP\n");
+ else if(mode == 1)
+ printf(" Protocol: UDP\n");
+
+ ip = (uint8_t *)LwIP_GetIP(&xnetif[0]);
+ printf(" LOCAL_IP => %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ printf(" LOCAL_PORT => %d\n", local_port);
+ printf(" REMOTE_IP => %s\n", remote_addr);
+ printf(" REMOTE_PORT => %d\n", remote_port);
+
+// printf("\n\r");
+}
+
+void fATR0(void *arg){
+ if(packet_size <= 0){
+ packet_size = MAX_BUFFER;
+ printf("[ATR0]Notice: Didn't set the value of packet_size, will using the MAX_BUFFER: %d\n", MAX_BUFFER);
+ }
+ memset(rx_buffer, 0, MAX_BUFFER);
+ if(type == 1){//tcp server
+ if((read(newsockfd,rx_buffer,MAX_BUFFER)) > 0)
+ printf("[ATR0]Receive the data:%s\n with packet_size: %d\n", rx_buffer, packet_size);
+ else
+ printf("[ATR0]ERROR: Failed to receive data!\n");
+ close(newsockfd);
+ newsockfd = -1;
+ }
+ else{
+ if((read(sockfd,rx_buffer,MAX_BUFFER)) > 0)
+ printf("[ATR0]Receive the data:%s\n with packet_size: %d\n", rx_buffer, packet_size);
+ else
+ printf("[ATR0]ERROR: Failed to receive data!\n");
+ }
+}
+
+void fATR1(void *arg){
+ int size;
+ if(!arg){
+ printf("[ATR1]Usage: ATR1=packet_size(cannot exceed %d)\n\r", MAX_BUFFER);
+ goto exit;
+ }
+ size = atoi((char*)arg);
+ printf("[ATR1]: _AT_TRANSPORT_RECEIVE_PACKET_SIZE_ [%d]\n\r", size);
+ if(size < 1)
+ printf("[ATR1]Error: packet size need be larger than 0!\n\r");
+ else if(size > MAX_BUFFER)
+ printf("[ATR1]Error: packet size exceeds the MAX_BUFFER value: %d!\n\r", MAX_BUFFER);
+ else
+ packet_size = size;
+exit:
+ return;
+}
+
+
+void fATRA(void *arg){
+ if(!arg){
+ printf("[ATRA]Usage: ATRA=[data](Data size cannot exceed the MAX_BUFFER SIZE: %d)\n\r", MAX_BUFFER);
+ return;
+ }
+
+ if(packet_size <= 0){
+ packet_size = MAX_BUFFER;
+ printf("[ATRA]Notice: Didn't set the value of packet_size, will using the MAX_BUFFER SIZE: %d\n", MAX_BUFFER);
+ }
+
+
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+
+ if((argc = parse_param(arg, argv)) != 2){
+ printf("[ATRA]Usage: ATRA=[data](Data size cannot exceed the MAX_BUFFER SIZE: %d)\n\r", MAX_BUFFER);
+ goto exit;
+ }
+ else
+ printf("[ATRA]: _AT_TRANSPORT_WRITE_DATA_ [%s]\n\r", argv[1]);
+ memset(tx_buffer, 0, MAX_BUFFER);
+ memcpy(tx_buffer, argv[1], strlen(argv[1]));
+
+ if(type == 1){//tcp server
+ if((write(newsockfd,tx_buffer,strlen(tx_buffer))) > 0)
+ printf("[ATRA] Sending data:%s\n with packet_size:%d\n", tx_buffer, packet_size);
+ else
+ printf("[ATRA]ERROR: Failed to send data\n");
+ close(newsockfd);
+ newsockfd = -1;
+ }
+ else if(type == 4){//udp client
+ int ret = 0;
+ ret = sendto(sockfd, tx_buffer, strlen(tx_buffer), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
+
+ printf("The value of ret is %d\n", ret);
+ }
+ else if(type == 3)
+ printf("The UDP Server mode not support Sending data service!\n");
+ else{
+ if((write(sockfd,tx_buffer, strlen(tx_buffer))) > 0)
+ printf("[ATRA] Sending data:%s\n with packet_size:%d\n", tx_buffer, packet_size);
+ else
+ printf("[ATRA]ERROR: Failed to send data\n");
+ }
+exit:
+ return;
+}
+
+void fATRB(void *arg){
+ int size;
+ if(!arg){
+ printf("[ATRB]Usage: ATRB=packet_size(cannot exceed %d)\n\r", MAX_BUFFER);
+ goto exit;
+ }
+ size = atoi((char*)arg);
+ printf("[ATRB]: _AT_TRANSPORT_WRITE_PACKET_SIZE_ [%d]\n\r", size);
+ if(size < 1)
+ printf("[ATRB]Error: packet size need be larger than 0!\n\r");
+ else if(size > MAX_BUFFER)
+ printf("[ATRB]Error: packet size exceeds the MAX_BUFFER value: %d!\n\r", MAX_BUFFER);
+ else
+ packet_size = size;
+exit:
+ return;
+}
+#endif
+#if ATCMD_VER == ATVER_2
+void fATP0(void *arg){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATP0]: _AT_TRANSPORT_ERRNO");
+#ifdef ERRNO
+ at_printf("\r\n[ATP0] OK:%d", errno);
+#else
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"errno isn't enabled");
+ at_printf("\r\n[ATP0] ERROR");
+#endif
+}
+
+void fATPC(void *arg){
+
+ int argc;
+ char* argv[MAX_ARGC] = {0};
+ node* clientnode = NULL;
+ int mode = 0;
+ int remote_port;
+ int local_port = 0;
+ //char remote_addr[DNS_MAX_NAME_LENGTH];
+ struct in_addr addr;
+ int error_no = 0;
+#if LWIP_DNS
+ struct hostent *server_host;
+#endif
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPC]: _AT_TRANSPORT_START_CLIENT");
+
+ if(atcmd_lwip_is_tt_mode() && mainlist->next){
+ error_no = 13;
+ goto err_exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if(argc < 4){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPC] Usage: ATPC=,,,[]");
+ error_no = 1;
+ goto err_exit;
+ }
+
+ mode = atoi((char*)argv[1]);//tcp or udp
+ //strcpy((char*)remote_addr, (char*)argv[2]);
+
+ remote_port = atoi((char*)argv[3]);
+ if (inet_aton(argv[2], &addr) == 0)
+ {
+#if LWIP_DNS
+ server_host = gethostbyname(argv[2]);
+ if (server_host){
+ memcpy(&addr, server_host->h_addr, 4);
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPC] Found name '%s' = %s",
+ argv[2],
+ inet_ntoa(addr)
+ );
+ }
+ else
+#endif
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPC] ERROR: Host '%s' not found.", argv[2]);
+ error_no = 2;
+ goto err_exit;
+ }
+ }
+
+ if(remote_port < 0 || remote_port > 65535) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPC] ERROR: remote port invalid");
+ error_no = 3;
+ goto err_exit;
+ }
+
+ if(argv[4]){
+ local_port = atoi((char*)argv[4]);
+ if(local_port < 0 || local_port > 65535) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPC] ERROR: local port invalid");
+ error_no = 11;
+ goto err_exit;
+ }
+ }
+
+ clientnode = create_node(mode, NODE_ROLE_CLIENT);
+ if(clientnode == NULL){
+ error_no = 4;
+ goto err_exit;
+ }
+ clientnode->port = remote_port;
+ clientnode->addr = ntohl(addr.s_addr);
+ clientnode->local_port = local_port;
+
+ if(xTaskCreate(client_start_task, ((const char*)"client_start_task"), ATCP_STACK_SIZE, clientnode, ATCMD_LWIP_TASK_PRIORITY, NULL) != pdPASS)
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPC] ERROR: Create tcp/udp client task failed.");
+ error_no = 5;
+ goto err_exit;
+ }
+
+ goto exit;
+err_exit:
+ if(clientnode)
+ delete_node(clientnode);
+ at_printf("\r\n[ATPC] ERROR:%d", error_no);
+exit:
+ return;
+}
+
+
+void fATPS(void *arg){
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+ node* servernode = NULL;
+ int mode;
+ int local_port;
+ int error_no = 0;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPS]: _AT_TRANSPORT_START_SERVER");
+
+ if(atcmd_lwip_is_tt_mode()){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPS] ERROR: Server can only start when TT is disabled");
+ error_no = 13;
+ goto err_exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if(argc != 3){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPS] Usage: ATPS=[TCP:0/UDP:1],[Local port(1~65535)]");
+ error_no = 1;
+ goto err_exit;
+ }
+
+ mode = atoi((char*)argv[1]);
+ local_port = atoi((char*)argv[2]);
+
+ if(local_port < 0 || local_port > 65535){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPS] Usage: ATPS=[TCP:0/UDP:1],[Local port]");
+ error_no = 2;
+ goto err_exit;
+ }
+
+ servernode = create_node(mode, NODE_ROLE_SERVER);
+ if(servernode == NULL){
+ error_no = 3;
+ goto err_exit;
+ }
+ servernode->port = local_port;
+
+ if(xTaskCreate(server_start_task, ((const char*)"server_start_task"), ATCP_STACK_SIZE, servernode, ATCMD_LWIP_TASK_PRIORITY, &servernode->handletask) != pdPASS)
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPS] ERROR: Create tcp/udp server task failed.");
+ error_no = 4;
+ goto err_exit;
+ }
+
+ goto exit;
+err_exit:
+ if(servernode)
+ delete_node(servernode);
+ at_printf("\r\n[ATPS] ERROR:%d", error_no);
+exit:
+ return;
+}
+
+void socket_close_all(void)
+{
+ node *currNode = mainlist->next;
+
+ while(currNode)
+ {
+ delete_node(currNode);
+ currNode = mainlist->next;
+ }
+ currNode = NULL;
+}
+
+void fATPD(void *arg){
+ int con_id = INVALID_CON_ID;
+ int error_no = 0;
+ node *s_node;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPD]: _AT_TRANSPORT_CLOSE_CONNECTION");
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPD] Usage: ATPD=con_id or 0 (close all)");
+ error_no = 1;
+ goto exit;
+ }
+ con_id = atoi((char*)arg);
+
+ if(con_id == 0){
+ if(atcmd_lwip_is_autorecv_mode()){
+ atcmd_lwip_set_autorecv_mode(FALSE);
+ }
+ socket_close_all();
+ goto exit;
+ }
+
+ s_node = seek_node(con_id);
+ if(s_node == NULL){
+ error_no = 3;
+ goto exit;
+ }
+ delete_node(s_node);
+
+exit:
+ s_node = NULL;
+ if(error_no)
+ at_printf("\r\n[ATPD] ERROR:%d", error_no);
+ else
+ at_printf("\r\n[ATPD] OK");
+ return;
+}
+
+int atcmd_lwip_send_data(node *curnode, u8 *data, u16 data_sz, struct sockaddr_in cli_addr){
+ int error_no = 0;
+
+ if((curnode->protocol == NODE_MODE_UDP) && (curnode->role == NODE_ROLE_SERVER))
+ {
+ if (sendto(curnode->sockfd, data, data_sz, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr)) <= 0 ){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPT] ERROR:Failed to send data");
+ error_no = 5;
+ }
+ }else{
+ if(curnode->protocol == NODE_MODE_UDP) //UDP server
+ {
+ struct sockaddr_in serv_addr;
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(curnode->port);
+ serv_addr.sin_addr.s_addr = htonl(curnode->addr);
+ if(sendto( curnode->sockfd, data, data_sz, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) <= 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPT] ERROR:Failed to send data\n");
+ error_no = 6;
+ }
+ }else if(curnode->protocol == NODE_MODE_TCP)//TCP server
+ {
+ if(curnode->role == NODE_ROLE_SERVER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPT] ERROR: TCP Server must send data to the seed");
+ error_no = 7;
+ goto exit;
+ }
+
+ if((write(curnode->sockfd, data, data_sz)) <= 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPT] ERROR:Failed to send data\n");
+ error_no = 8;
+ }
+ }
+ }
+
+exit:
+ return error_no;
+}
+
+void fATPT(void *arg){
+
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+ int con_id = INVALID_CON_ID;
+ int error_no = 0;
+ node* curnode = NULL;
+ struct sockaddr_in cli_addr;
+ int data_sz;
+ int data_pos = C_NUM_AT_CMD + C_NUM_AT_CMD_DLT+ strlen(arg) + 1;
+ u8 *data = (u8 *)log_buf + data_pos;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPT]: _AT_TRANSPORT_SEND_DATA");
+
+ argc = parse_param(arg, argv);
+
+ if(argc != 3 && argc != 5) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPT] Usage: ATPT=,"
+ "[,,]"
+ ":(MAX %d)",
+ MAX_BUFFER);
+ error_no = 1;
+ goto exit;
+ }
+
+ data_sz = atoi((char*)argv[1]);
+ if(data_sz > MAX_BUFFER){
+ error_no = 2;
+ goto exit;
+ }
+
+ con_id = atoi((char*)argv[2]);
+ curnode = seek_node(con_id);
+ if(curnode == NULL){
+ error_no = 3;
+ goto exit;
+ }
+
+ if((curnode->protocol == NODE_MODE_UDP)
+ &&(curnode->role == NODE_ROLE_SERVER))
+ {
+ char udp_clientaddr[16]={0};
+ strcpy((char*)udp_clientaddr, (char*)argv[3]);
+ cli_addr.sin_family = AF_INET;
+ cli_addr.sin_port = htons(atoi((char*)argv[4]));
+ if (inet_aton(udp_clientaddr , &cli_addr.sin_addr) == 0)
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPT]ERROR:inet_aton() failed");
+ error_no = 4;
+ goto exit;
+ }
+ }
+ error_no = atcmd_lwip_send_data(curnode, data, data_sz, cli_addr);
+exit:
+ if(error_no)
+ at_printf("\r\n[ATPT] ERROR:%d,%d", error_no, con_id);
+ else
+ at_printf("\r\n[ATPT] OK,%d", con_id);
+ return;
+}
+
+void fATPR(void *arg){
+
+ int argc,con_id = INVALID_CON_ID;
+ char *argv[MAX_ARGC] = {0};
+ int error_no = 0;
+ int recv_size = 0;
+ int packet_size = 0;
+ node* curnode = NULL;
+ u8_t udp_clientaddr[16] = {0};
+ u16_t udp_clientport = 0;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPR]: _AT_TRANSPORT_RECEIVE_DATA");
+
+ if(atcmd_lwip_is_autorecv_mode()){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR: Receive changed to auto mode.");
+ error_no = 10;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if( argc != 3){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] Usage: ATPR =,\n\r");
+ error_no = 1;
+ goto exit;
+ }
+
+ con_id = atoi((char*)argv[1]);
+ if(con_id <= 0 || con_id > NUM_NS){
+ error_no = 9;
+ goto exit;
+ }
+
+ packet_size = atoi((char*)argv[2]);
+
+ if(packet_size <= 0 || packet_size > MAX_BUFFER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] Recv Size(%d) exceeds MAX_BUFFER(%d)", packet_size,
+ MAX_BUFFER);
+ error_no = 2;
+ goto exit;
+ }
+
+ curnode = seek_node(con_id);
+ if(curnode == NULL){
+ error_no = 3;
+ goto exit;
+ }
+
+ if(curnode->protocol == NODE_MODE_TCP && curnode->role == NODE_ROLE_SERVER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR: TCP Server must receive data from the seed");
+ error_no = 6;
+ goto exit;
+ }
+
+ memset(rx_buffer, 0, MAX_BUFFER);
+ error_no = atcmd_lwip_receive_data(curnode, rx_buffer, ETH_MAX_MTU, &recv_size, udp_clientaddr, &udp_clientport);
+exit:
+ if(error_no == 0){
+ if(curnode->protocol == NODE_MODE_UDP && curnode->role == NODE_ROLE_SERVER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "\r\n[ATPR] OK,%d,%d,%s,%d:", recv_size, con_id, udp_clientaddr, udp_clientport);
+ at_printf("\r\n[ATPR] OK,%d,%d,%s,%d:", recv_size, con_id, udp_clientaddr, udp_clientport);
+ }
+ else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "\r\n[ATPR] OK,%d,%d:", recv_size, con_id);
+ at_printf("\r\n[ATPR] OK,%d,%d:", recv_size, con_id);
+ }
+ if(recv_size)
+ at_print_data(rx_buffer, recv_size);
+ }
+ else
+ at_printf("\r\n[ATPR] ERROR:%d,%d", error_no, con_id);
+ return;
+}
+
+void fATPK(void *arg){
+
+ int argc;
+ int error_no = 0;
+ int enable = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPK]: _AT_TRANSPORT_AUTO_RECV");
+
+ argc = parse_param(arg, argv);
+ if( argc < 2){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPK] Usage: ATPK=<0/1>\n\r");
+ error_no = 1;
+ goto exit;
+ }
+
+ enable = atoi((char*)argv[1]);
+
+ if(enable){
+ if(atcmd_lwip_is_autorecv_mode()){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS, "[ATPK] already enter auto receive mode");
+ }
+ else{
+ if(atcmd_lwip_start_autorecv_task())
+ error_no = 2;
+ }
+ }else{
+ if(atcmd_lwip_is_autorecv_mode())
+ atcmd_lwip_set_autorecv_mode(FALSE);
+ else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"[ATPK] already leave auto receive mode");
+ }
+ }
+
+exit:
+ if(error_no)
+ at_printf("\r\n[ATPK] ERROR:%d", error_no);
+ else
+ at_printf("\r\n[ATPK] OK");
+ return;
+}
+
+void fATPU(void *arg){
+
+ int argc;
+ int error_no = 0;
+ int enable = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPU]: _AT_TRANSPORT_TT_MODE");
+
+ argc = parse_param(arg, argv);
+ if( argc < 2){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPU] Usage: ATPU=<1>\n\r");
+ error_no = 1;
+ goto exit;
+ }
+
+ enable = atoi((char*)argv[1]);
+
+ if(enable){
+ if(!mainlist->next){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR, "[ATPU] No conn found");
+ error_no = 2;
+ }else if(mainlist->next->role == NODE_ROLE_SERVER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR, "[ATPU] No TT mode for server");
+ error_no = 3;
+ }
+ else if(mainlist->next->next || mainlist->next->nextseed){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR, "[ATPU] More than one conn found");
+ error_no = 4;
+ }
+ else{
+ if(atcmd_lwip_start_tt_task()){
+ error_no = 5;
+ }
+ }
+ }
+
+exit:
+ if(error_no)
+ at_printf("\r\n[ATPU] ERROR:%d", error_no);
+ else
+ at_printf("\r\n[ATPU] OK");
+ return;
+}
+
+//ATPL=
+void fATPL(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "\r\n[ATPL] Usage : ATPL=");
+ error_no = 1;
+ goto exit;
+ }
+ argc = parse_param(arg, argv);
+ if(argc != 2){
+ error_no = 2;
+ goto exit;
+ }
+
+ //ENABLE LWIP FAST CONNECT
+ if(argv[1] != NULL){
+ int enable = atoi(argv[1]);
+ struct atcmd_lwip_conn_info cur_conn = {0};
+ node *cur_node = mainlist->next;
+ if(enable && cur_node == NULL){
+ error_no = 3;
+ goto exit;
+ }
+ cur_conn.role = cur_node->role;
+ cur_conn.protocol = cur_node->protocol;
+ cur_conn.remote_addr = cur_node->addr;
+ cur_conn.remote_port = cur_node->port;
+ cur_conn.local_addr = cur_node->local_addr;
+ cur_conn.local_port = cur_node->local_port;
+ atcmd_lwip_write_info_to_flash(&cur_conn, enable);
+ }
+
+exit:
+ if(error_no == 0)
+ at_printf("\r\n[ATPL] OK");
+ else
+ at_printf("\r\n[ATPL] ERROR:%d",error_no);
+
+ return;
+}
+
+extern void do_ping_call(char *ip, int loop, int count);
+void fATPP(void *arg){
+ int count, argc = 0;
+ char buf[32] = {0};
+ char *argv[MAX_ARGC] = {0};
+ int con_id=INVALID_CON_ID;
+ int error_no = 0;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPP]: _AT_TRANSPORT_PING");
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"[ATPP] Usage: ATPP=xxxx.xxxx.xxxx.xxxx[y/loop] or ATPP=[con_id],[y/loop]\n\r");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+
+ if( strlen(argv[1]) < 3 )
+ {
+ node* curnode;
+ struct in_addr addr;
+ con_id = atoi( (char*)argv[1] );
+ curnode = seek_node(con_id);
+ if(curnode == NULL){
+ error_no = 2;
+ goto exit;
+ }
+ if( curnode->role == 1){ //ping remote server
+ addr.s_addr = htonl(curnode->addr);
+ inet_ntoa_r(addr, buf, sizeof(buf));
+ }else if( curnode->role == 0){//ping local server
+ strcpy(buf,SERVER);
+ }else if( curnode->role == 2){ //ping seed
+ strcpy(buf,(char*) curnode->addr);
+ }
+ }else
+ strcpy(buf, argv[1]);
+
+ if(argc == 2){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"[ATPP]Repeat Count: 5");
+ do_ping_call(buf, 0, 5); //Not loop, count=5
+ }else{
+ if(strcmp(argv[2], "loop") == 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"[ATPP]Repeat Count: %s", "loop");
+ do_ping_call(buf, 1, 0); //loop, no count
+ }else{
+ count = atoi(argv[2]);
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"[ATPP]Repeat Count: %d", count);
+ do_ping_call(buf, 0, count); //Not loop, with count
+ }
+ }
+
+exit:
+ if(error_no)
+ at_printf("\r\n[ATPP] ERROR:%d", error_no);
+ else
+ at_printf("\r\n[ATPP] OK");
+ return;
+}
+
+void fATPI(void *arg){
+ node* n = mainlist->next;
+ struct in_addr addr;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "[ATPI]: _AT_TRANSPORT_CONNECTION_INFO");
+
+ while (n != NULL)
+ {
+ if(n->con_id == 0)
+ continue;
+
+ at_printf("\r\ncon_id:%d,", n->con_id);
+
+ if(n->role == 0)
+ at_printf("server,");
+ else
+ at_printf("client,");
+ if(n->protocol == 0)
+ at_printf("tcp,");
+ else
+ at_printf("udp,");
+
+ addr.s_addr = htonl(n->addr);
+ at_printf("address:%s,port:%d,socket:%d", inet_ntoa(addr) ,n->port, n->sockfd);
+ if(n->nextseed != NULL)
+ {
+ node* seed = n;
+ do{
+ seed = seed->nextseed;
+ at_printf("\r\ncon_id:%d,seed,", seed->con_id);
+ if(seed->protocol == 0)
+ at_printf("tcp,");
+ else
+ at_printf("udp,");
+ addr.s_addr = htonl(seed->addr);
+ at_printf("address:%s,port:%d,socket:%d", inet_ntoa(addr), seed->port, seed->sockfd);
+ }while (seed->nextseed != NULL);
+ }
+ n = n->next;
+ }
+
+ at_printf("\r\n[ATPI] OK");
+
+ return;
+}
+
+void init_node_pool(void){
+ int i;
+ memset(node_pool, 0, sizeof(node_pool));
+ for(i=0;inext )
+ {
+ if(currNode == n){
+ prevNode->next = currNode->next;
+ }
+
+ if(currNode->role != NODE_ROLE_SERVER)
+ continue;
+
+ precvSeed = currNode;
+ currSeed = currNode->nextseed;
+ while (currSeed != NULL)
+ {
+ if(currSeed == n){
+ precvSeed->nextseed = n->nextseed;
+ }
+ precvSeed = currSeed;
+ currSeed = currSeed->nextseed;
+ }
+ }
+ SYS_ARCH_UNPROTECT(lev);
+
+ if(n->role == NODE_ROLE_SERVER){
+ //node may have seed if it's under server mode
+ while(n->nextseed != NULL){
+ currSeed = n->nextseed;
+ // only tcp seed has its own socket, udp seed uses its server's
+ // so delete udp seed can't close socket which is used by server
+ if(currSeed->protocol == NODE_MODE_TCP && currSeed->sockfd != INVALID_SOCKET_ID){
+ close(currSeed->sockfd);
+ currSeed->sockfd = INVALID_SOCKET_ID;
+ }
+ // no task created for seed
+ //if(s->handletask != NULL)
+ // vTaskDelete(s->handletask);
+ n->nextseed = currSeed->nextseed;
+ currSeed->con_id = INVALID_CON_ID;
+ };
+ }
+
+ if(!((n->protocol == NODE_MODE_UDP)&&(n->role == NODE_ROLE_SEED))){
+ if(n->sockfd != INVALID_SOCKET_ID){
+ close(n->sockfd);
+ n->sockfd = INVALID_SOCKET_ID;
+ }
+ }
+ //task will exit itself in fail case
+ if(n->handletask){
+ vTaskDelete(n->handletask);
+ n->handletask = NULL;
+ }
+ n->con_id = INVALID_CON_ID;
+ return;
+}
+
+int hang_node(node* insert_node)
+{
+ node* n = mainlist;
+ SYS_ARCH_DECL_PROTECT(lev);
+ SYS_ARCH_PROTECT(lev);
+ while (n->next != NULL)
+ {
+ n = n->next;
+ if(insert_node->role == NODE_ROLE_SERVER) //need to check for server in case that two conns are binded to same port, because SO_REUSEADDR is enabled
+ {
+ if( (n->port == insert_node->port) && ((n->addr== insert_node->addr) && (n->role == insert_node->role) && (n->protocol == insert_node->protocol) ) ){
+ SYS_ARCH_UNPROTECT(lev);
+ struct in_addr addr;
+ addr.s_addr = htonl(insert_node->addr);
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "This conn(IP:%s PORT:%d) already exist",
+ inet_ntoa(addr),insert_node->port);
+ return -1;
+ }
+ }
+ }
+
+ n->next = insert_node;
+ SYS_ARCH_UNPROTECT(lev);
+ return 0;
+}
+
+int hang_seednode(node* main_node ,node* insert_node)
+{
+ node* n = main_node;
+
+ SYS_ARCH_DECL_PROTECT(lev);
+ SYS_ARCH_PROTECT(lev);
+ while (n->nextseed != NULL)
+ {
+ n = n->nextseed;
+ if( (n->port == insert_node->port) && (n->addr == insert_node->addr)){
+ SYS_ARCH_UNPROTECT(lev);
+ struct in_addr addr;
+ addr.s_addr = htonl(insert_node->addr);
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "This seed IP:%s PORT:%d already exist",
+ inet_ntoa(addr),insert_node->port);
+ return -1;
+ }
+ }
+
+ n->nextseed = insert_node;
+ SYS_ARCH_UNPROTECT(lev);
+ return 0;
+}
+
+node *seek_node(int con_id)
+{
+ node* n = mainlist;
+ while (n->next != NULL)
+ {
+ n = n->next;
+ if(n->con_id == con_id)
+ return n;
+
+ if(n->nextseed != NULL)
+ {
+ node* seed = n;
+ do{
+ seed = seed->nextseed;
+ if(seed->con_id == con_id)
+ return seed;
+ }while (seed->nextseed != NULL);
+ }
+ }
+ return NULL;
+}
+
+node *tryget_node(int n)
+{
+ SYS_ARCH_DECL_PROTECT(lev);
+ if ((n <= 0) || (n > NUM_NS)) {
+ return NULL;
+ }
+ SYS_ARCH_PROTECT(lev);
+ if (node_pool[n].con_id == INVALID_CON_ID || node_pool[n].sockfd == INVALID_SOCKET_ID) {
+ SYS_ARCH_UNPROTECT(lev);
+ return NULL;
+ }
+ SYS_ARCH_UNPROTECT(lev);
+ return &node_pool[n];
+}
+
+int atcmd_lwip_receive_data(node *curnode, u8 *buffer, u16 buffer_size, int *recv_size,
+ u8_t *udp_clientaddr, u16_t *udp_clientport){
+
+ struct timeval tv;
+ fd_set readfds;
+ int error_no = 0, ret = 0, size = 0;
+
+ FD_ZERO(&readfds);
+ FD_SET(curnode->sockfd, &readfds);
+ tv.tv_sec = RECV_SELECT_TIMEOUT_SEC;
+ tv.tv_usec = RECV_SELECT_TIMEOUT_USEC;
+ ret = select(curnode->sockfd + 1, &readfds, NULL, NULL, &tv);
+ if(!((ret > 0)&&(FD_ISSET(curnode->sockfd, &readfds))))
+ {
+ //AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ // "[ATPR] No receive event for con_id %d", curnode->con_id);
+ goto exit;
+ }
+
+ if(curnode->protocol == NODE_MODE_UDP) //udp server receive from client
+ {
+ if(curnode->role == NODE_ROLE_SERVER){
+ //node * clinode;
+ struct sockaddr_in client_addr;
+ u32_t addr_len = sizeof(struct sockaddr_in);
+ memset((char *) &client_addr, 0, sizeof(client_addr));
+
+ if ((size = recvfrom(curnode->sockfd, buffer, buffer_size, 0, (struct sockaddr *) &client_addr, &addr_len)) > 0){
+ //at_printf("[ATPR]:%d,%s,%d,%s\r\n with packet_size: %d\r\n",con_id, inet_ntoa(client_addr.sin_addr.s_addr), ntohs(client_addr.sin_port), rx_buffer, packet_size);
+ //at_printf("\r\nsize: %d\r\n", recv_size);
+ //at_printf("%s", rx_buffer);
+ }
+ else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR:Failed to receive data");
+ error_no = 4;
+ }
+#if 0
+ clinode = create_node(NODE_MODE_UDP, NODE_ROLE_SEED);
+ clinode->sockfd = curnode->sockfd;
+ clinode->addr = ntohl(client_addr.sin_addr.s_addr);
+ clinode->port = ntohs(client_addr.sin_port);
+ if(hang_seednode(curnode,clinode) < 0){
+ delete_node(clinode);
+ clinode = NULL;
+ }
+#else
+ inet_ntoa_r(client_addr.sin_addr.s_addr, (char *)udp_clientaddr, 16);
+ *udp_clientport = ntohs(client_addr.sin_port);
+#endif
+ }
+ else{
+ struct sockaddr_in serv_addr;
+ u32_t addr_len = sizeof(struct sockaddr_in);
+ memset((char *) &serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(curnode->port);
+ serv_addr.sin_addr.s_addr = htonl(curnode->addr);
+
+ if ((size = recvfrom(curnode->sockfd, buffer, buffer_size, 0, (struct sockaddr *) &serv_addr, &addr_len)) > 0){
+ //at_printf("[ATPR]:%d,%s,%d,%s\r\n with packet_size: %d\r\n",con_id, inet_ntoa(serv_addr.sin_addr.s_addr), ntohs(serv_addr.sin_port), rx_buffer, packet_size);
+ //at_printf("\r\nsize: %d\r\n", recv_size);
+ //at_printf("%s", rx_buffer);
+ }
+ else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR:Failed to receive data");
+ error_no = 5;
+ }
+ }
+ }
+ else{
+ #if 0
+ if(curnode->role == NODE_ROLE_SERVER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR: TCP Server must receive data from the seed");
+ error_no = 6;
+ }
+ #endif
+ //receive from seed or server
+ if((size = read(curnode->sockfd,buffer,buffer_size)) > 0)
+ {
+ //struct in_addr addr;
+ //addr.s_addr = htonl(curnode->addr);
+ //at_printf("[ATPR]:%d,%s,%d,%s\r\n with packet_size: %d\r\n",con_id, inet_ntoa(addr), curnode->port, rx_buffer, packet_size);
+ //at_printf("\r\nsize: %d\r\n", recv_size);
+ //at_printf("%s", rx_buffer);
+ }
+ else{
+ if(size == 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR:Connection is closed!");
+ error_no = 7;
+ }
+ else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "[ATPR] ERROR:Failed to receive data!");
+ error_no = 8;
+ }
+ }
+ }
+exit:
+ if(error_no == 0)
+ *recv_size = size;
+ else{
+ close(curnode->sockfd);
+ curnode->sockfd = INVALID_SOCKET_ID;
+ }
+ return error_no;
+}
+
+static void atcmd_lwip_receive_task(void *param)
+{
+
+ int i;
+ int packet_size = ETH_MAX_MTU;
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "Enter auto receive mode");
+
+ while(atcmd_lwip_is_autorecv_mode())
+ {
+ for (i = 0; i < NUM_NS; ++i) {
+ node* curnode = NULL;
+ int error_no = 0;
+ int recv_size = 0;
+ u8_t udp_clientaddr[16] = {0};
+ u16_t udp_clientport = 0;
+ curnode = tryget_node(i);
+ if(curnode == NULL)
+ continue;
+ if(curnode->protocol == NODE_MODE_TCP && curnode->role == NODE_ROLE_SERVER){
+ //TCP Server must receive data from the seed
+ continue;
+ }
+ error_no = atcmd_lwip_receive_data(curnode, rx_buffer, packet_size, &recv_size, udp_clientaddr, &udp_clientport);
+
+ if(atcmd_lwip_is_tt_mode()){
+ if((error_no == 0) && recv_size){
+ rx_buffer[recv_size] = '\0';
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"Recv[%d]:%s", recv_size, rx_buffer);
+ at_print_data(rx_buffer, recv_size);
+ rtw_msleep_os(20);
+ }
+ continue;
+ }
+
+ if(error_no == 0){
+ if(recv_size){
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ if(curnode->protocol == NODE_MODE_UDP && curnode->role == NODE_ROLE_SERVER){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "\r\n[ATPR] OK,%d,%d,%s,%d:", recv_size, curnode->con_id, udp_clientaddr, udp_clientport);
+ at_printf("\r\n[ATPR] OK,%d,%d,%s,%d:", recv_size, curnode->con_id, udp_clientaddr, udp_clientport);
+ }
+ else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "\r\n[ATPR] OK,%d,%d:",
+ recv_size,
+ curnode->con_id);
+ at_printf("\r\n[ATPR] OK,%d,%d:", recv_size, curnode->con_id);
+ }
+ at_print_data(rx_buffer, recv_size);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ }
+ }
+ else{
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+ #endif
+ at_printf("\r\n[ATPR] ERROR:%d,%d", error_no, curnode->con_id);
+ at_printf(STR_END_OF_ATCMD_RET);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ }
+ }
+ }
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "Leave auto receive mode");
+
+ vTaskDelete(NULL);
+}
+
+int atcmd_lwip_start_autorecv_task(void){
+ atcmd_lwip_set_autorecv_mode(TRUE);
+ if(xTaskCreate(atcmd_lwip_receive_task, ((const char*)"atcmd_lwip_receive_task"), ATCP_STACK_SIZE, NULL, ATCMD_LWIP_TASK_PRIORITY, NULL) != pdPASS)
+ {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "ERROR: Create receive task failed.");
+ atcmd_lwip_set_autorecv_mode(FALSE);
+ return -1;
+ }
+ return 0;
+}
+
+int atcmd_lwip_is_tt_mode(void){
+ return (atcmd_lwip_tt_mode == TRUE);
+}
+void atcmd_lwip_set_tt_mode(int enable){
+ atcmd_lwip_tt_mode = enable;
+}
+
+int atcmd_lwip_is_autorecv_mode(void){
+ return (atcmd_lwip_auto_recv == TRUE);
+}
+void atcmd_lwip_set_autorecv_mode(int enable){
+ atcmd_lwip_auto_recv = enable;
+}
+
+static void _tt_wait_rx_complete(){
+ s32 tick_current = rtw_get_current_time();
+
+ while(rtw_systime_to_ms(tick_current -atcmd_lwip_tt_lasttickcnt) < ATCMD_LWIP_TT_MAX_DELAY_TIME_MS ){
+ rtw_msleep_os(5);
+ tick_current = rtw_get_current_time();
+ }
+}
+
+static void atcmd_lwip_tt_handler(void* param)
+{
+ struct sockaddr_in cli_addr;
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "Enter TT data mode");
+ while(RtlDownSema((_Sema *)&atcmd_lwip_tt_sema) == _SUCCESS) {
+ _lock lock;
+ _irqL irqL;
+ int tt_size = 0;
+ _tt_wait_rx_complete();
+
+ rtw_enter_critical(&lock, &irqL);
+ if((atcmd_lwip_tt_datasize >= 4) && (memcmp(log_buf, "----", 4) == 0)){
+ atcmd_lwip_set_tt_mode(FALSE);
+ atcmd_lwip_tt_datasize = 0;
+ rtw_exit_critical(&lock, &irqL);
+ break;
+ }
+ rtw_memcpy(tx_buffer, log_buf, atcmd_lwip_tt_datasize);
+ tt_size = atcmd_lwip_tt_datasize;
+ atcmd_lwip_tt_datasize = 0;
+ rtw_exit_critical(&lock, &irqL);
+ tx_buffer[tt_size] = '\0';
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"Send[%d]:%s", tt_size, tx_buffer);
+ atcmd_lwip_send_data(mainlist->next, tx_buffer, tt_size, cli_addr);
+ }
+
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "Leave TT data mode");
+ RtlFreeSema((_Sema *)&atcmd_lwip_tt_sema);
+ atcmd_lwip_set_autorecv_mode(FALSE);
+ at_printf(STR_END_OF_ATCMD_RET); //mark return to command mode
+ vTaskDelete(NULL);
+}
+
+int atcmd_lwip_start_tt_task(void){
+ RtlInitSema((_Sema *)&atcmd_lwip_tt_sema, 0);
+ atcmd_lwip_set_tt_mode(TRUE);
+ if(xTaskCreate(atcmd_lwip_tt_handler, ((const char*)"tt_hdl"), ATCP_STACK_SIZE, NULL, ATCMD_LWIP_TASK_PRIORITY, &atcmd_lwip_tt_task) != pdPASS){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,
+ "ERROR: Create tt task failed.");
+ goto err_exit;
+ }
+ RtlMsleepOS(20);
+ if(atcmd_lwip_is_autorecv_mode() != 1){
+ if(atcmd_lwip_start_autorecv_task()){
+ vTaskDelete(atcmd_lwip_tt_task);
+ goto err_exit;
+ }
+ }
+
+ return 0;
+
+err_exit:
+ atcmd_lwip_set_tt_mode(FALSE);
+ return -1;
+}
+
+void atcmd_lwip_erase_info(void){
+ atcmd_update_partition_info(AT_PARTITION_LWIP, AT_PARTITION_ERASE, NULL, 0);
+}
+
+int atcmd_lwip_write_info_to_flash(struct atcmd_lwip_conn_info *cur_conn, int enable)
+{
+ struct atcmd_lwip_conf read_data = {0};
+ int i = 0, found = 0;
+
+ atcmd_update_partition_info(AT_PARTITION_LWIP, AT_PARTITION_READ, (u8 *) &read_data, sizeof(struct atcmd_lwip_conf));
+
+ //fake that the conn exists already when disabling or there is no active conn on this moment
+ if(enable == 0){
+ atcmd_lwip_erase_info();
+ goto exit;
+ }
+
+ if(read_data.conn_num < 0 || read_data.conn_num > ATCMD_LWIP_CONN_STORE_MAX_NUM){
+ read_data.conn_num = 0;
+ read_data.last_index = -1;
+ }
+
+ for(i = 0; i < read_data.conn_num; i++){
+ if(memcmp((u8 *)cur_conn, (u8 *)&read_data.conn[i], sizeof(struct atcmd_lwip_conn_info)) == 0) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "the same profile found in flash");
+ found = 1;
+ break;
+ }
+ }
+
+ if(!found){
+ read_data.last_index++;
+ if(read_data.last_index >= ATCMD_LWIP_CONN_STORE_MAX_NUM)
+ read_data.last_index -= ATCMD_LWIP_CONN_STORE_MAX_NUM;
+ memcpy((u8 *)&read_data.conn[read_data.last_index], (u8 *)cur_conn, sizeof(struct atcmd_lwip_conn_info));
+ read_data.conn_num++;
+ if(read_data.conn_num > ATCMD_LWIP_CONN_STORE_MAX_NUM)
+ read_data.conn_num = ATCMD_LWIP_CONN_STORE_MAX_NUM;
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "not the same proto/addr/port, write new profile to flash");
+ }
+ if(!found || read_data.enable != enable){
+ read_data.enable = enable;
+ atcmd_update_partition_info(AT_PARTITION_LWIP, AT_PARTITION_WRITE, (u8 *) &read_data, sizeof(struct atcmd_lwip_conf));
+ }
+exit:
+ return 0;
+}
+
+int atcmd_lwip_read_info_from_flash(u8 *read_data, u32 read_len)
+{
+ atcmd_update_partition_info(AT_PARTITION_LWIP, AT_PARTITION_READ, read_data, read_len);
+ return 0;
+}
+
+int atcmd_lwip_auto_connect(void)
+{
+ struct atcmd_lwip_conf read_data = {0};
+ struct atcmd_lwip_conn_info *re_conn;
+ node* re_node = NULL;
+ int i, error_no = 0;
+ int last_index;
+
+ atcmd_lwip_read_info_from_flash((u8 *)&read_data, sizeof(struct atcmd_lwip_conf));
+ if(read_data.enable == 0){
+ error_no = 1;
+ goto exit;
+ }
+ if(read_data.conn_num > ATCMD_LWIP_CONN_STORE_MAX_NUM || read_data.conn_num <= 0){
+ error_no = 2;
+ goto exit;
+ }
+
+ last_index = read_data.last_index;
+ for(i = 0; i < read_data.conn_num; i++){
+ re_conn = &read_data.conn[last_index];
+ last_index ++;
+ if(last_index >= ATCMD_LWIP_CONN_STORE_MAX_NUM)
+ last_index -= ATCMD_LWIP_CONN_STORE_MAX_NUM;
+ re_node = create_node(re_conn->protocol, re_conn->role);
+ if(re_node == NULL){
+ error_no = 3;
+ break;
+ }
+ re_node->addr = re_conn->remote_addr;
+ re_node->port = re_conn->remote_port;
+ re_node->local_addr = re_conn->local_addr;
+ re_node->local_port = re_conn->local_port;
+ if(re_node->protocol == NODE_MODE_UDP)
+ re_node->sockfd = socket(AF_INET,SOCK_DGRAM,0);
+ else
+ re_node->sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (re_node->sockfd == INVALID_SOCKET_ID) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"Failed to create sock_fd!");
+ error_no = 4;
+ break;
+ }
+
+ struct in_addr addr;
+ addr.s_addr = htonl(re_node->addr);
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,
+ "\r\nTry connect: %d,%d,%s,%d",
+ re_node->sockfd, re_node->protocol,
+ inet_ntoa(addr), re_node->port);
+
+ if(re_node->role == NODE_ROLE_SERVER){
+ //TODO: start server here
+ goto exit;
+ }
+
+ if (re_node->protocol == NODE_MODE_TCP){//TCP MODE
+ struct sockaddr_in c_serv_addr;
+ memset(&c_serv_addr, 0, sizeof(c_serv_addr));
+ c_serv_addr.sin_family = AF_INET;
+ c_serv_addr.sin_addr.s_addr = htonl(re_node->addr);
+ c_serv_addr.sin_port = htons(re_node->port);
+ if(connect(re_node->sockfd, (struct sockaddr *)&c_serv_addr, sizeof(c_serv_addr)) == 0){
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"Connect to Server successful!");
+ if(hang_node(re_node) < 0){
+ error_no = 5;
+ }
+ break;
+ }else{
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"Connect to Server failed(%d)!", errno);
+ error_no = 6;
+ delete_node(re_node);
+ re_node = NULL;
+ continue; //try next conn
+ }
+ }
+ else{
+ if(re_node->local_port){
+ struct sockaddr_in addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family=AF_INET;
+ addr.sin_port=htons(re_node->local_port);
+ addr.sin_addr.s_addr=htonl(INADDR_ANY) ;
+ if (bind(re_node->sockfd, (struct sockaddr *)&addr, sizeof(addr))<0) {
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ERROR,"bind sock error!");
+ error_no = 7;
+ delete_node(re_node);
+ re_node = NULL;
+ continue;
+ }
+ }
+ if(hang_node(re_node) < 0){
+ error_no = 8;
+ }
+ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS,"UDP client starts successful!");
+ break;
+ }
+ }
+
+exit:
+ if(re_node && error_no)
+ delete_node(re_node);
+ return error_no;
+}
+
+int atcmd_lwip_restore_from_flash(void){
+ int ret = -1;
+ if(atcmd_lwip_auto_connect() == 0){
+ if(atcmd_lwip_start_tt_task() == 0)
+ ret = 0;
+ }
+ return ret;
+}
+#endif
+
+#if CONFIG_TRANSPORT
+log_item_t at_transport_items[ ] = {
+#if ATCMD_VER == ATVER_1
+ {"ATP1", fATP1,},//mode TCP=0,UDP=1
+ {"ATP2", fATP2,},//LOCAL PORT
+ {"ATP3", fATP3,},//REMOTE IP
+ {"ATP4", fATP4,},//REMOTE PORT
+ {"ATP5", fATP5,},//START SERVER
+ {"ATP6", fATP6,},//START CLIENT
+ {"ATP?", fATPZ,},//SETTING
+ {"ATR0", fATR0,},//READ DATA
+ {"ATR1", fATR1,},//SET PACKET SIZE
+ {"ATRA", fATRA,},//WRITE DATA
+ {"ATRB", fATRB,},//SET WRITE PACKET SIZE
+#endif
+#if ATCMD_VER == ATVER_2
+ {"ATP0", fATP0,},//query errno if defined
+ {"ATPS", fATPS,},//Create Server
+ {"ATPD", fATPD,},//Close Server/Client connection
+ {"ATPC", fATPC,},//Create Client
+ {"ATPT", fATPT,},//WRITE DATA
+ {"ATPR", fATPR,},//READ DATA
+ {"ATPK", fATPK,},//Auto recv
+ {"ATPP", fATPP,},//PING
+ {"ATPI", fATPI,},//printf connection status
+ {"ATPU", fATPU,}, //transparent transmission mode
+ {"ATPL", fATPL,}, //lwip auto reconnect setting
+#endif
+};
+
+#if ATCMD_VER == ATVER_2
+void print_tcpip_at(void *arg){
+ int index;
+ int cmd_len = 0;
+
+ cmd_len = sizeof(at_transport_items)/sizeof(at_transport_items[0]);
+ for(index = 0; index < cmd_len; index++)
+ at_printf("\r\n%s", at_transport_items[index].log_cmd);
+}
+#endif
+
+void at_transport_init(void)
+{
+#if ATCMD_VER == ATVER_2
+ init_node_pool();
+ mainlist = create_node(-1,-1);
+#endif
+ log_service_add_table(at_transport_items, sizeof(at_transport_items)/sizeof(at_transport_items[0]));
+}
+
+log_module_init(at_transport_init);
+#endif
+#endif //#ifdef CONFIG_AT_LWIP
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_lwip.h b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_lwip.h
new file mode 100644
index 0000000..bbdb35c
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_lwip.h
@@ -0,0 +1,100 @@
+#ifndef __ATCMD_LWIP_H__
+#define __ATCMD_LWIP_H__
+
+#include
+#ifdef CONFIG_AT_LWIP
+
+#include "main.h"
+#include
+#include "lwip/sockets.h"
+#include "lwip/api.h"
+#include "lwip/sys.h"
+#include "lwip/igmp.h"
+#include "lwip/inet.h"
+#include "lwip/tcp.h"
+#include "lwip/raw.h"
+#include "lwip/udp.h"
+#include "lwip/tcpip.h"
+#include "lwip/pbuf.h"
+#include "lwip/netdb.h"
+#include "lwip_netconf.h"
+
+
+#define _AT_TRANSPORT_MODE_ "ATP1"
+#define _AT_TRANSPORT_LOCAL_PORT_ "ATP2"
+#define _AT_TRANSPORT_REMOTE_IP_ "ATP3"
+#define _AT_TRANSPORT_REMOTE_PORT_ "ATP4"
+#define _AT_TRANSPORT_START_SERVER_ "ATP5"
+#define _AT_TRANSPORT_START_CLIENT_ "ATP6"
+#define _AT_TRANSPORT_SHOW_SETTING_ "ATP?"
+#define _AT_TRANSPORT_RECEIVE_DATA_ "ATR0"
+#define _AT_TRANSPORT_RECEIVE_PACKET_SIZE_ "ATR1"
+#define _AT_TRANSPORT_WRITE_DATA_ "ATRA"
+#define _AT_TRANSPORT_WRITE_PACKET_SIZE_ "ATRB"
+
+#define NODE_MODE_TCP 0
+#define NODE_MODE_UDP 1
+
+#define NODE_ROLE_SERVER 0
+#define NODE_ROLE_CLIENT 1
+#define NODE_ROLE_SEED 2
+
+#define INVALID_SOCKET_ID (-1)
+
+//parameters
+#ifndef NET_IF_NUM
+#define NET_IF_NUM 2
+#endif
+
+#define ATCMD_LWIP_TASK_PRIORITY (tskIDLE_PRIORITY + 1)
+
+#if ATCMD_VER == ATVER_2
+
+#define SERVER "127.0.0.1"
+
+#define NUM_NS (MEMP_NUM_NETCONN) //maximum number of node and seed, same as NUM_SOCKETS
+
+#define ETH_MAX_MTU 1500
+
+#define INVALID_CON_ID (-1)
+
+#define RECV_SELECT_TIMEOUT_SEC (0)
+#define RECV_SELECT_TIMEOUT_USEC (20000) //20ms
+
+typedef struct ns
+{
+ int con_id;
+ int sockfd;
+ s8_t role;
+ int protocol;
+ u32_t addr;
+ u16_t port;
+ u32_t local_addr;
+ u16_t local_port;
+ xTaskHandle handletask;
+ struct ns* next;
+ struct ns* nextseed;
+} node;
+
+extern xTaskHandle atcmd_lwip_tt_task;
+extern xSemaphoreHandle atcmd_lwip_tt_sema;
+extern volatile int atcmd_lwip_tt_datasize;
+extern volatile int atcmd_lwip_tt_lasttickcnt;
+#define ATCMD_LWIP_TT_MAX_DELAY_TIME_MS (20) //transparent transmission interval
+
+extern int atcmd_lwip_is_tt_mode(void);
+extern void atcmd_lwip_set_tt_mode(int enable);
+int atcmd_lwip_send_data(node *curnode, u8 *data, u16 data_sz, struct sockaddr_in cli_addr);
+int atcmd_lwip_receive_data(node *curnode, u8 *buffer, u16 buffer_size, int *recv_size,
+ u8_t *udp_clientaddr, u16_t *udp_clientport);
+node* create_node(int mode, s8_t role);
+void init_node_pool(void);
+void delete_node(node *n);
+int hang_node(node* insert_node);
+int hang_seednode(node* main_node ,node* insert_node);
+node *seek_node(int con_id);
+node *tryget_node(int n);
+#endif
+
+#endif //#ifdef CONFIG_AT_LWIP
+#endif //#ifndef __ATCMD_LWIP_H__
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_sys.c b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_sys.c
new file mode 100644
index 0000000..3a88399
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_sys.c
@@ -0,0 +1,1268 @@
+#include
+#ifdef CONFIG_AT_SYS
+
+#include "platform_stdlib.h"
+//#include "platform_autoconf.h"
+//#include "main.h"
+#include "autoconf.h"
+#include "hal_adc.h"
+#include "gpio_api.h" // mbed
+#include "sys_api.h"
+#include "flash_api.h"
+#include "rtl_lib.h"
+#include "build_info.h"
+#include "analogin_api.h"
+#include "log_service.h"
+#include "atcmd_sys.h"
+#include "osdep_api.h"
+#include "atcmd_wifi.h"
+#include "tcm_heap.h"
+#if CONFIG_OTA_UPDATE
+#include "update.h"
+#endif
+
+#ifndef ATCMD_VER
+#define ATVER_1 1
+#define ATVER_2 2
+#define ATCMD_VER ATVER_2
+#if CONFIG_EXAMPLE_UART_ATCMD
+#define ATCMD_VER ATVER_2
+#else
+#define ATCMD_VER ATVER_1
+#endif
+#endif
+
+#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
+#include "freertos_pmu.h"
+#endif
+
+extern u32 ConfigDebugErr;
+extern u32 ConfigDebugInfo;
+extern u32 ConfigDebugWarn;
+extern u32 CmdDumpWord(IN u16 argc, IN u8 *argv[]);
+extern u32 CmdWriteWord(IN u16 argc, IN u8 *argv[]);
+#if CONFIG_UART_XMODEM
+extern void OTU_FW_Update(u8, u8, u32);
+#endif
+
+struct _dev_id2name {
+ u8 id;
+ u8 *name;
+};
+struct _dev_id2name dev_id2name[] = {
+{0, "UART0"}, {1, "UART1"},{2, "UART2"},
+{8, "SPI0"}, {9, "SPI1"}, {10, "SPI2"},
+{15, "SPI0_MCS"},
+{16, "I2C0"}, {17, "I2C1"}, {18, "I2C2"}, {19, "I2C3"},
+{24, "I2S0"}, {25, "I2S1"},
+{28, "PCM0"}, {29, "PCM1"},
+{32, "ADC0"},
+{36, "DAC0"}, {37, "DAC1"},
+{64, "SDIOD"}, {65, "SDIOH"},
+{66, "USBOTG"},
+{88, "MII"},
+{96, "WL_LED"},
+{104,"WL_ANT0"}, {105,"WL_ANT1"},
+{108,"WL_BTCOEX"}, {109,"WL_BTCMD"},
+{112,"NFC"},
+{160,"PWM0"}, {161,"PWM1"}, {162,"PWM2"}, {163,"PWM3"},
+{164,"ETE0"}, {165,"ETE1"}, {166,"ETE2"}, {167,"ETE3"},
+{168,"EGTIM"},
+{196,"SPI_FLASH"},
+{200,"SDR"},
+{216,"JTAG"},
+{217,"TRACE"},
+{220,"LOG_UART"}, {221,"LOG_UART_IR"},
+{224,"SIC"},
+{225,"EEPROM"},
+{226,"DEBUG"},
+{255,""}};
+
+void fATXX(void *arg)
+{
+ uint32 x = 0;
+ int i;
+ u8 * s;
+ for(i = 0; dev_id2name[i].id != 255; i++ ) {
+ ReadHWPwrState(dev_id2name[i].id, &x);
+ s = "?";
+ switch(x) {
+ case HWACT:
+ s = "ACT";
+ break;
+ case HWCG:
+ s = "CG";
+ break;
+ case HWINACT:
+ s = "WACT";
+ break;
+ case UNDEF:
+ s = "UNDEF";
+ break;
+ case ALLMET:
+ s = "ALLMET";
+ break;
+ }
+ printf("Dev %s, state = %s\n", dev_id2name[i].name, s);
+ }
+}
+
+//-------- AT SYS commands ---------------------------------------------------------------
+void fATSD(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSD]: _AT_SYSTEM_DUMP_REGISTER_");
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSD] Usage: ATSD=REGISTER");
+ return;
+ }
+ argc = parse_param(arg, argv);
+ if(argc == 2 || argc == 3)
+ CmdDumpWord(argc-1, (unsigned char**)(argv+1));
+}
+
+#if ATCMD_VER == ATVER_1
+
+void fATSE(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ AT_DBG_MSG(AT_FLAG_EDIT, AT_DBG_ALWAYS, "[ATSE]: _AT_SYSTEM_EDIT_REGISTER_");
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_EDIT, AT_DBG_ALWAYS, "[ATSE] Usage: ATSE=REGISTER[VALUE]");
+ return;
+ }
+ argc = parse_param(arg, argv);
+ if(argc == 3)
+ CmdWriteWord(argc-1, (unsigned char**)(argv+1));
+}
+
+void fATSC(void *arg)
+{
+ AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ALWAYS, "[ATSC]: _AT_SYSTEM_CLEAR_OTA_SIGNATURE_");
+ sys_clear_ota_signature();
+}
+
+void fATSR(void *arg)
+{
+ AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ALWAYS, "[ATSR]: _AT_SYSTEM_RECOVER_OTA_SIGNATURE_");
+ sys_recover_ota_signature();
+}
+
+#if CONFIG_UART_XMODEM
+void fATSY(void *arg)
+{
+ // use xmodem to update, RX: PA_6, TX: PA_7, baudrate: 1M
+ OTU_FW_Update(0, 2, 115200);
+}
+#endif
+
+
+#if SUPPORT_MP_MODE
+void fATSA(void *arg)
+{
+ u32 tConfigDebugInfo = ConfigDebugInfo;
+ int argc = 0, channel;
+ char *argv[MAX_ARGC] = {0}, *ptmp;
+ u16 offset, gain;
+
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA]: _AT_SYSTEM_ADC_TEST_");
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=CHANNEL(0~2)");
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_get");
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_set[offet(hex),gain(hex)]");
+ return;
+ }
+
+ argc = parse_param(arg, argv);
+ if(strcmp(argv[1], "k_get") == 0){
+ sys_adc_calibration(0, &offset, &gain);
+// AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
+ }else if(strcmp(argv[1], "k_set") == 0){
+ if(argc != 4){
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_set[offet(hex),gain(hex)]");
+ return;
+ }
+ offset = strtoul(argv[2], &ptmp, 16);
+ gain = strtoul(argv[3], &ptmp, 16);
+ sys_adc_calibration(1, &offset, &gain);
+// AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
+ }else{
+ channel = atoi(argv[1]);
+ if(channel < 0 || channel > 2){
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=CHANNEL(0~2)");
+ return;
+ }
+ analogin_t adc;
+ u16 adcdat;
+
+ // Remove debug info massage
+ ConfigDebugInfo = 0;
+ if(channel == 0)
+ analogin_init(&adc, AD_1);
+ else if(channel == 1)
+ analogin_init(&adc, AD_2);
+ else
+ analogin_init(&adc, AD_3);
+ adcdat = analogin_read_u16(&adc)>>4;
+ analogin_deinit(&adc);
+ // Recover debug info massage
+ ConfigDebugInfo = tConfigDebugInfo;
+
+ AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] A%d = 0x%04X", channel, adcdat);
+ }
+}
+
+void fATSG(void *arg)
+{
+ gpio_t gpio_test;
+ int argc = 0, val;
+ char *argv[MAX_ARGC] = {0}, port, num;
+ PinName pin = NC;
+ u32 tConfigDebugInfo = ConfigDebugInfo;
+
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: _AT_SYSTEM_GPIO_TEST_");
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] Usage: ATSG=PINNAME(ex:A0)");
+ return;
+ }else{
+ argc = parse_param(arg, argv);
+ if(argc != 2){
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] Usage: ATSG=PINNAME(ex:A0)");
+ return;
+ }
+ }
+ port = argv[1][0];
+ num = argv[1][1];
+ if(port >= 'a' && port <= 'z')
+ port -= ('a' - 'A');
+ if(num >= 'a' && num <= 'z')
+ num -= ('a' - 'A');
+ switch(port){
+ case 'A':
+ switch(num){
+ case '0': pin = PA_0; break; case '1': pin = PA_1; break; case '2': pin = PA_2; break; case '3': pin = PA_3; break;
+ case '4': pin = PA_4; break; case '5': pin = PA_5; break; case '6': pin = PA_6; break; case '7': pin = PA_7; break;
+ }
+ break;
+ case 'B':
+ switch(num){
+ case '0': pin = PB_0; break; case '1': pin = PB_1; break; case '2': pin = PB_2; break; case '3': pin = PB_3; break;
+ case '4': pin = PB_4; break; case '5': pin = PB_5; break; case '6': pin = PB_6; break; case '7': pin = PB_7; break;
+ }
+ break;
+ case 'C':
+ switch(num){
+ case '0': pin = PC_0; break; case '1': pin = PC_1; break; case '2': pin = PC_2; break; case '3': pin = PC_3; break;
+ case '4': pin = PC_4; break; case '5': pin = PC_5; break; case '6': pin = PC_6; break; case '7': pin = PC_7; break;
+ case '8': pin = PC_8; break; case '9': pin = PC_9; break;
+ }
+ break;
+ case 'D':
+ switch(num){
+ case '0': pin = PD_0; break; case '1': pin = PD_1; break; case '2': pin = PD_2; break; case '3': pin = PD_3; break;
+ case '4': pin = PD_4; break; case '5': pin = PD_5; break; case '6': pin = PD_6; break; case '7': pin = PD_7; break;
+ case '8': pin = PD_8; break; case '9': pin = PD_9; break;
+ }
+ break;
+ case 'E':
+ switch(num){
+ case '0': pin = PE_0; break; case '1': pin = PE_1; break; case '2': pin = PE_2; break; case '3': pin = PE_3; break;
+ case '4': pin = PE_4; break; case '5': pin = PE_5; break; case '6': pin = PE_6; break; case '7': pin = PE_7; break;
+ case '8': pin = PE_8; break; case '9': pin = PE_9; break; case 'A': pin = PE_A; break;
+ }
+ break;
+ case 'F':
+ switch(num){
+ case '0': pin = PF_0; break; case '1': pin = PF_1; break; case '2': pin = PF_2; break; case '3': pin = PF_3; break;
+ case '4': pin = PF_4; break; case '5': pin = PF_5; break;
+ }
+ break;
+ case 'G':
+ switch(num){
+ case '0': pin = PG_0; break; case '1': pin = PG_1; break; case '2': pin = PG_2; break; case '3': pin = PG_3; break;
+ case '4': pin = PG_4; break; case '5': pin = PG_5; break; case '6': pin = PG_6; break; case '7': pin = PG_7; break;
+ }
+ break;
+ case 'H':
+ switch(num){
+ case '0': pin = PH_0; break; case '1': pin = PH_1; break; case '2': pin = PH_2; break; case '3': pin = PH_3; break;
+ case '4': pin = PH_4; break; case '5': pin = PH_5; break; case '6': pin = PH_6; break; case '7': pin = PH_7; break;
+ }
+ break;
+ case 'I':
+ switch(num){
+ case '0': pin = PI_0; break; case '1': pin = PI_1; break; case '2': pin = PI_2; break; case '3': pin = PI_3; break;
+ case '4': pin = PI_4; break; case '5': pin = PI_5; break; case '6': pin = PI_6; break; case '7': pin = PI_7; break;
+ }
+ break;
+ case 'J':
+ switch(num){
+ case '0': pin = PJ_0; break; case '1': pin = PJ_1; break; case '2': pin = PJ_2; break; case '3': pin = PJ_3; break;
+ case '4': pin = PJ_4; break; case '5': pin = PJ_5; break; case '6': pin = PJ_6; break;
+ }
+ break;
+ case 'K':
+ switch(num){
+ case '0': pin = PK_0; break; case '1': pin = PK_1; break; case '2': pin = PK_2; break; case '3': pin = PK_3; break;
+ case '4': pin = PK_4; break; case '5': pin = PK_5; break; case '6': pin = PK_6; break;
+ }
+ break;
+ }
+ if(pin == NC){
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: Invalid Pin Name");
+ return;
+ }
+ // Remove debug info massage
+ ConfigDebugInfo = 0;
+ // Initial input control pin
+ gpio_init(&gpio_test, pin);
+ gpio_dir(&gpio_test, PIN_INPUT); // Direction: Input
+ gpio_mode(&gpio_test, PullUp); // Pull-High
+ val = gpio_read(&gpio_test);
+ // Recover debug info massage
+ ConfigDebugInfo = tConfigDebugInfo;
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] %c%c = %d", port, num, val);
+}
+
+
+void fATSP(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ unsigned long timeout; // ms
+ unsigned long time_begin, time_current;
+
+ gpio_t gpiob_1;
+ int val_old, val_new;
+
+ int expected_zerocount, zerocount;
+ int test_result;
+
+ // parameter check
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: _AT_SYSTEM_POWER_PIN_TEST_");
+ if(!arg) {
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
+ } else {
+ argc = parse_param(arg, argv);
+ if (argc < 2) {
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
+ return;
+ }
+ }
+
+ if ( strcmp(argv[1], "gpiob1" ) == 0 ) {
+ if (argc < 4) {
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
+ return;
+ }
+
+ // init gpiob1 test
+ test_result = 0;
+ timeout = strtoul(argv[2], NULL, 10);
+ expected_zerocount = atoi(argv[3]);
+ zerocount = 0;
+ val_old = 1;
+
+ sys_log_uart_off();
+
+ gpio_init(&gpiob_1, PB_1);
+ gpio_dir(&gpiob_1, PIN_INPUT);
+ gpio_mode(&gpiob_1, PullDown);
+
+ // gpiob1 test ++
+ time_begin = time_current = xTaskGetTickCount();
+ while (time_current < time_begin + timeout) {
+ val_new = gpio_read(&gpiob_1);
+
+ if (val_new != val_old && val_new == 0) {
+
+ zerocount ++;
+ if (zerocount == expected_zerocount) {
+ test_result = 1;
+ break;
+ }
+ }
+
+ val_old = val_new;
+ time_current = xTaskGetTickCount();
+ }
+ // gpio test --
+
+ sys_log_uart_on();
+
+ if (test_result == 1) {
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: success");
+ } else {
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: fail, it only got %d zeros", zerocount);
+ }
+ }
+}
+
+int write_otu_to_system_data(flash_t *flash, uint32_t otu_addr)
+{
+ uint32_t data, i = 0;
+ flash_read_word(flash, FLASH_SYSTEM_DATA_ADDR+0xc, &data);
+ //printf("\n\r[%s] data 0x%x otu_addr 0x%x", __FUNCTION__, data, otu_addr);
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: data 0x%x otu_addr 0x%x", data, otu_addr);
+ if(data == ~0x0){
+ flash_write_word(flash, FLASH_SYSTEM_DATA_ADDR+0xc, otu_addr);
+ }else{
+ //erase backup sector
+ flash_erase_sector(flash, FLASH_RESERVED_DATA_BASE);
+ //backup system data to backup sector
+ for(i = 0; i < 0x1000; i+= 4){
+ flash_read_word(flash, FLASH_SYSTEM_DATA_ADDR + i, &data);
+ if(i == 0xc)
+ data = otu_addr;
+ flash_write_word(flash, FLASH_RESERVED_DATA_BASE + i,data);
+ }
+ //erase system data
+ flash_erase_sector(flash, FLASH_SYSTEM_DATA_ADDR);
+ //write data back to system data
+ for(i = 0; i < 0x1000; i+= 4){
+ flash_read_word(flash, FLASH_RESERVED_DATA_BASE + i, &data);
+ flash_write_word(flash, FLASH_SYSTEM_DATA_ADDR + i,data);
+ }
+ //erase backup sector
+ flash_erase_sector(flash, FLASH_RESERVED_DATA_BASE);
+ }
+ return 0;
+}
+
+void fATSB(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ u32 boot_gpio, rb_boot_gpio;
+ u8 gpio_pin;
+ u8 uart_port, uart_index;
+ u8 gpio_pin_bar;
+ u8 uart_port_bar;
+ flash_t flash;
+
+ // parameter check
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: _AT_SYSTEM_BOOT_OTU_PIN_SET_");
+ if(!arg) {
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: Usage: ATSB=[GPIO_PIN, TRIGER_MODE, UART]");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: GPIO_PIN: PB_1, PC_4 ....");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: TRIGER_MODE: low_trigger, high_trigger");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: UART: UART0, UART2");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: example: ATSB=[PC_2, low_trigger, UART2]");
+
+ } else {
+ argc = parse_param(arg, argv);
+ if (argc != 4 ) {
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: Usage: ATSB=[GPIO_PIN, TRIGER_MODE, UART]");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: GPIO_PIN: PB_1, PC_4 ....");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: TRIGER_MODE: low_trigger, high_trigger");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: UART: UART0, UART2");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: example: ATSB=[PC_2, low_trigger, UART2]");
+ return;
+ }
+ }
+
+ if ( strncmp(argv[1], "P", 1) == 0 && strlen(argv[1]) == 4
+ && (strcmp(argv[2], "low_trigger") == 0 || strcmp(argv[2], "high_trigger") == 0)
+ && strncmp(argv[3], "UART", 4) == 0 && strlen(argv[3]) == 5) {
+ if((0x41 <= argv[1][1] <= 0x45) && (0x30 <= argv[1][3] <= 0x39) &&(0x30 <= argv[1][4] <= 0x32)){
+ if(strcmp(argv[2], "high_trigger") == 0)
+ gpio_pin = 1<< 7 | ((argv[1][1]-0x41)<<4) | (argv[1][3] - 0x30);
+ else
+ gpio_pin = ((argv[1][1]-0x41)<<4) | (argv[1][3] - 0x30);
+ gpio_pin_bar = ~gpio_pin;
+ uart_index = argv[3][4] - 0x30;
+ if(uart_index == 0)
+ uart_port = (uart_index<<4)|2;
+ else if(uart_index == 2)
+ uart_port = (uart_index<<4)|0;
+ else{
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: Input UART index error. Please choose UART0 or UART2.");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: example: ATSB=[PC_2, low_trigger, UART2]");
+ return;
+ }
+ uart_port_bar = ~uart_port;
+ boot_gpio = uart_port_bar<<24 | uart_port<<16 | gpio_pin_bar<<8 | gpio_pin;
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]:gpio_pin 0x%x", gpio_pin);
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]:gpio_pin_bar 0x%x", gpio_pin_bar);
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]:uart_port 0x%x", uart_port);
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]:uart_port_bar 0x%x", uart_port_bar);
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]:boot_gpio 0x%x", boot_gpio);
+ write_otu_to_system_data(&flash, boot_gpio);
+ flash_read_word(&flash, FLASH_SYSTEM_DATA_ADDR+0x0c, &rb_boot_gpio);
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]:Read 0x900c 0x%x", rb_boot_gpio);
+ }else{
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: Usage: ATSB=[GPIO_PIN, TRIGER_MODE, UART]");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: GPIO_PIN: PB_1, PC_4 ....");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: TRIGER_MODE: low_trigger, high_trigger");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: UART: UART0, UART2");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: example: ATSB=[PC_2, low_trigger, UART2]");
+ }
+ }else{
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: Usage: ATSB=[GPIO_PIN, TRIGER_MODE, UART]");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: GPIO_PIN: PB_1, PC_4 ....");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: TRIGER_MODE: low_trigger, high_trigger");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: UART: UART0, UART2");
+ AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSB]: example: ATSB=[PC_2, low_trigger, UART2]");
+ return;
+ }
+}
+#endif
+
+#if (configGENERATE_RUN_TIME_STATS == 1)
+void fATSS(void *arg) // Show CPU stats
+{
+ AT_PRINTK("[ATSS]: _AT_SYSTEM_CPU_STATS_");
+ char *cBuffer = pvPortMalloc(512);
+ if(cBuffer != NULL) {
+ vTaskGetRunTimeStats((char *)cBuffer);
+ AT_PRINTK("%s", cBuffer);
+ }
+ vPortFree(cBuffer);
+}
+#endif
+
+void fATSs(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ AT_PRINTK("[ATS@]: _AT_SYSTEM_DBG_SETTING_");
+ if(!arg){
+ AT_PRINTK("[ATS@] Usage: ATS@=[LEVLE,FLAG]");
+ }else{
+ argc = parse_param(arg, argv);
+ if(argc == 3){
+ char *ptmp;
+ gDbgLevel = atoi(argv[1]);
+ gDbgFlag = strtoul(argv[2], &ptmp, 16);
+ }
+ }
+ AT_PRINTK("[ATS@] level = %d, flag = 0x%08X", gDbgLevel, gDbgFlag);
+}
+
+void fATSc(void *arg)
+{
+ int argc = 0, config = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ AT_PRINTK("[ATS!]: _AT_SYSTEM_CONFIG_SETTING_");
+ if(!arg){
+ AT_PRINTK("[ATS!] Usage: ATS!=[CONFIG(0,1,2),FLAG]");
+ }else{
+ argc = parse_param(arg, argv);
+ if(argc == 3){
+ char *ptmp;
+ config = atoi(argv[1]);
+ if(config == 0)
+ ConfigDebugErr = strtoul(argv[2], &ptmp, 16);
+ if(config == 1)
+ ConfigDebugInfo = strtoul(argv[2], &ptmp, 16);
+ if(config == 2)
+ ConfigDebugWarn = strtoul(argv[2], &ptmp, 16);
+ }
+ }
+ AT_PRINTK("[ATS!] ConfigDebugErr = 0x%08X", ConfigDebugErr);
+ AT_PRINTK("[ATS!] ConfigDebugInfo = 0x%08X", ConfigDebugInfo);
+ AT_PRINTK("[ATS!] ConfigDebugWarn = 0x%08X", ConfigDebugWarn);
+}
+
+#define SUPPORT_CP_TEST 0
+#if SUPPORT_CP_TEST
+extern void MFi_auth_test(void);
+void fATSM(void *arg)
+{
+ AT_PRINTK("[ATSM]: _AT_SYSTEM_CP_");
+ MFi_auth_test();
+}
+#endif
+
+extern u8 __HeapLimit, __StackTop;
+void fATSt(void *arg)
+{
+ AT_PRINTK("[ATS#]: _AT_SYSTEM_TEST_");
+ DBG_8195A("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nRAM stack\t%d bytes\nTCM heap\t%d bytes\n",
+ HalGetCpuClk(), xPortGetFreeHeapSize(), (int)&__StackTop - (int)&__HeapLimit, tcm_heap_freeSpace());
+ dump_mem_block_list();
+ tcm_heap_dump();
+ DBG_8195A("\n");
+}
+
+void fATSJ(void *arg)
+{
+ int argc = 0, config = 0;
+ char *argv[MAX_ARGC] = {0};
+ AT_PRINTK("[ATSJ]: _AT_SYSTEM_JTAG_");
+ if(!arg){
+ AT_PRINTK("[ATS!] Usage: ATSJ=off");
+ }else{
+ argc = parse_param(arg, argv);
+ if (strcmp(argv[1], "off" ) == 0)
+ sys_jtag_off();
+ else
+ AT_PRINTK("ATSL=%s is not supported!", argv[1]);
+ }
+}
+
+void fATSx(void *arg)
+{
+// uint32_t ability = 0;
+ char buf[64];
+
+ AT_PRINTK("[ATS?]: _AT_SYSTEM_HELP_");
+ AT_PRINTK("[ATS?]: COMPILE TIME: %s", RTL8195AFW_COMPILE_TIME);
+// wifi_get_drv_ability(&ability);
+ strcpy(buf, "v");
+// if(ability & 0x1)
+// strcat(buf, "m");
+ strcat(buf, ".3.5." RTL8195AFW_COMPILE_DATE);
+ AT_PRINTK("[ATS?]: SW VERSION: %s", buf);
+}
+#elif ATCMD_VER == ATVER_2
+
+#define ATCMD_VERSION "v2" //ATCMD MAJOR VERSION, AT FORMAT CHANGED
+#define ATCMD_SUBVERSION "2" //ATCMD MINOR VERSION, NEW COMMAND ADDED
+#define ATCMD_REVISION "1" //ATCMD FIX BUG REVISION
+#define SDK_VERSION "v3.5" //SDK VERSION
+extern void sys_reset(void);
+void print_system_at(void *arg);
+extern void print_wifi_at(void *arg);
+extern void print_tcpip_at(void *arg);
+
+// uart version 2 echo info
+extern unsigned char gAT_Echo;
+
+
+void fATS0(void *arg){
+ at_printf("\r\n[AT] OK");
+}
+
+void fATSh(void *arg){
+ // print common AT command
+ at_printf("\r\n[ATS?] ");
+ at_printf("\r\nCommon AT Command:");
+ print_system_at(arg);
+#if CONFIG_WLAN
+ at_printf("\r\nWi-Fi AT Command:");
+ print_wifi_at(arg);
+#endif
+
+#if CONFIG_TRANSPORT
+ at_printf("\r\nTCP/IP AT Command:");
+ print_tcpip_at(arg);
+#endif
+
+ at_printf("\r\n[ATS?] OK");
+}
+
+void fATSR(void *arg){
+ at_printf("\r\n[ATSR] OK");
+ sys_reset();
+}
+
+void fATSV(void *arg){
+ char at_buf[32];
+ char fw_buf[32];
+
+ // get at version
+ strcpy(at_buf, ATCMD_VERSION"."ATCMD_SUBVERSION"."ATCMD_REVISION);
+
+ // get fw version
+ strcpy(fw_buf, SDK_VERSION);
+
+ at_printf("\r\n[ATSV] OK:%s,%s(%s)",at_buf,fw_buf,RTL8195AFW_COMPILE_TIME);
+}
+
+#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
+
+void fATSP(void *arg){
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ uint32_t lock_id;
+ uint32_t bitmap;
+
+ if (!arg) {
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP=");
+ at_printf("\r\n[ATSP] ERROR:1");
+ return;
+ } else {
+ if((argc = parse_param(arg, argv)) != 2){
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP=");
+ at_printf("\r\n[ATSP] ERROR:1");
+ return;
+ }
+ }
+
+ switch(argv[1][0]) {
+ case 'a': // acquire
+ {
+ acquire_wakelock(WAKELOCK_OS);
+ //at_printf("\r\n[ATSP] wakelock:0x%08x", get_wakelock_status());
+ break;
+ }
+
+ case 'r': // release
+ {
+ release_wakelock(WAKELOCK_OS);
+ //at_printf("\r\n[ATSP] wakelock:0x%08x", get_wakelock_status());
+ break;
+ }
+
+ case '?': // get status
+ break;
+ default:
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP=");
+ at_printf("\r\n[ATSP] ERROR:2");
+ return;
+ }
+ bitmap = get_wakelock_status();
+ at_printf("\r\n[ATSP] OK:%s", (bitmap&WAKELOCK_OS)?"1":"0");
+}
+#endif
+
+void fATSE(void *arg){
+ int argc = 0;
+ int echo = 0, mask = gDbgFlag, dbg_lv = gDbgLevel;
+ char *argv[MAX_ARGC] = {0};
+ int err_no = 0;
+
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "[ATSE]: _AT_SYSTEM_ECHO_DBG_SETTING");
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "[ATSE] Usage: ATSE=,,");
+ err_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+
+ if(argc < 2 || argc > 4){
+ err_no = 2;
+ goto exit;
+ }
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+ if(argv[1] != NULL){
+ echo = atoi(argv[1]);
+ if(echo>1 || echo <0){
+ err_no = 3;
+ goto exit;
+ }
+ gAT_Echo = echo?1:0;
+ }
+#endif
+
+ if((argc > 2) && (argv[2] != NULL)){
+ mask = strtoul(argv[2], NULL, 0);
+ at_set_debug_mask(mask);
+ }
+
+ if((argc == 4) && (argv[3] != NULL)){
+ dbg_lv = strtoul(argv[3], NULL, 0);
+ at_set_debug_level(dbg_lv);
+ }
+
+exit:
+ if(err_no)
+ at_printf("\r\n[ATSE] ERROR:%d", err_no);
+ else
+ at_printf("\r\n[ATSE] OK");
+ return;
+}
+#if CONFIG_WLAN
+#if CONFIG_WEBSERVER
+#include "wifi_structures.h"
+#include "wifi_constants.h"
+extern rtw_wifi_setting_t wifi_setting;
+void fATSW(void *arg){
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ if (!arg) {
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSW] Usage: ATSW=");
+ at_printf("\r\n[ATSW] ERROR:1");
+ return;
+ } else {
+ if((argc = parse_param(arg, argv)) != 2){
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSW] Usage: ATSW=");
+ at_printf("\r\n[ATSW] ERROR:1");
+ return;
+ }
+ }
+
+ if(argv[1][0]!='c'&&argv[1][0]!='s'){
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSW] Usage: ATSW=");
+ at_printf("\r\n[ATSW] ERROR:2");
+ return;
+ }
+
+ // make sure AP mode
+ LoadWifiConfig();
+ if(wifi_setting.mode != RTW_MODE_AP){
+ at_printf("\r\n[ATSW] ERROR:3");
+ return;
+ }
+
+ switch(argv[1][0]) {
+ case 'c': // create webserver
+ {
+ start_web_server();
+ break;
+ }
+ case 's': // stop webserver
+ {
+ stop_web_server();
+ break;
+ }
+ }
+ at_printf("\r\n[ATSW] OK");
+}
+#endif
+
+extern int EraseApinfo();
+//extern int Erase_Fastconnect_data();
+
+void fATSY(void *arg){
+#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
+// Erase_Fastconnect_data();
+#endif
+
+#if CONFIG_WEBSERVER
+ EraseApinfo();
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+extern int reset_uart_atcmd_setting(void);
+ reset_uart_atcmd_setting();
+#endif
+
+#if CONFIG_OTA_UPDATE
+ // Reset ota image signature
+ cmd_ota_image(0);
+#endif
+
+ at_printf("\r\n[ATSY] OK");
+ // reboot
+ sys_reset();
+}
+
+#if CONFIG_OTA_UPDATE
+extern int wifi_is_connected_to_ap( void );
+void fATSO(void *arg){
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ERROR, "\r\n[ATSO] Usage: ATSO=,");
+ at_printf("\r\n[ATSO] ERROR:1");
+ return;
+ }
+ argv[0] = "update";
+ if((argc = parse_param(arg, argv)) != 3){
+ AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ERROR, "\r\n[ATSO] Usage: ATSO=,");
+ at_printf("\r\n[ATSO] ERROR:1");
+ return;
+ }
+
+ // check wifi connect first
+ if(wifi_is_connected_to_ap()==0){
+ cmd_update(argc, argv);
+ at_printf("\r\n[ATSO] OK");
+
+ }else{
+ at_printf("\r\n[ATSO] ERROR:3");
+ }
+}
+
+void fATSC(void *arg){
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ int cmd = 0;
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ERROR, "\r\n[ATSC] Usage: ATSC=<0/1>");
+ at_printf("\r\n[ATSC] ERROR:1");
+ return;
+ }
+ if((argc = parse_param(arg, argv)) != 2){
+ AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ERROR, "\r\n[ATSC] Usage: ATSC=<0/1>");
+ at_printf("\r\n[ATSC] ERROR:1");
+ return;
+ }
+
+ cmd = atoi(argv[1]);
+
+ if((cmd!=0)&&(cmd!=1)){
+ at_printf("\r\n[ATSC] ERROR:2");
+ return;
+ }
+
+ at_printf("\r\n[ATSC] OK");
+
+ if(cmd == 1){
+ cmd_ota_image(1);
+ }
+ else{
+ cmd_ota_image(0);
+ }
+ // reboot
+ sys_reset();
+}
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+extern const u32 log_uart_support_rate[];
+
+void fATSU(void *arg){
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ u32 baud = 0;
+ u8 databits = 0;
+ u8 stopbits = 0;
+ u8 parity = 0;
+ u8 flowcontrol = 0;
+ u8 configmode = 0;
+ int i;
+ UART_LOG_CONF uartconf;
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR,
+ "[ATSU] Usage: ATSU=,,,,,");
+ at_printf("\r\n[ATSU] ERROR:1");
+ return;
+ }
+ if((argc = parse_param(arg, argv)) != 7){
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR,
+ "[ATSU] Usage: ATSU=,,,,,");
+ at_printf("\r\n[ATSU] ERROR:1");
+ return;
+ }
+
+ baud = atoi(argv[1]);
+ databits = atoi(argv[2]);
+ stopbits = atoi(argv[3]);
+ parity = atoi(argv[4]);
+ flowcontrol = atoi(argv[5]);
+ configmode = atoi(argv[6]);
+/*
+ // Check Baud rate
+ for (i=0; log_uart_support_rate[i]!=0xFFFFFF; i++) {
+ if (log_uart_support_rate[i] == baud) {
+ break;
+ }
+ }
+
+ if (log_uart_support_rate[i]== 0xFFFFFF) {
+ at_printf("\r\n[ATSU] ERROR:2");
+ return;
+ }
+*/
+ if(((databits < 5) || (databits > 8))||\
+ ((stopbits < 1) || (stopbits > 2))||\
+ ((parity < 0) || (parity > 2))||\
+ ((flowcontrol < 0) || (flowcontrol > 1))||\
+ ((configmode < 0) || (configmode > 3))\
+ ){
+ at_printf("\r\n[ATSU] ERROR:2");
+ return;
+ }
+
+ memset((void*)&uartconf, 0, sizeof(UART_LOG_CONF));
+ uartconf.BaudRate = baud;
+ uartconf.DataBits = databits;
+ uartconf.StopBits = stopbits;
+ uartconf.Parity = parity;
+ uartconf.FlowControl = flowcontrol;
+ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS,
+ "AT_UART_CONF: %d,%d,%d,%d,%d", uartconf.BaudRate, uartconf.DataBits,uartconf.StopBits,uartconf.Parity,uartconf.FlowControl);
+ switch(configmode){
+ case 0: // set current configuration, won't save
+ uart_atcmd_reinit(&uartconf);
+ break;
+ case 1: // set current configuration, and save
+ write_uart_atcmd_setting_to_system_data(&uartconf);
+ uart_atcmd_reinit(&uartconf);
+ break;
+ case 2: // set configuration, reboot to take effect
+ write_uart_atcmd_setting_to_system_data(&uartconf);
+ break;
+ }
+
+ at_printf("\r\n[ATSU] OK");
+}
+#endif //#if CONFIG_EXAMPLE_UART_ATCMD
+#endif //#if CONFIG_WLAN
+
+void fATSG(void *arg)
+{
+ gpio_t gpio_ctrl;
+ int argc = 0, val, error_no = 0;
+ char *argv[MAX_ARGC] = {0}, port, num;
+ PinName pin = NC;
+
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: _AT_SYSTEM_GPIO_CTRL_");
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ERROR,
+ "[ATSG] Usage: ATSG=,,,,");
+ error_no = 1;
+ goto exit;
+ }
+ if((argc = parse_param(arg, argv)) < 3){
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ERROR,
+ "[ATSG] Usage: ATSG=,,,,");
+ error_no = 2;
+ goto exit;
+ }
+
+ port = argv[2][1];
+ num = strtoul(&argv[2][3], NULL, 0);
+ port -= 'A';
+ pin = (port << 4 | num);
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "PORT: %s[%d]", argv[2], pin);
+
+ if(gpio_set(pin) == 0xff)
+ {
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ERROR, "[ATSG]: Invalid Pin Name [%d]", pin);
+ error_no = 3;
+ goto exit;
+ }
+
+ gpio_init(&gpio_ctrl, pin);
+ if(argv[4]){
+ int dir = atoi(argv[4]);
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "DIR: %s", argv[4]);
+ gpio_dir(&gpio_ctrl, dir);
+ }
+ if(argv[5]){
+ int pull = atoi(argv[5]);
+ AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "PULL: %s", argv[5]);
+ gpio_mode(&gpio_ctrl, pull);
+ }
+ if(argv[1][0] == 'R'){
+ val = gpio_read(&gpio_ctrl);
+ }
+ else{
+ val = atoi(argv[3]);
+ gpio_write(&gpio_ctrl, val);
+ }
+
+exit:
+ if(error_no){
+ at_printf("\r\n[ATSG] ERROR:%d", error_no);
+ }
+ else{
+ at_printf("\r\n[ATSG] OK:%d", val);
+ }
+}
+
+#endif //#elif ATCMD_VER == ATVER_2
+#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
+/*
+ * bitmask:
+ * bit0: OS
+ * bit1: WLAN
+ * bit2: LOGUART
+ * bit3: SDIO
+ */
+void fATSL(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ int err_no = 0;
+ uint32_t lock_id;
+
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL]: _AT_SYS_WAKELOCK_TEST_");
+
+ if (!arg) {
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
+ err_no = 1;
+ goto exit;
+ } else {
+ argc = parse_param(arg, argv);
+ if (argc < 2) {
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
+ err_no = 2;
+ goto exit;
+ }
+ }
+
+ switch(argv[1][0]) {
+ case 'a': // acquire
+ {
+ if (argc == 3) {
+ lock_id = strtoul(argv[2], NULL, 16);
+ acquire_wakelock(lock_id);
+ }
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
+ break;
+ }
+
+ case 'r': // release
+ {
+ if (argc == 3) {
+ lock_id = strtoul(argv[2], NULL, 16);
+ release_wakelock(lock_id);
+ }
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
+ break;
+ }
+
+ case '?': // get status
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
+#if (configGENERATE_RUN_TIME_STATS == 1)
+ char *cBuffer = pvPortMalloc(512);
+ if(cBuffer != NULL) {
+ get_wakelock_hold_stats((char *)cBuffer);
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "%s", cBuffer);
+ }
+ vPortFree(cBuffer);
+#endif
+ break;
+
+#if (configGENERATE_RUN_TIME_STATS == 1)
+ case 'c': // clean wakelock info (for recalculate wakelock hold time)
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] clean wakelock stat");
+ clean_wakelock_stat();
+ break;
+#endif
+ default:
+ AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
+ err_no = 3;
+ break;
+ }
+exit:
+#if ATCMD_VER == ATVER_2
+ if(err_no)
+ at_printf("\r\n[ATSL] ERROR:%d", err_no);
+ else
+ at_printf("\r\n[ATSL] OK:0x%08x",get_wakelock_status());
+#endif
+ return;
+}
+
+#if CONFIG_UART_XMODEM
+void fATSX(void *arg)
+{
+ // use xmodem to update, RX: PA_6, TX: PA_7, baudrate: 1M
+ OTU_FW_Update(0, 2, 115200);
+ at_printf("\r\n[ATSX] OK");
+}
+#endif
+
+#endif
+
+
+void fATST(void *arg){
+ extern void dump_mem_block_list(void); // heap_5.c
+ extern u8 __HeapLimit, __StackTop;
+ extern struct Heap g_tcm_heap;
+ //DBG_INFO_MSG_ON(_DBG_TCM_HEAP_); // On Debug TCM MEM
+#if DEBUG_AT_USER_LEVEL > 1
+ printf("ATST: Mem info:\n");
+#endif
+// vPortFree(pvPortMalloc(4)); // Init RAM heap
+ printf("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nRAM free\t%d bytes\nTCM heap\t%d bytes\n",
+ HalGetCpuClk(), xPortGetFreeHeapSize(), (int)&__StackTop - (int)&__HeapLimit, tcm_heap_freeSpace());
+ printf("TCM ps_monitor\t%d bytes\n", 0x20000000 - (u32)&tcm_heap - tcm_heap_size);
+ dump_mem_block_list();
+ u32 saved = ConfigDebugInfo;
+ DBG_INFO_MSG_ON(_DBG_TCM_HEAP_); // On Debug TCM MEM
+ tcm_heap_dump();
+ ConfigDebugInfo = saved;
+ printf("\n");
+#if (configGENERATE_RUN_TIME_STATS == 1)
+ char *cBuffer = pvPortMalloc(512);
+ if(cBuffer != NULL) {
+ vTaskGetRunTimeStats((char *)cBuffer);
+ printf("%s", cBuffer);
+ }
+ vPortFree(cBuffer);
+#endif
+}
+
+log_item_t at_sys_items[] = {
+#if (ATCMD_VER == ATVER_1)
+ {"ATSD", fATSD,}, // Dump register
+ {"ATSE", fATSE,}, // Edit register
+ {"ATSC", fATSC,}, // Clear OTA signature
+ {"ATSR", fATSR,}, // Recover OTA signature
+#if CONFIG_UART_XMODEM
+ {"ATSY", fATSY,}, // uart ymodem upgrade
+#endif
+#if SUPPORT_MP_MODE
+ {"ATSA", fATSA,}, // MP ADC test
+ {"ATSG", fATSG,}, // MP GPIO test
+ {"ATSP", fATSP,}, // MP Power related test
+ {"ATSB", fATSB,}, // OTU PIN setup
+#endif
+#if (configGENERATE_RUN_TIME_STATS == 1)
+ {"ATSS", fATSS,}, // Show CPU stats
+#endif
+#if SUPPORT_CP_TEST
+ {"ATSM", fATSM,}, // Apple CP test
+#endif
+ {"ATSJ", fATSJ,}, //trun off JTAG
+ {"ATS@", fATSs,}, // Debug message setting
+ {"ATS!", fATSc,}, // Debug config setting
+ {"ATS#", fATSt,}, // test command
+ {"ATS?", fATSx,}, // Help
+#elif ATCMD_VER == ATVER_2 //#if ATCMD_VER == ATVER_1
+ {"AT", fATS0,}, // test AT command ready
+ {"ATS?", fATSh,}, // list all AT command
+ {"ATSR", fATSR,}, // system restart
+ {"ATSV", fATSV,}, // show version info
+ {"ATSP", fATSP,}, // power saving mode
+ {"ATSE", fATSE,}, // enable and disable echo
+#if CONFIG_WLAN
+#if CONFIG_WEBSERVER
+ {"ATSW", fATSW,}, // start webserver
+#endif
+ {"ATSY", fATSY,}, // factory reset
+#if CONFIG_OTA_UPDATE
+ {"ATSO", fATSO,}, // ota upgrate
+ {"ATSC", fATSC,}, // chose the activited image
+#endif
+#if CONFIG_EXAMPLE_UART_ATCMD
+ {"ATSU", fATSU,}, // AT uart configuration
+#endif
+#endif
+ {"ATSG", fATSG,}, // GPIO control
+#if CONFIG_UART_XMODEM
+ {"ATSX", fATSX,}, // uart xmodem upgrade
+#endif
+ {"ATSD", fATSD,}, // Dump register
+#endif // end of #if ATCMD_VER == ATVER_1
+
+// Following commands exist in two versions
+#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
+ {"ATSL", fATSL,}, // wakelock test
+#endif
+ {"ATST", fATST}, // add pvvx: mem info
+ {"ATXX", fATXX}, // test
+};
+
+#if ATCMD_VER == ATVER_2
+void print_system_at(void *arg){
+ int index;
+ int cmd_len = 0;
+
+ cmd_len = sizeof(at_sys_items)/sizeof(at_sys_items[0]);
+ for(index = 0; index < cmd_len; index++)
+ at_printf("\r\n%s", at_sys_items[index].log_cmd);
+}
+#endif
+void at_sys_init(void)
+{
+ log_service_add_table(at_sys_items, sizeof(at_sys_items)/sizeof(at_sys_items[0]));
+}
+
+#if SUPPORT_LOG_SERVICE
+log_module_init(at_sys_init);
+#endif
+
+#endif //#ifdef CONFIG_AT_SYS
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_sys.h b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_sys.h
new file mode 100644
index 0000000..9eaee49
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_sys.h
@@ -0,0 +1,6 @@
+#ifndef __ATCMD_SYS_H__
+#define __ATCMD_SYS_H__
+#ifdef CONFIG_AT_SYS
+#endif //
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_wifi.c b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_wifi.c
new file mode 100644
index 0000000..3fb680c
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_wifi.c
@@ -0,0 +1,2727 @@
+#include
+#ifdef CONFIG_AT_WIFI
+
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#include "log_service.h"
+#include "atcmd_wifi.h"
+#include
+#include "tcpip.h"
+#include
+#include "osdep_service.h"
+
+#if CONFIG_WLAN
+#include
+#include
+#include
+
+rtw_mode_t wifi_mode = RTW_MODE_STA;
+
+#endif
+
+#ifndef ATCMD_VER
+#define ATVER_1 1
+#define ATVER_2 2
+#define ATCMD_VER ATVER_2
+#if CONFIG_EXAMPLE_UART_ATCMD
+#define ATCMD_VER ATVER_2
+#else
+#define ATCMD_VER ATVER_1
+#endif
+#endif
+
+
+#if ATCMD_VER == ATVER_2
+#include "flash_api.h"
+#ifdef USE_FLASH_EEP
+#include "flash_eep.h"
+#endif
+#include "device_lock.h"
+#include
+#include
+#endif
+
+/******************************************************************************/
+#define _AT_WLAN_SET_SSID_ "ATW0"
+#define _AT_WLAN_SET_PASSPHRASE_ "ATW1"
+#define _AT_WLAN_SET_KEY_ID_ "ATW2"
+#define _AT_WLAN_AP_SET_SSID_ "ATW3"
+#define _AT_WLAN_AP_SET_SEC_KEY_ "ATW4"
+#define _AT_WLAN_AP_SET_CHANNEL_ "ATW5"
+#define _AT_WLAN_SET_BSSID_ "ATW6"
+#define _AT_WLAN_AP_ACTIVATE_ "ATWA"
+#define _AT_WLAN_AP_STA_ACTIVATE_ "ATWB"
+#define _AT_WLAN_JOIN_NET_ "ATWC"
+#define _AT_WLAN_DISC_NET_ "ATWD"
+#define _AT_WLAN_WEB_SERVER_ "ATWE"
+#define _AT_WLAN_P2P_FIND_ "ATWF"
+#define _AT_WLAN_P2P_START_ "ATWG"
+#define _AT_WLAN_P2P_STOP_ "ATWH"
+#define _AT_WLAN_PING_TEST_ "ATWI"
+#define _AT_WLAN_P2P_CONNECT_ "ATWJ"
+#define _AT_WLAN_P2P_DISCONNECT_ "ATWK"
+#define _AT_WLAN_SSL_CLIENT_ "ATWL"
+#define _AT_WLAN_PROMISC_ "ATWM"
+#define _AT_WLAN_P2P_INFO_ "ATWN"
+#define _AT_WLAN_OTA_UPDATE_ "ATWO"
+#define _AT_WLAN_POWER_ "ATWP"
+#define _AT_WLAN_SIMPLE_CONFIG_ "ATWQ"
+#define _AT_WLAN_GET_RSSI_ "ATWR"
+#define _AT_WLAN_SCAN_ "ATWS"
+#define _AT_WLAN_SCAN_WITH_SSID_ "ATWs"
+#define _AT_WLAN_TCP_TEST_ "ATWT"
+#define _AT_WLAN_UDP_TEST_ "ATWU"
+#define _AT_WLAN_WPS_ "ATWW"
+#define _AT_WLAN_AP_WPS_ "ATWw"
+#define _AT_WLAN_AIRKISS_ "ATWX"
+#define _AT_WLAN_IWPRIV_ "ATWZ"
+#define _AT_WLAN_INFO_ "ATW?"
+
+#define _AT_WLAN_EXTEND_POWER_MODE_ "ATXP"
+
+#ifndef CONFIG_SSL_CLIENT
+#define CONFIG_SSL_CLIENT 0
+#endif
+#ifndef CONFIG_WEBSERVER
+#define CONFIG_WEBSERVER 0
+#endif
+#ifndef CONFIG_OTA_UPDATE
+#define CONFIG_OTA_UPDATE 0
+#endif
+#ifndef CONFIG_BSD_TCP
+#define CONFIG_BSD_TCP 1
+#endif
+#ifndef CONFIG_ENABLE_P2P
+#define CONFIG_ENABLE_P2P 0
+#endif
+#define SCAN_WITH_SSID 0
+#if CONFIG_WEBSERVER
+#define CONFIG_READ_FLASH 1
+extern rtw_wifi_setting_t wifi_setting;
+#endif
+
+#ifndef CONFIG_WOWLAN_SERVICE
+#define CONFIG_WOWLAN_SERVICE 0
+#endif
+
+#if CONFIG_LWIP_LAYER
+extern void cmd_tcp(int argc, char **argv);
+extern void cmd_udp(int argc, char **argv);
+extern void cmd_ping(int argc, char **argv);
+extern void cmd_ssl_client(int argc, char **argv);
+#endif
+
+#if CONFIG_WLAN
+extern void cmd_promisc(int argc, char **argv);
+extern void cmd_update(int argc, char **argv);
+extern void cmd_simple_config(int argc, char **argv);
+#if CONFIG_ENABLE_WPS
+extern void cmd_wps(int argc, char **argv);
+#endif
+
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+extern void cmd_ap_wps(int argc, char **argv);
+extern int wpas_wps_dev_config(u8 *dev_addr, u8 bregistrar);
+#endif
+#if CONFIG_ENABLE_P2P
+extern void cmd_wifi_p2p_start(int argc, char **argv);
+extern void cmd_wifi_p2p_stop(int argc, char **argv);
+extern void cmd_p2p_listen(int argc, char **argv);
+extern void cmd_p2p_find(int argc, char **argv);
+extern void cmd_p2p_peers(int argc, char **argv);
+extern void cmd_p2p_info(int argc, char **argv);
+extern void cmd_p2p_disconnect(int argc, char **argv);
+extern void cmd_p2p_connect(int argc, char **argv);
+extern int cmd_wifi_p2p_auto_go_start(int argc, char **argv);
+#endif //CONFIG_ENABLE_P2P
+#if CONFIG_AIRKISS
+extern int airkiss_start();
+#endif
+#if CONFIG_LWIP_LAYER
+extern struct netif xnetif[NET_IF_NUM];
+#endif
+#if CONFIG_WOWLAN_SERVICE
+extern void cmd_wowlan_service(int argc, char **argv);
+#endif
+#if CONFIG_INIC_CMD_RSP
+extern void inic_c2h_wifi_info(const char *atcmd, char status);
+extern void inic_c2h_msg(const char *atcmd, u8 status, char *msg, u16 msg_len);
+#endif
+
+/* fastconnect use wifi AT command. Not init_wifi_struct when log service disabled
+ * static initialize all values for using fastconnect when log service disabled
+ */
+static rtw_network_info_t wifi = {
+ {0}, // ssid
+ {0}, // bssid
+ 0, // security
+ NULL, // password
+ 0, // password len
+ -1 // key id
+};
+
+static rtw_ap_info_t ap = {0};
+static unsigned char password[65] = {0};
+
+#if ATCMD_VER == ATVER_2
+unsigned char dhcp_mode_sta = 1, dhcp_mode_ap = 1;
+unsigned char sta_ip[4] = {192,168,3,80}, sta_netmask[4] = {255,255,255,0}, sta_gw[4] = {192,168,3,1};
+unsigned char ap_ip[4] = {192,168,43,1}, ap_netmask[4] = {255,255,255,0}, ap_gw[4] = {192,168,43,1};
+#endif
+
+
+static void init_wifi_struct(void)
+{
+ memset(wifi.ssid.val, 0, sizeof(wifi.ssid.val));
+ memset(wifi.bssid.octet, 0, ETH_ALEN);
+ memset(password, 0, sizeof(password));
+ wifi.ssid.len = 0;
+ wifi.password = NULL;
+ wifi.password_len = 0;
+ wifi.key_id = -1;
+ memset(ap.ssid.val, 0, sizeof(ap.ssid.val));
+ ap.ssid.len = 0;
+ ap.password = NULL;
+ ap.password_len = 0;
+ ap.channel = 1;
+}
+
+static void print_scan_result( rtw_scan_result_t* record )
+{
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("%s,%d,%s,%d,"MAC_FMT"", record->SSID.val, record->channel,
+ ( record->security == RTW_SECURITY_OPEN ) ? "Open" :
+ ( record->security == RTW_SECURITY_WEP_PSK ) ? "WEP" :
+ ( record->security == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
+ ( record->security == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
+ ( record->security == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
+ ( record->security == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
+ ( record->security == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
+ ( record->security == RTW_SECURITY_WPA_WPA2_MIXED ) ? "WPA/WPA2 AES" : "Unknown",
+ record->signal_strength, MAC_ARG(record->BSSID.octet) );
+#else
+ RTW_API_INFO( ( "%s\t ", ( record->bss_type == RTW_BSS_TYPE_ADHOC ) ? "Adhoc" : "Infra" ) );
+ RTW_API_INFO( ( MAC_FMT, MAC_ARG(record->BSSID.octet) ) );
+ RTW_API_INFO( ( " %d\t ", record->signal_strength ) );
+ RTW_API_INFO( ( " %d\t ", record->channel ) );
+ RTW_API_INFO( ( " %d\t ", record->wps_type ) );
+ RTW_API_INFO( ( "%s\t\t ", ( record->security == RTW_SECURITY_OPEN ) ? "Open" :
+ ( record->security == RTW_SECURITY_WEP_PSK ) ? "WEP" :
+ ( record->security == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
+ ( record->security == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
+ ( record->security == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
+ ( record->security == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
+ ( record->security == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
+ ( record->security == RTW_SECURITY_WPA_WPA2_MIXED ) ? "WPA/WPA2 AES" :
+ "Unknown" ) );
+
+ RTW_API_INFO( ( " %s ", record->SSID.val ) );
+ RTW_API_INFO( ( "\r\n" ) );
+#endif
+}
+
+static rtw_result_t app_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
+{
+ static int ApNum = 0;
+
+ if (malloced_scan_result->scan_complete != RTW_TRUE) {
+ rtw_scan_result_t* record = &malloced_scan_result->ap_details;
+ record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("\r\nAP : %d,", ++ApNum);
+#else
+ RTW_API_INFO( ( "%d\t ", ++ApNum ) );
+#endif
+ print_scan_result(record);
+#if CONFIG_INIC_CMD_RSP
+ if(malloced_scan_result->user_data)
+ memcpy((void *)((char *)malloced_scan_result->user_data+(ApNum-1)*sizeof(rtw_scan_result_t)), (char *)record, sizeof(rtw_scan_result_t));
+#endif
+ } else{
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATWS", RTW_SUCCESS, (char *)malloced_scan_result->user_data, ApNum*sizeof(rtw_scan_result_t));
+ if(malloced_scan_result->user_data)
+ free(malloced_scan_result->user_data);
+ inic_c2h_msg("ATWS", RTW_SUCCESS, NULL, 0);
+#endif
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("\r\n[ATWS] OK");
+ at_printf(STR_END_OF_ATCMD_RET);
+#endif
+ ApNum = 0;
+ }
+ return RTW_SUCCESS;
+}
+
+// WIFI disconnect
+void fATWD(void *arg){
+ int timeout = 10000/200;
+ char essid[33];
+ int ret = RTW_SUCCESS;
+#if ATCMD_VER == ATVER_2
+ int error_no = 0;
+#endif
+
+ printf("[ATWD]: _AT_WLAN_DISC_NET_\n");
+ printf("Deassociating AP ...\n");
+
+ if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
+ printf("WIFI disconnected\n");
+ goto exit_success;
+ }
+
+ if((ret = wifi_disconnect()) < 0) {
+ printf("ERROR: Operation failed!\n");
+#if ATCMD_VER == ATVER_2
+ error_no = 3;
+#endif
+ goto exit;
+ }
+
+ while(1) {
+ if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
+ printf("WIFI disconnected\n");
+ break;
+ }
+
+ if(timeout == 0) {
+ printf("ERROR: Deassoc timeout!\n");
+ ret = RTW_TIMEOUT;
+#if ATCMD_VER == ATVER_2
+ error_no = 4;
+#endif
+ break;
+ }
+// vTaskDelay(1 * configTICK_RATE_HZ);
+ vTaskDelay(200/portTICK_RATE_MS);
+ timeout --;
+ }
+ printf("\n");
+exit:
+#if CONFIG_INIC_CMD_RSP
+ if(ret != RTW_SUCCESS)
+ inic_c2h_msg("ATWD", ret, NULL, 0);
+#endif
+ init_wifi_struct( );
+#if ATCMD_VER == ATVER_2
+ if(error_no==0)
+ at_printf("\r\n[ATWD] OK");
+ else
+ at_printf("\r\n[ATWD] ERROR:%d",error_no);
+#endif
+ return;
+exit_success:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATWD", RTW_SUCCESS, NULL, 0);
+#endif
+ init_wifi_struct( );
+#if ATCMD_VER == ATVER_2
+ at_printf("\r\n[ATWD] OK");
+#endif
+ return;
+}
+
+// wifi simpleconfig
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+void fATWQ(void *arg){
+ int argc=0;
+ char *argv[2] = {0};
+ printf("[ATWQ]: _AT_WLAN_SIMPLE_CONFIG_\n");
+ argv[argc++] = "wifi_simple_config";
+ if(arg){
+ argv[argc++] = arg;
+ }
+ cmd_simple_config(argc, argv);
+}
+#endif
+
+// WIFI scan
+void fATWS(void *arg){
+ char buf[32] = {0};
+ u8 *channel_list = NULL;
+ u8 *pscan_config = NULL;
+ int num_channel = 0;
+ int i, argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ int ret = RTW_SUCCESS;
+#if CONFIG_INIC_CMD_RSP
+ u8 *inic_scan_buf = NULL;
+#endif
+#if ATCMD_VER == ATVER_2
+ int error_no = 0;
+#endif
+ printf("[ATWS]: _AT_WLAN_SCAN_\n");
+ if(arg){
+ strcpy(buf, arg);
+ argc = parse_param(buf, argv);
+ if(argc < 2){
+ ret = RTW_BADARG;
+#if ATCMD_VER == ATVER_2
+ error_no = 1;
+#endif
+ goto exit;
+ }
+ num_channel = atoi(argv[1]);
+ channel_list = (u8*)malloc(num_channel);
+ if(!channel_list){
+ printf("[ATWS]ERROR: Can't malloc memory for channel list\n");
+ ret = RTW_BUFFER_UNAVAILABLE_TEMPORARY;
+#if ATCMD_VER == ATVER_2
+ error_no = 2;
+#endif
+ goto exit;
+ }
+ pscan_config = (u8*)malloc(num_channel);
+ if(!pscan_config){
+ printf("[ATWS]ERROR: Can't malloc memory for pscan_config\n");
+ ret = RTW_BUFFER_UNAVAILABLE_TEMPORARY;
+#if ATCMD_VER == ATVER_2
+ error_no = 3;
+#endif
+ goto exit;
+ }
+ //parse command channel list
+ for(i = 2; i <= argc -1 ; i++){
+ *(channel_list + i - 2) = (u8)atoi(argv[i]);
+ *(pscan_config + i - 2) = PSCAN_ENABLE;
+ }
+
+ if((ret = wifi_set_pscan_chan(channel_list, pscan_config, num_channel)) < 0){
+ printf("[ATWS]ERROR: wifi set partial scan channel fail\n");
+#if ATCMD_VER == ATVER_2
+ error_no = 4;
+#endif
+ goto exit;
+ }
+ }
+#if CONFIG_INIC_CMD_RSP
+ inic_scan_buf = malloc(65*sizeof(rtw_scan_result_t));
+ if(inic_scan_buf == NULL){
+ ret = RTW_BUFFER_UNAVAILABLE_TEMPORARY;
+ goto exit;
+ }
+ memset(inic_scan_buf, 0, 65*sizeof(rtw_scan_result_t));
+ if((ret = wifi_scan_networks(app_scan_result_handler, inic_scan_buf)) != RTW_SUCCESS){
+ printf("[ATWS]ERROR: wifi scan failed\n");
+ goto exit;
+ }
+#else
+ if((ret = wifi_scan_networks(app_scan_result_handler, NULL )) != RTW_SUCCESS){
+ printf("[ATWS]ERROR: wifi scan failed\n");
+#if ATCMD_VER == ATVER_2
+ error_no = 5;
+#endif
+ goto exit;
+ }
+#endif
+exit:
+#if CONFIG_INIC_CMD_RSP
+ if(ret != RTW_SUCCESS){
+ if(inic_scan_buf)
+ free(inic_scan_buf);
+ inic_c2h_msg("ATWS", ret, NULL, 0);
+ }
+#endif
+#if ATCMD_VER == ATVER_2
+ if(error_no)
+ at_printf("[ATWS] ERROR:%d\n",error_no);
+#endif
+ if(arg && channel_list)
+ free(channel_list);
+ if(arg && pscan_config)
+ free(pscan_config);
+}
+
+void fATWx(void *arg){
+ int i = 0;
+#if CONFIG_LWIP_LAYER
+ u8 *mac = LwIP_GetMAC(&xnetif[0]);
+ u8 *ip = LwIP_GetIP(&xnetif[0]);
+ u8 *gw = LwIP_GetGW(&xnetif[0]);
+#endif
+ u8 *ifname[2] = {WLAN0_NAME,WLAN1_NAME};
+ rtw_wifi_setting_t setting;
+
+ printf("[ATW?]: _AT_WLAN_INFO_\n");
+#if CONFIG_INIC_CMD_RSP
+ int ret = RTW_SUCCESS;
+ int info_sz = 0;
+ u8 *info = malloc(NET_IF_NUM*sizeof(rtw_wifi_setting_t)+3*sizeof(rtw_mac_t));
+ if(info == NULL)
+ ret = RTW_BUFFER_UNAVAILABLE_TEMPORARY;
+#endif
+ for(i=0;i %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ;
+ printf("\tIP => %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ printf("\tGW => %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]);
+#endif
+ if(setting.mode == RTW_MODE_AP || i == 1)
+ {
+ int client_number;
+ struct {
+ int count;
+ rtw_mac_t mac_list[AP_STA_NUM];
+ } client_info;
+
+ client_info.count = AP_STA_NUM;
+ wifi_get_associated_client_list(&client_info, sizeof(client_info));
+
+ printf("Associated Client List:\n==============================\n");
+
+ if(client_info.count == 0)
+ printf("Client Num: 0\n", client_info.count);
+ else
+ {
+ printf("Client Num: %d\n", client_info.count);
+ for( client_number=0; client_number < client_info.count; client_number++ )
+ {
+ printf("Client %d:\n", client_number + 1);
+ printf("\tMAC => "MAC_FMT"\n",
+ MAC_ARG(client_info.mac_list[client_number].octet));
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("CLIENT : %d,"MAC_FMT"\n", client_number + 1, MAC_ARG(client_info.mac_list[client_number].octet));
+#endif
+#if CONFIG_INIC_CMD_RSP
+ if(info){
+ memcpy(info+info_sz, (void *)&client_info.mac_list[client_number], sizeof(rtw_mac_t));
+ info_sz += sizeof(rtw_mac_t);
+ }
+#endif
+ }
+ printf("\n\r");
+ }
+ }
+ }
+// show the ethernet interface info
+ else
+ {
+#if CONFIG_ETHERNET
+ if(i == NET_IF_NUM - 1)
+ {
+#if CONFIG_LWIP_LAYER
+ mac = LwIP_GetMAC(&xnetif[i]);
+ ip = LwIP_GetIP(&xnetif[i]);
+ gw = LwIP_GetGW(&xnetif[i]);
+ printf("Interface ethernet\n==============================\n");
+ printf("\tMAC => %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ;
+ printf("\tIP => %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ printf("\tGW => %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]);
+#endif // end CONFIG_LWIP_LAYER
+ }
+#endif // end CONFIG_ETHERNET
+ }
+ }
+
+#if defined(configUSE_TRACE_FACILITY) && (configUSE_TRACE_FACILITY == 1) && (configUSE_STATS_FORMATTING_FUNCTIONS == 1)
+ {
+ signed char pcWriteBuffer[1024];
+ vTaskList((char*)pcWriteBuffer);
+ printf("Task List:\n%s\n", pcWriteBuffer);
+ }
+#endif
+
+#if CONFIG_INIC_CMD_RSP
+ if(ret != RTW_SUCCESS)
+ inic_c2h_msg("ATW?", ret, NULL, 0);
+ else
+ inic_c2h_msg("ATW?", RTW_SUCCESS, (char *)info, info_sz);
+
+ if(info)
+ free(info);
+ info = NULL;
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("\r\n[ATW?] OK");
+#endif
+
+}
+
+#if ATCMD_VER == ATVER_1
+void fATW0(void *arg){
+ int ret = RTW_SUCCESS;
+ if(!arg){
+ printf("[ATW0]Usage: ATW0=SSID\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ printf("[ATW0]: _AT_WLAN_SET_SSID_ [%s]\n", (char*)arg);
+ strcpy((char *)wifi.ssid.val, (char*)arg);
+ wifi.ssid.len = strlen((char*)arg);
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW0", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATW1(void *arg){
+ int ret = RTW_SUCCESS;
+ printf("[ATW1]: _AT_WLAN_SET_PASSPHRASE_ [%s]\n", (char*)arg);
+ strcpy((char *)password, (char*)arg);
+ wifi.password = password;
+ wifi.password_len = strlen((char*)arg);
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW1", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATW2(void *arg){
+ int ret = RTW_SUCCESS;
+ printf("[ATW2]: _AT_WLAN_SET_KEY_ID_ [%s]\n", (char*)arg);
+ if((strlen((const char *)arg) != 1 ) || (*(char*)arg <'0' ||*(char*)arg >'3')) {
+ printf("Wrong WEP key id. Must be one of 0,1,2, or 3.\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ wifi.key_id = atoi((const char *)(arg));
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW2", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATW3(void *arg){
+ int ret = RTW_SUCCESS;
+ if(!arg){
+ printf("[ATW3]Usage: ATW3=SSID\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+
+ ap.ssid.len = strlen((char*)arg);
+
+ if(ap.ssid.len > 32){
+ printf("[ATW3]Error: SSID length can't exceed 32\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ strcpy((char *)ap.ssid.val, (char*)arg);
+
+ printf("[ATW3]: _AT_WLAN_AP_SET_SSID_ [%s]\n", ap.ssid.val);
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW3", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATW4(void *arg){
+ int ret = RTW_SUCCESS;
+ strcpy((char *)password, (char*)arg);
+ ap.password = password;
+ ap.password_len = strlen((char*)arg);
+ printf("[ATW4]: _AT_WLAN_AP_SET_SEC_KEY_ [%s]\n", ap.password);
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW4", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATW5(void *arg){
+ int ret = RTW_SUCCESS;
+ ap.channel = (unsigned char) atoi((const char *)arg);
+ printf("[ATW5]: _AT_WLAN_AP_SET_CHANNEL_ [channel %d]\n", ap.channel);
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW5", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATW6(void *arg){
+ u32 mac[ETH_ALEN];
+ u32 i;
+ int ret = RTW_SUCCESS;
+ if(!arg){
+ printf("[ATW6]Usage: ATW6=BSSID\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ printf("[ATW6]: _AT_WLAN_SET_BSSID_ [%s]\n", (char*)arg);
+ sscanf(arg, MAC_FMT, mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5);
+ for(i = 0; i < ETH_ALEN; i ++)
+ wifi.bssid.octet[i] = (u8)mac[i] & 0xFF;
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATW6", ret, NULL, 0);
+#endif
+ return;
+}
+
+void fATWA(void *arg){
+#if CONFIG_LWIP_LAYER
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+ struct netif * pnetif = &xnetif[0];
+#endif
+ int timeout = 10000/200;
+ int ret = RTW_SUCCESS;
+ printf("[ATWA]: _AT_WLAN_AP_ACTIVATE_\n");
+ if(ap.ssid.val[0] == 0){
+ printf("[ATWA]Error: SSID can't be empty\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ if(ap.password == NULL){
+ ap.security_type = RTW_SECURITY_OPEN;
+ }
+ else{
+ ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ }
+
+#if CONFIG_WEBSERVER
+ //store into flash
+ memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));;
+ memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val));
+ wifi_setting.ssid[ap.ssid.len] = '\0';
+ wifi_setting.security_type = ap.security_type;
+ if(ap.security_type !=0)
+ wifi_setting.security_type = 1;
+ else
+ wifi_setting.security_type = 0;
+ if (ap.password)
+ memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password));
+ else
+ memset(wifi_setting.password, 0, sizeof(wifi_setting.password));
+ wifi_setting.channel = ap.channel;
+#if CONFIG_READ_FLASH
+ StoreApInfo();
+#endif
+#endif
+
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+ IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
+#ifdef CONFIG_DONT_CARE_TP
+ pnetif->flags |= NETIF_FLAG_IPSWITCH;
+#endif
+#endif
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_AP) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ ret = RTW_ERROR;
+ goto exit;
+ }
+ printf("Starting AP ...\n");
+
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ wpas_wps_dev_config(pnetif->hwaddr, 1);
+#endif
+ if((ret = wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) )< 0) {
+ printf("ERROR: Operation failed!\n");
+ goto exit;
+ }
+
+ while(1) {
+ char essid[33];
+
+ if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) {
+ if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
+ printf("%s started\n", ap.ssid.val);
+ ret = RTW_SUCCESS;
+ break;
+ }
+ }
+
+ if(timeout == 0) {
+ printf("ERROR: Start AP timeout!\n");
+ ret = RTW_TIMEOUT;
+ break;
+ }
+ //vTaskDelay(1 * configTICK_RATE_HZ);
+ vTaskDelay(200/portTICK_RATE_MS);
+ timeout --;
+ }
+#if CONFIG_LWIP_LAYER
+ //LwIP_UseStaticIP(pnetif);
+ dhcps_init(pnetif);
+#endif
+
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_wifi_info("ATWA", ret);
+#endif
+ init_wifi_struct( );
+}
+
+#if CONFIG_INIC_EN
+static int _find_ap_from_scan_buf(char*buf, int buflen, char *target_ssid, void *user_data)
+{
+ rtw_wifi_setting_t *pwifi = (rtw_wifi_setting_t *)user_data;
+ int plen = 0;
+
+ while(plen < buflen){
+ u8 len, ssid_len, security_mode;
+ char *ssid;
+
+ // len offset = 0
+ len = (int)*(buf + plen);
+ // check end
+ if(len == 0) break;
+ // ssid offset = 14
+ ssid_len = len - 14;
+ ssid = buf + plen + 14 ;
+ if((ssid_len == strlen(target_ssid))
+ && (!memcmp(ssid, target_ssid, ssid_len)))
+ {
+ strcpy((char*)pwifi->ssid, target_ssid);
+ // channel offset = 13
+ pwifi->channel = *(buf + plen + 13);
+ // security_mode offset = 11
+ security_mode = (u8)*(buf + plen + 11);
+ if(security_mode == IW_ENCODE_ALG_NONE)
+ pwifi->security_type = RTW_SECURITY_OPEN;
+ else if(security_mode == IW_ENCODE_ALG_WEP)
+ pwifi->security_type = RTW_SECURITY_WEP_PSK;
+ else if(security_mode == IW_ENCODE_ALG_CCMP)
+ pwifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ }
+ plen += len;
+ }
+ return 0;
+}
+
+static int _get_ap_security_mode(IN char * ssid, OUT rtw_security_t *security_mode, OUT u8 * channel)
+{
+ rtw_wifi_setting_t wifi;
+ u32 scan_buflen = 1000;
+
+ memset(&wifi, 0, sizeof(wifi));
+
+ if(wifi_scan_networks_with_ssid(_find_ap_from_scan_buf, (void*)&wifi, scan_buflen, ssid, strlen(ssid)) != RTW_SUCCESS){
+ printf("Wifi scan failed!\n");
+ return 0;
+ }
+
+ if(strcmp(wifi.ssid, ssid) == 0){
+ *security_mode = wifi.security_type;
+ *channel = wifi.channel;
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
+void fATWC(void *arg){
+ int mode, ret;
+ unsigned long tick1 = xTaskGetTickCount();
+ unsigned long tick2, tick3;
+ char empty_bssid[6] = {0}, assoc_by_bssid = 0;
+
+ printf("[ATWC]: _AT_WLAN_JOIN_NET_\n");
+ if(memcmp (wifi.bssid.octet, empty_bssid, 6))
+ assoc_by_bssid = 1;
+ else if(wifi.ssid.val[0] == 0){
+ printf("[ATWC]Error: SSID can't be empty\n");
+ ret = RTW_BADARG;
+ goto EXIT;
+ }
+ if(wifi.password != NULL){
+ if((wifi.key_id >= 0)&&(wifi.key_id <= 3)) {
+ wifi.security_type = RTW_SECURITY_WEP_PSK;
+ }
+ else{
+ wifi.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ }
+ }
+ else{
+ wifi.security_type = RTW_SECURITY_OPEN;
+ }
+ //Check if in AP mode
+ wext_get_mode(WLAN0_NAME, &mode);
+ if(mode == IW_MODE_MASTER) {
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_STA) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ ret = RTW_ERROR;
+ goto EXIT;
+ }
+ }
+
+#if CONFIG_INIC_EN //get security mode from scan list
+ u8 connect_channel;
+ u8 pscan_config;
+ //the keyID may be not set for WEP which may be confued with WPA2
+ if((wifi.security_type == RTW_SECURITY_UNKNOWN)||(wifi.security_type == RTW_SECURITY_WPA2_AES_PSK))
+ {
+ int security_retry_count = 0;
+ while (1) {
+ if (_get_ap_security_mode((char*)wifi.ssid.val, &wifi.security_type, &connect_channel))
+ break;
+ security_retry_count++;
+ if(security_retry_count >= 3){
+ printf("Can't get AP security mode and channel.\n");
+ ret = RTW_NOTFOUND;
+ goto EXIT;
+ }
+ }
+ if(wifi.security_type == RTW_SECURITY_WEP_PSK || wifi.security_type == RTW_SECURITY_WEP_SHARED)
+ wifi.key_id = (wifi.key_id <0 || wifi.key_id >3)?0:wifi.key_id;
+#if 0 //implemented in wifi_connect()
+ //hex to ascii conversion
+ if(wifi.security_type == RTW_SECURITY_WEP_PSK)
+ {
+ if(wifi.password_len == 10)
+ {
+ u32 p[5];
+ u8 pwd[6], i = 0;
+ sscanf((const char*)wifi.password, "%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4]);
+ for(i=0; i< 5; i++)
+ pwd[i] = (u8)p[i];
+ pwd[5] = '\0';
+ memset(wifi.password, 0, 65);
+ strcpy((char*)wifi.password, (char*)pwd);
+ wifi.password_len = 5;
+ }else if(wifi.password_len == 26){
+ u32 p[13];
+ u8 pwd[14], i = 0;
+ sscanf((const char*)wifi.password, "%02x%02x%02x%02x%02x%02x%02x"\
+ "%02x%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4],\
+ &p[5], &p[6], &p[7], &p[8], &p[9], &p[10], &p[11], &p[12]);
+ for(i=0; i< 13; i++)
+ pwd[i] = (u8)p[i];
+ pwd[13] = '\0';
+ memset(wifi.password, 0, 65);
+ strcpy((char*)wifi.password, (char*)pwd);
+ wifi.password_len = 13;
+ }
+ }
+#endif
+ }
+ pscan_config = PSCAN_ENABLE;
+ if(connect_channel > 0 && connect_channel < 14)
+ wifi_set_pscan_chan(&connect_channel, &pscan_config, 1);
+#endif
+
+ if(assoc_by_bssid){
+ printf("Joining BSS by BSSID "MAC_FMT" ...\n", MAC_ARG(wifi.bssid.octet));
+ ret = wifi_connect_bssid(wifi.bssid.octet, (char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password,
+ ETH_ALEN, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
+ } else {
+ printf("Joining BSS by SSID %s...\n", (char*)wifi.ssid.val);
+ ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len,
+ wifi.password_len, wifi.key_id, NULL);
+ }
+
+ if(ret!= RTW_SUCCESS){
+ printf("ERROR: Can't connect to AP\n");
+ goto EXIT;
+ }
+ tick2 = xTaskGetTickCount();
+ printf("Connected after %dms.\n", (tick2-tick1));
+#if CONFIG_LWIP_LAYER
+ /* Start DHCPClient */
+ LwIP_DHCP(0, DHCP_START);
+ tick3 = xTaskGetTickCount();
+ printf("Got IP after %dms.\n", (tick3-tick1));
+#endif
+// printf("\n\r");
+EXIT:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_wifi_info("ATWC", ret);
+#endif
+
+ init_wifi_struct( );
+}
+
+#if SCAN_WITH_SSID
+void fATWs(void *arg){
+ char buf[32] = {0};
+ u8 *channel_list = NULL;
+ u8 *pscan_config = NULL;
+ int scan_buf_len = 500;
+ int num_channel = 0;
+ int i, argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ printf("[ATWs]: _AT_WLAN_SCAN_WITH_SSID_ [%s]\n", (char*)wifi.ssid.val);
+ if(arg){
+ strcpy(buf, arg);
+ argc = parse_param(buf, argv);
+ if(argc == 2){
+ scan_buf_len = atoi(argv[1]);
+ if(scan_buf_len < 36){
+ printf("[ATWs] BUFFER_LENGTH too short\n");
+ goto exit;
+ }
+ }else if(argc > 2){
+ num_channel = atoi(argv[1]);
+ channel_list = (u8*)malloc(num_channel);
+ if(!channel_list){
+ printf("[ATWs]ERROR: Can't malloc memory for channel list\n");
+ goto exit;
+ }
+ pscan_config = (u8*)malloc(num_channel);
+ if(!pscan_config){
+ printf("[ATWs]ERROR: Can't malloc memory for pscan_config\n");
+ goto exit;
+ }
+ //parse command channel list
+ for(i = 2; i <= argc -1 ; i++){
+ *(channel_list + i - 2) = (u8)atoi(argv[i]);
+ *(pscan_config + i - 2) = PSCAN_ENABLE;
+ }
+
+ if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){
+ printf("[ATWs]ERROR: wifi set partial scan channel fail\n");
+ goto exit;
+ }
+ }
+ }else{
+ printf("[ATWs]For Scan all channel Usage: ATWs=BUFFER_LENGTH\n");
+ printf("[ATWs]For Scan partial channel Usage: ATWs=num_channels[channel_num1, ...]\n");
+ goto exit;
+ }
+
+ if(wifi_scan_networks_with_ssid(NULL, NULL, scan_buf_len, (char*)wifi.ssid.val, wifi.ssid.len) != RTW_SUCCESS){
+ printf("[ATWs]ERROR: wifi scan failed\n");
+ }
+exit:
+ init_wifi_struct( );
+ if(arg && channel_list)
+ free(channel_list);
+ if(arg && pscan_config)
+ free(pscan_config);
+}
+#endif
+
+void fATWR(void *arg){
+ int rssi = 0;
+ printf("[ATWR]: _AT_WLAN_GET_RSSI_\n");
+ wifi_get_rssi(&rssi);
+ printf("wifi_get_rssi: rssi = %d\n", rssi);
+// printf("");
+}
+
+void fATWP(void *arg){
+ unsigned int parm = atoi((const char *)(arg));
+ printf("[ATWP]: _AT_WLAN_POWER_[%s]\n", parm?"ON":"OFF");
+ if(parm == 1){
+ if(wifi_on(RTW_MODE_STA)<0){
+ printf("ERROR: Wifi on failed!\n");
+ }
+ }
+ else if(parm == 0)
+ {
+#if CONFIG_WEBSERVER
+ stop_web_server();
+#endif
+ wifi_off();
+ }
+ else
+ printf("[ATWP]Usage: ATWP=0/1\n");
+}
+
+#if CONFIG_WOWLAN_SERVICE
+//for wowlan setting
+void fATWV(void *arg){
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+
+ printf("[ATWV]: _AT_WLAN_WOWLAN_\n");
+
+ argc = parse_param(arg, argv);
+
+ cmd_wowlan_service(argc, argv);
+
+ return;
+}
+#endif
+
+#ifdef CONFIG_CONCURRENT_MODE
+void fATWB(void *arg)
+{
+ int timeout = 10000/200;
+ int ret = RTW_SUCCESS;
+#if CONFIG_LWIP_LAYER
+ struct netif * pnetiff = (struct netif *)&xnetif[1];
+#endif
+ printf("[ATWB](_AT_WLAN_AP_STA_ACTIVATE_)\n");
+ if(ap.ssid.val[0] == 0){
+ printf("[ATWB]Error: SSID can't be empty\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ if(ap.channel > 14){
+ printf("[ATWB]Error:bad channel! channel is from 1 to 14\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ if(ap.password == NULL){
+ ap.security_type = RTW_SECURITY_OPEN;
+ }
+ else{
+ ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ }
+
+#if CONFIG_WEBSERVER
+ //store into flash
+ memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));;
+ memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val));
+ wifi_setting.ssid[ap.ssid.len] = '\0';
+ wifi_setting.security_type = ap.security_type;
+ if(ap.security_type !=0)
+ wifi_setting.security_type = 1;
+ else
+ wifi_setting.security_type = 0;
+ if (ap.password)
+ memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password));
+ else
+ memset(wifi_setting.password, 0, sizeof(wifi_setting.password));;
+ wifi_setting.channel = ap.channel;
+#if CONFIG_READ_FLASH
+ StoreApInfo();
+#endif
+#endif
+
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+
+ wifi_off();
+ vTaskDelay(20);
+ if ((ret = wifi_on(RTW_MODE_STA_AP)) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ ret = RTW_ERROR;
+ goto exit;
+ }
+
+ printf("Starting AP ...\n");
+ if((ret = wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel)) < 0) {
+ printf("ERROR: Operation failed!\n");
+ goto exit;
+ }
+ while(1) {
+ char essid[33];
+
+ if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
+ if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
+ printf("%s started\n", ap.ssid.val);
+ ret = RTW_SUCCESS;
+ break;
+ }
+ }
+
+ if(timeout == 0) {
+ printf("ERROR: Start AP timeout!\n");
+ ret = RTW_TIMEOUT;
+ break;
+ }
+
+// vTaskDelay(1 * configTICK_RATE_HZ);
+ vTaskDelay(200/portTICK_RATE_MS);
+ timeout --;
+ }
+#if CONFIG_LWIP_LAYER
+ LwIP_UseStaticIP(&xnetif[1]);
+#ifdef CONFIG_DONT_CARE_TP
+ pnetiff->flags |= NETIF_FLAG_IPSWITCH;
+#endif
+ dhcps_init(pnetiff);
+#endif
+
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_wifi_info("ATWB", ret);
+#endif
+ init_wifi_struct();
+}
+#endif
+
+#ifdef CONFIG_PROMISC
+void fATWM(void *arg){
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+ argv[0] = "wifi_promisc";
+ printf("[ATWM]: _AT_WLAN_PROMISC_\n");
+ if(!arg){
+ printf("[ATWM]Usage: ATWM=DURATION_SECONDS[with_len]\n");
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATWM", RTW_BADARG, NULL, 0);
+#endif
+ return;
+ }
+ if((argc = parse_param(arg, argv)) > 1){
+ cmd_promisc(argc, argv);
+ }
+}
+#endif
+
+#if CONFIG_WEBSERVER
+void fATWE(void *arg){
+ printf("[ATWE]: _AT_WLAN_START_WEB_SERVER_\n");
+ start_web_server();
+}
+#endif
+
+void fATWW(void *arg){
+#if CONFIG_ENABLE_WPS
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWW]: _AT_WLAN_WPS_\n");
+ if(!arg){
+ printf("[ATWW]Usage: ATWW=pbc/pin\n");
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATWW", RTW_BADARG, NULL, 0);
+#endif
+ return;
+ }
+ argv[argc++] = "wifi_wps";
+ argv[argc++] = arg;
+ cmd_wps(argc, argv);
+#else
+ printf("Please set CONFIG_ENABLE_WPS 1 in platform_opts.h to enable ATWW command\n");
+#endif
+}
+void fATWw(void *arg){
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWw]: _AT_WLAN_AP_WPS_\n");
+ if(!arg){
+ printf("[ATWw]Usage: ATWw=pbc/pin\n");
+ return;
+ }
+ argv[argc++] = "wifi_ap_wps";
+ argv[argc++] = arg;
+ cmd_ap_wps(argc, argv);
+#endif
+}
+
+#if CONFIG_ENABLE_P2P
+void fATWG(void *arg){
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWG]: _AT_WLAN_P2P_START_\n");
+ argv[argc++] = "p2p_start";
+ cmd_wifi_p2p_start(argc, argv);
+}
+
+void fATWg(void *arg){
+ int argc = 0;
+ char *argv[4];
+ int ret =0;
+ printf("[ATWg]: _AT_WLAN_P2P_AUTO_GO_START_\n");
+ argv[argc++] = "p2p_auto_go_start";
+ ret = cmd_wifi_p2p_auto_go_start(argc, argv);
+ if(ret < 0)
+ printf("[ATWg]: Nothing to do. Please enter ATWG to initialize P2P.\n");
+}
+
+void fATWH(void *arg){
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWH]: _AT_WLAN_P2P_STOP_\n");
+ argv[argc++] = "p2p_stop";
+ cmd_wifi_p2p_stop(argc, argv);
+}
+void fATWJ(void *arg){
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWJ]: _AT_WLAN_P2P_CONNECT_\n");
+ argv[0] = "p2p_connect";
+ if(!arg){
+ printf("ATWc=[DEST_MAC,pbc/pin]\n");
+ return;
+ }
+ if((argc = parse_param(arg, argv)) > 1){
+ cmd_p2p_connect(argc, argv);
+ }
+}
+void fATWK(void *arg){
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWK]: _AT_WLAN_P2P_DISCONNECT_\n");
+ argv[argc++] = "p2p_disconnect";
+ cmd_p2p_disconnect(argc, argv);
+}
+void fATWN(void *arg){
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWN]: _AT_WLAN_P2P_INFO_\n");
+ argv[argc++] = "p2p_info";
+ cmd_p2p_info(argc, argv);
+}
+void fATWF(void *arg){
+ int argc = 0;
+ char *argv[4];
+ printf("[ATWF]: _AT_WLAN_P2P_FIND_\n");
+ argv[argc++] = "p2p_find";
+ cmd_p2p_find(argc, argv);
+}
+#endif
+#if CONFIG_OTA_UPDATE
+void fATWO(void *arg){
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ printf("[ATWO]: _AT_WLAN_OTA_UPDATE_\n");
+ if(!arg){
+ printf("[ATWO]Usage: ATWO=IP[PORT] or ATWO= REPOSITORY[FILE_PATH]\n");
+ return;
+ }
+ argv[0] = "update";
+ if((argc = parse_param(arg, argv)) != 3){
+ printf("[ATWO]Usage: ATWO=IP[PORT] or ATWO= REPOSITORY[FILE_PATH]\n");
+ return;
+ }
+ cmd_update(argc, argv);
+}
+#endif
+
+#if CONFIG_AIRKISS
+void fATWX(void *arg)
+{
+ int ret = RTW_SUCCESS;
+
+ rtw_network_info_t wifi;
+ memset(&wifi, 0 , sizeof(rtw_network_info_t));
+
+ ret = airkiss_start(&wifi);
+#if CONFIG_INIC_CMD_RSP
+ if(ret != RTW_SUCCESS)
+ inic_c2h_msg("ATWX", RTW_ERROR, NULL, 0);
+#endif
+}
+#endif
+
+void fATWZ(void *arg){
+ char buf[32] = {0};
+ char *copy = buf;
+ int i = 0;
+ int len = 0;
+ int ret = RTW_SUCCESS;
+
+ printf("[ATWZ]: _AT_WLAN_IWPRIV_\n");
+ if(!arg){
+ printf("[ATWZ]Usage: ATWZ=COMMAND[PARAMETERS]\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ strcpy(copy, arg);
+ len = strlen(copy);
+ do{
+ if((*(copy+i)=='['))
+ *(copy+i)=' ';
+ if((*(copy+i)==']')||(*(copy+i)=='\0')){
+ *(copy+i)='\0';
+ break;
+ }
+ }while((i++) < len);
+
+ i = 0;
+ do{
+ if((*(copy+i)==',')) {
+ *(copy+i)=' ';
+ break;
+ }
+ }while((i++) < len);
+
+#if CONFIG_INIC_CMD_RSP
+ ret = wext_private_command_with_retval(WLAN0_NAME, copy, buf, 32);
+ printf("Private Message: %s\n", (char *) buf);
+ if(ret == RTW_SUCCESS)
+ inic_c2h_msg("ATWZ", ret, buf, strlen(buf));
+#else
+ wext_private_command(WLAN0_NAME, copy, 1);
+#endif
+exit:
+#if CONFIG_INIC_CMD_RSP
+ if(ret != RTW_SUCCESS)
+ inic_c2h_msg("ATWZ", ret, NULL, 0);
+#endif
+ return; // exit label cannot be last statement
+}
+
+#ifdef CONFIG_POWER_SAVING
+void fATXP(void *arg)
+{
+ int argc = 0;
+ char *argv[MAX_ARGC] = {0};
+ int ret = 0;
+ int mode, dtim;
+ int tdma_slot_period, tdma_rfon_period_len_1, tdma_rfon_period_len_2, tdma_rfon_period_len_3;
+#if CONFIG_INIC_CMD_RSP
+ char *res = NULL;
+ int res_len = 0;
+#endif
+
+ printf("[ATXP]: _AT_WLAN_POWER_MODE_\n");
+
+ if (!arg) {
+ printf("[ATXP] Usage: ATXP=lps/ips/dtim/tdma[mode]\n");
+ ret = RTW_BADARG;
+ goto exit;
+ } else {
+ argc = parse_param(arg, argv);
+ if (argc < 3) {
+ printf("[ATXP] Usage: ATXP=lps/ips/dtim/tdma[mode]\n");
+ ret = RTW_BADARG;
+ goto exit;
+ }
+ }
+
+ if (strcmp(argv[1], "lps") == 0) {
+ mode = atoi(argv[2]);
+ if (mode >= 0 && mode < 0xFF) {
+ printf("lps mode:%d\n", mode);
+ wifi_set_power_mode(0xff, mode);
+ }
+ }
+
+ if (strcmp(argv[1], "ips") == 0) {
+ mode = atoi(argv[2]);
+ if (mode >= 0 && mode < 0xFF) {
+ printf("ips mode:%d\n", mode);
+ wifi_set_power_mode(mode, 0xFF);
+ }
+ }
+
+ if (strcmp(argv[1], "tdma") == 0) {
+ if (argc >= 6) {
+ tdma_slot_period = atoi(argv[2]);
+ tdma_rfon_period_len_1 = atoi(argv[3]);
+ tdma_rfon_period_len_2 = atoi(argv[4]);
+ tdma_rfon_period_len_3 = atoi(argv[5]);
+ printf("tdma param: %d %d %d %d\n", tdma_slot_period, tdma_rfon_period_len_1, tdma_rfon_period_len_2, tdma_rfon_period_len_3);
+ wifi_set_tdma_param(tdma_slot_period, tdma_rfon_period_len_1, tdma_rfon_period_len_2, tdma_rfon_period_len_3);
+ }
+ }
+
+ if (strcmp(argv[1], "dtim") == 0) {
+ dtim = atoi(argv[2]);
+ printf("dtim: %d\n", dtim);
+ wifi_set_lps_dtim(dtim);
+ }
+
+ if (strcmp(argv[1], "get") == 0) {
+#if CONFIG_INIC_CMD_RSP
+ char buf[32];
+ int index = 0;
+ memset(buf, 0, sizeof(buf));
+ snprintf(buf, 32, "%s,%s,", argv[1], argv[2]);
+ index = strlen(buf);
+#endif
+ if(strcmp(argv[2], "dtim") == 0){
+ wifi_get_lps_dtim((unsigned char *)&dtim);
+ printf("get dtim: %d\n", (unsigned char)dtim);
+#if CONFIG_INIC_CMD_RSP
+ sprintf(buf+index, "0x%02x", (unsigned char)dtim);
+ res = (char *)buf;
+ res_len = strlen(buf);
+#endif
+ }
+ }
+
+exit:
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_msg("ATXP", ret, res, res_len);
+ res = NULL;
+ res_len = 0;
+#endif
+ return;
+}
+#endif
+
+void print_wlan_help(void *arg){
+ printf("WLAN AT COMMAND SET:\n==============================\n");
+ printf("1. Wlan Scan for Network Access Point\n");
+ printf(" # ATWS\n");
+ printf("2. Connect to an AES AP\n");
+ printf(" # ATW0=SSID\n");
+ printf(" # ATW1=PASSPHRASE\n");
+ printf(" # ATWC\n");
+ printf("3. Create an AES AP\n");
+ printf(" # ATW3=SSID\n");
+ printf(" # ATW4=PASSPHRASE\n");
+ printf(" # ATW5=CHANNEL\n");
+ printf(" # ATWA\n");
+ printf("4. Ping\n");
+ printf(" # ATWI=xxx.xxx.xxx.xxx\n");
+}
+
+#elif ATCMD_VER == ATVER_2 // UART module at command
+
+//ATPA=,,,[,]
+void fATPA(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+
+#if CONFIG_LWIP_LAYER
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+ struct netif * pnetif;
+#endif
+ int timeout = 10000/200;
+ unsigned char hidden_ssid = 0;
+ rtw_mode_t wifi_mode_copy;
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPA] Usage: ATPA=,,,[,]");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if(argc < 5){
+ //at_printf("\r\n[ATPA] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if( (wifi_mode!=RTW_MODE_AP) && (wifi_mode!=RTW_MODE_STA_AP) ){
+ //at_printf("\r\n[ATPA] ERROR : wifi mode error");
+ error_no = 5;
+ goto exit;
+ }
+ wifi_mode_copy = wifi_mode;
+
+ //SSID
+ if(argv[1] != NULL){
+ ap.ssid.len = strlen((char*)argv[1]);
+ if(ap.ssid.len > 32){
+ //at_printf("\r\n[ATPA] ERROR : SSID length can't exceed 32");
+ error_no = 2;
+ goto exit;
+ }
+ strcpy((char *)ap.ssid.val, (char*)argv[1]);
+ }
+ else{
+ //at_printf("\r\n[ATPA] ERROR : SSID can't be empty");
+ error_no = 2;
+ goto exit;
+ }
+
+ //PASSWORD
+ if(argv[2] != NULL){
+ if( (strlen(argv[2]) < 8) || (strlen(argv[2]) > 64)){
+ //at_printf("\r\n[ATPA] ERROR : PASSWORD length error");
+ error_no = 2;
+ goto exit;
+ }
+ strcpy((char *)password, (char*)argv[2]);
+ ap.password = password;
+ ap.password_len = strlen((char*)argv[2]);
+ ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ }
+ else{
+ ap.security_type = RTW_SECURITY_OPEN;
+ }
+
+ //CHANNEL
+ if(argv[3] != NULL){
+ ap.channel = (unsigned char) atoi((const char *)argv[3]);
+ if( (ap.channel < 0) || (ap.channel > 11) ){
+ //at_printf("\r\n[ATPA] ERROR : channel number error");
+ error_no = 2;
+ goto exit;
+ }
+ }
+
+ //HIDDEN SSID
+ if(argv[4] != NULL){
+ if( (atoi(argv[4]) != 0) && (atoi(argv[4]) != 1)){
+ //at_printf("\r\n[ATPA] ERROR : HIDDEN SSID must be 0 or 1");
+ error_no = 2;
+ goto exit;
+ }
+ hidden_ssid = (unsigned char) atoi((const char *)argv[4]);
+ }
+
+ //MAX NUMBER OF STATION
+ if(argv[5] != NULL){
+ unsigned char max_sta = atoi(argv[5]);
+ if(wext_set_sta_num(max_sta) != 0){
+ error_no = 2;
+ goto exit;
+ }
+ }
+
+#if CONFIG_WEBSERVER
+ //store into flash
+ memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));
+ memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val));
+ wifi_setting.ssid[ap.ssid.len] = '\0';
+ wifi_setting.security_type = ap.security_type;
+ if(ap.security_type !=0)
+ wifi_setting.security_type = 1;
+ else
+ wifi_setting.security_type = 0;
+ if (ap.password)
+ memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password));
+ else
+ memset(wifi_setting.password, 0, sizeof(wifi_setting.password));
+ wifi_setting.channel = ap.channel;
+#if CONFIG_READ_FLASH
+ StoreApInfo();
+#endif
+#endif
+
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+ wifi_off();
+ vTaskDelay(20);
+
+ if (wifi_on(wifi_mode_copy) < 0){
+ //at_printf("\r\n[ATPA] ERROR : Wifi on failed");
+ error_no = 3;
+ goto exit;
+ }
+
+ if(hidden_ssid){
+ if(wifi_start_ap_with_hidden_ssid((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) {
+ //at_printf("\r\n[ATPA] ERROR : Start AP failed");
+ error_no = 4;
+ goto exit;
+ }
+ }
+ else{
+ if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) {
+ //at_printf("\r\n[ATPA] ERROR : Start AP failed");
+ error_no = 4;
+ goto exit;
+ }
+ }
+
+ while(1) {
+ char essid[33];
+ if(wifi_mode_copy == RTW_MODE_AP ){
+ if(wext_get_ssid( WLAN0_NAME , (unsigned char *) essid) > 0) {
+ if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
+ break;
+ }
+ }
+ }
+ else if(wifi_mode_copy == RTW_MODE_STA_AP ){
+ if(wext_get_ssid( WLAN1_NAME , (unsigned char *) essid) > 0) {
+ if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
+ break;
+ }
+ }
+ }
+
+ if(timeout == 0) {
+ //at_printf("\r\n[ATPA] ERROR : Start AP timeout");
+ error_no = 4;
+ break;
+ }
+ vTaskDelay(200/portTICK_RATE_MS);
+// vTaskDelay(1 * configTICK_RATE_HZ);
+ timeout --;
+ }
+#if CONFIG_LWIP_LAYER
+ if(wifi_mode == RTW_MODE_STA_AP)
+ pnetif = &xnetif[1];
+ else
+ pnetif = &xnetif[0];
+
+ LwIP_UseStaticIP(pnetif);
+
+ if(dhcp_mode_ap == 1)
+ dhcps_init(pnetif);
+#endif
+exit:
+ init_wifi_struct();
+
+ if(error_no == 0) {
+#if CONFIG_WLAN_CONNECT_CB
+ extern void connect_start(void);
+ connect_start();
+#endif
+ at_printf("\r\n[ATPA] OK");
+ } else
+ at_printf("\r\n[ATPA] ERROR:%d",error_no);
+
+ return;
+}
+
+/*find ap with "ssid" from scan list*/
+static int _find_ap_from_scan_buf(char*buf, int buflen, char *target_ssid, void *user_data)
+{
+ rtw_wifi_setting_t *pwifi = (rtw_wifi_setting_t *)user_data;
+ int plen = 0;
+
+ while(plen < buflen){
+ u8 len, ssid_len, security_mode;
+ char *ssid;
+
+ // len offset = 0
+ len = (int)*(buf + plen);
+ // check end
+ if(len == 0) break;
+ // ssid offset = 14
+ ssid_len = len - 14;
+ ssid = buf + plen + 14 ;
+ if((ssid_len == strlen(target_ssid))
+ && (!memcmp(ssid, target_ssid, ssid_len)))
+ {
+ strcpy((char*)pwifi->ssid, target_ssid);
+ // channel offset = 13
+ pwifi->channel = *(buf + plen + 13);
+ // security_mode offset = 11
+ security_mode = (u8)*(buf + plen + 11);
+ if(security_mode == IW_ENCODE_ALG_NONE)
+ pwifi->security_type = RTW_SECURITY_OPEN;
+ else if(security_mode == IW_ENCODE_ALG_WEP)
+ pwifi->security_type = RTW_SECURITY_WEP_PSK;
+ else if(security_mode == IW_ENCODE_ALG_CCMP)
+ pwifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ }
+ plen += len;
+ }
+ return 0;
+}
+
+/*get ap security mode from scan list*/
+static int _get_ap_security_mode(IN char * ssid, OUT rtw_security_t *security_mode, OUT u8 * channel)
+{
+ rtw_wifi_setting_t wifi;
+ u32 scan_buflen = 1000;
+
+ memset(&wifi, 0, sizeof(wifi));
+
+ if(wifi_scan_networks_with_ssid(_find_ap_from_scan_buf, (void*)&wifi, scan_buflen, ssid, strlen(ssid)) != RTW_SUCCESS){
+ printf("Wifi scan failed!\n");
+ return 0;
+ }
+
+ if(strcmp(wifi.ssid, ssid) == 0){
+ *security_mode = wifi.security_type;
+ *channel = wifi.channel;
+ return 1;
+ }
+
+ return 0;
+}
+
+extern u8 key_2char2num(u8 hch, u8 lch);
+
+//ATPN=,,(,)
+void fATPN(void *arg)
+{
+ int argc, error_no = 0;
+ int i,j;
+ char *argv[MAX_ARGC] = {0};
+
+ int mode, ret;
+ unsigned long tick1 = xTaskGetTickCount();
+ unsigned long tick2, tick3;
+ char empty_bssid[6] = {0}, assoc_by_bssid = 0;
+ u8 connect_channel;
+ u8 pscan_config;
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPN] Usage : ATPN=,,(,)");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if( (argc < 2) || (argc > 5) ){
+ //at_printf("\r\n[ATPN] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if( (wifi_mode!=RTW_MODE_STA) && (wifi_mode!=RTW_MODE_STA_AP) ){
+ //at_printf("\r\n[ATPN] ERROR : wifi mode error");
+ error_no = 5;
+ goto exit;
+ }
+
+ //SSID
+ if(argv[1] != NULL){
+ strcpy((char *)wifi.ssid.val, (char*)argv[1]);
+ wifi.ssid.len = strlen((char*)argv[1]);
+ }else{
+ //at_printf("\r\n[ATPN] ERROR : SSID can't be Empty");
+ error_no = 2;
+ goto exit;
+ }
+ wifi.security_type = RTW_SECURITY_OPEN;
+
+ //PASSWORD
+ if(argv[2] != NULL){
+ int pwd_len = strlen(argv[2]);
+ if(pwd_len > 64 || (pwd_len < 8 && pwd_len != 5)){
+ //at_printf("\r\n[ATPN] ERROR : PASSWORD format error");
+ error_no = 2;
+ goto exit;
+ }
+ strcpy((char *)password, (char*)argv[2]);
+ wifi.password = password;
+ wifi.password_len = strlen((char*)argv[2]);
+ wifi.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ }
+
+ //KEYID
+ if(argv[3] != NULL){
+ if((strlen((const char *)argv[3]) != 1 ) || (*(char*)argv[3] <'0' ||*(char*)argv[3] >'3')) {
+ //at_printf("\r\n[ATPN] ERROR : Wrong WEP key id. Must be one of 0,1,2, or 3");
+ error_no = 2;
+ goto exit;
+ }
+ wifi.key_id = atoi((const char *)(argv[3]));
+ wifi.security_type = RTW_SECURITY_WEP_PSK;
+ }
+
+ //BSSID
+ if(argv[4] != NULL){
+ if(strlen(argv[4]) != 12){
+ //at_printf("\r\n[ATPN] ERROR : BSSID format error");
+ error_no = 2;
+ goto exit;
+ }
+ for (i=0, j=0; i= 3){
+ printf("Can't get AP security mode and channel.\n");
+ error_no = 6;
+ goto exit;
+ }
+ }
+ if(wifi.security_type == RTW_SECURITY_WEP_PSK || wifi.security_type == RTW_SECURITY_WEP_SHARED)
+ wifi.key_id = (wifi.key_id <0 || wifi.key_id >3)?0:wifi.key_id;
+ }
+ pscan_config = PSCAN_ENABLE;
+ if(connect_channel > 0 && connect_channel < 14)
+ wifi_set_pscan_chan(&connect_channel, &pscan_config, 1);
+#endif
+
+ if(assoc_by_bssid){
+ ret = wifi_connect_bssid(wifi.bssid.octet, (char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password,
+ ETH_ALEN, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
+ } else {
+ ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len,
+ wifi.password_len, wifi.key_id, NULL);
+ }
+
+ if(ret!= RTW_SUCCESS){
+ //at_printf("\r\n[ATPN] ERROR: Can't connect to AP");
+ error_no = 4;
+ goto exit;
+ }
+
+#if CONFIG_LWIP_LAYER
+ if (dhcp_mode_sta == 2){
+ struct netif * pnetif = &xnetif[0];
+ LwIP_UseStaticIP(pnetif);
+ dhcps_init(pnetif);
+ }
+ else{
+ ret = LwIP_DHCP(0, DHCP_START);
+ if(ret != DHCP_ADDRESS_ASSIGNED)
+ error_no = 7;
+ }
+#endif
+exit:
+ init_wifi_struct();
+ if(error_no == 0) {
+#if CONFIG_WLAN_CONNECT_CB
+ extern void connect_start(void);
+ connect_start();
+#endif
+ at_printf("\r\n[ATPN] OK");
+ } else
+ at_printf("\r\n[ATPN] ERROR:%d",error_no);
+
+ return;
+}
+
+//ATPH=,
+void fATPH(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+ int mode,enable;
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPH] Usage : ATPH=,");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if(argc != 3){
+ //at_printf("\r\n[ATPH] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if(argv[1] != NULL){
+ mode = atoi((const char *)(argv[1]));
+ if(mode != 1 && mode != 2){
+ //at_printf("\r\n[ATPH] ERROR : parameter must be 1 or 2");
+ error_no = 2;
+ goto exit;
+ }
+ }
+
+ if(argv[2] != NULL){
+ enable = atoi((const char *)(argv[2]));
+ if(enable != 1 && enable != 2){
+ //at_printf("\r\n[ATPH] ERROR : parameter must be 1 or 2");
+ error_no = 2;
+ goto exit;
+ }
+ if(mode == 1)
+ dhcp_mode_ap = enable;
+ else if(mode == 2)
+ dhcp_mode_sta = enable;
+ }
+
+exit:
+ if(error_no==0)
+ at_printf("\r\n[ATPH] OK");
+ else
+ at_printf("\r\n[ATPH] ERROR:%d",error_no);
+
+ return;
+
+}
+
+//ATPE=(,,)
+void fATPE(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+ unsigned int ip_addr = 0;
+ //unsigned char sta_ip[4] = {192,168,3,80}, sta_netmask[4] = {255,255,255,0}, sta_gw[4] = {192,168,3,1};
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPE] Usage : ATPE=(,,)");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if( (argc > 4) || (argc < 2) ){
+ //at_printf("\r\n[ATPE] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if(argv[1] != NULL){
+ ip_addr = inet_addr(argv[1]);
+ sta_ip[0] = (unsigned char) ip_addr & 0xff;
+ sta_ip[1] = (unsigned char) (ip_addr >> 8) & 0xff;
+ sta_ip[2] = (unsigned char) (ip_addr >> 16) & 0xff;
+ sta_ip[3] = (unsigned char) (ip_addr >> 24) & 0xff;
+ }
+ else{
+ //at_printf("\r\n[ATPE] ERROR : parameter format error");
+ error_no = 2;
+ goto exit;
+ }
+
+ if(argv[2] != NULL){
+ ip_addr = inet_addr(argv[2]);
+ sta_gw[0] = (unsigned char) ip_addr & 0xff;
+ sta_gw[1] = (unsigned char) (ip_addr >> 8) & 0xff;
+ sta_gw[2] = (unsigned char) (ip_addr >> 16) & 0xff;
+ sta_gw[3] = (unsigned char) (ip_addr >> 24) & 0xff;
+ }
+ else{
+ sta_gw[0] = sta_ip[0];
+ sta_gw[1] = sta_ip[1];
+ sta_gw[2] = sta_ip[2];
+ sta_gw[3] = 1;
+ }
+
+ if(argv[3] != NULL){
+ ip_addr = inet_addr(argv[3]);
+ sta_netmask[0] = (unsigned char) ip_addr & 0xff;
+ sta_netmask[1] = (unsigned char) (ip_addr >> 8) & 0xff;
+ sta_netmask[2] = (unsigned char) (ip_addr >> 16) & 0xff;
+ sta_netmask[3] = (unsigned char) (ip_addr >> 24) & 0xff;
+ }
+ else{
+ sta_netmask[0] = 255;
+ sta_netmask[1] = 255;
+ sta_netmask[2] = 255;
+ sta_netmask[3] = 0;
+ }
+
+exit:
+ if(error_no==0)
+ at_printf("\r\n[ATPE] OK");
+ else
+ at_printf("\r\n[ATPE] ERROR:%d",error_no);
+
+ return;
+
+}
+
+//ATPF=,,
+void fATPF(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+ unsigned int ip_addr = 0;
+ struct ip_addr start_ip, end_ip;
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPF] Usage : ATPF=,,(,,)");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if( (argc != 4) ){
+ //at_printf("\r\n[ATPF] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if(argv[1] != NULL){
+ start_ip.addr = inet_addr(argv[1]);
+ }
+ else{
+ //at_printf("\r\n[ATPF] ERROR : parameter format error");
+ error_no = 2;
+ goto exit;
+ }
+
+ if(argv[2] != NULL){
+ end_ip.addr = inet_addr(argv[2]);
+ }
+ else{
+ //at_printf("\r\n[ATPF] ERROR : parameter format error");
+ error_no = 2;
+ goto exit;
+ }
+
+ dhcps_set_addr_pool(1,&start_ip,&end_ip);
+
+ if(argv[3] != NULL){
+ ip_addr = inet_addr(argv[3]);
+ ap_ip[0] = (unsigned char) ip_addr & 0xff;
+ ap_ip[1] = (unsigned char) (ip_addr >> 8) & 0xff;
+ ap_ip[2] = (unsigned char) (ip_addr >> 16) & 0xff;
+ ap_ip[3] = (unsigned char) (ip_addr >> 24) & 0xff;
+ }
+ else{
+ //at_printf("\r\n[ATPF] ERROR : parameter format error");
+ error_no = 2;
+ goto exit;
+ }
+
+ ap_gw[0] = ap_ip[0];
+ ap_gw[1] = ap_ip[1];
+ ap_gw[2] = ap_ip[2];
+ ap_gw[3] = ap_ip[3];
+
+ ap_netmask[0] = 255;
+ ap_netmask[1] = 255;
+ ap_netmask[2] = 255;
+ ap_netmask[3] = 0;
+
+exit:
+ if(error_no==0)
+ at_printf("\r\n[ATPF] OK");
+ else
+ at_printf("\r\n[ATPF] ERROR:%d",error_no);
+
+ return;
+}
+
+int atcmd_wifi_read_info_from_flash(u8 *read_data, u32 read_len)
+{
+ atcmd_update_partition_info(AT_PARTITION_WIFI, AT_PARTITION_READ, read_data, read_len);
+ return 0;
+}
+
+void atcmd_wifi_write_info_to_flash(rtw_wifi_setting_t *setting, int enable)
+{
+ struct atcmd_wifi_conf *data_to_flash;
+ rtw_wifi_setting_t *old_setting;
+
+// flash_t flash;
+ u32 channel = 0, i, write_needed = 0;
+ u8 index = 0;
+ u32 data;
+
+ data_to_flash = (struct atcmd_wifi_conf *)malloc(sizeof(struct atcmd_wifi_conf));
+
+ if(data_to_flash) {
+ if(enable){
+ memset((u8 *)data_to_flash, 0, sizeof(struct atcmd_wifi_conf));
+ atcmd_update_partition_info(AT_PARTITION_WIFI, AT_PARTITION_READ, (u8 *)data_to_flash, sizeof(struct atcmd_wifi_conf));
+ old_setting = &(data_to_flash->setting);
+ if(memcmp((u8 *)old_setting, setting, sizeof(rtw_wifi_setting_t))){
+ memcpy(old_setting, setting, sizeof(rtw_wifi_setting_t));
+ write_needed = 1;
+ }
+ if(setting->mode == RTW_MODE_STA || setting->mode == RTW_MODE_STA_AP){
+ struct wlan_fast_reconnect reconn;
+ int found = 0;
+ /*clean wifi ssid,key and bssid*/
+ memset((u8 *)&reconn, 0, sizeof(struct wlan_fast_reconnect));
+
+ channel = setting->channel;
+
+ memset(psk_essid[index], 0, sizeof(psk_essid[index]));
+ strncpy(psk_essid[index], setting->ssid, strlen(setting->ssid));
+ switch(setting->security_type){
+ case RTW_SECURITY_OPEN:
+ memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index]));
+ memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index]));
+ reconn.security_type = RTW_SECURITY_OPEN;
+ break;
+ case RTW_SECURITY_WEP_PSK:
+ channel |= (setting->key_idx) << 28;
+ memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index]));
+ memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index]));
+ memcpy(psk_passphrase[index], setting->password, sizeof(psk_passphrase[index]));
+ reconn.security_type = RTW_SECURITY_WEP_PSK;
+ break;
+ case RTW_SECURITY_WPA_TKIP_PSK:
+ reconn.security_type = RTW_SECURITY_WPA_TKIP_PSK;
+ break;
+ case RTW_SECURITY_WPA2_AES_PSK:
+ reconn.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ default:
+ break;
+ }
+
+ memcpy(reconn.psk_essid, psk_essid[index], sizeof(reconn.psk_essid));
+ if (strlen(psk_passphrase64) == 64) {
+ memcpy(reconn.psk_passphrase, psk_passphrase64, sizeof(reconn.psk_passphrase));
+ } else {
+ memcpy(reconn.psk_passphrase, psk_passphrase[index], sizeof(reconn.psk_passphrase));
+ }
+ memcpy(reconn.wpa_global_PSK, wpa_global_PSK[index], sizeof(reconn.wpa_global_PSK));
+ memcpy(&(reconn.channel), &channel, 4);
+
+ if(data_to_flash->reconn_num < 0 || data_to_flash->reconn_num > ATCMD_WIFI_CONN_STORE_MAX_NUM ||
+ data_to_flash->reconn_last_index < 0 || data_to_flash->reconn_last_index > ATCMD_WIFI_CONN_STORE_MAX_NUM
+ ){
+ data_to_flash->reconn_num = 0;
+ data_to_flash->reconn_last_index = -1;
+ }
+
+ reconn.enable = enable;
+ for(i = 0; i < data_to_flash->reconn_num; i++){
+ if(memcmp((u8 *)&reconn, (u8 *)&(data_to_flash->reconn[i]), sizeof(struct wlan_fast_reconnect)) == 0) {
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ALWAYS,
+ "the same profile found in flash");
+ found = 1;
+ break;
+ }
+ }
+ if(!found){
+ data_to_flash->reconn_last_index++;
+ if(data_to_flash->reconn_last_index >= ATCMD_WIFI_CONN_STORE_MAX_NUM)
+ data_to_flash->reconn_last_index -= ATCMD_WIFI_CONN_STORE_MAX_NUM;
+ memcpy((u8 *)&data_to_flash->reconn[data_to_flash->reconn_last_index], (u8 *)&reconn, sizeof(struct wlan_fast_reconnect));
+ data_to_flash->reconn_num++;
+ if(data_to_flash->reconn_num > ATCMD_WIFI_CONN_STORE_MAX_NUM)
+ data_to_flash->reconn_num = ATCMD_WIFI_CONN_STORE_MAX_NUM;
+ write_needed = 1;
+ }
+ }
+ if(write_needed || data_to_flash->auto_enable != enable){
+ data_to_flash->auto_enable = enable;
+ atcmd_update_partition_info(AT_PARTITION_WIFI, AT_PARTITION_WRITE, (u8 *)data_to_flash, sizeof(struct atcmd_wifi_conf));
+ }
+ }else{
+ atcmd_update_partition_info(AT_PARTITION_WIFI, AT_PARTITION_ERASE, (u8 *)data_to_flash, sizeof(struct atcmd_wifi_conf));
+ }
+ }
+ if(data_to_flash) {
+ free(data_to_flash);
+ }
+}
+
+int atcmd_wifi_restore_from_flash(void)
+{
+// flash_t flash;
+ struct atcmd_wifi_conf *data;
+ rtw_wifi_setting_t *setting;
+ struct wlan_fast_reconnect *reconn;
+ uint32_t channel;
+ uint32_t security_type;
+ uint8_t pscan_config;
+ char key_id[2] = {0};
+ int ret = -1, i;
+ int mode;
+ rtw_network_info_t wifi = {
+ {0}, // ssid
+ {0}, // bssid
+ 0, // security
+ NULL, // password
+ 0, // password len
+ -1 // key id
+ };
+ data = (struct atcmd_wifi_conf *)rtw_zmalloc(sizeof(struct atcmd_wifi_conf));
+ if(data){
+ atcmd_update_partition_info(AT_PARTITION_WIFI, AT_PARTITION_READ, (u8 *)data, sizeof(struct atcmd_wifi_conf));
+ if(data->auto_enable != 1)
+ goto exit;
+ setting = &data->setting;
+ if(setting->mode == RTW_MODE_AP || setting->mode == RTW_MODE_STA_AP){
+ //start AP here
+ goto exit;
+ }
+
+ //Check if in AP mode
+ wext_get_mode(WLAN0_NAME, &mode);
+ if(mode == IW_MODE_MASTER) {
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_STA) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ ret = -1;
+ goto exit;
+ }
+ }
+
+#if CONFIG_AUTO_RECONNECT
+ //setup reconnection flag
+ wifi_set_autoreconnect(0);
+#endif
+ int last_index = data->reconn_last_index;
+ for(i = 0; i < data->reconn_num; i++){
+ reconn = &data->reconn[last_index];
+ last_index ++;
+ if(last_index >= ATCMD_WIFI_CONN_STORE_MAX_NUM)
+ last_index -= ATCMD_WIFI_CONN_STORE_MAX_NUM;
+ if(reconn->enable != 1){
+ continue;
+ }
+ memcpy(psk_essid, reconn->psk_essid, sizeof(reconn->psk_essid));
+ memcpy(psk_passphrase, reconn->psk_passphrase, sizeof(reconn->psk_passphrase));
+ memcpy(wpa_global_PSK, reconn->wpa_global_PSK, sizeof(reconn->wpa_global_PSK));
+ channel = reconn->channel;
+ sprintf(key_id,"%d",(char) (channel>>28));
+ channel &= 0xff;
+ security_type = reconn->security_type;
+ pscan_config = PSCAN_ENABLE | PSCAN_FAST_SURVEY;
+ //set partial scan for entering to listen beacon quickly
+ wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1);
+
+ wifi.security_type = security_type;
+ //SSID
+ strcpy((char *)wifi.ssid.val, (char*)psk_essid);
+ wifi.ssid.len = strlen((char*)psk_essid);
+
+ switch(security_type){
+ case RTW_SECURITY_WEP_PSK:
+ wifi.password = (unsigned char*) psk_passphrase;
+ wifi.password_len = strlen((char*)psk_passphrase);
+ wifi.key_id = atoi((const char *)key_id);
+ break;
+ case RTW_SECURITY_WPA_TKIP_PSK:
+ case RTW_SECURITY_WPA2_AES_PSK:
+ wifi.password = (unsigned char*) psk_passphrase;
+ wifi.password_len = strlen((char*)psk_passphrase);
+ break;
+ default:
+ break;
+ }
+
+ ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len,
+ wifi.password_len, wifi.key_id, NULL);
+ if(ret == RTW_SUCCESS){
+ LwIP_DHCP(0, DHCP_START);
+ ret = 0;
+#if CONFIG_WLAN_CONNECT_CB
+ extern void connect_start(void);
+ connect_start();
+#endif
+ break;
+ }
+ }
+ }
+
+exit:
+ if(data)
+ rtw_mfree((u8 *)data, sizeof(struct wlan_fast_reconnect));
+ return ret;
+}
+
+//ATPG=
+void fATPG(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+// flash_t flash;
+// struct wlan_fast_reconnect read_data = {0};
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "[ATPG] Usage : ATPG=\r\n");
+ error_no = 1;
+ goto exit;
+ }
+ argc = parse_param(arg, argv);
+ if(argc != 2){
+ //at_printf("\r\n[ATPG] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ //ENABLE FAST CONNECT
+ if(argv[1] != NULL){
+#if 0
+ device_mutex_lock(RT_DEV_LOCK_FLASH);
+ flash_stream_read(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (u8 *) &read_data);
+ read_data.enable = atoi((const char *)(argv[1]));
+ if(read_data.enable != 0 && read_data.enable != 1){
+ //at_printf("\r\n[ATPG] ERROR : parameter must be 0 or 1");
+ error_no = 2;
+ device_mutex_unlock(RT_DEV_LOCK_FLASH);
+ goto exit;
+ }
+ flash_erase_sector(&flash, FAST_RECONNECT_DATA);
+ flash_stream_write(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (u8 *) &read_data);
+ device_mutex_unlock(RT_DEV_LOCK_FLASH);
+#else
+ rtw_wifi_setting_t setting;
+ int enable = atoi((const char *)(argv[1]));
+ if(enable != 0 && enable != 1){
+ error_no = 2;
+ goto exit;
+ }
+ if(enable == 1){
+ u8 *ifname[1] = {WLAN0_NAME};
+ if(wifi_get_setting((const char*)ifname[0],&setting)){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "wifi_get_setting fail");
+ error_no = 3;
+ goto exit;
+ }
+ }
+ atcmd_wifi_write_info_to_flash(&setting, enable);
+#endif
+ }
+
+exit:
+ if(error_no==0)
+ at_printf("\r\n[ATPG] OK");
+ else
+ at_printf("\r\n[ATPG] ERROR:%d",error_no);
+
+ return;
+}
+
+// set MAC address
+//ATPM=
+void fATPM(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPM] Usage : ATPM=");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if(argc != 2){
+ //at_printf("\r\n[ATPM] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if(argv[1] != NULL){
+ if(strlen(argv[1]) != 12){
+ //at_printf("\r\n[ATPM] ERROR : BSSID format error");
+ error_no = 2;
+ goto exit;
+ }
+ wifi_set_mac_address(argv[1]);
+ }
+
+exit:
+ if(error_no==0)
+ at_printf("\r\n[ATPM] OK");
+ else
+ at_printf("\r\n[ATPM] ERROR:%d",error_no);
+
+ return;
+
+}
+
+// set Wifi mode
+// ATPW=
+void fATPW(void *arg)
+{
+ int argc, error_no = 0;
+ char *argv[MAX_ARGC] = {0};
+
+ if(!arg){
+ AT_DBG_MSG(AT_FLAG_WIFI, AT_DBG_ERROR,
+ "\r\n[ATPW] Usage : ATPW=");
+ error_no = 1;
+ goto exit;
+ }
+
+ argc = parse_param(arg, argv);
+ if(argc != 2){
+ //at_printf("\r\n[ATPW] ERROR : command format error");
+ error_no = 1;
+ goto exit;
+ }
+
+ if(argv[1] != NULL){
+ wifi_mode = atoi((const char *)(argv[1]));
+ if((wifi_mode!=RTW_MODE_STA) && (wifi_mode!=RTW_MODE_AP) && (wifi_mode!=RTW_MODE_STA_AP) ){
+ //at_printf("\r\n[ATPW] ERROR : parameter must be 1 , 2 or 3");
+ error_no = 2;
+ }
+ }
+
+exit:
+ if(error_no==0)
+ at_printf("\r\n[ATPW] OK");
+ else
+ at_printf("\r\n[ATPW] ERROR:%d",error_no);
+
+ return;
+}
+
+void print_wlan_help(void *arg){
+ at_printf("\r\nWLAN AT COMMAND SET:");
+ at_printf("\r\n==============================");
+ at_printf("\r\n1. Wlan Scan for Network Access Point");
+ at_printf("\r\n # ATWS");
+ at_printf("\r\n2. Connect to an AES AP");
+ at_printf("\r\n # ATPN=,,(,)");
+ at_printf("\r\n3. Create an AES AP");
+ at_printf("\r\n # ATPA=,,,");
+ at_printf("\r\n4. Set auto connect");
+ at_printf("\r\n # ATPG=<0/1>");
+}
+
+#endif // end of #if ATCMD_VER == ATVER_1
+
+#endif // end of #if CONFIG_WLAN
+
+#if CONFIG_LWIP_LAYER
+#if ATCMD_VER == ATVER_1
+void fATWL(void *arg){
+#if CONFIG_SSL_CLIENT
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+ printf("[ATWL]: _AT_WLAN_SSL_CLIENT_\n");
+ argv[0] = "ssl_client";
+ if(!arg){
+ printf("ATWL=SSL_SERVER_HOST\n");
+ return;
+ }
+ if((argc = parse_param(arg, argv)) > 1){
+ if(argc != 2) {
+ printf("ATWL=SSL_SERVER_HOST\n");
+ return;
+ }
+
+ cmd_ssl_client(argc, argv);
+ }
+#else
+ printf("Please set CONFIG_SSL_CLIENT 1 in platform_opts.h to enable ATWL command\n");
+#endif
+}
+
+void fATWI(void *arg){
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+
+ printf("[ATWI]: _AT_WLAN_PING_TEST_\n");
+
+ if(!arg){
+ printf("[ATWI] Usage: ATWI=[host],[options]\n");
+ printf(" -t Ping the specified host until stopped\n");
+ printf(" -n # Number of echo requests to send (default 4 times)\n");
+ printf(" -l # Send buffer size (default 32 bytes)\n");
+ printf(" Example:\n");
+ printf(" ATWI=192.168.1.2,-n,100,-l,5000\n");
+ return;
+ }
+
+ argv[0] = "ping";
+
+ if((argc = parse_param(arg, argv)) > 1){
+ cmd_ping(argc, argv);
+ }
+}
+
+void fATWT(void *arg)
+{
+#if CONFIG_BSD_TCP
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+
+ printf("[ATWT]: _AT_WLAN_TCP_TEST_\n");
+
+ if(!arg){
+ printf("[ATWT] Usage: ATWT=[-s|-c,host|stop],[options]\n");
+ printf(" Client/Server:\n");
+ printf(" stop terminate client & server\n");
+ printf(" -l # length of buffer to read or write (default 1460 Bytes)\n");
+ printf(" -p # server port to listen on/connect to (default 5001)\n");
+ printf(" Server specific:\n");
+ printf(" -s run in server mode\n");
+ printf(" Client specific:\n");
+ printf(" -c run in client mode, connecting to \n");
+ printf(" -d do a bidirectional test simultaneously\n");
+ printf(" -t # time in seconds to transmit for (default 10 secs)\n");
+ printf(" -n #[KM] number of bytes to transmit (instead of -t)\n");
+ printf(" Example:\n");
+ printf(" ATWT=-s,-p,5002\n");
+ printf(" ATWT=-c,192.168.1.2,-t,100,-p,5002\n");
+ return;
+ }
+
+ argv[0] = "tcp";
+
+ if((argc = parse_param(arg, argv)) > 1){
+ cmd_tcp(argc, argv);
+ }
+#else
+ printf("Please set CONFIG_BSD_TCP 1 in platform_opts.h to enable ATWT command\n");
+#endif
+}
+
+void fATWU(void *arg)
+{
+#if CONFIG_BSD_TCP
+ int argc;
+ char *argv[MAX_ARGC] = {0};
+
+ printf("[ATWU]: _AT_WLAN_UDP_TEST_\n");
+
+ if(!arg){
+ printf("[ATWU] Usage: ATWU=[-s|-c,host|stop][options]\n");
+ printf(" Client/Server:\n");
+ printf(" stop terminate client & server\n");
+ printf(" -l # length of buffer to read or write (default 1460 Bytes)\n");
+ printf(" -p # server port to listen on/connect to (default 5001)\n");
+ printf(" Server specific:\n");
+ printf(" -s run in server mode\n");
+ printf(" Client specific:\n");
+ printf(" -b #[KM] for UDP, bandwidth to send at in bits/sec (default 1 Mbit/sec)\n");
+ printf(" -c run in client mode, connecting to \n");
+ printf(" -d do a bidirectional test simultaneously\n");
+ printf(" -t # time in seconds to transmit for (default 10 secs)\n");
+ printf(" -n #[KM] number of bytes to transmit (instead of -t)\n");
+ printf(" -S # set the IP 'type of service'\n");
+ printf(" Example:\n");
+ printf(" ATWU=-s,-p,5002\n");
+ printf(" ATWU=-c,192.168.1.2,-t,100,-p,5002\n");
+ return;
+ }
+
+ argv[0] = "udp";
+
+ if((argc = parse_param(arg, argv)) > 1){
+ cmd_udp(argc, argv);
+ }
+#else
+ printf("Please set CONFIG_BSD_TCP 1 in platform_opts.h to enable ATWU command\n");
+#endif
+}
+#elif ATCMD_VER == ATVER_2 // uart at command
+//move to atcmd_lwip.c
+#endif
+#endif
+log_item_t at_wifi_items[ ] = {
+#if ATCMD_VER == ATVER_1
+#if CONFIG_LWIP_LAYER
+ {"ATWL", fATWL,},
+ {"ATWI", fATWI,},
+ {"ATWT", fATWT,},
+ {"ATWU", fATWU,},
+#endif
+#if CONFIG_WLAN
+ {"ATW0", fATW0,},
+ {"ATW1", fATW1,},
+ {"ATW2", fATW2,},
+ {"ATW3", fATW3,},
+ {"ATW4", fATW4,},
+ {"ATW5", fATW5,},
+ {"ATW6", fATW6,},
+ {"ATWA", fATWA,},
+#ifdef CONFIG_CONCURRENT_MODE
+ {"ATWB", fATWB,},
+#endif
+ {"ATWC", fATWC,},
+ {"ATWD", fATWD,},
+ {"ATWP", fATWP,},
+#if CONFIG_WOWLAN_SERVICE
+ {"ATWV", fATWV,},
+#endif
+ {"ATWR", fATWR,},
+ {"ATWS", fATWS,},
+#if SCAN_WITH_SSID
+ {"ATWs", fATWs,},
+#endif
+#ifdef CONFIG_PROMISC
+ {"ATWM", fATWM,},
+#endif
+ {"ATWZ", fATWZ,},
+#if CONFIG_OTA_UPDATE
+ {"ATWO", fATWO,},
+#endif
+#if CONFIG_WEBSERVER
+ {"ATWE", fATWE,},
+#endif
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+ {"ATWQ", fATWQ,},
+#endif
+#ifdef CONFIG_WPS
+ {"ATWW", fATWW,},
+ {"ATWw", fATWw,}, //wps registrar for softap
+#if CONFIG_ENABLE_P2P
+ {"ATWG", fATWG,}, //p2p start
+ {"ATWH", fATWH,}, //p2p stop
+ {"ATWJ", fATWJ,}, //p2p connect
+ {"ATWK", fATWK,}, //p2p disconnect
+ {"ATWN", fATWN,}, //p2p info
+ {"ATWF", fATWF,}, //p2p find
+ {"ATWg", fATWg,}, //p2p auto go start
+#endif
+#endif
+
+#if CONFIG_AIRKISS
+ {"ATWX", fATWX,},
+#endif
+ {"ATW?", fATWx,},
+ {"ATW+ABC", fATWx,},
+#ifdef CONFIG_POWER_SAVING
+ {"ATXP", fATXP,},
+#endif
+#endif
+#elif ATCMD_VER == ATVER_2 // uart at command
+#if CONFIG_WLAN
+ {"ATPA", fATPA,}, // set AP
+ {"ATPN", fATPN,}, // connect to Network
+ {"ATPH", fATPH,}, // set DHCP mode
+ {"ATPE", fATPE,}, // set static IP for STA
+ {"ATPF", fATPF,}, // set DHCP rule for AP
+ {"ATPG", fATPG,}, // set auto connect
+ {"ATPM", fATPM,}, // set MAC address
+ {"ATPW", fATPW,}, // set Wifi mode
+ {"ATWD", fATWD,}, // WIFI disconnect
+ {"ATWS", fATWS,}, // WIFI scan
+ {"ATW?", fATWx,}, // WIFI Info
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+ {"ATWQ", fATWQ,}, // wifi simpleconfig
+#endif // #if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+#endif // #if CONFIG_WLAN
+#endif // end of #if ATCMD_VER == ATVER_1
+};
+
+#if ATCMD_VER == ATVER_2
+void print_wifi_at(void *arg){
+ int index;
+ int cmd_len = 0;
+
+ cmd_len = sizeof(at_wifi_items)/sizeof(at_wifi_items[0]);
+ for(index = 0; index < cmd_len; index++)
+ at_printf("\r\n%s", at_wifi_items[index].log_cmd);
+}
+#endif
+
+void at_wifi_init(void)
+{
+#if CONFIG_WLAN
+ init_wifi_struct();
+#endif
+ log_service_add_table(at_wifi_items, sizeof(at_wifi_items)/sizeof(at_wifi_items[0]));
+}
+
+#if SUPPORT_LOG_SERVICE
+log_module_init(at_wifi_init);
+#endif
+
+#endif //#ifdef CONFIG_AT_WIFI
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_wifi.h b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_wifi.h
new file mode 100644
index 0000000..e367a88
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/atcmd_wifi.h
@@ -0,0 +1,171 @@
+#ifndef __ATCMD_WIFI_H__
+#define __ATCMD_WIFI_H__
+#include
+#ifdef CONFIG_AT_WIFI
+#include "main.h"
+#include "lwip_netconf.h"
+#ifdef USE_FLASH_EEP
+#include "flash_eep.h"
+#include "feep_config.h"
+#endif
+
+
+#ifndef WLAN0_NAME
+ #define WLAN0_NAME "wlan0"
+#endif
+#ifndef WLAN1_NAME
+ #define WLAN1_NAME "wlan1"
+#endif
+/* Give default value if not defined */
+#ifndef NET_IF_NUM
+ #ifdef CONFIG_CONCURRENT_MODE
+ #define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN) + 1)
+ #else
+ #define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN))
+ #endif // end of CONFIG_CONCURRENT_MODE
+#endif // end of NET_IF_NUM
+
+/*Static IP ADDRESS*/
+#ifndef IP_ADDR0
+#define IP_ADDR0 192
+#define IP_ADDR1 168
+#define IP_ADDR2 3
+#define IP_ADDR3 80
+#endif
+
+/*NETMASK*/
+#ifndef NETMASK_ADDR0
+#define NETMASK_ADDR0 255
+#define NETMASK_ADDR1 255
+#define NETMASK_ADDR2 255
+#define NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef GW_ADDR0
+#define GW_ADDR0 192
+#define GW_ADDR1 168
+#define GW_ADDR2 3
+#define GW_ADDR3 1
+#endif
+
+/*Static IP ADDRESS*/
+#ifndef AP_IP_ADDR0
+#define AP_IP_ADDR0 192
+#define AP_IP_ADDR1 168
+#define AP_IP_ADDR2 43
+#define AP_IP_ADDR3 1
+#endif
+
+/*NETMASK*/
+#ifndef AP_NETMASK_ADDR0
+#define AP_NETMASK_ADDR0 255
+#define AP_NETMASK_ADDR1 255
+#define AP_NETMASK_ADDR2 255
+#define AP_NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef AP_GW_ADDR0
+#define AP_GW_ADDR0 192
+#define AP_GW_ADDR1 168
+#define AP_GW_ADDR2 43
+#define AP_GW_ADDR3 1
+#endif
+
+#endif // CONFIG_AT_WIFI
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+
+#include "wifi_structures.h"
+#include
+typedef struct _UART_LOG_CONF_{
+ u32 BaudRate;
+ u8 DataBits;
+ u8 StopBits;
+ u8 Parity;
+ u8 FlowControl;
+}UART_LOG_CONF, *PUART_LOG_CONF;
+
+#define ATCMD_WIFI_CONN_STORE_MAX_NUM (1)
+struct atcmd_wifi_conf{
+ struct wlan_fast_reconnect reconn[ATCMD_WIFI_CONN_STORE_MAX_NUM];
+ int32_t auto_enable;
+ rtw_wifi_setting_t setting;
+ int32_t reconn_num;
+ int32_t reconn_last_index;
+};
+
+#define ATCMD_LWIP_CONN_STORE_MAX_NUM (1)
+struct atcmd_lwip_conn_info{
+ int32_t role; //client, server or seed
+ uint32_t protocol; //tcp or udp
+ uint32_t remote_addr; //remote ip
+ uint32_t remote_port; //remote port
+ uint32_t local_addr; //locale ip, not used yet
+ uint32_t local_port; //locale port, not used yet
+ uint32_t reserved; //reserve for further use
+};
+struct atcmd_lwip_conf {
+ int32_t enable; //enable or not
+ int32_t conn_num;
+ int32_t last_index;
+ int32_t reserved; //reserve for further use
+ struct atcmd_lwip_conn_info conn[ATCMD_LWIP_CONN_STORE_MAX_NUM];
+};
+
+typedef enum {
+ AT_PARTITION_ALL = 0,
+ AT_PARTITION_UART = FEEP_ID_UART_CFG,
+ AT_PARTITION_WIFI = FEEP_ID_WIFI_CFG,
+ AT_PARTITION_LWIP = FEEP_ID_LWIP_CFG
+} AT_PARTITION;
+
+typedef enum {
+ AT_PARTITION_READ = 0,
+ AT_PARTITION_WRITE = 1,
+ AT_PARTITION_ERASE = 2
+} AT_PARTITION_OP;
+
+//first segment for uart
+#define UART_SETTING_BACKUP_SECTOR (0x8000)
+#define UART_CONF_DATA_OFFSET (0)
+#define UART_CONF_DATA_SIZE ((((sizeof(UART_LOG_CONF)-1)>>2) + 1)<<2)
+
+//second segment for wifi config
+#define WIFI_CONF_DATA_OFFSET (UART_CONF_DATA_OFFSET+UART_CONF_DATA_SIZE)
+#define WIFI_CONF_DATA_SIZE ((((sizeof(struct atcmd_wifi_conf)-1)>>2) + 1)<<2)
+
+//fouth segment for lwip config
+#define LWIP_CONF_DATA_OFFSET (WIFI_CONF_DATA_OFFSET+WIFI_CONF_DATA_SIZE)
+#define LWIP_CONF_DATA_SIZE ((((sizeof(struct atcmd_lwip_conf)-1)>>2) + 1)<<2)
+
+extern void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data, u16 len);
+
+#define ATSTRING_LEN (LOG_SERVICE_BUFLEN)
+extern char at_string[ATSTRING_LEN];
+
+extern unsigned char gAT_Echo; // default echo on
+//extern void uart_at_lock(void);
+//extern void uart_at_unlock(void);
+extern void uart_at_send_string(char *str);
+extern void uart_at_send_buf(u8 *buf, u32 len);
+
+#define at_printf(fmt, args...) do{\
+ /*uart_at_lock();*/\
+ snprintf(at_string, ATSTRING_LEN, fmt, ##args); \
+ uart_at_send_string(at_string);\
+ /*uart_at_unlock();*/\
+ }while(0)
+#define at_print_data(data, size) do{\
+ /*uart_at_lock();*/\
+ uart_at_send_buf(data, size);\
+ /*uart_at_unlock();*/\
+ }while(0)
+
+#else
+#define at_printf(fmt, args...) do{printf(fmt, ##args);}while(0)
+#define at_print_data(data, size) do{__rtl_memDump(data, size, NULL);}while(0)
+#endif//#if CONFIG_EXAMPLE_UART_ATCMD
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/log_service.c b/RTL00_SDKV35a/component/common/api/at_cmd/log_service.c
new file mode 100644
index 0000000..2f36dac
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/log_service.c
@@ -0,0 +1,497 @@
+#include
+#include
+#include
+#include "FreeRTOS.h"
+#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
+#include "freertos_pmu.h"
+#endif
+#include "log_service.h"
+#include "task.h"
+#include "semphr.h"
+#include "main.h"
+#include "wifi_util.h"
+#include "atcmd_wifi.h"
+#include "osdep_api.h"
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+#include "atcmd_lwip.h"
+#endif
+
+#if SUPPORT_LOG_SERVICE
+//======================================================
+struct list_head log_hash[ATC_INDEX_NUM];
+#ifdef CONFIG_AT_USR
+extern void at_user_init(void);
+#endif
+#ifdef CONFIG_AT_WIFI
+extern void at_wifi_init(void);
+#endif
+//extern void at_fs_init(void);
+
+#ifdef CONFIG_AT_SYS
+extern void at_sys_init(void);
+#endif
+#if CONFIG_ETHERNET
+extern void at_ethernet_init(void);
+#endif
+#if CONFIG_GOOGLE_NEST
+extern void at_google_init(void);
+#endif
+#ifdef CONFIG_AT_LWIP
+extern void at_transport_init(void);
+#endif
+//extern void at_app_init(void);
+#if CONFIG_ALINK
+extern void at_cloud_init(void);
+#endif
+
+
+char log_buf[LOG_SERVICE_BUFLEN];
+#if CONFIG_LOG_HISTORY
+char log_history[LOG_HISTORY_LEN][LOG_SERVICE_BUFLEN];
+static unsigned int log_history_count = 0;
+#endif
+xSemaphoreHandle log_rx_interrupt_sema = NULL;
+#if CONFIG_LOG_SERVICE_LOCK
+xSemaphoreHandle log_service_sema = NULL;
+#endif
+extern xSemaphoreHandle uart_rx_interrupt_sema;
+
+#if CONFIG_INIC_EN
+extern unsigned char inic_cmd_ioctl;
+#endif
+
+#if defined (__ICCARM__)
+#pragma section=".data.log_init"
+
+unsigned int __log_init_begin__;
+unsigned int __log_init_end__;
+#elif defined ( __CC_ARM ) || defined(__GNUC__)
+//#pragma section=".data.log_init"
+log_init_t* __log_init_begin__;
+log_init_t* __log_init_end__;
+log_init_t log_init_table[] = {
+
+#ifdef CONFIG_AT_WIFI
+ at_wifi_init,
+#endif
+ // at_fs_init,
+#ifdef CONFIG_AT_SYS
+ at_sys_init,
+#endif
+
+#if CONFIG_ETHERNET
+ at_ethernet_init
+#endif
+
+#if CONFIG_GOOGLE_NEST
+ at_google_init
+#endif
+
+#if CONFIG_TRANSPORT
+ at_transport_init
+#endif
+
+#if CONFIG_ALINK
+ at_cloud_init
+#endif
+
+#ifdef CONFIG_AT_USR
+ at_user_init
+#endif
+
+ // at_app_init
+};
+#else
+#error "not implement, add to linker script"
+extern unsigned int __log_init_begin__;
+extern unsigned int __log_init_end__;
+#endif
+
+#if defined(__GNUC__)
+#define USE_STRSEP
+#endif
+
+//======================================================
+int hash_index(char *str)
+{
+ unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
+ unsigned int hash = 0;
+
+ while (*str)
+ {
+ hash = hash * seed + (*str++);
+ }
+
+ return (hash & 0x7FFFFFFF);
+}
+
+void log_add_new_command(log_item_t *new)
+{
+ int index = hash_index(new->log_cmd)%ATC_INDEX_NUM;
+
+ list_add(&new->node, &log_hash[index]);
+}
+void start_log_service(void);
+void log_service_init(void)
+{
+ int i;
+
+#if defined (__ICCARM__)
+ log_init_t *log_init_table;
+ __log_init_begin__ = (unsigned int)__section_begin(".data.log_init");
+ __log_init_end__ = (unsigned int)__section_end(".data.log_init");
+ log_init_table = (log_init_t *)__log_init_begin__;
+#elif defined(__CC_ARM) || defined(__GNUC__)
+ __log_init_begin__ = log_init_table;
+ __log_init_end__ = log_init_table + sizeof(log_init_table);
+#else
+ #error "not implement"
+#endif
+
+
+ for(i=0;ilog_cmd, cmd) == 0){
+ //printf("%s match %s, search cnt %d\n\r", cmd, item->log_cmd, search_cnt);
+ act = (void*)item->at_act;
+ break;
+ }
+ }
+
+ return act;
+}
+
+void* log_handler(char *cmd)
+{
+ log_act_t action=NULL;
+ char buf[LOG_SERVICE_BUFLEN] = {0};
+ char *copy=buf;
+ char *token = NULL;
+ char *param = NULL;
+ char tok[5] = {0};//'\0'
+#if CONFIG_LOG_HISTORY
+ strcpy(log_history[((log_history_count++)%LOG_HISTORY_LEN)], log_buf);
+#endif
+ strncpy(copy, cmd,LOG_SERVICE_BUFLEN-1);
+
+#if defined(USE_STRSEP)
+ token = _strsep(©, "=");
+ param = copy;
+#else
+ token = strtok(copy, "=");
+ param = strtok(NULL, NULL);
+#endif
+ if(token && (strlen(token) <= 4))
+ strcpy(tok, token);
+ else{
+ //printf("\n\rAT Cmd format error!\n");
+ return NULL;
+ };
+ //printf(" Command %s \n\r ", tok);
+ //printf(" Param %s \n\r", param);
+ action = (log_act_t)log_action(tok);
+
+ if(action){
+ action(param);
+ }
+ return (void*)action;
+
+}
+
+int parse_param(char *buf, char **argv)
+{
+ int argc = 1;
+ char str_buf[LOG_SERVICE_BUFLEN] = "\0";
+ int str_count = 0;
+ int buf_cnt = 0;
+
+ if(buf == NULL)
+ goto exit;
+
+ while((argc < MAX_ARGC) && (*buf != '\0')) {
+ while((*buf == ',') || (*buf == '[') || (*buf == ']')){
+ if((*buf == ',') && (*(buf+1) == ',')){
+ argv[argc] = NULL;
+ argc++;
+ }
+ *buf = '\0';
+ buf++;
+ }
+
+ if(*buf == '\0')
+ break;
+ else if(*buf == '"'){
+ memset(str_buf,'\0',LOG_SERVICE_BUFLEN);
+ str_count = 0;
+ buf_cnt = 0;
+ *buf = '\0';
+ buf ++;
+ if(*buf == '\0')
+ break;
+ argv[argc] = buf;
+ while((*buf != '"')&&(*buf != '\0')){
+ if(*buf == '\\'){
+ buf ++;
+ buf_cnt++;
+ }
+ str_buf[str_count] = *buf;
+ str_count++;
+ buf_cnt++;
+ buf ++;
+ }
+ *buf = '\0';
+ memcpy(buf-buf_cnt,str_buf,buf_cnt);
+ }
+ else{
+ argv[argc] = buf;
+ }
+ argc++;
+ buf++;
+
+ while( (*buf != ',')&&(*buf != '\0')&&(*buf != '[')&&(*buf != ']') )
+ buf++;
+ }
+exit:
+ return argc;
+}
+
+unsigned char gDbgLevel = AT_DBG_ERROR;
+unsigned int gDbgFlag = 0xFFFFFFFF;
+void at_set_debug_level(unsigned char newDbgLevel)
+{
+ gDbgLevel = newDbgLevel;
+}
+
+void at_set_debug_mask(unsigned int newDbgFlag)
+{
+ gDbgFlag = newDbgFlag;
+}
+
+#if SUPPORT_INTERACTIVE_MODE
+extern char uart_buf[64];
+void legency_interactive_handler(unsigned char argc, unsigned char **argv)
+{
+#if 0 //defined(CONFIG_PLATFORM_8195A)
+ if(argc<1)
+ {
+ DiagPrintf("Wrong argument number!\r\n");
+ return;
+ }
+
+
+ DiagPrintf("Wlan Normal Mode\n");
+
+ WlanNormal( argc, argv);
+#else
+ strncpy(uart_buf, log_buf, 63);//uart_buf[64]
+ xSemaphoreGive(uart_rx_interrupt_sema);
+#endif
+}
+#endif
+
+#if CONFIG_WLAN
+#ifndef WLAN0_NAME
+ #define WLAN0_NAME "wlan0"
+#endif
+#ifndef WLAN1_NAME
+ #define WLAN1_NAME "wlan1"
+#endif
+int mp_commnad_handler(char *cmd)
+{
+ char buf[64] = {0};
+ char *token = NULL;
+
+ //strcpy(buf, cmd);
+ strncpy(buf, cmd, (64-1));
+ token = strtok(buf, " ");
+ if(token && (strcmp(buf, "iwpriv") == 0)){
+ token = strtok(NULL, "");
+ wext_private_command(WLAN0_NAME, token, 1);
+ return 0;
+ }
+ return -1;
+}
+#endif
+void print_help_msg(void){
+#if CONFIG_WLAN
+extern void print_wlan_help(void);
+ print_wlan_help();
+#endif
+//add other help message print here
+}
+
+int print_help_handler(char *cmd){
+ if(strcmp(cmd, "help") == 0){
+ print_help_msg();
+ return 0;
+ }
+ return -1;
+}
+
+#if CONFIG_LOG_SERVICE_LOCK
+void log_service_lock(void)
+{
+ RtlDownSema(&log_service_sema);
+}
+
+u32 log_service_lock_timeout(u32 ms)
+{
+ return RtlDownSemaWithTimeout(&log_service_sema, ms);
+}
+
+void log_service_unlock(void)
+{
+ RtlUpSema(&log_service_sema);
+}
+
+void log_service_lock_init(void){
+ RtlInitSema(&log_service_sema, 1);
+}
+#endif
+
+void log_service(void *param)
+{
+ _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\rStart LOG SERVICE MODE\n\r");
+ _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\r# ");
+ while(1){
+ while(xSemaphoreTake(log_rx_interrupt_sema, portMAX_DELAY) != pdTRUE);
+#if CONFIG_LOG_SERVICE_LOCK
+ log_service_lock();
+#endif
+ if(log_handler((char *)log_buf) == NULL){
+#if CONFIG_WLAN
+ if(mp_commnad_handler((char *)log_buf) < 0)
+#endif
+ {
+ #if SUPPORT_INTERACTIVE_MODE
+ print_help_handler((char *)log_buf);
+ legency_interactive_handler(NULL, NULL);
+ #if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+ #endif
+ continue;
+ #else
+ if(print_help_handler((char *)log_buf) < 0){
+ at_printf("\r\nunknown command '%s'", log_buf);
+ }
+ #endif
+ }
+ }
+ log_buf[0] = '\0';
+#if CONFIG_INIC_EN
+ inic_cmd_ioctl = 0;
+#endif
+ _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\r[MEM] After do cmd, available heap %d+%d\n\r", xPortGetFreeHeapSize(), tcm_heap_freeSpace());
+ _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\r\n\n# "); //"#" is needed for mp tool
+#if CONFIG_EXAMPLE_UART_ATCMD
+ if(atcmd_lwip_is_tt_mode())
+ at_printf(STR_END_OF_ATDATA_RET);
+ else
+ at_printf(STR_END_OF_ATCMD_RET);
+#endif
+#if CONFIG_LOG_SERVICE_LOCK
+ log_service_unlock();
+#endif
+#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
+ release_wakelock(WAKELOCK_LOGUART);
+#endif
+ }
+}
+
+#define STACKSIZE 1280
+void start_log_service(void)
+{
+ xTaskHandle CreatedTask;
+ int result;
+
+#if CONFIG_USE_TCM_HEAP
+ extern void *tcm_heap_malloc(int size);
+ void *stack_addr = tcm_heap_malloc(STACKSIZE * sizeof(int));
+
+ if(stack_addr == NULL){
+ }
+
+ result = xTaskGenericCreate(
+ log_service,
+ ( signed portCHAR * ) "log_service",
+ STACKSIZE,
+ NULL,
+ tskIDLE_PRIORITY + 5,
+ &CreatedTask,
+ stack_addr,
+ NULL);
+#else
+ result = xTaskCreate( log_service, ( signed portCHAR * ) "log_service", STACKSIZE, NULL, tskIDLE_PRIORITY + 5, &CreatedTask );
+#endif
+
+ if(result != pdPASS) {
+ printf("\n\r%s xTaskCreate failed", __FUNCTION__);
+ }
+
+}
+
+void fAT_exit(void *arg){
+ printf("\n\rLeave LOG SERVICE");
+ vTaskDelete(NULL);
+}
+#if CONFIG_LOG_HISTORY
+void fAT_log(void *arg){
+ int i = 0;
+ printf("[AT]log history:\n\n\r");
+ if(log_history_count > LOG_HISTORY_LEN){
+ for(i=0; i<4; i++)
+ printf(" %s\n\r", log_history[((log_history_count+i)%LOG_HISTORY_LEN)]);
+ }
+ else{
+ for(i=0; i<(log_history_count-1); i++)
+ printf(" %s\n\r", log_history[i]);
+ }
+}
+#endif
+log_item_t at_log_items[ ] = {
+ {"AT--", fAT_exit,},
+#if CONFIG_LOG_HISTORY
+ {"AT??", fAT_log,},
+#endif
+ {"ATxx", fAT_exit,}
+};
+void at_log_init(void)
+{
+ log_service_add_table(at_log_items, sizeof(at_log_items)/sizeof(at_log_items[0]));
+}
+log_module_init(at_log_init);
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/at_cmd/log_service.h b/RTL00_SDKV35a/component/common/api/at_cmd/log_service.h
new file mode 100644
index 0000000..3e9e7d1
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/at_cmd/log_service.h
@@ -0,0 +1,123 @@
+#ifndef LOG_SERVICE_H
+#define LOG_SERVICE_H
+
+#include "dlist.h"
+/*
+ * Include user defined options first. Anything not defined in these files
+ * will be set to standard values. Override anything you dont like!
+ */
+#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
+#include "platform_opts.h"
+#include "platform_stdlib.h"
+#endif
+
+#ifdef __ICCARM__
+#define STRINGIFY(s) #s
+#define SECTION(_name) _Pragma( STRINGIFY(location=_name))
+#define log_module_init(fn) \
+ SECTION(".data.log_init") __root static void* log_##fn = (void*)fn
+#elif defined(__CC_ARM)
+#define log_module_init(fn) \
+static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
+#define DiagPrintf printf
+#elif defined(__GNUC__)
+#define log_module_init(fn) \
+static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
+#else
+#error "not implement"
+#endif
+
+#define ATC_INDEX_NUM 32
+
+#ifndef SUPPORT_LOG_SERVICE
+#define SUPPORT_LOG_SERVICE 1
+#endif
+
+//LOG_SERVICE_BUFLEN: default, only 63 bytes could be used for keeping input
+// cmd, the last byte is for string end ('\0').
+#ifndef LOG_SERVICE_BUFLEN
+#define LOG_SERVICE_BUFLEN 64
+#endif
+
+#ifndef CONFIG_LOG_HISTORY
+#define CONFIG_LOG_HISTORY 0
+#if CONFIG_LOG_HISTORY
+#define LOG_HISTORY_LEN 5
+#endif
+#endif //#ifndef CONFIG_LOG_HISTORY
+
+#ifndef MAX_ARGC
+#define MAX_ARGC 12
+#endif
+
+#ifndef CONFIG_LOG_SERVICE_LOCK
+#define CONFIG_LOG_SERVICE_LOCK 0 // //to protect log_buf[], only one command processed per time
+#endif
+
+#define AT_BIT(n) (1< " //data transparent transmission indicator
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/lwip_netconf.c b/RTL00_SDKV35a/component/common/api/lwip_netconf.c
new file mode 100644
index 0000000..426fd93
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/lwip_netconf.c
@@ -0,0 +1,406 @@
+/* Includes ------------------------------------------------------------------*/
+#include "lwip/mem.h"
+#include "lwip/memp.h"
+#include "lwip/dhcp.h"
+#include "lwip/dns.h"
+#include "ethernetif.h"
+#include "main.h"
+#include "lwip_netconf.h"
+#if CONFIG_WLAN
+#include "wifi_ind.h"
+#endif
+#if defined(STM32F2XX)
+#include "stm322xg_eval_lcd.h"
+#elif defined(STM32F4XX)
+#include "stm324xg_eval_lcd.h"
+#endif
+#include
+
+
+/*Static IP ADDRESS*/
+#ifndef IP_ADDR0
+#define IP_ADDR0 192
+#define IP_ADDR1 168
+#define IP_ADDR2 1
+#define IP_ADDR3 80
+#endif
+
+/*NETMASK*/
+#ifndef NETMASK_ADDR0
+#define NETMASK_ADDR0 255
+#define NETMASK_ADDR1 255
+#define NETMASK_ADDR2 255
+#define NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef GW_ADDR0
+#define GW_ADDR0 192
+#define GW_ADDR1 168
+#define GW_ADDR2 1
+#define GW_ADDR3 1
+#endif
+
+/*Static IP ADDRESS*/
+#ifndef AP_IP_ADDR0
+#define AP_IP_ADDR0 192
+#define AP_IP_ADDR1 168
+#define AP_IP_ADDR2 43
+#define AP_IP_ADDR3 1
+#endif
+
+/*NETMASK*/
+#ifndef AP_NETMASK_ADDR0
+#define AP_NETMASK_ADDR0 255
+#define AP_NETMASK_ADDR1 255
+#define AP_NETMASK_ADDR2 255
+#define AP_NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef AP_GW_ADDR0
+#define AP_GW_ADDR0 192
+#define AP_GW_ADDR1 168
+#define AP_GW_ADDR2 43
+#define AP_GW_ADDR3 1
+#endif
+
+/*Static IP ADDRESS FOR ETHERNET*/
+#ifndef ETH_IP_ADDR0
+#define ETH_IP_ADDR0 192
+#define ETH_IP_ADDR1 168
+#define ETH_IP_ADDR2 0
+#define ETH_IP_ADDR3 80
+#endif
+
+/*NETMASK FOR ETHERNET*/
+#ifndef ETH_NETMASK_ADDR0
+#define ETH_NETMASK_ADDR0 255
+#define ETH_NETMASK_ADDR1 255
+#define ETH_NETMASK_ADDR2 255
+#define ETH_NETMASK_ADDR3 0
+#endif
+
+/*Gateway address for ethernet*/
+#ifndef ETH_GW_ADDR0
+#define ETH_GW_ADDR0 192
+#define ETH_GW_ADDR1 168
+#define ETH_GW_ADDR2 0
+#define ETH_GW_ADDR3 1
+#endif
+
+/* Private define ------------------------------------------------------------*/
+#define MAX_DHCP_TRIES 5
+
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+
+struct netif xnetif[NET_IF_NUM]; /* network interface structure */
+/* Private functions ---------------------------------------------------------*/
+/**
+ * @brief Initializes the lwIP stack
+ * @param None
+ * @retval None
+ */
+#if CONFIG_WLAN
+extern int error_flag;
+extern rtw_mode_t wifi_mode;
+#endif
+
+int lwip_init_done = 0;
+
+void LwIP_Init(void)
+{
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+ int8_t idx = 0;
+ /* Create tcp_ip stack thread */
+ tcpip_init( NULL, NULL );
+
+ /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
+ struct ip_addr *netmask, struct ip_addr *gw,
+ void *state, err_t (* init)(struct netif *netif),
+ err_t (* input)(struct pbuf *p, struct netif *netif))
+
+ Adds your network interface to the netif_list. Allocate a struct
+ netif and pass a pointer to this structure as the first argument.
+ Give pointers to cleared ip_addr structures when using DHCP,
+ or fill them with sane numbers otherwise. The state pointer may be NULL.
+
+ The init function pointer must point to a initialization function for
+ your ethernet netif interface. The following code illustrates it's use.*/
+ //printf("NET_IF_NUM:%d\n\r",NET_IF_NUM);
+ for(idx=NET_IF_NUM - 1;idx>=0;idx--){
+ if(idx==0){
+ IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ }
+ else{
+ IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
+ IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
+ IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
+ }
+#if CONFIG_ETHERNET
+ if(idx == NET_IF_NUM - 1)
+ {
+ IP4_ADDR(&ipaddr, ETH_IP_ADDR0, ETH_IP_ADDR1, ETH_IP_ADDR2, ETH_IP_ADDR3);
+ IP4_ADDR(&netmask, ETH_NETMASK_ADDR0, ETH_NETMASK_ADDR1 , ETH_NETMASK_ADDR2, ETH_NETMASK_ADDR3);
+ IP4_ADDR(&gw, ETH_GW_ADDR0, ETH_GW_ADDR1, ETH_GW_ADDR2, ETH_GW_ADDR3);
+ }
+#endif
+ xnetif[idx].name[0] = 'r';
+ xnetif[idx].name[1] = '0'+idx;
+
+#if CONFIG_ETHERNET
+ if(idx == NET_IF_NUM - 1)
+ netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_mii_init, &tcpip_input);
+ else
+ netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
+#else
+ netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
+#endif
+ printf("interface %d is initialized\n", idx);
+
+ }
+
+ /* Registers the default network interface. */
+ netif_set_default(&xnetif[0]);
+
+ /* When the netif is fully configured this function must be called.*/
+ for(idx = 0;idx < NET_IF_NUM;idx++)
+ netif_set_up(&xnetif[idx]);
+
+ lwip_init_done = 1;
+}
+
+/**
+ * @brief LwIP_DHCP_Process_Handle
+ * @param None
+ * @retval None
+ */
+uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state) {
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+ uint32_t IPaddress;
+ uint8_t iptab[4];
+ uint8_t DHCP_state;
+ int mscnt = 0;
+ struct netif *pnetif = NULL;
+
+ DHCP_state = dhcp_state;
+
+#if !CONFIG_ETHERNET
+ if (idx > 1)
+ idx = 1;
+#endif
+
+ pnetif = &xnetif[idx];
+ if (DHCP_state == 0) {
+ pnetif->ip_addr.addr = 0;
+ pnetif->netmask.addr = 0;
+ pnetif->gw.addr = 0;
+ }
+
+ for (;;) {
+ //printf("\n\r ========DHCP_state:%d============\n\r",DHCP_state);
+ switch (DHCP_state) {
+ case DHCP_START: {
+#if CONFIG_WLAN
+ wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl);
+#endif
+ dhcp_start(pnetif);
+ IPaddress = 0;
+ DHCP_state = DHCP_WAIT_ADDRESS;
+ }
+ break;
+
+ case DHCP_WAIT_ADDRESS: {
+ /* Read the new IP address */
+ IPaddress = pnetif->ip_addr.addr;
+
+ if (IPaddress != 0) {
+ DHCP_state = DHCP_ADDRESS_ASSIGNED;
+#if CONFIG_WLAN
+ wifi_reg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl, NULL);
+#endif
+
+ /* Stop DHCP */
+ // dhcp_stop(pnetif); /* can not stop, need to renew, Robbie*/
+ iptab[0] = (uint8_t) (IPaddress >> 24);
+ iptab[1] = (uint8_t) (IPaddress >> 16);
+ iptab[2] = (uint8_t) (IPaddress >> 8);
+ iptab[3] = (uint8_t) (IPaddress);
+ printf("Interface %d IP address: %d.%d.%d.%d\n", idx, iptab[3],
+ iptab[2], iptab[1], iptab[0]);
+#if CONFIG_WLAN
+ error_flag = RTW_NO_ERROR;
+#endif
+ return DHCP_ADDRESS_ASSIGNED;
+ } else {
+ /* DHCP timeout */
+ if (pnetif->dhcp->tries > MAX_DHCP_TRIES) {
+ DHCP_state = DHCP_TIMEOUT;
+
+ /* Stop DHCP */
+ dhcp_stop(pnetif);
+
+ /* Static address used */
+ IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ netif_set_addr(pnetif, &ipaddr, &netmask, &gw);
+
+ iptab[0] = IP_ADDR3;
+ iptab[1] = IP_ADDR2;
+ iptab[2] = IP_ADDR1;
+ iptab[3] = IP_ADDR0;
+ printf("Interface %d DHCP timeout\n", idx);
+ printf("Static IP address: %d.%d.%d.%d\n", iptab[3], iptab[2], iptab[1], iptab[0]);
+#if CONFIG_WLAN
+ error_flag = RTW_DHCP_FAIL;
+#endif
+ return DHCP_TIMEOUT;
+ } else {
+ //sys_msleep(DHCP_FINE_TIMER_MSECS);
+ vTaskDelay(DHCP_FINE_TIMER_MSECS);
+ dhcp_fine_tmr();
+ mscnt += DHCP_FINE_TIMER_MSECS;
+ if (mscnt >= DHCP_COARSE_TIMER_SECS * 1000) {
+ dhcp_coarse_tmr();
+ mscnt = 0;
+ }
+ }
+ }
+ }
+ break;
+ case DHCP_RELEASE_IP:
+#if CONFIG_WLAN
+ wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl);
+#endif
+ printf("LwIP_DHCP: Release ip\n");
+ dhcp_release_unicast(pnetif);
+ return DHCP_RELEASE_IP;
+ case DHCP_STOP:
+#if CONFIG_WLAN
+ wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl);
+#endif
+ printf("LwIP_DHCP: dhcp stop.\n");
+ dhcp_stop(pnetif);
+ return DHCP_STOP;
+ default:
+ break;
+ }
+ }
+}
+
+uint8_t* LwIP_GetMAC(struct netif *pnetif)
+{
+ return (uint8_t *) (pnetif->hwaddr);
+}
+
+uint8_t* LwIP_GetIP(struct netif *pnetif)
+{
+ return (uint8_t *) &(pnetif->ip_addr);
+}
+
+uint8_t* LwIP_GetGW(struct netif *pnetif)
+{
+ return (uint8_t *) &(pnetif->gw);
+}
+
+uint8_t* LwIP_GetMASK(struct netif *pnetif)
+{
+ return (uint8_t *) &(pnetif->netmask);
+}
+
+uint8_t* LwIP_GetBC(struct netif *pnetif)
+{
+ return (uint8_t *) &(pnetif->dhcp->offered_bc_addr);
+}
+
+#if LWIP_DNS
+void LwIP_GetDNS(struct ip_addr* dns)
+{
+ *dns = dns_getserver(0);
+}
+
+void LwIP_SetDNS(struct ip_addr* dns)
+{
+ dns_setserver(0, dns);
+}
+#endif
+void LwIP_UseStaticIP(struct netif *pnetif)
+{
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+
+ /* Static address used */
+ if(pnetif->name[1] == '0'){
+#if CONFIG_WLAN
+ if(wifi_mode == RTW_MODE_STA){
+ IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ }
+ else if(wifi_mode == RTW_MODE_AP){
+ IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
+ IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
+ IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
+ }
+#endif
+ }else{
+ IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
+ IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
+ IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
+ }
+
+ netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
+}
+#if LWIP_AUTOIP
+#include
+
+void LwIP_AUTOIP(struct netif *pnetif)
+{
+ uint8_t *ip = LwIP_GetIP(pnetif);
+
+ autoip_start(pnetif);
+
+ while((pnetif->autoip->state == AUTOIP_STATE_PROBING) || (pnetif->autoip->state == AUTOIP_STATE_ANNOUNCING)) {
+ vTaskDelay(1000);
+ }
+
+ if(*((uint32_t *) ip) == 0) {
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+
+ printf("AUTOIP timeout\n");
+
+ /* Static address used */
+ IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
+ printf("Static IP address : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ }
+ else {
+ printf("Link-local address: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ }
+}
+#endif
+#if LWIP_IPV6
+/* Get IPv6 address with lwip 1.5.0 */
+void LwIP_AUTOIP_IPv6(struct netif *pnetif)
+{
+ uint8_t *ipv6 = (uint8_t *) &(pnetif->ip6_addr[0].addr[0]);
+
+ netif_create_ip6_linklocal_address(pnetif, 1);
+ printf("IPv6 link-local address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
+ ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5], ipv6[6], ipv6[7],
+ ipv6[8], ipv6[9], ipv6[10], ipv6[11], ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
+}
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/lwip_netconf.h b/RTL00_SDKV35a/component/common/api/lwip_netconf.h
new file mode 100644
index 0000000..8ac0e46
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/lwip_netconf.h
@@ -0,0 +1,91 @@
+/**
+ ******************************************************************************
+ * @file netconf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 07-October-2011
+ * @brief This file contains all the functions prototypes for the netconf.c
+ * file.
+ ******************************************************************************
+ * @attention
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * © COPYRIGHT 2011 STMicroelectronics
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __NETCONF_H
+#define __NETCONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#include "tcpip.h"
+/* Includes ------------------------------------------------------------------*/
+#include
+#include "platform_opts.h"
+#include "autoconf.h"
+
+// macros
+/* Give default value if not defined */
+#ifndef NET_IF_NUM
+ #ifdef CONFIG_CONCURRENT_MODE
+ #define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN) + 1)
+ #else
+ #define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN))
+ #endif // end of CONFIG_CONCURRENT_MODE
+#endif // end of NET_IF_NUM
+
+/* Private typedef -----------------------------------------------------------*/
+typedef enum
+{
+ DHCP_START=0,
+ DHCP_WAIT_ADDRESS,
+ DHCP_ADDRESS_ASSIGNED,
+ DHCP_RELEASE_IP,
+ DHCP_STOP,
+ DHCP_TIMEOUT
+} DHCP_State_TypeDef;
+
+/* Extern functions ------------------------------------------------------------*/
+void wifi_rx_beacon_hdl( char* buf, int buf_len, int flags, void* userdata);
+
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void LwIP_Init(void);
+uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state);
+unsigned char* LwIP_GetMAC(struct netif *pnetif);
+unsigned char* LwIP_GetIP(struct netif *pnetif);
+unsigned char* LwIP_GetGW(struct netif *pnetif);
+uint8_t* LwIP_GetMASK(struct netif *pnetif);
+uint8_t* LwIP_GetBC(struct netif *pnetif);
+#if LWIP_DNS
+void LwIP_GetDNS(struct ip_addr* dns);
+void LwIP_SetDNS(struct ip_addr* dns);
+#endif
+void LwIP_UseStaticIP(struct netif *pnetif);
+#if LWIP_AUTOIP
+void LwIP_AUTOIP(struct netif *pnetif);
+#endif
+#if LWIP_IPV6
+void LwIP_AUTOIP_IPv6(struct netif *pnetif);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NETCONF_H */
+
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/RTL00_SDKV35a/component/common/api/network/include/lwipopts.h.0 b/RTL00_SDKV35a/component/common/api/network/include/lwipopts.h.0
new file mode 100644
index 0000000..99c159b
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/lwipopts.h.0
@@ -0,0 +1,304 @@
+/**
+ ******************************************************************************
+ * @file lwipopts.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 07-October-2011
+ * @brief lwIP Options Configuration.
+ * This file is based on Utilities\lwip_v1.3.2\src\include\lwip\opt.h
+ * and contains the lwIP configuration for the STM32F2x7 demonstration.
+ ******************************************************************************
+ * @attention
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * © COPYRIGHT 2011 STMicroelectronics
+ ******************************************************************************
+ */
+
+#ifndef __LWIPOPTS_H__
+#define __LWIPOPTS_H__
+
+#include
+#include "platform_opts.h"
+#define WIFI_LOGO_CERTIFICATION_CONFIG 0 //for ping 10k test buffer setting
+
+/**
+ * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
+ * critical regions during buffer allocation, deallocation and memory
+ * allocation and deallocation.
+ */
+#define SYS_LIGHTWEIGHT_PROT 1
+
+/* Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores
+ should be used instead */
+#define LWIP_COMPAT_MUTEX 1
+
+#define ETHARP_TRUST_IP_MAC 0
+#define IP_REASSEMBLY 1
+#define IP_FRAG 1
+#define ARP_QUEUEING 0
+
+/**
+ * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
+ * use lwIP facilities.
+ */
+#define NO_SYS 0
+
+/* ---------- Memory options ---------- */
+/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
+ lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
+ byte alignment -> define MEM_ALIGNMENT to 2. */
+#define MEM_ALIGNMENT 4
+
+/* MEM_SIZE: the size of the heap memory. If the application will send
+a lot of data that needs to be copied, this should be set high. */
+#if WIFI_LOGO_CERTIFICATION_CONFIG
+ #define MEM_SIZE (10*1024) //for ping 10k test
+#else
+ #define MEM_SIZE (5*1024)
+#endif
+
+/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
+ sends a lot of data out of ROM (or other static memory), this
+ should be set high. */
+#define MEMP_NUM_PBUF 100
+/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
+ per active UDP "connection". */
+#define MEMP_NUM_UDP_PCB 6
+/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
+ connections. */
+#define MEMP_NUM_TCP_PCB 10
+/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
+ connections. */
+#define MEMP_NUM_TCP_PCB_LISTEN 5
+/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
+ segments. */
+#define MEMP_NUM_TCP_SEG 20
+/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
+ timeouts. */
+#define MEMP_NUM_SYS_TIMEOUT 10
+
+
+/* ---------- Pbuf options ---------- */
+/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
+#if WIFI_LOGO_CERTIFICATION_CONFIG
+ #define PBUF_POOL_SIZE 30 //for ping 10k test
+#else
+ #define PBUF_POOL_SIZE 20
+#endif
+
+/* IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled.*/
+#if WIFI_LOGO_CERTIFICATION_CONFIG
+ #define IP_REASS_MAX_PBUFS 30 //for ping 10k test
+#else
+ #define IP_REASS_MAX_PBUFS 10
+#endif
+
+/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
+#define PBUF_POOL_BUFSIZE 500
+
+
+/* ---------- TCP options ---------- */
+#define LWIP_TCP 1
+#define TCP_TTL 255
+
+/* Controls if TCP should queue segments that arrive out of
+ order. Define to 0 if your device is low on memory. */
+#define TCP_QUEUE_OOSEQ 1
+
+/* TCP Maximum segment size. */
+#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
+
+/* TCP sender buffer space (bytes). */
+#define TCP_SND_BUF (5*TCP_MSS)
+
+/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
+ as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
+
+#define TCP_SND_QUEUELEN (4* TCP_SND_BUF/TCP_MSS)
+
+/* TCP receive window. */
+#define TCP_WND (2*TCP_MSS)
+
+
+/* ---------- ICMP options ---------- */
+#define LWIP_ICMP 1
+
+/* ---------- ARP options ----------- */
+#define LWIP_ARP 1
+
+/* ---------- DHCP options ---------- */
+/* Define LWIP_DHCP to 1 if you want DHCP configuration of
+ interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
+ turning this on does currently not work. */
+#define LWIP_DHCP 1
+
+
+/* ---------- UDP options ---------- */
+#define LWIP_UDP 1
+#define UDP_TTL 255
+/* ---------- DNS options ---------- */
+#define LWIP_DNS 1
+
+/* ---------- UPNP options --------- */
+#define LWIP_UPNP 0
+
+/* Support Multicast */
+#define LWIP_IGMP 1
+#define LWIP_RAND() rand()
+
+/* Support TCP Keepalive */
+#define LWIP_TCP_KEEPALIVE 1
+
+/*LWIP_UART_ADAPTER==1: Enable LWIP_UART_ADAPTER when CONFIG_GAGENT is enabled,
+ because some GAGENT functions denpond on the following macro definitions.*/
+#define LWIP_UART_ADAPTER 0
+
+#if LWIP_UART_ADAPTER
+#undef LWIP_SO_SNDTIMEO
+#define LWIP_SO_SNDTIMEO 1
+
+#undef SO_REUSE
+#define SO_REUSE 1
+
+#undef MEMP_NUM_NETCONN
+#define MEMP_NUM_NETCONN 10
+
+#undef TCP_WND
+#define TCP_WND (4*TCP_MSS)
+
+#define TCP_KEEPIDLE_DEFAULT 10000UL
+#define TCP_KEEPINTVL_DEFAULT 1000UL
+#define TCP_KEEPCNT_DEFAULT 10U
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+#undef LWIP_SO_SNDTIMEO
+#define LWIP_SO_SNDTIMEO 1
+
+#undef SO_REUSE
+#define SO_REUSE 1
+
+#undef MEMP_NUM_NETCONN
+#define MEMP_NUM_NETCONN 10
+
+#undef MEMP_NUM_TCP_PCB
+#define MEMP_NUM_TCP_PCB (MEMP_NUM_NETCONN)
+
+#undef MEMP_NUM_UDP_PCB
+#define MEMP_NUM_UDP_PCB (MEMP_NUM_NETCONN)
+
+#undef TCP_WND
+#define TCP_WND (4*TCP_MSS)
+
+#define TCP_KEEPIDLE_DEFAULT 10000UL
+#define TCP_KEEPINTVL_DEFAULT 1000UL
+#define TCP_KEEPCNT_DEFAULT 10U
+
+#define ERRNO 1
+#endif
+
+/* ---------- Statistics options ---------- */
+#define LWIP_STATS 0
+#define LWIP_PROVIDE_ERRNO 1
+
+
+/*
+ --------------------------------------
+ ---------- Checksum options ----------
+ --------------------------------------
+*/
+
+/*
+The STM32F2x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
+ - To use this feature let the following define uncommented.
+ - To disable it and process by CPU comment the the checksum.
+*/
+//Do checksum by lwip - WLAN nic does not support Checksum offload
+//#define CHECKSUM_BY_HARDWARE
+
+
+#ifdef CHECKSUM_BY_HARDWARE
+ /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
+ #define CHECKSUM_GEN_IP 0
+ /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
+ #define CHECKSUM_GEN_UDP 0
+ /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
+ #define CHECKSUM_GEN_TCP 0
+ /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
+ #define CHECKSUM_CHECK_IP 0
+ /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
+ #define CHECKSUM_CHECK_UDP 0
+ /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
+ #define CHECKSUM_CHECK_TCP 0
+#else
+ /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
+ #define CHECKSUM_GEN_IP 1
+ /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
+ #define CHECKSUM_GEN_UDP 1
+ /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
+ #define CHECKSUM_GEN_TCP 1
+ /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
+ #define CHECKSUM_CHECK_IP 1
+ /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
+ #define CHECKSUM_CHECK_UDP 1
+ /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
+ #define CHECKSUM_CHECK_TCP 1
+#endif
+
+
+/*
+ ----------------------------------------------
+ ---------- Sequential layer options ----------
+ ----------------------------------------------
+*/
+/**
+ * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
+ */
+#define LWIP_NETCONN 1
+
+/*
+ ------------------------------------
+ ---------- Socket options ----------
+ ------------------------------------
+*/
+/**
+ * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
+ */
+#define LWIP_SOCKET 1
+
+/*
+ -----------------------------------
+ ---------- DEBUG options ----------
+ -----------------------------------
+*/
+
+#define LWIP_DEBUG 0
+
+
+/*
+ ---------------------------------
+ ---------- OS options ----------
+ ---------------------------------
+*/
+
+#define TCPIP_THREAD_STACKSIZE 1000
+#define TCPIP_MBOX_SIZE 6
+#define DEFAULT_UDP_RECVMBOX_SIZE 6
+#define DEFAULT_TCP_RECVMBOX_SIZE 6
+#define DEFAULT_RAW_RECVMBOX_SIZE 6
+#define DEFAULT_ACCEPTMBOX_SIZE 6
+#define DEFAULT_THREAD_STACKSIZE 500
+#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 2)
+
+
+
+#endif /* __LWIPOPTS_H__ */
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/RTL00_SDKV35a/component/common/api/network/include/lwipopts.h.1 b/RTL00_SDKV35a/component/common/api/network/include/lwipopts.h.1
new file mode 100644
index 0000000..b51d92e
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/lwipopts.h.1
@@ -0,0 +1,312 @@
+/**
+ ******************************************************************************
+ * @file lwipopts.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 07-October-2011
+ * @brief lwIP Options Configuration.
+ * This file is based on Utilities\lwip_v1.3.2\src\include\lwip\opt.h
+ * and contains the lwIP configuration for the STM32F2x7 demonstration.
+ ******************************************************************************
+ * @attention
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * © COPYRIGHT 2011 STMicroelectronics
+ ******************************************************************************
+ */
+
+#ifndef __LWIPOPTS_H__
+#define __LWIPOPTS_H__
+
+#include
+#include "platform_opts.h"
+#define WIFI_LOGO_CERTIFICATION_CONFIG 0 //for ping 10k test buffer setting
+
+/**
+ * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
+ * critical regions during buffer allocation, deallocation and memory
+ * allocation and deallocation.
+ */
+#define SYS_LIGHTWEIGHT_PROT 1
+
+/* Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores
+ should be used instead */
+#define LWIP_COMPAT_MUTEX 1
+
+#define ETHARP_TRUST_IP_MAC 0
+#define IP_REASSEMBLY 1
+#define IP_FRAG 1
+#define ARP_QUEUEING 0
+
+/**
+ * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
+ * use lwIP facilities.
+ */
+#define NO_SYS 0
+
+/* ---------- Memory options ---------- */
+/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
+ lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
+ byte alignment -> define MEM_ALIGNMENT to 2. */
+#define MEM_ALIGNMENT 4
+
+/* MEM_SIZE: the size of the heap memory. If the application will send
+a lot of data that needs to be copied, this should be set high. */
+#if WIFI_LOGO_CERTIFICATION_CONFIG
+ #define MEM_SIZE (10*1024) //for ping 10k test
+#else
+ #define MEM_SIZE (5*1024)
+#endif
+
+/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
+ sends a lot of data out of ROM (or other static memory), this
+ should be set high. */
+#define MEMP_NUM_PBUF 100
+/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
+ per active UDP "connection". */
+#define MEMP_NUM_UDP_PCB 6
+/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
+ connections. */
+#define MEMP_NUM_TCP_PCB 10
+/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
+ connections. */
+#define MEMP_NUM_TCP_PCB_LISTEN 5
+/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
+ segments. */
+#define MEMP_NUM_TCP_SEG 20
+/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
+ timeouts. */
+#define MEMP_NUM_SYS_TIMEOUT 10
+
+
+/* ---------- Pbuf options ---------- */
+/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
+#if WIFI_LOGO_CERTIFICATION_CONFIG
+ #define PBUF_POOL_SIZE 30 //for ping 10k test
+#else
+ #define PBUF_POOL_SIZE 20
+#endif
+
+/* IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled.*/
+#if WIFI_LOGO_CERTIFICATION_CONFIG
+ #define IP_REASS_MAX_PBUFS 30 //for ping 10k test
+#else
+ #define IP_REASS_MAX_PBUFS 10
+#endif
+
+/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
+#define PBUF_POOL_BUFSIZE 500
+
+
+/* ---------- TCP options ---------- */
+#define LWIP_TCP 1
+#define TCP_TTL 255
+
+/* Controls if TCP should queue segments that arrive out of
+ order. Define to 0 if your device is low on memory. */
+#define TCP_QUEUE_OOSEQ 1
+
+/* TCP Maximum segment size. */
+#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
+
+/* TCP sender buffer space (bytes). */
+#define TCP_SND_BUF (5*TCP_MSS)
+
+/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
+ as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
+
+#define TCP_SND_QUEUELEN (4* TCP_SND_BUF/TCP_MSS)
+
+/* TCP receive window. */
+#define TCP_WND (2*TCP_MSS)
+
+
+/* ---------- ICMP options ---------- */
+#define LWIP_ICMP 1
+
+/* ---------- ARP options ----------- */
+#define LWIP_ARP 1
+
+/* ---------- DHCP options ---------- */
+/* Define LWIP_DHCP to 1 if you want DHCP configuration of
+ interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
+ turning this on does currently not work. */
+#define LWIP_DHCP 1
+
+
+/* ---------- UDP options ---------- */
+#define LWIP_UDP 1
+#define UDP_TTL 255
+/* ---------- DNS options ---------- */
+#define LWIP_DNS 1
+
+/* ---------- UPNP options --------- */
+#define LWIP_UPNP 0
+
+/* Support Multicast */
+#define LWIP_IGMP 1
+#define LWIP_RAND() rand()
+
+/* Support TCP Keepalive */
+#define LWIP_TCP_KEEPALIVE 1
+
+/*LWIP_UART_ADAPTER==1: Enable LWIP_UART_ADAPTER when CONFIG_GAGENT is enabled,
+ because some GAGENT functions denpond on the following macro definitions.*/
+#if CONFIG_EXAMPLE_UART_ADAPTER
+#define LWIP_UART_ADAPTER 1
+#else
+#define LWIP_UART_ADAPTER 0
+#endif
+
+#if LWIP_UART_ADAPTER
+#undef LWIP_SO_SNDTIMEO
+#define LWIP_SO_SNDTIMEO 1
+
+#undef SO_REUSE
+#define SO_REUSE 1
+
+#undef MEMP_NUM_NETCONN
+#define MEMP_NUM_NETCONN 10
+
+#undef TCP_WND
+#define TCP_WND (4*TCP_MSS)
+
+#define TCP_KEEPIDLE_DEFAULT 10000UL
+#define TCP_KEEPINTVL_DEFAULT 1000UL
+#define TCP_KEEPCNT_DEFAULT 10U
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+#undef LWIP_SO_SNDTIMEO
+#define LWIP_SO_SNDTIMEO 1
+
+#undef SO_REUSE
+#define SO_REUSE 1
+
+#undef MEMP_NUM_NETCONN
+#define MEMP_NUM_NETCONN 10
+
+#undef MEMP_NUM_TCP_PCB
+#define MEMP_NUM_TCP_PCB (MEMP_NUM_NETCONN)
+
+#undef MEMP_NUM_UDP_PCB
+#define MEMP_NUM_UDP_PCB (MEMP_NUM_NETCONN)
+
+#undef TCP_WND
+#define TCP_WND (4*TCP_MSS)
+
+#define TCP_KEEPIDLE_DEFAULT 10000UL
+#define TCP_KEEPINTVL_DEFAULT 1000UL
+#define TCP_KEEPCNT_DEFAULT 10U
+
+#define ERRNO 1
+#endif
+
+/* ---------- Statistics options ---------- */
+#define LWIP_STATS 0
+#define LWIP_PROVIDE_ERRNO 1
+
+
+/*
+ --------------------------------------
+ ---------- Checksum options ----------
+ --------------------------------------
+*/
+
+/*
+The STM32F2x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
+ - To use this feature let the following define uncommented.
+ - To disable it and process by CPU comment the the checksum.
+*/
+//Do checksum by lwip - WLAN nic does not support Checksum offload
+//#define CHECKSUM_BY_HARDWARE
+
+
+#ifdef CHECKSUM_BY_HARDWARE
+ /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
+ #define CHECKSUM_GEN_IP 0
+ /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
+ #define CHECKSUM_GEN_UDP 0
+ /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
+ #define CHECKSUM_GEN_TCP 0
+ /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
+ #define CHECKSUM_CHECK_IP 0
+ /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
+ #define CHECKSUM_CHECK_UDP 0
+ /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
+ #define CHECKSUM_CHECK_TCP 0
+#else
+ /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
+ #define CHECKSUM_GEN_IP 1
+ /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
+ #define CHECKSUM_GEN_UDP 1
+ /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
+ #define CHECKSUM_GEN_TCP 1
+ /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
+ #define CHECKSUM_CHECK_IP 1
+ /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
+ #define CHECKSUM_CHECK_UDP 1
+ /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
+ #define CHECKSUM_CHECK_TCP 1
+#endif
+
+
+/*
+ ----------------------------------------------
+ ---------- Sequential layer options ----------
+ ----------------------------------------------
+*/
+/**
+ * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
+ */
+#define LWIP_NETCONN 1
+
+/*
+ ------------------------------------
+ ---------- Socket options ----------
+ ------------------------------------
+*/
+/**
+ * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
+ */
+#define LWIP_SOCKET 1
+
+/*
+ -----------------------------------
+ ---------- DEBUG options ----------
+ -----------------------------------
+*/
+
+#define LWIP_DEBUG 0
+
+
+/*
+ ---------------------------------
+ ---------- OS options ----------
+ ---------------------------------
+*/
+
+#define TCPIP_THREAD_STACKSIZE 1000
+#define TCPIP_MBOX_SIZE 6
+#define DEFAULT_UDP_RECVMBOX_SIZE 6
+#define DEFAULT_TCP_RECVMBOX_SIZE 6
+#define DEFAULT_RAW_RECVMBOX_SIZE 6
+#define DEFAULT_ACCEPTMBOX_SIZE 6
+#define DEFAULT_THREAD_STACKSIZE 500
+#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 2)
+
+/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
+ * by your system, set this to 0 and include in cc.h */
+#if defined(_SYS__TIMEVAL_H_)
+#define LWIP_TIMEVAL_PRIVATE 0
+#endif
+
+#endif /* __LWIPOPTS_H__ */
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/RTL00_SDKV35a/component/common/api/network/include/main.h.0 b/RTL00_SDKV35a/component/common/api/network/include/main.h.0
new file mode 100644
index 0000000..756cbdf
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/main.h.0
@@ -0,0 +1,68 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+#include
+
+//#define CONFIG_WLAN 1
+
+
+/* Header file declaration*/
+void wlan_network();
+
+
+/* Interactive Mode */
+#define SERIAL_DEBUG_RX 1
+#if defined(__ICCARM__)
+static
+#endif
+char uart_buf[64];
+
+
+/* WLAN and Netork */
+#define STA_MODE_SSID "ap" /* Set SSID here */
+#define AP_MODE_SSID "wlan_ap_ssid" /* Set SSID here */
+#define AP_DEFAULT_CH 6
+#define WLAN0_NAME "wlan0"
+#define WLAN1_NAME "wlan1"
+#define WPA_PASSPHRASE "1234567890" /* Max 32 cahracters */
+#define WEP40_KEY {0x12, 0x34, 0x56, 0x78, 0x90}
+
+/*Static IP ADDRESS*/
+#define IP_ADDR0 192
+#define IP_ADDR1 168
+#define IP_ADDR2 3
+#define IP_ADDR3 80
+
+/*NETMASK*/
+#define NETMASK_ADDR0 255
+#define NETMASK_ADDR1 255
+#define NETMASK_ADDR2 255
+#define NETMASK_ADDR3 0
+
+/*Gateway Address*/
+#define GW_ADDR0 192
+#define GW_ADDR1 168
+#define GW_ADDR2 3
+#define GW_ADDR3 1
+
+/*******************************************/
+
+/*Static IP ADDRESS*/
+#define AP_IP_ADDR0 192
+#define AP_IP_ADDR1 168
+#define AP_IP_ADDR2 43
+#define AP_IP_ADDR3 1
+
+/*NETMASK*/
+#define AP_NETMASK_ADDR0 255
+#define AP_NETMASK_ADDR1 255
+#define AP_NETMASK_ADDR2 255
+#define AP_NETMASK_ADDR3 0
+
+/*Gateway Address*/
+#define AP_GW_ADDR0 192
+#define AP_GW_ADDR1 168
+#define AP_GW_ADDR2 43
+#define AP_GW_ADDR3 1
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/network/include/main.h.1 b/RTL00_SDKV35a/component/common/api/network/include/main.h.1
new file mode 100644
index 0000000..5cef1a6
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/main.h.1
@@ -0,0 +1,68 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+#include
+
+//#define CONFIG_WLAN 1
+
+
+/* Header file declaration*/
+void wlan_network();
+
+
+/* Interactive Mode */
+#define SERIAL_DEBUG_RX 1
+#if defined(__ICCARM__)
+static
+#endif
+extern char uart_buf[64];
+
+
+/* WLAN and Netork */
+#define STA_MODE_SSID "ap" /* Set SSID here */
+#define AP_MODE_SSID "wlan_ap_ssid" /* Set SSID here */
+#define AP_DEFAULT_CH 6
+#define WLAN0_NAME "wlan0"
+#define WLAN1_NAME "wlan1"
+#define WPA_PASSPHRASE "1234567890" /* Max 32 cahracters */
+#define WEP40_KEY {0x12, 0x34, 0x56, 0x78, 0x90}
+
+/*Static IP ADDRESS*/
+#define IP_ADDR0 192
+#define IP_ADDR1 168
+#define IP_ADDR2 3
+#define IP_ADDR3 80
+
+/*NETMASK*/
+#define NETMASK_ADDR0 255
+#define NETMASK_ADDR1 255
+#define NETMASK_ADDR2 255
+#define NETMASK_ADDR3 0
+
+/*Gateway Address*/
+#define GW_ADDR0 192
+#define GW_ADDR1 168
+#define GW_ADDR2 3
+#define GW_ADDR3 1
+
+/*******************************************/
+
+/*Static IP ADDRESS*/
+#define AP_IP_ADDR0 192
+#define AP_IP_ADDR1 168
+#define AP_IP_ADDR2 43
+#define AP_IP_ADDR3 1
+
+/*NETMASK*/
+#define AP_NETMASK_ADDR0 255
+#define AP_NETMASK_ADDR1 255
+#define AP_NETMASK_ADDR2 255
+#define AP_NETMASK_ADDR3 0
+
+/*Gateway Address*/
+#define AP_GW_ADDR0 192
+#define AP_GW_ADDR1 168
+#define AP_GW_ADDR2 43
+#define AP_GW_ADDR3 1
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/network/include/main_test.h b/RTL00_SDKV35a/component/common/api/network/include/main_test.h
new file mode 100644
index 0000000..c9f3227
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/main_test.h
@@ -0,0 +1,21 @@
+//----------------------------------------------------------------------------//
+#ifndef __MAIN_TEST_H
+#define __MAIN_TEST_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported test functions ------------------------------------------------------- */
+void do_ping_test(char *ip, int size, int count, int interval);
+void do_ping_call(char *ip, int loop, int count);
+void interactive_question(char *question, char *choice, char *buf, int buf_size);
+void start_interactive_mode(void);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif // __MAIN_TEST_H
+
+//----------------------------------------------------------------------------//
diff --git a/RTL00_SDKV35a/component/common/api/network/include/netconf.h b/RTL00_SDKV35a/component/common/api/network/include/netconf.h
new file mode 100644
index 0000000..600cd06
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/netconf.h
@@ -0,0 +1,50 @@
+/**
+ ******************************************************************************
+ * @file netconf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 07-October-2011
+ * @brief This file contains all the functions prototypes for the netconf.c
+ * file.
+ ******************************************************************************
+ * @attention
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * © COPYRIGHT 2011 STMicroelectronics
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __NETCONF_H
+#define __NETCONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+// TODO: remove this file
+#include "lwip_netconf.h"
+#if 0
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void LwIP_Init(void);
+void LwIP_DHCP(void);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NETCONF_H */
+
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/RTL00_SDKV35a/component/common/api/network/include/rtl8195a_it.h b/RTL00_SDKV35a/component/common/api/network/include/rtl8195a_it.h
new file mode 100644
index 0000000..8d5cf19
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/rtl8195a_it.h
@@ -0,0 +1,8 @@
+
+#ifndef __RTL8195A_IT_H_
+#define __RTL8195A_IT_H_
+
+
+int irq_alloc_wlan(void *contex);
+
+#endif //__RTL8195A_IT_H_
\ No newline at end of file
diff --git a/RTL00_SDKV35a/component/common/api/network/include/util.h b/RTL00_SDKV35a/component/common/api/network/include/util.h
new file mode 100644
index 0000000..1572c8f
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/include/util.h
@@ -0,0 +1,46 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "wifi_util.h"
+#if 0
+typedef enum _WIFI_EVENT_INDICATE{
+ WIFI_EVENT_CONNECT = 0,
+ WIFI_EVENT_DISCONNECT = 1,
+ WIFI_EVENT_FOURWAY_HANDSHAKE_DONE = 2,
+}WIFI_EVENT_INDICATE;
+
+int wext_get_ssid(const char *ifname, __u8 *ssid);
+int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
+int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value);
+int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len);
+int wext_get_enc_ext(const char *ifname, __u16 *alg);
+int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len);
+int wext_get_passphrase(const char *ifname, __u8 *passphrase);
+int wext_set_mode(const char *ifname, int mode);
+int wext_get_mode(const char *ifname, int *mode);
+int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
+int wext_set_country(const char *ifname, char *country_code);
+int wext_get_rssi(const char *ifname, int *rssi);
+int wext_set_channel(const char *ifname, __u8 ch);
+int wext_get_channel(const char *ifname, __u8 *ch);
+int wext_set_scan(const char *ifname, char *buf, __u16 buf_len);
+int wext_get_scan(const char *ifname, char *buf, __u16 buf_len);
+int wext_mp_command(const char *ifname, char *cmd, int show_msg);
+int wext_wifi_priv(const char *ifname, int argc, char **argv);
+void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra);
+#endif
+
+#define wext_handshake_done rltk_wlan_handshake_done
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UTIL_H */
diff --git a/RTL00_SDKV35a/component/common/api/network/src/ping_test.c b/RTL00_SDKV35a/component/common/api/network/src/ping_test.c
new file mode 100644
index 0000000..a46578c
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/src/ping_test.c
@@ -0,0 +1,222 @@
+#include "FreeRTOS.h"
+#include "task.h"
+#include "main.h"
+
+#include
+#if LWIP_SOCKET
+#include
+#include
+#include
+#include
+
+//#define PING_IP "192.168.0.1"
+#define PING_IP "192.168.159.1"
+#define PING_TO 1000
+#define PING_ID 0xABCD
+#define BUF_SIZE 10000
+#define STACKSIZE 1024
+
+static unsigned short ping_seq = 0;
+static int infinite_loop, ping_count, data_size, ping_interval, ping_call;
+static char ping_ip[16];
+
+static void generate_ping_echo(unsigned char *buf, int size)
+{
+ int i;
+ struct icmp_echo_hdr *pecho;
+
+ for(i = 0; i < size; i ++) {
+ buf[sizeof(struct icmp_echo_hdr) + i] = (unsigned char) i;
+ }
+
+ pecho = (struct icmp_echo_hdr *) buf;
+ ICMPH_TYPE_SET(pecho, ICMP_ECHO);
+ ICMPH_CODE_SET(pecho, 0);
+ pecho->chksum = 0;
+ pecho->id = PING_ID;
+ pecho->seqno = htons(++ ping_seq);
+
+ //Checksum includes icmp header and data. Need to calculate after fill up icmp header
+ pecho->chksum = inet_chksum(pecho, sizeof(struct icmp_echo_hdr) + size);
+}
+
+void ping_test(void *param)
+//void ping_test()
+{
+ int i, ping_socket;
+ int pint_timeout = PING_TO;
+ struct sockaddr_in to_addr, from_addr;
+ int from_addr_len = sizeof(struct sockaddr);
+ int ping_size, reply_size;
+ unsigned char *ping_buf, *reply_buf;
+ unsigned int ping_time, reply_time;
+ struct ip_hdr *iphdr;
+ struct icmp_echo_hdr *pecho;
+
+ if(data_size > BUF_SIZE){
+ printf("[ERROR] %s: data size error, can't exceed %d\n",__func__,BUF_SIZE);
+ return;
+ }
+
+ //Ping size = icmp header(8 bytes) + data size
+ ping_size = sizeof(struct icmp_echo_hdr) + data_size;
+
+ ping_buf = pvPortMalloc(ping_size);
+ if(NULL == ping_buf){
+ printf("[ERROR] %s: Allocate ping_buf failed\n",__func__);
+ return;
+ }
+
+ reply_buf = pvPortMalloc(ping_size);
+ if(NULL == reply_buf){
+ vPortFree(ping_buf);
+ printf("[ERROR] %s: Allocate reply_buf failed\n",__func__);
+ return;
+ }
+
+ printf("[%s] PING %s %d(%d) bytes of data\n", __FUNCTION__, ping_ip, data_size, sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr) + data_size);
+
+ for(i = 0; (i < ping_count) || (infinite_loop == 1); i ++) {
+ ping_socket = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
+#ifdef CONFIG_LWIP_1_5_0
+ struct timeval timeout;
+ timeout.tv_sec = pint_timeout / 1000;
+ timeout.tv_usec = pint_timeout % 1000 * 1000;
+ setsockopt(ping_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+#else
+ setsockopt(ping_socket, SOL_SOCKET, SO_RCVTIMEO, &pint_timeout, sizeof(pint_timeout));
+#endif
+ to_addr.sin_len = sizeof(to_addr);
+ to_addr.sin_family = AF_INET;
+ to_addr.sin_addr.s_addr = inet_addr(ping_ip);
+
+ generate_ping_echo(ping_buf, data_size);
+ sendto(ping_socket, ping_buf, ping_size, 0, (struct sockaddr *) &to_addr, sizeof(to_addr));
+
+ ping_time = xTaskGetTickCount();
+ if((reply_size = recvfrom(ping_socket, reply_buf, ping_size, 0, (struct sockaddr *) &from_addr, (socklen_t *) &from_addr_len))
+ >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
+
+ reply_time = xTaskGetTickCount();
+ iphdr = (struct ip_hdr *)reply_buf;
+ pecho = (struct icmp_echo_hdr *)(reply_buf + (IPH_HL(iphdr) * 4));
+
+ if((pecho->id == PING_ID) && (pecho->seqno == htons(ping_seq))) {
+ printf("[%s] %d bytes from %s: icmp_seq=%d time=%d ms\n", __FUNCTION__, reply_size - sizeof(struct ip_hdr), inet_ntoa(from_addr.sin_addr), htons(pecho->seqno), (reply_time - ping_time) * portTICK_RATE_MS);
+ }
+ }
+ else
+ printf("[%s] Request timeout for icmp_seq %d\n", __FUNCTION__, ping_seq);
+
+ close(ping_socket);
+ vTaskDelay(ping_interval * configTICK_RATE_HZ);
+ }
+
+ vPortFree(ping_buf);
+ vPortFree(reply_buf);
+
+ if(!ping_call)
+ vTaskDelete(NULL);
+}
+
+void do_ping_call(char *ip, int loop, int count)
+{
+ ping_call = 1;
+ ping_seq = 0;
+ data_size = 120;
+ ping_interval = 1;
+ infinite_loop = loop;
+ ping_count = count;
+ strcpy(ping_ip, ip);
+ ping_test(NULL);
+}
+
+void cmd_ping(int argc, char **argv)
+{
+ int argv_count = 2;
+
+ if(argc < 2)
+ goto Exit;
+
+ //ping cmd default value
+ infinite_loop = 0;
+ ping_count = 4;
+ data_size = 32;
+ ping_interval = 1;
+ ping_call = 1;
+ ping_seq = 0;
+
+ while(argv_count<=argc){
+ //first operation
+ if(argv_count == 2){
+ memset(ping_ip, 0, sizeof(ping_ip));
+ strncpy(ping_ip, argv[argv_count-1], (strlen(argv[argv_count-1])>16)?16:strlen(argv[argv_count-1]));
+ argv_count++;
+ }
+ else{
+ if(strcmp(argv[argv_count-1], "-t") == 0){
+ infinite_loop = 1;
+ argv_count++;
+ }
+ else if(strcmp(argv[argv_count-1], "-n") == 0){
+ if(argc < (argv_count+1))
+ goto Exit;
+ ping_count = (int) atoi(argv[argv_count]);
+ argv_count+=2;
+ }
+ else if(strcmp(argv[argv_count-1], "-l") == 0){
+ if(argc < (argv_count+1))
+ goto Exit;
+ data_size = (int) atoi(argv[argv_count]);
+ argv_count+=2;
+ }
+ else{
+ goto Exit;
+ }
+ }
+ }
+
+ ping_test(NULL);
+
+ return;
+
+Exit:
+ printf("[ATWI] Usage: ATWI=[host],[options]\n");
+ printf("\t-t\tPing the specified host until stopped\n");
+ printf("\t-n\t# Number of echo requests to send (default 4 times)\n");
+ printf("\t-l\t# Send buffer size (default 32 bytes)\n");
+ printf("\tExample:\n");
+ printf("\t\tATWI=192.168.1.2,-n,100,-l,5000\n");
+ return;
+}
+
+void do_ping_test(char *ip, int size, int count, int interval)
+{
+ if((sizeof(struct icmp_echo_hdr) + size) > BUF_SIZE) {
+ printf("%s BUF_SIZE(%d) is too small\n", __FUNCTION__, BUF_SIZE);
+ return;
+ }
+
+ if(ip == NULL)
+ strcpy(ping_ip, PING_IP);
+ else
+ strcpy(ping_ip, ip);
+
+ ping_call = 0;
+ ping_seq = 0;
+ data_size = size;
+ ping_interval = interval;
+
+ if(count == 0) {
+ infinite_loop = 1;
+ ping_count = 0;
+ }
+ else {
+ infinite_loop = 0;
+ ping_count = count;
+ }
+
+ if(xTaskCreate(ping_test, ((const signed char*)"ping_test"), STACKSIZE, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
+ printf("%s xTaskCreate failed\n", __FUNCTION__);
+}
+#endif // LWIP_SOCKET
diff --git a/RTL00_SDKV35a/component/common/api/network/src/rtl8195a_it.c b/RTL00_SDKV35a/component/common/api/network/src/rtl8195a_it.c
new file mode 100644
index 0000000..91c0667
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/src/rtl8195a_it.c
@@ -0,0 +1,110 @@
+#include "rtl8195a.h"
+#include
+#include "rtl8195a_it.h"
+
+/* os dependent*/
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#include "semphr.h"
+
+
+#include
+#define printf DiagPrintf
+
+/*-----------------------------Global Variable ---------------------*/
+//#ifdef CONFIG_WLAN
+//#ifdef CONFIG_ISR_THREAD_MODE_INTERRUPT
+extern xSemaphoreHandle *pExportWlanIrqSemaphore;
+//#endif
+//#endif
+
+
+#ifdef CONFIG_WLAN
+#ifdef CONFIG_ISR_THREAD_MODE_INTERRUPT
+
+//TODO: chris
+#define IRQ_HANDLED 1
+#define IRQ_NONE 0
+
+int wlan_Interrupt (
+ IN VOID* Data
+)
+{
+#if 1
+
+ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
+
+ printf("wlan interrupt\n");
+ /* This semaphore is initialized once wlan interrupt handler thread is created and initialized*/
+ if(!pExportWlanIrqSemaphore)
+ {
+ printf("%s(%d)\n", __FUNCTION__, __LINE__);
+ goto exit;
+ }
+
+ printf("%s(%d)\n", __FUNCTION__, __LINE__);
+ xSemaphoreGiveFromISR( *pExportWlanIrqSemaphore, &xHigherPriorityTaskWoken );
+
+ printf("%s(%d)\n", __FUNCTION__, __LINE__);
+ /* Switch tasks if necessary. */
+ if( xHigherPriorityTaskWoken != pdFALSE )
+ {
+ printf("%s(%d)\n", __FUNCTION__, __LINE__);
+ portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
+ }
+
+exit:
+
+ return IRQ_HANDLED;
+#else
+ struct dvobj_priv *dvobj = (struct dvobj_priv *)Data;
+ _adapter *adapter = dvobj->if1;
+ DBG_8192C("Dma isr\n");
+
+ if (dvobj->irq_enabled == 0) {
+ return IRQ_HANDLED;
+ }
+DBG_871X("%s(%d)\n", __FUNCTION__, __LINE__);
+ if(rtw_hal_interrupt_handler(adapter) == _FAIL)
+ return IRQ_HANDLED;
+ //return IRQ_NONE;
+DBG_871X("%s(%d)\n", __FUNCTION__, __LINE__);
+ return IRQ_HANDLED;
+#endif
+
+}
+
+
+VOID
+lextra_bus_dma_Interrupt (
+ IN VOID* Data
+);
+
+
+/*
+ * This function register interrupt handler and is called by wlan driver
+ * Return 0 if success, Others if fail
+ */
+
+int irq_alloc_wlan(void *contex)
+{
+ int ret = 0;
+ IRQ_HANDLE IrqHandle = {0};
+
+ printf("Register Interrupt\n");
+ IrqHandle.Data = (u32) (contex);
+ IrqHandle.IrqNum = WL_DMA_IRQ;
+ IrqHandle.IrqFun = (IRQ_FUN)wlan_Interrupt;
+ //IrqHandle.IrqFun = (IRQ_FUN)lextra_bus_dma_Interrupt;
+ IrqHandle.Priority = 0;
+
+ InterruptRegister(&IrqHandle);
+ InterruptEn(&IrqHandle);
+
+ return ret;
+
+}
+#endif
+#endif
+
diff --git a/RTL00_SDKV35a/component/common/api/network/src/wlan_network.c b/RTL00_SDKV35a/component/common/api/network/src/wlan_network.c
new file mode 100644
index 0000000..cac209f
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/network/src/wlan_network.c
@@ -0,0 +1,95 @@
+/*
+ * Hello World
+ *
+ * Copyright (c) 2013 Realtek Semiconductor Corp.
+ *
+ * This module is a confidential and proprietary property of RealTek and
+ * possession or use of this module requires written permission of RealTek.
+ */
+
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+
+#include "main.h"
+#include "main_test.h"
+#if CONFIG_WLAN
+#include "wifi_conf.h"
+#include "wlan_intf.h"
+#include "wifi_constants.h"
+#endif
+#include "lwip_netconf.h"
+#include
+//#include "wifi_interactive_ext.h"
+
+#ifndef CONFIG_INIT_NET
+#define CONFIG_INIT_NET 1
+#endif
+#ifndef CONFIG_INTERACTIVE_MODE
+#define CONFIG_INTERACTIVE_MODE 1
+#endif
+
+#define STACKSIZE (512 + 768)
+
+xSemaphoreHandle uart_rx_interrupt_sema = NULL;
+
+void init_thread(void *param)
+{
+
+#if CONFIG_INIT_NET
+#if CONFIG_LWIP_LAYER
+ /* Initilaize the LwIP stack */
+ // DBG_8195A("\nLwIP Init\n");
+ LwIP_Init();
+#endif
+#endif
+#if CONFIG_WIFI_IND_USE_THREAD
+ wifi_manager_init();
+#endif
+#if CONFIG_WLAN
+ // DBG_8195A("\nWiFi_on(RTW_MODE_STA)\n");
+ wifi_on(RTW_MODE_STA);
+#if CONFIG_AUTO_RECONNECT
+ //setup reconnection flag
+// u8 mode;
+// if(wifi_get_autoreconnect(&mode) > 0 && mode != 1)
+ wifi_set_autoreconnect(1);
+#endif
+// printf("\n\r%s(%d), Available heap %d\n\r", __FUNCTION__, __LINE__, xPortGetFreeHeapSize());
+#endif
+
+#if CONFIG_INTERACTIVE_MODE
+ /* Initial uart rx swmaphore*/
+ vSemaphoreCreateBinary(uart_rx_interrupt_sema);
+ xSemaphoreTake(uart_rx_interrupt_sema, 1/portTICK_RATE_MS);
+ start_interactive_mode();
+#endif
+
+ /* Kill init thread after all init tasks done */
+ vTaskDelete(NULL);
+}
+
+void wlan_network()
+{
+#if 0
+ {
+ void *stack_addr = tcm_heap_malloc(STACKSIZE*sizeof(int));
+ if(stack_addr == NULL){
+ printf("%s: Out of TCM heap!\n", __FUNCTION__);
+ }
+ if (xTaskGenericCreate(
+ init_thread,
+ (const char *)"init",
+ STACKSIZE,
+ NULL,
+ tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET,
+ NULL,
+ stack_addr,
+ NULL) != pdTRUE)
+ printf("%s: xTaskCreate(init_thread) failed\n", __FUNCTION__);
+ }
+#else
+ if(xTaskCreate(init_thread, ((const char*)"init"), STACKSIZE, NULL, tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET, NULL) != pdPASS) // +3
+ printf("%s: xTaskCreate(init_thread) failed\n", __FUNCTION__);
+#endif
+}
diff --git a/RTL00_SDKV35a/component/common/api/platform/dlist.h b/RTL00_SDKV35a/component/common/api/platform/dlist.h
new file mode 100644
index 0000000..5fa8dd1
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/platform/dlist.h
@@ -0,0 +1,262 @@
+#ifndef __LIST_H
+#define __LIST_H
+
+#if defined ( __CC_ARM )
+#ifndef inline
+#define inline __inline
+#endif
+#endif
+
+/* This file is from Linux Kernel (include/linux/list.h)
+ * and modified by simply removing hardware prefetching of list items.
+ * Here by copyright, credits attributed to wherever they belong.
+ * Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
+ */
+
+/*
+ * Simple doubly linked list implementation.
+ *
+ * Some of the internal functions ("__xxx") are useful when
+ * manipulating whole lists rather than single entries, as
+ * sometimes we already know the next/prev entries and we can
+ * generate better code by using them directly rather than
+ * using the generic single-entry routines.
+ */
+
+struct list_head {
+ struct list_head *next, *prev;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+ struct list_head name = LIST_HEAD_INIT(name)
+
+#define INIT_LIST_HEAD(ptr) do { \
+ (ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_add(struct list_head *new,
+ struct list_head *prev,
+ struct list_head *next)
+{
+ next->prev = new;
+ new->next = next;
+ new->prev = prev;
+ prev->next = new;
+}
+
+/**
+ * list_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head, head->next);
+}
+
+/**
+ * list_add_tail - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it before
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head *prev, struct list_head *next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
+ */
+static inline void list_del(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ entry->next = (void *) 0;
+ entry->prev = (void *) 0;
+}
+
+/**
+ * list_del_init - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ */
+static inline void list_del_init(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ INIT_LIST_HEAD(entry);
+}
+
+/**
+ * list_move - delete from one list and add as another's head
+ * @list: the entry to move
+ * @head: the head that will precede our entry
+ */
+static inline void list_move(struct list_head *list, struct list_head *head)
+{
+ __list_del(list->prev, list->next);
+ list_add(list, head);
+}
+
+/**
+ * list_move_tail - delete from one list and add as another's tail
+ * @list: the entry to move
+ * @head: the head that will follow our entry
+ */
+static inline void list_move_tail(struct list_head *list,
+ struct list_head *head)
+{
+ __list_del(list->prev, list->next);
+ list_add_tail(list, head);
+}
+
+/**
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int list_empty(struct list_head *head)
+{
+ return head->next == head;
+}
+
+static inline void __list_splice(struct list_head *list,
+ struct list_head *head)
+{
+ struct list_head *first = list->next;
+ struct list_head *last = list->prev;
+ struct list_head *at = head->next;
+
+ first->prev = head;
+ head->next = first;
+
+ last->next = at;
+ at->prev = last;
+}
+
+/**
+ * list_splice - join two lists
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ */
+static inline void list_splice(struct list_head *list, struct list_head *head)
+{
+ if (!list_empty(list))
+ __list_splice(list, head);
+}
+
+/**
+ * list_splice_init - join two lists and reinitialise the emptied list.
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ *
+ * The list at @list is reinitialised
+ */
+static inline void list_splice_init(struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list)) {
+ __list_splice(list, head);
+ INIT_LIST_HEAD(list);
+ }
+}
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_entry(ptr, type, member) \
+ ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
+/**
+* list_first_entry - get the first element from a list
+* @ptr: the list head to take the element from.
+* @type: the type of the struct this is embedded in.
+* @member: the name of the list_head within the struct.
+*
+* Note, that list is expected to be not empty.
+*/
+
+#define list_first_entry(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+
+/**
+ * list_for_each - iterate over a list
+ * @pos: the &struct list_head to use as a loop counter.
+ * @head: the head for your list.
+ */
+#define list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); \
+ pos = pos->next)
+/**
+ * list_for_each_prev - iterate over a list backwards
+ * @pos: the &struct list_head to use as a loop counter.
+ * @head: the head for your list.
+ */
+#define list_for_each_prev(pos, head) \
+ for (pos = (head)->prev; pos != (head); \
+ pos = pos->prev)
+
+/**
+ * list_for_each_safe - iterate over a list safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop counter.
+ * @n: another &struct list_head to use as temporary storage
+ * @head: the head for your list.
+ */
+#define list_for_each_safe(pos, n, head) \
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
+
+/**
+ * list_for_each_entry - iterate over list of given type
+ * @pos: the type * to use as a loop counter.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry(pos, head, member, type) \
+ for (pos = list_entry((head)->next, type, member); \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.next, type, member))
+
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos: the type * to use as a loop counter.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member, type) \
+ for (pos = list_entry((head)->next, type, member), \
+ n = list_entry(pos->member.next, type, member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, type, member))
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/platform/platform_stdlib.h b/RTL00_SDKV35a/component/common/api/platform/platform_stdlib.h
new file mode 100644
index 0000000..f0b817e
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/platform/platform_stdlib.h
@@ -0,0 +1,247 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2007 - 2014 Realtek Corporation. All rights reserved.
+ *
+ *
+ ******************************************************************************/
+#ifndef __PLATFORM_STDLIB_H__
+#define __PLATFORM_STDLIB_H__
+
+#define USE_CLIB_PATCH 0
+#if defined (__GNUC__)
+#define USE_RTL_ROM_CLIB 1
+#else
+#define USE_RTL_ROM_CLIB 1
+#endif
+
+#if defined(CONFIG_PLATFORM_8195A)
+#if defined (__IARSTDLIB__)
+ #include
+ #include
+ #include
+ #include
+ #include "diag.h"
+
+ #define strsep(str, delim) _strsep(str, delim)
+#else
+ #include
+ #include
+ #include
+ #include "diag.h"
+ #include "strproc.h"
+ #include "basic_types.h"
+ #include "hal_misc.h"
+ #if USE_RTL_ROM_CLIB
+ #include "rtl_lib.h"
+ #endif
+
+ #undef printf
+ #undef sprintf
+ #undef snprintf
+ #undef atoi
+ #undef memcmp
+ #undef memcpy
+ #undef memset
+ #undef strcmp
+ #undef strcpy
+ #undef strlen
+ #undef strncmp
+ #undef strncpy
+ #undef strsep
+ #undef strtok
+ #if USE_RTL_ROM_CLIB
+ #undef memchr
+ #undef memmove
+ #undef strcat
+ #undef strchr
+ #undef strncat
+ #undef strstr
+ #endif
+
+ #if USE_RTL_ROM_CLIB
+ #define printf rtl_printf
+ #define sprintf rtl_sprintf
+ #define snprintf rtl_snprintf
+ #define memchr rtl_memchr
+ #define memcmp rtl_memcmp
+ #define memcpy rtl_memcpy
+ #define memmove rtl_memmove
+ #define memset rtl_memset
+ #define bzero(s,l) rtl_memset(s,0,l)
+ #define strcat rtl_strcat
+ #define strchr rtl_strchr
+ #define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2)
+ #define strcpy rtl_strcpy
+ #define strlen(str) rtl_strlen((const char *)str)
+ #define strncat rtl_strncat
+ #define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n)
+ #define strncpy rtl_strncpy
+ #define strstr rtl_strstr
+ #define strsep rtl_strsep
+ #define strtok rtl_strtok
+ #else
+ #if USE_CLIB_PATCH
+ extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
+ extern char* DiagStrtokPatch(char *str, const char* delim);
+ extern char* DiagStrstrPatch(char *string, char *substring);
+ extern int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...);
+ extern u32 DiagPrintfPatch(const char *fmt, ...);
+ extern u32 DiagSPrintfPatch(u8 *buf, const char *fmt, ...);
+ #define printf DiagPrintfPatch
+ #define sprintf DiagSPrintfPatch
+ #define snprintf DiagSnPrintfPatch
+ #define strstr(a, b) DiagStrstrPatch((char *)(a), (char *)(b))
+ #define strtok DiagStrtokPatch
+ #else
+ #define printf DiagPrintf
+ #define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
+ #if defined (__GNUC__)
+ #define snprintf DiagSnPrintf // NULL function
+ #define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
+ #endif
+ #define strtok(str, delim) _strsep(str, delim)
+ #endif
+ #define memcmp(dst, src, sz) _memcmp(dst, src, sz)
+ #define memcpy(dst, src, sz) _memcpy(dst, src, sz)
+ #define memset(dst, val, sz) _memset(dst, val, sz)
+ #define strchr(s, c) _strchr(s, c) // for B-cut ROM
+ #define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
+ #define strcpy(dest, src) _strcpy(dest, src)
+ #define strlen(str) prvStrLen((const unsigned char *) str)
+ #define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
+ #define strncpy(dest, src, count) _strncpy(dest, src, count)
+ #define strsep(str, delim) _strsep(str, delim)
+ #endif
+
+ #define atoi(str) prvAtoi(str)
+ #define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
+
+ #if USE_CLIB_PATCH
+ #undef sscanf
+ #define sscanf DiagSscanfPatch
+ #else
+ #if defined (__GNUC__)
+ #undef sscanf //_sscanf
+ //extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
+ //#define sscanf DiagSscanfPatch
+ #define sscanf sscanf // use libc sscanf
+ #endif
+ #endif
+#endif // defined (__IARSTDLIB__)
+
+//
+// memory management
+//
+extern void *pvPortMalloc( size_t xWantedSize );
+extern void vPortFree( void *pv );
+#undef malloc
+#define malloc pvPortMalloc
+#undef free
+#define free vPortFree
+#elif defined (CONFIG_PLATFORM_8711B)
+#if defined (__IARSTDLIB__)
+ #include
+ #include
+ #include
+ #include
+ #include "diag.h"
+
+ #define strsep(str, delim) _strsep(str, delim)
+#else
+ #include
+ #include
+ #include
+ #include "diag.h"
+ #include "strproc.h"
+ #include "basic_types.h"
+ #include "hal_misc.h"
+
+ #undef printf
+ #undef sprintf
+ #undef snprintf
+ #undef atoi
+ #undef memcmp
+ #undef memcpy
+ #undef memset
+ #undef strcmp
+ #undef strcpy
+ #undef strlen
+ #undef strncmp
+ #undef strncpy
+ #undef strsep
+ #undef strtok
+
+#if USE_RTL_ROM_CLIB
+ #undef memchr
+ #undef memmove
+ #undef strcat
+ #undef strchr
+ #undef strncat
+ #undef strstr
+
+ #define printf rtl_printf
+ #define sprintf rtl_sprintf
+ #define snprintf rtl_snprintf
+ #define memchr rtl_memchr
+ #define memcmp rtl_memcmp
+ #define memcpy rtl_memcpy
+ #define memmove rtl_memmove
+ #define memset rtl_memset
+ #define strcat rtl_strcat
+ #define strchr rtl_strchr
+ #define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2)
+ #define strcpy rtl_strcpy
+ #define strlen(str) rtl_strlen((const char *)str)
+ #define strncat rtl_strncat
+ #define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n)
+ #define strncpy rtl_strncpy
+ #define strstr rtl_strstr
+ #define strsep rtl_strsep
+ #define strtok rtl_strtok
+#else
+ #define printf DiagPrintf
+ #define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
+#if defined (__GNUC__)
+ #define snprintf DiagSnPrintf // NULL function
+ #define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
+#endif
+ #define strtok(str, delim) _strsep(str, delim)
+
+ #define memcmp(dst, src, sz) _memcmp(dst, src, sz)
+ #define memcpy(dst, src, sz) _memcpy(dst, src, sz)
+ #define memset(dst, val, sz) _memset(dst, val, sz)
+ #define strchr(s, c) _strchr(s, c) // for B-cut ROM
+ #define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
+ #define strcpy(dest, src) _strcpy(dest, src)
+ #define strlen(str) prvStrLen((const unsigned char *) str)
+ #define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
+ #define strncpy(dest, src, count) _strncpy(dest, src, count)
+ #define strsep(str, delim) _strsep(str, delim)
+
+ #define atoi(str) prvAtoi(str)
+ #define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
+
+#if defined (__GNUC__)
+ #undef sscanf
+ #define sscanf _sscanf
+#endif
+
+#endif
+#endif // defined (__IARSTDLIB__)
+
+//
+// memory management
+//
+extern void *pvPortMalloc( size_t xWantedSize );
+extern void vPortFree( void *pv );
+#define malloc pvPortMalloc
+#define free vPortFree
+#elif defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL) || defined(STM32F10X_XL)
+ #include
+ #include
+ #include
+ #include
+#endif
+
+
+#endif //__PLATFORM_STDLIB_H__
diff --git a/RTL00_SDKV35a/component/common/api/platform/stdlib_patch.c b/RTL00_SDKV35a/component/common/api/platform/stdlib_patch.c
new file mode 100644
index 0000000..c4e2ea5
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/platform/stdlib_patch.c
@@ -0,0 +1,918 @@
+/*
+
+ this is the c lib patch, It can help when the clib provided by IAR
+ does not work well.
+
+ How to use this:
+ 1.You must include platform_stdlib.h in you source file。
+ 2.There is a macro USE_CLIB_PATCH in platform_stdlib.h should be opened.
+
+ If there is some problems using this patch,
+ You'd better check if you code runs into these functions:
+
+ DiagSscanfPatch
+ DiagStrtokPatch
+ DiagStrstrPatch
+ DiagSnPrintfPatch
+ DiagPrintfPatch
+ DiagSPrintfPatch
+ DiagPrintfPatch
+ DiagSPrintfPatch
+ DiagSnPrintfPatch
+ DiagStrstrPatch
+ DiagStrtokPatch
+
+ */
+#ifndef CONFIG_PLATFORM_8711B
+
+#include
+
+#define DiagPutChar HalSerialPutcRtl8195a
+
+#define IN
+#define NULL 0
+
+typedef unsigned int size_t;
+typedef unsigned int SIZE_T;
+typedef unsigned long long u64;
+typedef unsigned int u32;
+typedef unsigned short int u16;
+typedef unsigned char u8;
+typedef signed long long s64;
+typedef signed int s32;
+typedef signed short int s16;
+typedef unsigned char bool;
+
+
+#define in_range(c, lo, up) ((u8)c >= lo && (u8)c <= up)
+#define isprint(c) in_range(c, 0x20, 0x7f)
+#define isdigit(c) in_range(c, '0', '9')
+#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
+#define islower(c) in_range(c, 'a', 'z')
+#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == ',')
+#define ULLONG_MAX (~0ULL)
+#define USHRT_MAX ((u16)(~0U))
+#define KSTRTOX_OVERFLOW (1U << 31)
+#define SHRT_MAX ((s16)(USHRT_MAX>>1))
+
+static inline char _tolower(const char c)
+{
+ return c | 0x20;
+}
+
+
+extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
+extern s64 div_s64(s64 dividend, s32 divisor);
+extern inline char _tolower(const char c);
+extern u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder);
+extern u64 div_u64(u64 dividend, u32 divisor);
+extern unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p);
+extern const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
+extern char *skip_spaces(const char *str);
+extern int skip_atoi(const char **s);
+extern void HalSerialPutcRtl8195a(u8 c);
+
+
+static unsigned long long simple_strtoull_patch(const char *cp, char **endp, unsigned int base)
+{
+ unsigned long long result;
+ unsigned int rv;
+
+ cp = _parse_integer_fixup_radix(cp, &base);
+ rv = _parse_integer(cp, base, &result);
+
+ return result;
+}
+
+static long long simple_strtoll_patch(const char *cp, char **endp, unsigned int base)
+{
+ if(*cp == '-')
+ return -simple_strtoull_patch(cp + 1, endp, base);
+
+ return simple_strtoull_patch(cp, endp, base);
+}
+static unsigned long simple_strtoul_patch(const char *cp, char **endp, unsigned int base)
+{
+ return simple_strtoull_patch(cp, endp, base);
+}
+
+static long simple_strtol_patch(const char *cp, char **endp, unsigned int base)
+{
+ if(*cp == '-')
+ return -simple_strtoul_patch(cp + 1, endp, base);
+
+ return simple_strtoul_patch(cp, endp, base);
+}
+
+
+
+
+static int judge_digit_width(const char *str)
+{
+
+ int width = 0;
+
+ while(isdigit(*str)) {
+ width++;
+ str++;
+ }
+
+ return width;
+}
+
+
+static int _vsscanf_patch(const char *buf, const char *fmt, va_list args)
+{
+ const char *str = buf;
+ char *next;
+ char digit;
+ int num = 0;
+ int i =0;
+ u8 qualifier;
+ unsigned int base;
+ union {
+ long long s;
+ unsigned long long u;
+ } val;
+ s16 field_width;
+ bool is_sign;
+
+ char str_store[20] = {0};
+
+
+
+ while(*fmt) {
+ /* skip any white space in format */
+ /* white space in format matchs any amount of
+ * white space, including none, in the input.
+ */
+ if(isspace(*fmt)) {
+ fmt = skip_spaces(++fmt);
+ str = skip_spaces(str);
+ }
+
+ /* anything that is not a conversion must match exactly */
+ if(*fmt != '%' && *fmt) {
+ if(*fmt++ != *str++) {
+ break;
+ }
+
+ continue;
+ }
+
+ if(!*fmt) {
+ break;
+ }
+
+ ++fmt;
+
+ /* skip this conversion.
+ * advance both strings to next white space
+ */
+ if(*fmt == '*') {
+ if(!*str) {
+ break;
+ }
+
+ while(!isspace(*fmt) && *fmt != '%' && *fmt)
+ fmt++;
+
+ while(!isspace(*str) && *str)
+ str++;
+
+ continue;
+ }
+
+ /* get field width */
+ field_width = -1;
+
+ if(isdigit(*fmt)) {
+
+ field_width = skip_atoi(&fmt);
+
+
+
+ if(field_width <= 0) {
+
+ break;
+ }
+ }
+
+ /* get conversion qualifier */
+ qualifier = -1;
+
+ if(*fmt == 'h' || _tolower(*fmt) == 'l' ||
+ _tolower(*fmt) == 'z') {
+ qualifier = *fmt++;
+
+ if(qualifier == *fmt) {
+ if(qualifier == 'h') {
+ qualifier = 'H';
+ fmt++;
+ } else if(qualifier == 'l') {
+ qualifier = 'L';
+ fmt++;
+ }
+ }
+ }
+
+ if(!*fmt) {
+ break;
+ }
+
+ if(*fmt == 'n') {
+ /* return number of characters read so far */
+ *va_arg(args, int *) = str - buf;
+ ++fmt;
+ continue;
+ }
+
+ if(!*str) {
+ break;
+ }
+
+ base = 10;
+ is_sign = 0;
+
+ switch(*fmt++) {
+ case 'c': {
+ char *s = (char *)va_arg(args, char*);
+
+ if(field_width == -1)
+ field_width = 1;
+
+ do {
+ *s++ = *str++;
+ } while(--field_width > 0 && *str);
+
+ num++;
+ }
+
+ continue;
+
+ case 's': {
+ char *s = (char *)va_arg(args, char *);
+
+ if(field_width == -1)
+ field_width = SHRT_MAX;
+
+ /* first, skip leading white space in buffer */
+ str = skip_spaces(str);
+
+ /* now copy until next white space */
+ while(*str && !isspace(*str) && field_width--) {
+ *s++ = *str++;
+ }
+
+ *s = '\0';
+ num++;
+ }
+
+ continue;
+
+ case 'o':
+ base = 8;
+ break;
+
+ case 'x':
+ case 'X':
+ base = 16;
+ break;
+
+ case 'i':
+ base = 0;
+
+ case 'd':
+ is_sign = 1;
+
+ case 'u':
+ break;
+
+ case '%':
+
+ /* looking for '%' in str */
+ if(*str++ != '%') {
+ return num;
+ }
+
+ continue;
+
+ default:
+ /* invalid format; stop here */
+ return num;
+ }
+
+ /* have some sort of integer conversion.
+ * first, skip white space in buffer.
+ */
+ str = skip_spaces(str);
+
+ digit = *str;
+
+ if(is_sign && digit == '-')
+ digit = *(str + 1);
+
+ if(!digit
+ || (base == 16 && !isxdigit(digit))
+ || (base == 10 && !isdigit(digit))
+ || (base == 8 && (!isdigit(digit) || digit > '7'))
+ || (base == 0 && !isdigit(digit))) {
+ break;
+ }
+
+ //here problem *******************************************
+
+
+
+ //troy add ,fix support %2d, but not support %d
+ if(field_width <= 0) {
+
+ field_width = judge_digit_width(str);
+ }
+
+
+ /////troy add, fix str passed inwidth wrong
+ for(i = 0; i 0 && next - str > field_width) {
+ if(base == 0)
+ _parse_integer_fixup_radix(str, &base);
+
+ while(next - str > field_width) {
+ if(is_sign) {
+ val.s = div_s64(val.s, base);
+ } else {
+ val.u = div_u64(val.u, base);
+ }
+
+ --next;
+ }
+ }
+
+ switch(qualifier) {
+ case 'H': /* that's 'hh' in format */
+ if(is_sign)
+ *va_arg(args, signed char *) = val.s;
+ else
+ *va_arg(args, unsigned char *) = val.u;
+
+ break;
+
+ case 'h':
+ if(is_sign)
+ *va_arg(args, short *) = val.s;
+ else
+ *va_arg(args, unsigned short *) = val.u;
+
+ break;
+
+ case 'l':
+ if(is_sign)
+ *va_arg(args, long *) = val.s;
+ else
+ *va_arg(args, unsigned long *) = val.u;
+
+ break;
+
+ case 'L':
+ if(is_sign)
+ *va_arg(args, long long *) = val.s;
+ else
+ *va_arg(args, unsigned long long *) = val.u;
+
+ break;
+
+ case 'Z':
+ case 'z':
+ *va_arg(args, size_t *) = val.u;
+ break;
+
+ default:
+ if(is_sign)
+ *va_arg(args, int *) = val.s;
+ else
+ *va_arg(args, unsigned int *) = val.u;
+
+ break;
+ }
+
+ num++;
+
+ if(!next) {
+ break;
+ }
+
+ str = next;
+ }
+
+ return num;
+}
+
+
+int DiagSscanfPatch(const char *buf, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i = _vsscanf_patch(buf, fmt, args);
+ va_end(args);
+
+ return i;
+}
+
+
+
+/*********************************************************/
+
+
+
+char* DiagStrtokPatch(char *str, const char* delim) {
+ static char* _buffer;
+
+ if(str != NULL) _buffer = str;
+
+ if(_buffer[0] == '\0') return NULL;
+
+ char *ret = _buffer, *b;
+ const char *d;
+
+ for(b = _buffer; *b !='\0'; b++) {
+ for(d = delim; *d != '\0'; d++) {
+ if(*b == *d) {
+ *b = '\0';
+ _buffer = b+1;
+
+ // skip the beginning delimiters
+ if(b == ret) {
+ ret++;
+ continue;
+ }
+
+ return ret;
+ }
+ }
+ }
+
+ return ret;
+}
+
+
+
+/*********************************************************/
+
+
+
+char *DiagStrstrPatch(char *string, char *substring)
+{
+ register char *a, *b;
+
+ /* First scan quickly through the two strings looking for a
+ * single-character match. When it's found, then compare the
+ * rest of the substring.
+ */
+
+ b = substring;
+
+ if(*b == 0) {
+ return string;
+ }
+
+ for(; *string != 0; string += 1) {
+ if(*string != *b) {
+ continue;
+ }
+
+ a = string;
+
+ while(1) {
+ if(*b == 0) {
+ return string;
+ }
+
+ if(*a++ != *b++) {
+ break;
+ }
+ }
+
+ b = substring;
+ }
+
+ return (char *) 0;
+}
+
+
+
+
+
+/*********************************************************/
+
+
+
+
+int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...)
+{
+
+ va_list ap;
+ char *p, *s, *buf_end = NULL;
+ const int *dp = ((const int *)&fmt)+1;
+
+ if(buf == NULL)
+ return 0;
+
+
+ va_start(ap, fmt);
+ s = buf;
+ buf_end = size? (buf + size):(char*)~0;
+
+ for(; *fmt != '\0'; ++fmt) {
+
+ if(*fmt != '%') {
+ *s++ = *fmt;
+
+ if(s >= buf_end) {
+ goto Exit;
+ }
+
+ continue;
+ }
+
+ if(*++fmt == 's') {
+ for(p = (char *)*dp++; *p != '\0'; p++) {
+ *s++ = *p;
+
+ if(s >= buf_end) {
+ goto Exit;
+ }
+ }
+ }
+ else { /* Length of item is bounded */
+ char tmp[20], *q = tmp;
+ int alt = 0;
+ int shift = 0;// = 12;
+ const long *lpforchk = (const long *)dp;
+
+ if((*lpforchk) < 0x10) {
+ shift = 0;
+ }
+ else if(((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
+ shift = 4;
+ }
+ else if(((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
+ shift = 8;
+ }
+ else if(((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
+ shift = 12;
+ }
+ else if(((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
+ shift = 16;
+ }
+ else if(((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
+ shift = 20;
+ }
+ else if(((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
+ shift = 24;
+ }
+ else if((*lpforchk) >= 0x10000000) {
+ shift = 28;
+ }
+ else {
+ shift = 28;
+ }
+
+ if((*fmt >= '0') && (*fmt <= '9'))
+ {
+ int width;
+ unsigned char fch = *fmt;
+
+ for(width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
+ { width = width * 10 + fch - '0';
+ }
+
+ shift=(width-1)*4;
+ }
+
+ /*
+ * Before each format q points to tmp buffer
+ * After each format q points past end of item
+ */
+ if((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
+ /* With x86 gcc, sizeof(long) == sizeof(int) */
+ const long *lp = (const long *)dp;
+ long h = *lp++;
+ int hex_count = 0;
+ unsigned long h_back = h;
+ int ncase = (*fmt & 0x20);
+ dp = (const int *)lp;
+
+ if((*fmt == 'p') || (*fmt == 'P'))
+ alt=1;
+
+ if(alt) {
+ *q++ = '0';
+ *q++ = 'X' | ncase;
+ }
+
+ while(h_back) {
+ hex_count += (h_back & 0xF) ? 1 : 0;
+ h_back = h_back >> 4;
+ }
+
+ if(shift < (hex_count - 1)*4)
+ shift = (hex_count - 1)*4;
+
+ for(; shift >= 0; shift -= 4)
+ *q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
+ }
+ else if(*fmt == 'd') {
+ int i = *dp++;
+ char *r;
+ int digit_space = 0;
+
+
+ if(i < 0) {
+ *q++ = '-';
+ i = -i;
+ digit_space++;
+ }
+
+ p = q; /* save beginning of digits */
+
+
+ do {
+ *q++ = '0' + (i % 10);
+ i /= 10;
+ digit_space++;
+ } while(i);
+
+
+ for(; shift >= 0; shift -= 4) {
+
+ if(digit_space-- > 0) {
+ ; //do nothing
+ } else {
+ *q++ = '0';
+ }
+ }
+
+ /* reverse digits, stop in middle */
+ r = q; /* don't alter q */
+
+ while(--r > p) {
+ i = *r;
+ *r = *p;
+ *p++ = i;
+ }
+ }
+ else if(*fmt == 'c')
+ *q++ = *dp++;
+ else
+ *q++ = *fmt;
+
+ /* now output the saved string */
+ for(p = tmp; p < q; ++p) {
+ *s++ = *p;
+
+ if(s >= buf_end) {
+ goto Exit;
+ }
+ }
+ }
+ }
+
+Exit:
+
+ if(buf)
+ *s = '\0';
+
+ va_end(ap);
+ return(s-buf);
+
+}
+
+
+
+
+
+
+/*********************************************************/
+
+static int VSprintfPatch(char *buf, const char *fmt, const int *dp)
+{
+ char *p, *s;
+ s = buf;
+
+ for(; *fmt != '\0'; ++fmt) {
+ if(*fmt != '%') {
+ if(buf) {
+ *s++ = *fmt;
+ } else {
+ DiagPutChar(*fmt);
+ }
+
+ continue;
+ }
+
+ if(*++fmt == 's') {
+ for(p = (char *)*dp++; *p != '\0'; p++) {
+ if(buf) {
+ *s++ = *p;
+ } else {
+ DiagPutChar(*p);
+ }
+ }
+ }
+ else { /* Length of item is bounded */
+ char tmp[20], *q = tmp;
+ int alt = 0;
+ int shift = 0;// = 12;
+ const long *lpforchk = (const long *)dp;
+
+ if((*lpforchk) < 0x10) {
+ shift = 0;
+ }
+ else if(((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
+ shift = 4;
+ }
+ else if(((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
+ shift = 8;
+ }
+ else if(((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
+ shift = 12;
+ }
+ else if(((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
+ shift = 16;
+ }
+ else if(((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
+ shift = 20;
+ }
+ else if(((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
+ shift = 24;
+ }
+ else if((*lpforchk) >= 0x10000000) {
+ shift = 28;
+ }
+ else {
+ shift = 28;
+ }
+
+#if 1 //wei patch for %02x
+
+ if((*fmt >= '0') && (*fmt <= '9'))
+ {
+ int width;
+ unsigned char fch = *fmt;
+
+ for(width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
+ { width = width * 10 + fch - '0';
+ }
+
+ shift=(width-1)*4;
+ }
+
+#endif
+
+ /*
+ * Before each format q points to tmp buffer
+ * After each format q points past end of item
+ */
+
+ if((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
+ /* With x86 gcc, sizeof(long) == sizeof(int) */
+ const long *lp = (const long *)dp;
+ long h = *lp++;
+ int hex_count = 0;
+ unsigned long h_back = h;
+ int ncase = (*fmt & 0x20);
+ dp = (const int *)lp;
+
+ if((*fmt == 'p') || (*fmt == 'P'))
+ alt=1;
+
+ if(alt) {
+ *q++ = '0';
+ *q++ = 'X' | ncase;
+ }
+
+ //hback 是实际得到的数æ®ï¼Œhex_count是统计数æ®çš„HEXå—符个数
+ while(h_back) {
+ hex_count += (h_back & 0xF) ? 1 : 0;
+ h_back = h_back >> 4;
+ }
+
+ //è¿™é‡Œä¿®å¤ example: å—符有4个,但是用了%02x导致å—符被截æ–的情况
+ if(shift < (hex_count - 1)*4)
+ shift = (hex_count - 1)*4;
+
+ //printf("(%d,%d)", hex_count, shift);
+
+ for(; shift >= 0; shift -= 4) {
+
+ *q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
+ }
+
+ }
+ else if(*fmt == 'd') {
+ int i = *dp++;
+ char *r;
+ int digit_space = 0;
+
+ if(i < 0) {
+ *q++ = '-';
+ i = -i;
+ digit_space++;
+ }
+
+ p = q; /* save beginning of digits */
+
+ do {
+ *q++ = '0' + (i % 10);
+ i /= 10;
+ digit_space++;
+ } while(i);
+
+ //è¿™é‡Œä¿®å¤ example:用了%08dåŽï¼Œåœ¨æ•°å—å‰é¢æ²¡æœ‰0的情况
+ for(; shift >= 0; shift -= 4) {
+
+ if(digit_space-- > 0) {
+ ; //do nothing
+ } else {
+ *q++ = '0';
+ }
+ }
+
+ /* reverse digits, stop in middle */
+ r = q; /* don't alter q */
+
+ while(--r > p) {
+ i = *r;
+ *r = *p;
+ *p++ = i;
+ }
+ }
+ else if(*fmt == 'c')
+ *q++ = *dp++;
+ else
+ *q++ = *fmt;
+
+ /* now output the saved string */
+ for(p = tmp; p < q; ++p) {
+ if(buf) {
+ *s++ = *p;
+ } else {
+ DiagPutChar(*p);
+ }
+
+ if((*p) == '\n') {
+ DiagPutChar('\r');
+ }
+ }
+ }
+ }
+
+ if(buf)
+ *s = '\0';
+
+ return (s - buf);
+}
+
+
+u32 DiagPrintfPatch(
+ IN const char *fmt, ...
+)
+{
+ (void)VSprintfPatch(0, fmt, ((const int *)&fmt)+1);
+ return 1;
+}
+
+u32 DiagSPrintfPatch(
+ IN u8 *buf,
+ IN const char *fmt, ...
+)
+{
+ (void)VSprintfPatch((char*)buf, fmt, ((const int *)&fmt)+1);
+ return 1;
+}
+#endif
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h
new file mode 100644
index 0000000..2a0a4a7
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h
@@ -0,0 +1,593 @@
+/*
+ * OS specific functions
+ * Copyright (c) 2005-2009, Jouni Malinen
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef OS_H
+#define OS_H
+
+//#include "basic_types.h"
+#include
+#include "osdep_service.h"
+#include "freertos/wrapper.h"
+#include "utils/rom/rom_wps_os.h"
+
+typedef void* xqueue_handle_t;
+
+typedef long os_time_t;
+
+typedef _timer os_timer;
+
+/**
+ * os_sleep - Sleep (sec, usec)
+ * @sec: Number of seconds to sleep
+ * @usec: Number of microseconds to sleep
+ */
+void os_sleep(os_time_t sec, os_time_t usec);
+
+struct os_time {
+ os_time_t sec;
+ os_time_t usec;
+};
+
+struct os_reltime {
+ os_time_t sec;
+ os_time_t usec;
+};
+
+/**
+ * os_get_time - Get current time (sec, usec)
+ * @t: Pointer to buffer for the time
+ * Returns: 0 on success, -1 on failure
+ */
+int os_get_time(struct os_time *t);
+
+int os_get_reltime(struct os_reltime *t);
+/* Helper macros for handling struct os_time */
+/* (&timeout->time, &tmp->time) */
+#define os_time_before(a, b) \
+ ((a)->sec < (b)->sec || \
+ ((a)->sec == (b)->sec && (a)->usec < (b)->usec))
+
+#define os_time_sub(a, b, res) do { \
+ (res)->sec = (a)->sec - (b)->sec; \
+ (res)->usec = (a)->usec - (b)->usec; \
+ if ((res)->usec < 0) { \
+ (res)->sec--; \
+ (res)->usec += 1000000; \
+ } \
+} while (0)
+
+/**
+ * os_mktime - Convert broken-down time into seconds since 1970-01-01
+ * @year: Four digit year
+ * @month: Month (1 .. 12)
+ * @day: Day of month (1 .. 31)
+ * @hour: Hour (0 .. 23)
+ * @min: Minute (0 .. 59)
+ * @sec: Second (0 .. 60)
+ * @t: Buffer for returning calendar time representation (seconds since
+ * 1970-01-01 00:00:00)
+ * Returns: 0 on success, -1 on failure
+ *
+ * Note: The result is in seconds from Epoch, i.e., in UTC, not in local time
+ * which is used by POSIX mktime().
+ */
+int os_mktime(int year, int month, int day, int hour, int min, int sec,
+ os_time_t *t);
+
+struct os_tm {
+ int sec; /* 0..59 or 60 for leap seconds */
+ int min; /* 0..59 */
+ int hour; /* 0..23 */
+ int day; /* 1..31 */
+ int month; /* 1..12 */
+ int year; /* Four digit year */
+};
+
+int os_gmtime(os_time_t t, struct os_tm *tm);
+
+/* Helpers for handling struct os_time */
+
+/* Helpers for handling struct os_reltime */
+
+static inline int os_reltime_before(struct os_reltime *a,
+ struct os_reltime *b)
+{
+ return os_time_before(a,b);
+}
+
+
+static inline void os_reltime_sub(struct os_reltime *a, struct os_reltime *b,
+ struct os_reltime *res)
+{
+ os_time_sub(a,b,res);
+}
+
+
+static inline void os_reltime_age(struct os_reltime *start,
+ struct os_reltime *age)
+{
+ struct os_reltime now;
+
+ os_get_time((struct os_time *)&now);
+ os_reltime_sub(&now, start, age);
+}
+
+
+static inline int os_reltime_expired(struct os_reltime *now,
+ struct os_reltime *ts,
+ os_time_t timeout_secs)
+{
+ struct os_reltime age;
+
+ os_reltime_sub(now, ts, &age);
+ return (age.sec > timeout_secs) ||
+ (age.sec == timeout_secs && age.usec > 0);
+}
+
+/**
+ * os_daemonize - Run in the background (detach from the controlling terminal)
+ * @pid_file: File name to write the process ID to or %NULL to skip this
+ * Returns: 0 on success, -1 on failure
+ */
+int os_daemonize(const char *pid_file);
+
+/**
+ * os_daemonize_terminate - Stop running in the background (remove pid file)
+ * @pid_file: File name to write the process ID to or %NULL to skip this
+ */
+void os_daemonize_terminate(const char *pid_file);
+
+/**
+ * os_get_random - Get cryptographically strong pseudo random data
+ * @buf: Buffer for pseudo random data
+ * @len: Length of the buffer
+ * Returns: 0 on success, -1 on failure
+ */
+int os_get_random(unsigned char *buf, size_t len);
+
+/**
+ * os_random - Get pseudo random value (not necessarily very strong)
+ * Returns: Pseudo random value
+ */
+unsigned long os_random(void);
+
+/**
+ * os_rel2abs_path - Get an absolute path for a file
+ * @rel_path: Relative path to a file
+ * Returns: Absolute path for the file or %NULL on failure
+ *
+ * This function tries to convert a relative path of a file to an absolute path
+ * in order for the file to be found even if current working directory has
+ * changed. The returned value is allocated and caller is responsible for
+ * freeing it. It is acceptable to just return the same path in an allocated
+ * buffer, e.g., return strdup(rel_path). This function is only used to find
+ * configuration files when os_daemonize() may have changed the current working
+ * directory and relative path would be pointing to a different location.
+ */
+char * os_rel2abs_path(const char *rel_path);
+
+/**
+ * os_program_init - Program initialization (called at start)
+ * Returns: 0 on success, -1 on failure
+ *
+ * This function is called when a programs starts. If there are any OS specific
+ * processing that is needed, it can be placed here. It is also acceptable to
+ * just return 0 if not special processing is needed.
+ */
+int os_program_init(void);
+
+/**
+ * os_program_deinit - Program deinitialization (called just before exit)
+ *
+ * This function is called just before a program exists. If there are any OS
+ * specific processing, e.g., freeing resourced allocated in os_program_init(),
+ * it should be done here. It is also acceptable for this function to do
+ * nothing.
+ */
+void os_program_deinit(void);
+
+/**
+ * os_setenv - Set environment variable
+ * @name: Name of the variable
+ * @value: Value to set to the variable
+ * @overwrite: Whether existing variable should be overwritten
+ * Returns: 0 on success, -1 on error
+ *
+ * This function is only used for wpa_cli action scripts. OS wrapper does not
+ * need to implement this if such functionality is not needed.
+ */
+int os_setenv(const char *name, const char *value, int overwrite);
+
+/**
+ * os_unsetenv - Delete environent variable
+ * @name: Name of the variable
+ * Returns: 0 on success, -1 on error
+ *
+ * This function is only used for wpa_cli action scripts. OS wrapper does not
+ * need to implement this if such functionality is not needed.
+ */
+int os_unsetenv(const char *name);
+
+/**
+ * os_readfile - Read a file to an allocated memory buffer
+ * @name: Name of the file to read
+ * @len: For returning the length of the allocated buffer
+ * Returns: Pointer to the allocated buffer or %NULL on failure
+ *
+ * This function allocates memory and reads the given file to this buffer. Both
+ * binary and text files can be read with this function. The caller is
+ * responsible for freeing the returned buffer with os_free().
+ */
+char * os_readfile(const char *name, size_t *len);
+
+//#if 0
+/**
+ * os_zalloc - Allocate and zero memory
+ * @size: Number of bytes to allocate
+ * Returns: Pointer to allocated and zeroed memory or %NULL on failure
+ *
+ * Caller is responsible for freeing the returned buffer with os_free().
+ */
+void * os_zalloc(size_t size);
+
+/**
+ * os_calloc - Allocate and zero memory for an array
+ * @nmemb: Number of members in the array
+ * @size: Number of bytes in each member
+ * Returns: Pointer to allocated and zeroed memory or %NULL on failure
+ *
+ * This function can be used as a wrapper for os_zalloc(nmemb * size) when an
+ * allocation is used for an array. The main benefit over os_zalloc() is in
+ * having an extra check to catch integer overflows in multiplication.
+ *
+ * Caller is responsible for freeing the returned buffer with os_free().
+ */
+static inline void * os_calloc(size_t nmemb, size_t size)
+{
+ if (size && nmemb > (~(size_t) 0) / size)
+ return NULL;
+ return os_zalloc(nmemb * size);
+}
+//#endif
+
+
+static inline int os_memcmp_const(const void *a, const void *b, size_t len)
+{
+ const u8 *aa = a;
+ const u8 *bb = b;
+ size_t i;
+ u8 res;
+
+ for (res = 0, i = 0; i < len; i++)
+ res |= aa[i] ^ bb[i];
+
+ return res;
+}
+
+/*
+ * The following functions are wrapper for standard ANSI C or POSIX functions.
+ * By default, they are just defined to use the standard function name and no
+ * os_*.c implementation is needed for them. This avoids extra function calls
+ * by allowing the C pre-processor take care of the function name mapping.
+ *
+ * If the target system uses a C library that does not provide these functions,
+ * build_config.h can be used to define the wrappers to use a different
+ * function name. This can be done on function-by-function basis since the
+ * defines here are only used if build_config.h does not define the os_* name.
+ * If needed, os_*.c file can be used to implement the functions that are not
+ * included in the C library on the target system. Alternatively,
+ * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
+ * these functions need to be implemented in os_*.c file for the target system.
+ */
+
+#ifdef OS_NO_C_LIB_DEFINES
+
+/**
+ * os_malloc - Allocate dynamic memory
+ * @size: Size of the buffer to allocate
+ * Returns: Allocated buffer or %NULL on failure
+ *
+ * Caller is responsible for freeing the returned buffer with os_free().
+ */
+void * os_malloc(size_t size);
+
+/**
+ * os_realloc - Re-allocate dynamic memory
+ * @ptr: Old buffer from os_malloc() or os_realloc()
+ * @size: Size of the new buffer
+ * Returns: Allocated buffer or %NULL on failure
+ *
+ * Caller is responsible for freeing the returned buffer with os_free().
+ * If re-allocation fails, %NULL is returned and the original buffer (ptr) is
+ * not freed and caller is still responsible for freeing it.
+ */
+void * os_realloc(void *ptr, size_t size);
+
+/**
+ * os_free - Free dynamic memory
+ * @ptr: Old buffer from os_malloc() or os_realloc(); can be %NULL
+ */
+void os_free(void *ptr);
+
+/**
+ * os_memcpy - Copy memory area
+ * @dest: Destination
+ * @src: Source
+ * @n: Number of bytes to copy
+ * Returns: dest
+ *
+ * The memory areas src and dst must not overlap. os_memmove() can be used with
+ * overlapping memory.
+ */
+void * os_memcpy(void *dest, const void *src, size_t n);
+
+/**
+ * os_memmove - Copy memory area
+ * @dest: Destination
+ * @src: Source
+ * @n: Number of bytes to copy
+ * Returns: dest
+ *
+ * The memory areas src and dst may overlap.
+ */
+void *os_memmove(void *dest, const void *src, size_t n);
+
+/**
+ * os_memset - Fill memory with a constant byte
+ * @s: Memory area to be filled
+ * @c: Constant byte
+ * @n: Number of bytes started from s to fill with c
+ * Returns: s
+ */
+void *os_memset(void *s, int c, size_t n);
+
+/**
+ * os_memcmp - Compare memory areas
+ * @s1: First buffer
+ * @s2: Second buffer
+ * @n: Maximum numbers of octets to compare
+ * Returns: An integer less than, equal to, or greater than zero if s1 is
+ * found to be less than, to match, or be greater than s2. Only first n
+ * characters will be compared.
+ */
+int os_memcmp(const void *s1, const void *s2, size_t n);
+
+/**
+ * os_strdup - Duplicate a string
+ * @s: Source string
+ * Returns: Allocated buffer with the string copied into it or %NULL on failure
+ *
+ * Caller is responsible for freeing the returned buffer with os_free().
+ */
+char *os_strdup(const char *s);
+
+/**
+ * os_strlen - Calculate the length of a string
+ * @s: '\0' terminated string
+ * Returns: Number of characters in s (not counting the '\0' terminator)
+ */
+size_t os_strlen(const char *s);
+
+/**
+ * os_strcasecmp - Compare two strings ignoring case
+ * @s1: First string
+ * @s2: Second string
+ * Returns: An integer less than, equal to, or greater than zero if s1 is
+ * found to be less than, to match, or be greatred than s2
+ */
+int os_strcasecmp(const char *s1, const char *s2);
+
+/**
+ * os_strncasecmp - Compare two strings ignoring case
+ * @s1: First string
+ * @s2: Second string
+ * @n: Maximum numbers of characters to compare
+ * Returns: An integer less than, equal to, or greater than zero if s1 is
+ * found to be less than, to match, or be greater than s2. Only first n
+ * characters will be compared.
+ */
+int os_strncasecmp(const char *s1, const char *s2, size_t n);
+
+/**
+ * os_strchr - Locate the first occurrence of a character in string
+ * @s: String
+ * @c: Character to search for
+ * Returns: Pointer to the matched character or %NULL if not found
+ */
+char *os_strchr(const char *s, int c);
+
+/**
+ * os_strrchr - Locate the last occurrence of a character in string
+ * @s: String
+ * @c: Character to search for
+ * Returns: Pointer to the matched character or %NULL if not found
+ */
+char *os_strrchr(const char *s, int c);
+
+/**
+ * os_strcmp - Compare two strings
+ * @s1: First string
+ * @s2: Second string
+ * Returns: An integer less than, equal to, or greater than zero if s1 is
+ * found to be less than, to match, or be greatred than s2
+ */
+int os_strcmp(const char *s1, const char *s2);
+
+/**
+ * os_strncmp - Compare two strings
+ * @s1: First string
+ * @s2: Second string
+ * @n: Maximum numbers of characters to compare
+ * Returns: An integer less than, equal to, or greater than zero if s1 is
+ * found to be less than, to match, or be greater than s2. Only first n
+ * characters will be compared.
+ */
+int os_strncmp(const char *s1, const char *s2, size_t n);
+
+/**
+ * os_strncpy - Copy a string
+ * @dest: Destination
+ * @src: Source
+ * @n: Maximum number of characters to copy
+ * Returns: dest
+ */
+char *os_strncpy(char *dest, const char *src, size_t n);
+
+/**
+ * os_strstr - Locate a substring
+ * @haystack: String (haystack) to search from
+ * @needle: Needle to search from haystack
+ * Returns: Pointer to the beginning of the substring or %NULL if not found
+ */
+char *os_strstr(const char *haystack, const char *needle);
+
+/**
+ * os_snprintf - Print to a memory buffer
+ * @str: Memory buffer to print into
+ * @size: Maximum length of the str buffer
+ * @format: printf format
+ * Returns: Number of characters printed (not including trailing '\0').
+ *
+ * If the output buffer is truncated, number of characters which would have
+ * been written is returned. Since some C libraries return -1 in such a case,
+ * the caller must be prepared on that value, too, to indicate truncation.
+ *
+ * Note: Some C library implementations of snprintf() may not guarantee null
+ * termination in case the output is truncated. The OS wrapper function of
+ * os_snprintf() should provide this guarantee, i.e., to null terminate the
+ * output buffer if a C library version of the function is used and if that
+ * function does not guarantee null termination.
+ *
+ * If the target system does not include snprintf(), see, e.g.,
+ * http://www.ijs.si/software/snprintf/ for an example of a portable
+ * implementation of snprintf.
+ */
+int os_snprintf(char *str, size_t size, const char *format, ...);
+
+#else /* OS_NO_C_LIB_DEFINES */
+
+#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
+#ifdef CONFIG_MEM_MONITOR
+ u8* os_malloc(u32 sz);
+ void os_mfree(u8 *pbuf, u32 sz);
+ #ifndef os_free
+ #define os_free(p, sz) os_mfree(((u8*)(p)), (sz))
+ #endif
+#else
+ #ifndef os_malloc
+ #define os_malloc(sz) _rtw_malloc(sz)
+ #endif
+ #ifndef os_free
+ #define os_free(p, sz) _rtw_mfree(((u8*)(p)), (sz))
+ #endif
+#endif
+#endif
+ extern void *os_zalloc(size_t size);
+ extern char *os_strdup(const char *string_copy_from);
+
+ #ifndef os_sleep
+ #define os_sleep(s, us) rtw_mdelay_os((s)*1000 + (us)/1000)
+ #endif
+ #ifndef os_memcpy
+ #define os_memcpy(d, s, n) rtw_memcpy((void*)(d), ((void*)(s)), (n))
+ #endif
+ #ifndef os_memmove
+ #define os_memmove(d, s, n) memmove((d), (s), (n))
+ #endif
+ #ifndef os_memset
+ #define os_memset(pbuf, c, sz) rtw_memset(pbuf, c, sz)
+ #endif
+ #ifndef os_memcmp
+ #define os_memcmp(s1, s2, n) rtw_memcmp(((void*)(s1)), ((void*)(s2)), (n))
+ #endif
+ #ifndef os_memcmp_p2p
+ #define os_memcmp_p2p(s1, s2, n) memcmp((s1), (s2), (n))
+ #endif
+ #ifndef os_get_random_bytes
+ #define os_get_random_bytes(d,sz) rtw_get_random_bytes(((void*)(d)), (sz))
+ #endif
+ #ifndef os_strlen
+ #define os_strlen(s) strlen(s)
+ #endif
+ #ifndef os_strcasecmp
+ #ifdef _MSC_VER
+ #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
+ #else
+ #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
+ #endif
+ #endif
+ #ifndef os_strncasecmp
+ #ifdef _MSC_VER
+ #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
+ #else
+ #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
+ #endif
+ #endif
+ #ifndef os_init_timer
+ #define os_init_timer(t, p, f, x, n) rtw_init_timer((t), (p), (f), (x), (n))
+ #endif
+ #ifndef os_set_timer
+ #define os_set_timer(t, d) rtw_set_timer((t), (d))
+ #endif
+ #ifndef os_cancel_timer
+ #define os_cancel_timer(t) rtw_cancel_timer(t)
+ #endif
+ #ifndef os_del_timer
+ #define os_del_timer(t) rtw_del_timer(t)
+ #endif
+ #ifndef os_atoi
+ #define os_atoi(s) rtw_atoi(s)
+ #endif
+
+#ifndef os_strchr
+#define os_strchr(s, c) strchr((s), (c))
+#endif
+#ifndef os_strcmp
+#define os_strcmp(s1, s2) strcmp((s1), (s2))
+#endif
+#ifndef os_strncmp
+#define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
+#endif
+#ifndef os_strncpy
+#define os_strncpy(d, s, n) strncpy((d), (s), (n))
+#endif
+#ifndef os_strrchr
+#define os_strrchr(s, c) strrchr((s), (c))
+#endif
+#ifndef os_strstr
+#define os_strstr(h, n) strstr((h), (n))
+#endif
+
+#ifndef os_snprintf
+ #ifdef _MSC_VER
+ #define os_snprintf _snprintf
+ #else
+ #define os_snprintf snprintf
+ #endif
+#endif
+
+#endif /* OS_NO_C_LIB_DEFINES */
+
+
+static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
+{
+ if (size && nmemb > (~(size_t) 0) / size)
+ return NULL;
+ return os_realloc(ptr, nmemb * size, nmemb * size);
+}
+
+void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize) ;
+
+int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait);
+
+void os_xqueue_delete(xqueue_handle_t xQueue );
+
+int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait);
+
+
+#endif /* OS_H */
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/os_freertos.c b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/os_freertos.c
new file mode 100644
index 0000000..aed28f2
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/os_freertos.c
@@ -0,0 +1,119 @@
+/*
+ * OS specific functions for UNIX/POSIX systems
+ * Copyright (c) 2005-2009, Jouni Malinen
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+#include "utils/os.h"
+
+//#ifdef CONFIG_WPS
+
+#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
+#ifdef CONFIG_MEM_MONITOR
+#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
+_list wpa_mem_table;
+int wpa_mem_used_num;
+//int wpa_mem_used_size;
+#endif
+extern int min_free_heap_size;
+u8* os_malloc(u32 sz)
+{
+ int free_heap_size = rtw_getFreeHeapSize();
+ u8 *pbuf = _rtw_malloc(sz);
+#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
+ add_mem_usage(&wpa_mem_table, pbuf, sz, &wpa_mem_used_num, MEM_MONITOR_FLAG_WPAS);
+#else
+ add_mem_usage(NULL, pbuf, sz, NULL, MEM_MONITOR_FLAG_WPAS);
+#endif
+ if(min_free_heap_size > free_heap_size)
+ min_free_heap_size = free_heap_size;
+ return pbuf;
+}
+
+void os_mfree(u8 *pbuf, u32 sz)
+{
+ _rtw_mfree(pbuf, sz);
+#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
+ del_mem_usage(&wpa_mem_table, pbuf, &wpa_mem_used_num, MEM_MONITOR_FLAG_WPAS);
+#else
+ del_mem_usage(NULL, pbuf, NULL, MEM_MONITOR_FLAG_WPAS);
+#endif
+}
+#endif//CONFIG_MEM_MONITOR
+
+#endif// !defined(CONFIG_PLATFORM_8195A)
+
+#ifndef OS_NO_C_LIB_DEFINES
+char *os_strdup(const char *string_copy_from)
+{
+ char *string_copy_to = NULL;
+ string_copy_to = os_zalloc(strlen(string_copy_from) + 1);
+ os_memcpy((void *)string_copy_to, string_copy_from, strlen(string_copy_from));
+ string_copy_to[strlen(string_copy_from)] = '\0';
+ return string_copy_to;
+}
+#endif
+
+int os_get_random(unsigned char *buf, size_t len)
+{
+ //TODO implement it
+ rtw_get_random_bytes(buf, len);
+ return 0;
+}
+
+int os_get_time(struct os_time *t){
+ unsigned int tt = rtw_get_current_time();
+ t->sec = (os_time_t) (tt / 1000);
+ t->usec = (os_time_t) (tt % 1000)*1000;
+ return 0;
+}
+
+int os_get_reltime(struct os_reltime *t){
+ os_get_time((struct os_time *)t);
+ return 0;
+}
+#if 0
+void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize)
+{
+ return xQueueCreate( uxQueueLength, uxItemSize );
+}
+
+int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait)
+{
+ return xQueueReceive((xQueueHandle)xQueue, pvBuffer, (portTickType)(xSecsToWait*configTICK_RATE_HZ));
+}
+
+void os_xqueue_delete(xqueue_handle_t xQueue )
+{
+ vQueueDelete((xQueueHandle)xQueue);
+}
+
+int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait)
+{
+ return xQueueSendToBack((xQueueHandle)xQueue, pvItemToQueue, (portTickType)(xSecsToWait*configTICK_RATE_HZ));
+}
+#else
+void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize)
+{
+ void* xQueue = NULL;
+ rtw_init_xqueue(&xQueue, "queue", uxItemSize, uxQueueLength);
+ return xQueue;
+}
+
+int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait)
+{
+ return rtw_pop_from_xqueue(&xQueue, pvBuffer, xSecsToWait*1000);
+}
+
+void os_xqueue_delete(xqueue_handle_t xQueue )
+{
+ rtw_deinit_xqueue(&xQueue);
+}
+
+int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait)
+{
+ return rtw_push_to_xqueue(&xQueue, (void*)pvItemToQueue, xSecsToWait*1000);
+}
+#endif
+//#endif
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/rom/rom_wps_os.h b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/rom/rom_wps_os.h
new file mode 100644
index 0000000..cd41061
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/utils/rom/rom_wps_os.h
@@ -0,0 +1,24 @@
+/*
+ * OS specific functions
+ * Copyright (c) 2005-2009, Jouni Malinen
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef ROM_WPS_OS_H
+#define ROM_WPS_OS_H
+
+#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
+
+#include
+extern struct _rom_wlan_ram_map rom_wlan_ram_map;
+#define os_malloc(sz) rom_wlan_ram_map.rtw_malloc(sz)
+#define os_free(p, sz) rom_wlan_ram_map.rtw_mfree(((u8*)(p)), (sz))
+
+#endif
+
+extern u8 *WPS_realloc(u8 *old_buf, u32 old_sz, u32 new_sz);
+#define os_realloc(p, os, ns) WPS_realloc(((u8*)(p)),(os),(ns))
+
+#endif /* ROM_WPS_OS_H */
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h
new file mode 100644
index 0000000..73d5940
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h
@@ -0,0 +1,319 @@
+
+/*
+ * Wi-Fi Protected Setup - message definitions
+ * Copyright (c) 2008, Jouni Malinen
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef WPS_DEFS_H
+#define WPS_DEFS_H
+
+
+/* Diffie-Hellman 1536-bit MODP Group; RFC 3526, Group 5 */
+#define WPS_DH_GROUP (5)
+
+#define WPS_UUID_LEN (16)
+#define WPS_NONCE_LEN (16)
+#define WPS_AUTHENTICATOR_LEN (8)
+#define WPS_AUTHKEY_LEN (32)
+#define WPS_KEYWRAPKEY_LEN (16)
+#define WPS_EMSK_LEN (32)
+#define WPS_PSK_LEN (16)
+#define WPS_SECRET_NONCE_LEN (16)
+#define WPS_HASH_LEN (32)
+#define WPS_KWA_LEN (8)
+#define WPS_MGMTAUTHKEY_LEN (32)
+#define WPS_MGMTENCKEY_LEN (16)
+#define WPS_MGMT_KEY_ID_LEN (16)
+#define WPS_OOB_DEVICE_PASSWORD_MIN_LEN (16)
+#define WPS_OOB_DEVICE_PASSWORD_LEN (32)
+#define WPS_OOB_PUBKEY_HASH_LEN (20)
+
+/* Attribute Types */
+enum wps_attribute {
+ ATTR_AP_CHANNEL = 0x1001,
+ ATTR_ASSOC_STATE = 0x1002,
+ ATTR_AUTH_TYPE = 0x1003,
+ ATTR_AUTH_TYPE_FLAGS = 0x1004,
+ ATTR_AUTHENTICATOR = 0x1005,
+ ATTR_CONFIG_METHODS = 0x1008,
+ ATTR_CONFIG_ERROR = 0x1009,
+ ATTR_CONFIRM_URL4 = 0x100a,
+ ATTR_CONFIRM_URL6 = 0x100b,
+ ATTR_CONN_TYPE = 0x100c,
+ ATTR_CONN_TYPE_FLAGS = 0x100d,
+ ATTR_CRED = 0x100e,
+ ATTR_ENCR_TYPE = 0x100f,
+ ATTR_ENCR_TYPE_FLAGS = 0x1010,
+ ATTR_DEV_NAME = 0x1011,
+ ATTR_DEV_PASSWORD_ID = 0x1012,
+ ATTR_E_HASH1 = 0x1014,
+ ATTR_E_HASH2 = 0x1015,
+ ATTR_E_SNONCE1 = 0x1016,
+ ATTR_E_SNONCE2 = 0x1017,
+ ATTR_ENCR_SETTINGS = 0x1018,
+ ATTR_ENROLLEE_NONCE = 0x101a,
+ ATTR_FEATURE_ID = 0x101b,
+ ATTR_IDENTITY = 0x101c,
+ ATTR_IDENTITY_PROOF = 0x101d,
+ ATTR_KEY_WRAP_AUTH = 0x101e,
+ ATTR_KEY_ID = 0x101f,
+ ATTR_MAC_ADDR = 0x1020,
+ ATTR_MANUFACTURER = 0x1021,
+ ATTR_MSG_TYPE = 0x1022,
+ ATTR_MODEL_NAME = 0x1023,
+ ATTR_MODEL_NUMBER = 0x1024,
+ ATTR_NETWORK_INDEX = 0x1026,
+ ATTR_NETWORK_KEY = 0x1027,
+ ATTR_NETWORK_KEY_INDEX = 0x1028,
+ ATTR_NEW_DEVICE_NAME = 0x1029,
+ ATTR_NEW_PASSWORD = 0x102a,
+ ATTR_OOB_DEVICE_PASSWORD = 0x102c,
+ ATTR_OS_VERSION = 0x102d,
+ ATTR_POWER_LEVEL = 0x102f,
+ ATTR_PSK_CURRENT = 0x1030,
+ ATTR_PSK_MAX = 0x1031,
+ ATTR_PUBLIC_KEY = 0x1032,
+ ATTR_RADIO_ENABLE = 0x1033,
+ ATTR_REBOOT = 0x1034,
+ ATTR_REGISTRAR_CURRENT = 0x1035,
+ ATTR_REGISTRAR_ESTABLISHED = 0x1036,
+ ATTR_REGISTRAR_LIST = 0x1037,
+ ATTR_REGISTRAR_MAX = 0x1038,
+ ATTR_REGISTRAR_NONCE = 0x1039,
+ ATTR_REQUEST_TYPE = 0x103a,
+ ATTR_RESPONSE_TYPE = 0x103b,
+ ATTR_RF_BANDS = 0x103c,
+ ATTR_R_HASH1 = 0x103d,
+ ATTR_R_HASH2 = 0x103e,
+ ATTR_R_SNONCE1 = 0x103f,
+ ATTR_R_SNONCE2 = 0x1040,
+ ATTR_SELECTED_REGISTRAR = 0x1041,
+ ATTR_SERIAL_NUMBER = 0x1042,
+ ATTR_WPS_STATE = 0x1044,
+ ATTR_SSID = 0x1045,
+ ATTR_TOTAL_NETWORKS = 0x1046,
+ ATTR_UUID_E = 0x1047,
+ ATTR_UUID_R = 0x1048,
+ ATTR_VENDOR_EXT = 0x1049,
+ ATTR_VERSION = 0x104a,
+ ATTR_X509_CERT_REQ = 0x104b,
+ ATTR_X509_CERT = 0x104c,
+ ATTR_EAP_IDENTITY = 0x104d,
+ ATTR_MSG_COUNTER = 0x104e,
+ ATTR_PUBKEY_HASH = 0x104f,
+ ATTR_REKEY_KEY = 0x1050,
+ ATTR_KEY_LIFETIME = 0x1051,
+ ATTR_PERMITTED_CFG_METHODS = 0x1052,
+ ATTR_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053,
+ ATTR_PRIMARY_DEV_TYPE = 0x1054,
+ ATTR_SECONDARY_DEV_TYPE_LIST = 0x1055,
+ ATTR_PORTABLE_DEV = 0x1056,
+ ATTR_AP_SETUP_LOCKED = 0x1057,
+ ATTR_APPLICATION_EXT = 0x1058,
+ ATTR_EAP_TYPE = 0x1059,
+ ATTR_IV = 0x1060,
+ ATTR_KEY_PROVIDED_AUTO = 0x1061,
+ ATTR_802_1X_ENABLED = 0x1062,
+ ATTR_APPSESSIONKEY = 0x1063,
+ ATTR_WEPTRANSMITKEY = 0x1064,
+ ATTR_REQUESTED_DEV_TYPE = 0x106a,
+ ATTR_EXTENSIBILITY_TEST = 0x10fa /* _NOT_ defined in the spec */
+};
+
+#define WPS_VENDOR_ID_WFA 14122
+
+/* WFA Vendor Extension subelements */
+enum {
+ WFA_ELEM_VERSION2 = 0x00,
+ WFA_ELEM_AUTHORIZEDMACS = 0x01,
+ WFA_ELEM_NETWORK_KEY_SHAREABLE = 0x02,
+ WFA_ELEM_REQUEST_TO_ENROLL = 0x03,
+ WFA_ELEM_SETTINGS_DELAY_TIME = 0x04
+};
+
+/* Device Password ID */
+enum wps_dev_password_id {
+ DEV_PW_DEFAULT = 0x0000,
+ DEV_PW_USER_SPECIFIED = 0x0001,
+ DEV_PW_MACHINE_SPECIFIED = 0x0002,
+ DEV_PW_REKEY = 0x0003,
+ DEV_PW_PUSHBUTTON = 0x0004,
+ DEV_PW_REGISTRAR_SPECIFIED = 0x0005
+};
+
+/* Message Type */
+enum wps_msg_type {
+ WPS_START = 0x00,
+ WPS_Beacon = 0x01,
+ WPS_ProbeRequest = 0x02,
+ WPS_ProbeResponse = 0x03,
+ WPS_M1 = 0x04,
+ WPS_M2 = 0x05,
+ WPS_M2D = 0x06,
+ WPS_M3 = 0x07,
+ WPS_M4 = 0x08,
+ WPS_M5 = 0x09,
+ WPS_M6 = 0x0a,
+ WPS_M7 = 0x0b,
+ WPS_M8 = 0x0c,
+ WPS_WSC_ACK = 0x0d,
+ WPS_WSC_NACK = 0x0e,
+ WPS_WSC_DONE = 0x0f
+};
+
+/* Authentication Type Flags */
+#define WPS_AUTH_OPEN 0x0001
+#define WPS_AUTH_WPAPSK 0x0002
+#define WPS_AUTH_SHARED 0x0004
+#define WPS_AUTH_WPA 0x0008
+#define WPS_AUTH_WPA2 0x0010
+#define WPS_AUTH_WPA2PSK 0x0020
+#define WPS_AUTH_TYPES (WPS_AUTH_OPEN | WPS_AUTH_WPAPSK | WPS_AUTH_SHARED | \
+ WPS_AUTH_WPA | WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK)
+
+/* Encryption Type Flags */
+#define WPS_ENCR_NONE 0x0001
+#define WPS_ENCR_WEP 0x0002
+#define WPS_ENCR_TKIP 0x0004
+#define WPS_ENCR_AES 0x0008
+#define WPS_ENCR_TYPES (WPS_ENCR_NONE | WPS_ENCR_WEP | WPS_ENCR_TKIP | \
+ WPS_ENCR_AES)
+
+/* Configuration Error */
+enum wps_config_error {
+ WPS_CFG_NO_ERROR = 0,
+ WPS_CFG_OOB_IFACE_READ_ERROR = 1,
+ WPS_CFG_DECRYPTION_CRC_FAILURE = 2,
+ WPS_CFG_24_CHAN_NOT_SUPPORTED = 3,
+ WPS_CFG_50_CHAN_NOT_SUPPORTED = 4,
+ WPS_CFG_SIGNAL_TOO_WEAK = 5,
+ WPS_CFG_NETWORK_AUTH_FAILURE = 6,
+ WPS_CFG_NETWORK_ASSOC_FAILURE = 7,
+ WPS_CFG_NO_DHCP_RESPONSE = 8,
+ WPS_CFG_FAILED_DHCP_CONFIG = 9,
+ WPS_CFG_IP_ADDR_CONFLICT = 10,
+ WPS_CFG_NO_CONN_TO_REGISTRAR = 11,
+ WPS_CFG_MULTIPLE_PBC_DETECTED = 12,
+ WPS_CFG_ROGUE_SUSPECTED = 13,
+ WPS_CFG_DEVICE_BUSY = 14,
+ WPS_CFG_SETUP_LOCKED = 15,
+ WPS_CFG_MSG_TIMEOUT = 16,
+ WPS_CFG_REG_SESS_TIMEOUT = 17,
+ WPS_CFG_DEV_PASSWORD_AUTH_FAILURE = 18
+};
+
+/* RF Bands */
+#define WPS_RF_24GHZ (0x01)
+#define WPS_RF_50GHZ (0x02)
+
+/* Config Methods */
+#define WPS_CONFIG_USBA (0x0001)
+#define WPS_CONFIG_ETHERNET (0x0002)
+#define WPS_CONFIG_LABEL (0x0004)
+#define WPS_CONFIG_DISPLAY (0x0008)
+#define WPS_CONFIG_EXT_NFC_TOKEN (0x0010)
+#define WPS_CONFIG_INT_NFC_TOKEN (0x0020)
+#define WPS_CONFIG_NFC_INTERFACE (0x0040)
+#define WPS_CONFIG_PUSHBUTTON (0x0080)
+#define WPS_CONFIG_KEYPAD (0x0100)
+
+#ifdef CONFIG_WPS2
+#define WPS_CONFIG_VIRT_PUSHBUTTON (0x0280)
+#define WPS_CONFIG_PHY_PUSHBUTTON (0x0480)
+#define WPS_CONFIG_VIRT_DISPLAY (0x2008)
+#define WPS_CONFIG_PHY_DISPLAY (0x4008)
+#endif /* CONFIG_WPS2 */
+
+/* Connection Type Flags */
+#define WPS_CONN_ESS (0x01)
+#define WPS_CONN_IBSS (0x02)
+
+/* Wi-Fi Protected Setup State */
+enum wps_state {
+ WPS_STATE_NOT_CONFIGURED = 1,
+ WPS_STATE_CONFIGURED = 2
+};
+
+/* Association State */
+enum wps_assoc_state {
+ WPS_ASSOC_NOT_ASSOC = 0,
+ WPS_ASSOC_CONN_SUCCESS = 1,
+ WPS_ASSOC_CFG_FAILURE = 2,
+ WPS_ASSOC_FAILURE = 3,
+ WPS_ASSOC_IP_FAILURE = 4
+};
+
+
+#define WPS_DEV_OUI_WFA (0x0050f204)
+
+enum wps_dev_categ {
+ WPS_DEV_COMPUTER = 1,
+ WPS_DEV_INPUT = 2,
+ WPS_DEV_PRINTER = 3,
+ WPS_DEV_CAMERA = 4,
+ WPS_DEV_STORAGE = 5,
+ WPS_DEV_NETWORK_INFRA = 6,
+ WPS_DEV_DISPLAY = 7,
+ WPS_DEV_MULTIMEDIA = 8,
+ WPS_DEV_GAMING = 9,
+ WPS_DEV_PHONE = 10
+};
+
+enum wps_dev_subcateg {
+ WPS_DEV_COMPUTER_PC = 1,
+ WPS_DEV_COMPUTER_SERVER = 2,
+ WPS_DEV_COMPUTER_MEDIA_CENTER = 3,
+
+ WPS_DEV_PRINTER_PRINTER = 1,
+ WPS_DEV_PRINTER_SCANNER = 2,
+
+ WPS_DEV_CAMERA_DIGITAL_STILL_CAMERA = 1,
+
+ WPS_DEV_STORAGE_NAS = 1,
+
+ WPS_DEV_NETWORK_INFRA_AP = 1,
+ WPS_DEV_NETWORK_INFRA_ROUTER = 2,
+ WPS_DEV_NETWORK_INFRA_SWITCH = 3,
+
+ WPS_DEV_DISPLAY_TV = 1,
+ WPS_DEV_DISPLAY_PICTURE_FRAME = 2,
+ WPS_DEV_DISPLAY_PROJECTOR = 3,
+
+ WPS_DEV_MULTIMEDIA_DAR = 1,
+ WPS_DEV_MULTIMEDIA_PVR = 2,
+ WPS_DEV_MULTIMEDIA_MCX = 3,
+
+ WPS_DEV_GAMING_XBOX = 1,
+ WPS_DEV_GAMING_XBOX360 = 2,
+ WPS_DEV_GAMING_PLAYSTATION = 3,
+
+ WPS_DEV_PHONE_WINDOWS_MOBILE = 1
+};
+
+
+/* Request Type */
+enum wps_request_type {
+ WPS_REQ_ENROLLEE_INFO = 0,
+ WPS_REQ_ENROLLEE = 1,
+ WPS_REQ_REGISTRAR = 2,
+ WPS_REQ_WLAN_MANAGER_REGISTRAR = 3
+};
+
+/* Response Type */
+enum wps_response_type {
+ WPS_RESP_ENROLLEE_INFO = 0,
+ WPS_RESP_ENROLLEE = 1,
+ WPS_RESP_REGISTRAR = 2,
+ WPS_RESP_AP = 3
+};
+
+/* Walk Time for push button configuration (in seconds) */
+#define WPS_PBC_WALK_TIME (120)
+
+#define WPS_MAX_AUTHORIZED_MACS (5)
+
+#endif /* WPS_DEFS_H */
+
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_eap_config.c b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_eap_config.c
new file mode 100644
index 0000000..0ff9e3c
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_eap_config.c
@@ -0,0 +1,453 @@
+#include
+#include
+#include
+#include "FreeRTOS.h"
+#include "task.h"
+#include "main.h"
+#include "queue.h"
+#include "utils/os.h"
+#include
+#include
+#include "wifi/wifi_conf.h"
+#include
+#include
+#include
+
+#define WLAN0_NAME "wlan0"
+#ifndef ENABLE
+#define ENABLE (1)
+#endif
+#ifndef DISABLE
+#define DISABLE (0)
+#endif
+
+u8 eap_phase = 0;
+u8 eap_method = 0;
+
+// eap config arguments
+char *eap_target_ssid = NULL;
+char *eap_identity = NULL;
+char *eap_password = NULL;
+// if set eap_ca_cert and defined(EAP_SSL_VERIFY_SERVER), client will verify server's cert
+const unsigned char *eap_ca_cert = NULL;
+// if set eap_client_cert, eap_client_key, and defined(EAP_SSL_VERIFY_CLIENT), client will send its cert to server
+const unsigned char *eap_client_cert = NULL;
+const unsigned char *eap_client_key = NULL;
+char *eap_client_key_pwd = NULL;
+
+int max_buf_bio_size = SSL_BUFFER_LEN;
+
+#ifdef CONFIG_ENABLE_EAP
+void eap_eapol_recvd_hdl(char *buf, int buf_len, int flags, void* handler_user_data);
+void eap_eapol_start_hdl(char *buf, int buf_len, int flags, void* handler_user_data);
+#endif
+
+void set_eap_phase(unsigned char is_trigger_eap){
+ eap_phase = is_trigger_eap;
+}
+
+int get_eap_phase(void){
+ return eap_phase;
+}
+
+int get_eap_method(void){
+ return eap_method;
+}
+
+void reset_config(void){
+ eap_target_ssid = NULL;
+ eap_identity = NULL;
+ eap_password = NULL;
+ eap_ca_cert = NULL;
+ eap_client_cert = NULL;
+ eap_client_key = NULL;
+ eap_client_key_pwd = NULL;
+}
+
+void judge_station_disconnect(void)
+{
+ int mode = 0;
+ unsigned char ssid[33];
+
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ switch(mode) {
+ case IW_MODE_MASTER: //In AP mode
+ wifi_off();
+ vTaskDelay(20);
+ wifi_on(RTW_MODE_STA);
+ break;
+ case IW_MODE_INFRA: //In STA mode
+ if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
+ wifi_disconnect();
+ }
+}
+#ifdef CONFIG_ENABLE_EAP
+void eap_disconnected_hdl(char *buf, int buf_len, int flags, void* handler_user_data){
+// printf("disconnected\n");
+ wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, eap_eapol_recvd_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_DISCONNECT, eap_disconnected_hdl);
+ eap_peer_unregister_methods();
+ eap_sm_deinit();
+ //reset_config();
+}
+#endif
+/*
+void eap_config(void){
+ eap_target_ssid = "Test_eap";
+ eap_identity = "guest2";
+ eap_password = "test2";
+
+ eap_client_cert = \
+"-----BEGIN CERTIFICATE-----\r\n" \
+"MIIC9zCCAd8CAQMwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNVBAYTAkZSMQ8wDQYD\r\n" \
+"VQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhhbXBs\r\n" \
+"ZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQGA1UE\r\n" \
+"AxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzE1MDgwNzEx\r\n" \
+"WhcNMTcwMzE1MDgwNzExWjBzMQswCQYDVQQGEwJGUjEPMA0GA1UECBMGUmFkaXVz\r\n" \
+"MRUwEwYDVQQKEwxFeGFtcGxlIEluYy4xGjAYBgNVBAMUEXVzZXIyQGV4YW1wbGUu\r\n" \
+"Y29tMSAwHgYJKoZIhvcNAQkBFhF1c2VyMkBleGFtcGxlLmNvbTCBnzANBgkqhkiG\r\n" \
+"9w0BAQEFAAOBjQAwgYkCgYEAqESlV4OYfBcIgZ+Cs8mWpiBjhvKoa0/kIe7saqhC\r\n" \
+"e5q4snox0jdkUpLcc4vOs3vQ7ZGnimqTltA9oF6XNUzTWW4vlJTKEfrCWK085l7c\r\n" \
+"DHFvHavH3E6vuP71lI7jq4PLXbo2TvZK+uBul4ozjzVWihaZBtz8eLHq446h/D/p\r\n" \
+"kzkCAwEAATANBgkqhkiG9w0BAQQFAAOCAQEAAfhVAIkNdeeUNJud720uUHVnIcxz\r\n" \
+"GXWI+Svi1qchuTEnRNhLwXmnE+A0WWSHyfdR6FvzdT3xtz3K50iOif8jY2gCGkSK\r\n" \
+"8RjKr97228SwbrGO9y9+dYIjH1uz9cBpoVKcpzdsWpKObrDPDYyReHSWo99jM2+O\r\n" \
+"vfJxnBw4PLiBj7Q0/dpd6o4JXyp7Cxa0mB4/+cZqjCzzuKfuK3WP7j6laMCV6mg4\r\n" \
+"wRZ528IdwDqB7OOqsDm1PVQM8vzny9PM6ikWUCRTVNQJN8RDLkrHR3FRjy15YLdt\r\n" \
+"yOfDqVnT/z0wGBaxnNziSJjqPGHPpRi4bJFGXwXOhtknKmciKzfj9/npoQ==\r\n" \
+"-----END CERTIFICATE-----\r\n";
+
+ eap_client_key = \
+"-----BEGIN RSA PRIVATE KEY-----\r\n" \
+"MIICXQIBAAKBgQCoRKVXg5h8FwiBn4KzyZamIGOG8qhrT+Qh7uxqqEJ7mriyejHS\r\n" \
+"N2RSktxzi86ze9DtkaeKapOW0D2gXpc1TNNZbi+UlMoR+sJYrTzmXtwMcW8dq8fc\r\n" \
+"Tq+4/vWUjuOrg8tdujZO9kr64G6XijOPNVaKFpkG3Px4serjjqH8P+mTOQIDAQAB\r\n" \
+"AoGARI+LyweshssfxSkIKVc3EcNaqi6PHwJzUrw2ChM624AkR1xwllXJg7ehKVdK\r\n" \
+"xmjprRLO8CASuL1qjsBb3fTKnBl+sIVxIFS0AI4Y3ri8VUKbangvSsI7pCzAFry7\r\n" \
+"p1gmy9WWRV2ZEa+dV8xcrjb3bloT7hcdeLehgBCvExJIQM0CQQDXlSAKdW3AhYyj\r\n" \
+"1A+pfyBSGxJbpSwNyyWgwHIHHjxendxmdUbrc8EbAu1eNKbP58TLgdCZsKcMonAv\r\n" \
+"MY1Y2/nnAkEAx9CrUaCU8pJqXTRypM5JtexLKnYMJhpnA9uUILBQOq4Oe0eruyF5\r\n" \
+"SaSxhyJYXY491ahWYPF0PTb3jkUhoN+l3wJBAJZthjgGDJlEFwjSFkOtYz4nib3N\r\n" \
+"GVpeoFj1MBvrazCScpJDz0LIOLzCZCNSFfwIu3dNk+NKMqZMSn+D0h9pD40CQQC5\r\n" \
+"K9n4NXaTLbjAU2CC9mE85JPr76XmkcUxwAWQHZTcLH1jJdIyAx1hb+zNLLjzSmRn\r\n" \
+"Yi9ae6ibKhtUjyBQ87HFAkA2Bb3z7NUx+AA2g2HZocFZFShBxylACyQkl8FAFZtf\r\n" \
+"osudmKdFQHyAWuBMex4tpz/OLTqJ1ecL1JQeC7OvlpEX\r\n" \
+"-----END RSA PRIVATE KEY-----\r\n";
+
+ eap_ca_cert = \
+"-----BEGIN CERTIFICATE-----\r\n" \
+"MIIEpzCCA4+gAwIBAgIJAPvZaozpdfjkMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD\r\n" \
+"VQQGEwJGUjEPMA0GA1UECBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTAT\r\n" \
+"BgNVBAoTDEV4YW1wbGUgSW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBs\r\n" \
+"ZS5jb20xJjAkBgNVBAMTHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4X\r\n" \
+"DTE2MDMxNDExMjU0OVoXDTE2MDQxMzExMjU0OVowgZMxCzAJBgNVBAYTAkZSMQ8w\r\n" \
+"DQYDVQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhh\r\n" \
+"bXBsZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQG\r\n" \
+"A1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0GCSqGSIb3\r\n" \
+"DQEBAQUAA4IBDwAwggEKAoIBAQC9pireu0aCDLNfMaGv3vId7RXjUhQwSK0jV2Oc\r\n" \
+"SyvlKWH3P/N+5kLrP2iL6SCzyETVDXZ0vOsAMjcBF0zHp16prXV0d51cTUqeWBb0\r\n" \
+"I5UnGxleIuuOfSg8zLUJoBWZPqLv++eZ5WgOKHt7SXocjvg7TU5t/TMB0Y8OCz3H\r\n" \
+"CW2vJ/XKMgMA9HDUu4g57cJu88i1JPRpyFaz/HIQBc7+UNb9z+q09uTZKWTmEMqi\r\n" \
+"E2U0EEIs7EtbxnOze1/8C4XNlmztrEdwvu6UEBU/TFkUoh9M646NkkBK7wP9n9pv\r\n" \
+"T0nPQRJiiCrICzVqUtlEi9lIKpbBSMbQ0KzrGF7lGTgm4rz9AgMBAAGjgfswgfgw\r\n" \
+"HQYDVR0OBBYEFIVyecka74kvOKIW0BjlTc/B+a2NMIHIBgNVHSMEgcAwgb2AFIVy\r\n" \
+"ecka74kvOKIW0BjlTc/B+a2NoYGZpIGWMIGTMQswCQYDVQQGEwJGUjEPMA0GA1UE\r\n" \
+"CBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTATBgNVBAoTDEV4YW1wbGUg\r\n" \
+"SW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5jb20xJjAkBgNVBAMT\r\n" \
+"HUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5ggkA+9lqjOl1+OQwDAYDVR0T\r\n" \
+"BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAZYHM26sxbKOckVqJJ1QY0U2QFlGP\r\n" \
+"1GYd8v27znxdnRmSonDvv3GjFfhwoyDk0JUuxkK/33ikCxihrgoO/EQTY9BV2OpW\r\n" \
+"qkB1PDtb3i5ZRNvfjmW0pVA4p+GmdTGaEE5pTlcVnorzVrUeFKaZakb+IDFYzmeF\r\n" \
+"xp8B3Bb5wvinDligLOaJnSlgS8QeeIab9HZfaVTTuPmVK6zE6D54Y0dJPnykvDdE\r\n" \
+"cGN0FC+migfilFjJgkDJ0r78nwes55L8zjoofiZuO03rrHww6ARc3v1jYzAufddk\r\n" \
+"QTiZHgjlMQb2XXMmXLn8kBgoDnqkXFNe8j0h8uxIJSrjOoIyn1h1wvX5/w==\r\n" \
+"-----END CERTIFICATE-----\r\n";
+}
+*/
+
+int eap_start(char *method){
+#ifdef CONFIG_ENABLE_EAP
+ int ret = -1;
+
+ //unsigned long tick1 = xTaskGetTickCount();
+ //unsigned long tick2;
+
+ if(rltk_wlan_running(WLAN1_IDX)){
+ printf("\n\rNot support con-current mode!\n\r");
+ return -1;
+ }
+
+ judge_station_disconnect();
+
+#if CONFIG_ENABLE_PEAP
+ if(strcmp(method,"peap") == 0){
+ ret = set_eap_peap_method();
+ }
+#endif
+
+#if CONFIG_ENABLE_TLS
+ if(strcmp(method,"tls") == 0){
+ ret = set_eap_tls_method();
+ }
+#endif
+
+#if CONFIG_ENABLE_TTLS
+ if(strcmp(method,"ttls") == 0){
+ ret = set_eap_ttls_method();
+ }
+#endif
+
+ if(ret == -1){
+ printf("\r\neap method %s not supported\r\n", method);
+ return -1;
+ }
+
+ eap_method = get_eap_ctx_method();
+
+ printf("\n==================== %s_start ====================\n", method);
+
+ //eap_config();
+
+ set_eap_phase(ENABLE);
+ wifi_reg_event_handler(WIFI_EVENT_EAPOL_START, eap_eapol_start_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, eap_eapol_recvd_hdl, NULL);
+
+
+
+ ret = connect_by_open_system(eap_target_ssid);
+
+#if CONFIG_LWIP_LAYER
+ /* Start DHCPClient */
+ if(ret == 0)
+ LwIP_DHCP(0, DHCP_START);
+#endif
+
+ wifi_unreg_event_handler(WIFI_EVENT_EAPOL_START, eap_eapol_start_hdl);
+
+ // for re-authentication when session timeout
+ wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, eap_disconnected_hdl, NULL);
+ //wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, eap_eapol_recvd_hdl);
+
+ set_eap_phase(DISABLE);
+
+ // eap failed, disconnect
+ if(ret != 0){
+ judge_station_disconnect();
+ eap_disconnected_hdl(NULL, 0, 0, NULL);
+ rtw_msleep_os(200); //wait handler done
+ printf("\r\nERROR: connect to AP by %s failed\n", method);
+ }
+
+ eap_sm_deinit();
+ printf("\n==================== %s_finish ====================\n", method);
+
+ //tick2 = xTaskGetTickCount();
+ //printf("\r\nConnected after %dms.\n", (tick2-tick1));
+
+ return ret;
+#else
+ return -1;
+#endif
+}
+#ifdef CONFIG_ENABLE_EAP
+static int connect_by_open_system(char *target_ssid)
+{
+ int retry_count = 0, ret;
+
+ if (target_ssid != NULL) {
+ while (1) {
+ rtw_msleep_os(500); //wait scan complete.
+ ret = wifi_connect(target_ssid,
+ RTW_SECURITY_OPEN,
+ NULL,
+ strlen(target_ssid),
+ 0,
+ 0,
+ NULL);
+ if (ret == RTW_SUCCESS) {
+ //printf("\r\n[EAP]Associate with AP success\n");
+ break;
+ }
+ if (retry_count == 0) {
+ //printf("\r\n[EAP]Associate with AP failed %d\n", ret);
+ return -1;
+ }
+ retry_count --;
+ printf("Retry connection...\n");
+
+ judge_station_disconnect();
+ set_eap_phase(ENABLE);
+ }
+ } else {
+ printf("\r\n[EAP]Target SSID is NULL\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static void eap_autoreconnect_thread(void *method)
+{
+ eap_start((char*)method);
+ vTaskDelete(NULL);
+}
+#endif
+
+void eap_autoreconnect_hdl(u8 method_id){
+#ifdef CONFIG_ENABLE_EAP
+ char *method;
+ switch(method_id){
+ case 25: // EAP_TYPE_PEAP
+ method = "peap";
+ break;
+ case 13: // EAP_TYPE_TLS
+ method = "tls";
+ break;
+ case 21: // EAP_TYPE_TTLS
+ method = "ttls";
+ break;
+ default:
+ printf("invalid eap method\n");
+ return;
+ }
+ if(xTaskCreate(eap_autoreconnect_thread, ((const char*)"eap_autoreconnect_thread"), 1024, (void*) method, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
+ printf("\n\r%s xTaskCreate failed\n", __FUNCTION__);
+#endif
+}
+
+// copy from ssl_client_ext.c
+#if ENABLE_EAP_SSL_VERIFY_CLIENT
+static x509_crt* _cli_crt = NULL;
+static pk_context* _clikey_rsa = NULL;
+#endif
+
+#if ENABLE_EAP_SSL_VERIFY_SERVER
+static x509_crt* _ca_crt = NULL;
+
+static int eap_verify(void *data, x509_crt *crt, int depth, int *flags)
+{
+
+ //char buf[1024];
+ ((void) data);
+
+ printf("\nVerify requested for (Depth %d):\n", depth);
+ //x509_crt_info(buf, sizeof(buf) - 1, "", crt);
+ //printf("%s", buf);
+
+ if(((*flags) & BADCERT_EXPIRED) != 0)
+ printf("server certificate has expired\n");
+
+ if(((*flags) & BADCERT_REVOKED) != 0)
+ printf(" ! server certificate has been revoked\n");
+
+ if(((*flags) & BADCERT_CN_MISMATCH) != 0)
+ printf(" ! CN mismatch\n");
+
+ if(((*flags) & BADCERT_NOT_TRUSTED) != 0)
+ printf(" ! self-signed or not signed by a trusted CA\n");
+
+ if(((*flags) & BADCRL_NOT_TRUSTED) != 0)
+ printf(" ! CRL not trusted\n");
+
+ if(((*flags) & BADCRL_EXPIRED) != 0)
+ printf(" ! CRL expired\n");
+
+ if(((*flags) & BADCERT_OTHER) != 0)
+ printf(" ! other (unknown) flag\n");
+
+ if((*flags) == 0)
+ printf(" Certificate verified without error flags\n");
+
+ return(0);
+}
+#endif
+
+int eap_cert_init(void)
+{
+#if ENABLE_EAP_SSL_VERIFY_CLIENT
+ if(eap_client_cert != NULL && eap_client_key != NULL){
+ _cli_crt = polarssl_malloc(sizeof(x509_crt));
+
+ if(_cli_crt)
+ x509_crt_init(_cli_crt);
+ else
+ return -1;
+
+ _clikey_rsa = polarssl_malloc(sizeof(pk_context));
+
+ if(_clikey_rsa)
+ pk_init(_clikey_rsa);
+ else
+ return -1;
+ }
+#endif
+#if ENABLE_EAP_SSL_VERIFY_SERVER
+ if(eap_ca_cert != NULL){
+ _ca_crt = polarssl_malloc(sizeof(x509_crt));
+
+ if(_ca_crt)
+ x509_crt_init(_ca_crt);
+ else
+ return -1;
+ }
+#endif
+ return 0;
+}
+
+void eap_client_cert_free(void)
+{
+#if ENABLE_EAP_SSL_VERIFY_CLIENT
+ if(eap_client_cert != NULL && eap_client_key != NULL){
+ if(_cli_crt) {
+ x509_crt_free(_cli_crt);
+ polarssl_free(_cli_crt);
+ _cli_crt = NULL;
+ }
+
+ if(_clikey_rsa) {
+ pk_free(_clikey_rsa);
+ polarssl_free(_clikey_rsa);
+ _clikey_rsa = NULL;
+ }
+ }
+#endif
+}
+
+void eap_server_cert_free(void)
+{
+#if ENABLE_EAP_SSL_VERIFY_SERVER
+ if(eap_ca_cert != NULL){
+ if(_ca_crt) {
+ x509_crt_free(_ca_crt);
+ polarssl_free(_ca_crt);
+ _ca_crt = NULL;
+ }
+ }
+#endif
+}
+
+int eap_cert_setup(ssl_context *ssl)
+{
+#if ENABLE_EAP_SSL_VERIFY_CLIENT
+ if(eap_client_cert != NULL && eap_client_key != NULL){
+ if(x509_crt_parse(_cli_crt, eap_client_cert, strlen(eap_client_cert)) != 0)
+ return -1;
+
+ if(pk_parse_key(_clikey_rsa, eap_client_key, strlen(eap_client_key), eap_client_key_pwd, strlen(eap_client_key_pwd)) != 0)
+ return -1;
+
+ ssl_set_own_cert(ssl, _cli_crt, _clikey_rsa);
+ }
+#endif
+#if ENABLE_EAP_SSL_VERIFY_SERVER
+ if(eap_ca_cert != NULL){
+ if(x509_crt_parse(_ca_crt, eap_ca_cert, strlen(eap_ca_cert)) != 0)
+ return -1;
+ ssl_set_ca_chain(ssl, _ca_crt, NULL, NULL);
+ ssl_set_authmode(ssl, SSL_VERIFY_REQUIRED);
+ ssl_set_verify(ssl, eap_verify, NULL);
+ }
+#endif
+ return 0;
+}
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_p2p_config.c b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_p2p_config.c
new file mode 100644
index 0000000..ca4173d
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_p2p_config.c
@@ -0,0 +1,269 @@
+#include "FreeRTOS.h"
+#include "task.h"
+
+#include "utils/os.h"
+#include
+#include
+#include "wps/wps_defs.h"
+
+#if CONFIG_ENABLE_P2P
+enum p2p_wps_method {
+ WPS_NOT_READY, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC
+};
+
+/*NETMASK*/
+#define P2P_NETMASK_ADDR0 255
+#define P2P_NETMASK_ADDR1 255
+#define P2P_NETMASK_ADDR2 255
+#define P2P_NETMASK_ADDR3 0
+
+/*Gateway Address*/
+#define P2P_GW_ADDR0 192
+#define P2P_GW_ADDR1 168
+#define P2P_GW_ADDR2 42
+#define P2P_GW_ADDR3 1
+
+#define P2P_GO_NEGO_RESULT_SIZE 376//256
+
+xqueue_handle_t queue_for_p2p_nego;
+
+extern void dhcps_init(struct netif * pnetif);
+
+static int hex2num(char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ return -1;
+}
+
+/**
+ * hwaddr_aton - Convert ASCII string to MAC address (colon-delimited format)
+ * @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
+ * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
+ * Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
+ */
+int hwaddr_aton(const char *txt, u8 *addr)
+{
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ int a, b;
+
+ a = hex2num(*txt++);
+ if (a < 0)
+ return -1;
+ b = hex2num(*txt++);
+ if (b < 0)
+ return -1;
+ *addr++ = (a << 4) | b;
+ if (i < 5 && *txt++ != ':')
+ return -1;
+ }
+
+ return 0;
+}
+
+int wifi_start_p2p_go(char *ssid, char *passphrase, u8 channel)
+{
+ extern struct netif xnetif[NET_IF_NUM];
+ struct netif * pnetif = &xnetif[0];
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+
+ IP4_ADDR(&ipaddr, P2P_GW_ADDR0, P2P_GW_ADDR1, P2P_GW_ADDR2, P2P_GW_ADDR3);
+ IP4_ADDR(&netmask, P2P_NETMASK_ADDR0, P2P_NETMASK_ADDR1 , P2P_NETMASK_ADDR2, P2P_NETMASK_ADDR3);
+ IP4_ADDR(&gw, P2P_GW_ADDR0, P2P_GW_ADDR1, P2P_GW_ADDR2, P2P_GW_ADDR3);
+ netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
+
+ // start ap
+ if(wifi_start_ap(ssid,
+ RTW_SECURITY_WPA2_AES_PSK,
+ passphrase,
+ strlen(ssid),
+ strlen(passphrase),
+ channel
+ ) != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n");
+ return -1;
+ }
+
+ netif_set_default(pnetif);
+
+ // start dhcp server
+ dhcps_init(pnetif);
+
+ return 0;
+}
+
+void app_callback(char *msg)
+{
+ //From Application
+}
+
+void cmd_wifi_p2p_start(int argc, char **argv)
+{
+ extern struct netif xnetif[NET_IF_NUM];
+ int listen_ch = 1;
+ int op_ch = 5;
+ int go_intent = 1;
+#if 1
+ u32 r = 0;
+ os_get_random((u8 *) &r, sizeof(r));
+ go_intent = r%15+1; /*1-15*/
+
+ os_get_random((u8 *) &r, sizeof(r));
+ listen_ch = 1 + (r % 3) * 5;
+
+ os_get_random((u8 *) &r, sizeof(r));
+ op_ch = 1 + (r % 3) * 5;
+#endif
+ wifi_off();
+ os_sleep(0, 20000);
+ wifi_on(RTW_MODE_P2P);
+ wifi_p2p_init(xnetif[0].hwaddr, go_intent, listen_ch, op_ch);
+}
+
+int cmd_wifi_p2p_auto_go_start(int argc, char **argv)
+{
+ u8 *passphrase = "12345678";
+ u8 channel = 6; // 1, 6, 11
+ const char *ssid_in = "DIRECT-34-Ameba";
+ const char *dev_name = "Ameba1234"; // max strlen 32
+ const char *manufacturer = "by customer"; // max strlen 64
+ const char *model_name = "customer"; // max strlen 32
+ const char *model_number = "v2.0"; // max strlen 32
+ const char *serial_number = "9"; // max strlen 32
+ const u8 pri_dev_type[8] = {0x00,0x0A,0x00,0x50,0xF2,0x04,0x00,0x01}; // category ID:0x00,0x0A; sub category ID:0x00,0x01
+ u8 res[P2P_GO_NEGO_RESULT_SIZE];
+ u16 config_methods = WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_PUSHBUTTON;
+
+ if(!is_wifi_p2p_initialized())
+ return -1;
+
+ wifi_p2p_set_dev_name(dev_name);
+ wifi_p2p_set_manufacturer(manufacturer);
+ wifi_p2p_set_model_name(model_name);
+ wifi_p2p_set_model_number(model_number);
+ wifi_p2p_set_serial_number(serial_number);
+ wifi_p2p_set_pri_dev_type(pri_dev_type);
+ wifi_p2p_set_ssid(ssid_in);
+ wifi_p2p_set_config_methods(config_methods);
+ wifi_p2p_init_auto_go_params(res, passphrase, channel);
+ wifi_p2p_start_auto_go(res);
+ return 0;
+}
+void cmd_wifi_p2p_stop(int argc, char **argv)
+{
+ wifi_p2p_deinit();
+ wifi_off();
+}
+
+void cmd_p2p_listen(int argc, char **argv)
+{
+ u32 timeout = 0;
+
+ if(argc == 2){
+ timeout = os_atoi((u8*)argv[1]);
+ printf("\r\n%s(): timeout=%d\n", __func__, timeout);
+ if(timeout > 3600)
+ timeout = 3600;
+ }
+ wifi_cmd_p2p_listen(timeout);
+}
+
+void cmd_p2p_find(int argc, char **argv)
+{
+ wifi_cmd_p2p_find();
+}
+
+void cmd_p2p_peers(int argc, char **argv)
+{
+ wifi_cmd_p2p_peers();
+}
+
+void cmd_p2p_info(int argc, char **argv)
+{
+ wifi_cmd_p2p_info();
+}
+
+void cmd_p2p_disconnect(int argc, char **argv)
+{
+ wifi_cmd_p2p_disconnect();
+}
+
+void cmd_p2p_connect(int argc, char **argv)
+{
+ enum p2p_wps_method config_method = WPS_PBC;
+ char *pin = NULL;
+ u8 dest[ETH_ALEN] = {0x44, 0x6d, 0x57, 0xd7, 0xce, 0x41};
+ u8 res[P2P_GO_NEGO_RESULT_SIZE];
+ int ret = 0;
+
+#if 1
+ if((argc != 2) && (argc != 3) && (argc != 4)) {
+ printf("Usage: p2p_connect DEST_ADDR [pbc|pin] [pin code]\n");
+ printf("Example: p2p_connect 00:e0:4c:87:00:15 pin 12345678\n");
+ return;
+ }
+ if (hwaddr_aton(argv[1], dest)){
+ printf("P2P_CONNECT: dest address is not correct!\n");
+ return;
+ }
+
+ //printf("\r\nDEST: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", dest[0], dest[1], dest[2], dest[3], dest[4], dest[5]);
+ config_method = WPS_PBC;
+ if(argc == 3) {
+ if(os_strncmp(argv[2], "pbc", 3) == 0)
+ config_method = WPS_PBC;
+ else if(os_strncmp(argv[2], "pin", 3) == 0){
+ config_method = WPS_PIN_DISPLAY;
+ }else{
+ printf("Unknown config method!\n");
+ printf("Usage: p2p_connect DEST_ADDR [pbc|pin] \n");
+ printf("Example: p2p_connect 00:e0:4c:87:00:15 pin\n");
+ return;
+ }
+ }
+ else if(argc == 4) {
+ if(os_strncmp(argv[2], "pin", 3) == 0){
+ config_method = WPS_PIN_KEYPAD;
+ pin = argv[3];
+ }else{
+ printf("Unknown config method!\n");
+ printf("Usage: p2p_connect DEST_ADDR [pbc|pin] [pin code]\n");
+ printf("Example: p2p_connect 00:e0:4c:87:00:15 pin 12345678\n");
+ return;
+ }
+ }
+#else //For test
+ u8 dest1[ETH_ALEN] = {0xea, 0x92, 0xa4, 0x9b, 0x61, 0xd6}; //NEXUS 4
+ //u8 dest1[ETH_ALEN] = {0x0e, 0x37, 0xdc, 0xfc, 0xc4, 0x12}; //HUAWEI U9508_c001
+ //u8 dest1[ETH_ALEN] = {0x42, 0xcb, 0xa8, 0xd3, 0x2c, 0x50}; //HUAWEI G610-T00
+ os_memcpy(dest, dest1, ETH_ALEN);
+ config_method = WPS_PBC;
+#endif
+
+ if (queue_for_p2p_nego!= NULL) {
+ os_xqueue_delete(queue_for_p2p_nego);
+ queue_for_p2p_nego = NULL;
+ }
+ queue_for_p2p_nego = os_xqueue_create(1, P2P_GO_NEGO_RESULT_SIZE);
+ if(queue_for_p2p_nego != NULL) {
+ ret = wifi_cmd_p2p_connect(dest, config_method, pin);
+ if(ret == 0)
+ os_xqueue_receive(queue_for_p2p_nego, res, 15);
+
+ os_xqueue_delete(queue_for_p2p_nego);
+ queue_for_p2p_nego = NULL;
+
+ if(ret == 0)
+ wifi_p2p_start_wps(res);
+ }
+}
+
+#endif //CONFIG_ENABLE_P2P
diff --git a/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_wps_config.c b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_wps_config.c
new file mode 100644
index 0000000..cd8463f
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_wps_config.c
@@ -0,0 +1,753 @@
+#include
+#include
+#include
+#include "FreeRTOS.h"
+#include "task.h"
+#include "main.h"
+#include "queue.h"
+#include "utils/os.h"
+#include
+#include
+#include "wifi/wifi_conf.h"
+#include "wps/wps_defs.h"
+#include
+
+/*
+ * @brief struct wps_credential - WPS Credential
+ */
+struct dev_credential {
+ u8 ssid[32]; /**< SSID */
+ size_t ssid_len; /**< Length of SSID */
+ u16 auth_type; /**< Authentication Type (WPS_AUTH_OPEN, .. flags) */
+ u16 encr_type; /**< Encryption Type (WPS_ENCR_NONE, .. flags) */
+ u8 key_idx; /**< Key index */
+ u8 key[65]; /**< Key */
+ size_t key_len; /**< Key length in octets */
+ u8 mac_addr[6]; /**< MAC address of the Credential receiver */
+ const u8 *cred_attr; /**< Unparsed Credential attribute data (used only in cred_cb()).
+ This may be NULL, if not used. */
+ size_t cred_attr_len; /**< Length of cred_attr in octets */
+ u16 ap_channel; /**< AP channel */
+};
+
+typedef struct {
+ char *target_ssid;
+ u16 config_method;
+ _sema scan_sema;
+ int isoverlap;
+} internal_wps_scan_handler_arg_t;
+
+#define WLAN0_NAME "wlan0"
+#ifndef ENABLE
+#define ENABLE (1)
+#endif
+#ifndef DISABLE
+#define DISABLE (0)
+#endif
+#define STACKSIZE 512
+
+
+//static xSemaphoreHandle wps_reconnect_semaphore;
+//static struct _WIFI_NETWORK wifi_get_from_certificate = {0};
+
+#define WPS_AUTH_TYPE_OPEN (0x0001)
+#define WPS_AUTH_TYPE_WPA_PERSONAL (0x0002)
+#define WPS_AUTH_TYPE_SHARED (0x0004)
+#define WPS_AUTH_TYPE_WPA_ENTERPRISE (0x0008)
+#define WPS_AUTH_TYPE_WPA2_PERSONAL (0x0010)
+#define WPS_AUTH_TYPE_WPA2_ENTERPRISE (0x0020)
+
+#define WPS_ENCR_TYPE_NONE (0x0001)
+#define WPS_ENCR_TYPE_WEP (0x0002)
+#define WPS_ENCR_TYPE_TKIP (0x0004)
+#define WPS_ENCR_TYPE_AES (0x0008)
+
+#define SCAN_BUFFER_LENGTH (4096)
+
+#if CONFIG_ENABLE_P2P
+extern void _wifi_p2p_wps_success(const u8 *peer_addr, int registrar);
+extern void _wifi_p2p_wps_failed();
+#endif
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+extern u32 _wps_registrar_process_msg(void *priv, u32 op_code, const void *pmsg);
+extern void * _wps_registrar_get_msg(void *priv, u32 *op_code);
+extern void * _wps_registrar_init(void *priv, const void* pcfg);
+extern void _wps_registrar_deinit(void *priv);
+extern void *_wps_registrar_alloc();
+extern int _wps_registrar_add_pin(void *priv, const u8 *addr,
+ const u8 *uuid, const u8 *pin, size_t pin_len,
+ int timeout);
+extern int _wps_registrar_button_pushed(void *priv,
+ const u8 *p2p_dev_addr);
+extern int _wps_registrar_wps_cancel(void *priv);
+extern void _wpas_wsc_ap_send_eap_reqidentity(void *priv, u8 *rx_buf);
+extern void _wpas_wsc_ap_check_eap_rspidentity(void *priv, u8 *rx_buf);
+extern void _wpas_wsc_registrar_send_eap_fail(void *priv);
+extern void _wpas_wsc_registrar_handle_recvd(void *priv, u8 *rx_buf);
+extern void * _eap_wsc_server_process_hdl(void *priv, void* req, u8 id);
+extern void *_eap_wsc_server_reset(void *priv);
+#endif
+extern void wpas_wsc_sta_wps_start_hdl(char *buf, int buf_len, int flags, void *userdata);
+extern void wpas_wsc_wps_finish_hdl(char *buf, int buf_len, int flags, void *userdata);
+extern void wpas_wsc_eapol_recvd_hdl(char *buf, int buf_len, int flags, void *userdata);
+
+void wifi_p2p_wps_success(const u8 *peer_addr, int registrar)
+{
+#if CONFIG_ENABLE_P2P
+ _wifi_p2p_wps_success(peer_addr, registrar);
+#endif
+}
+
+void wifi_p2p_wps_failed()
+{
+#if CONFIG_ENABLE_P2P
+ _wifi_p2p_wps_failed();
+#endif
+}
+
+void * wps_registrar_init(void *priv, void *pcfg)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_init(priv, pcfg);
+#else
+ return NULL;
+#endif
+}
+
+void wps_registrar_deinit(void *priv)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ _wps_registrar_deinit(priv);
+#endif
+}
+
+void *wps_registrar_alloc()
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_alloc();
+#else
+ return NULL;
+#endif
+}
+
+u32 wps_registrar_process_msg(void *priv, u32 op_code, const void *pmsg)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_process_msg(priv, op_code, pmsg);
+#else
+ return 0;
+#endif
+}
+
+void * wps_registrar_get_msg(void *priv, u32 *op_code)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_get_msg(priv, op_code);
+#else
+ return NULL;
+#endif
+}
+
+
+int wps_registrar_add_pin(void *priv, const u8 *addr,
+ const u8 *uuid, const u8 *pin, size_t pin_len,
+ int timeout)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_add_pin(priv, NULL,NULL,pin,pin_len,0);
+#else
+ return 0;
+#endif
+}
+
+int wps_registrar_button_pushed(void *priv,
+ const u8 *p2p_dev_addr)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_button_pushed(priv, p2p_dev_addr);
+#else
+ return 0;
+#endif
+}
+
+int wps_registrar_wps_cancel(void *priv)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _wps_registrar_wps_cancel(priv);
+#else
+ return 0;
+#endif
+
+}
+
+void wpas_wsc_ap_send_eap_reqidentity(void *priv, u8 *rx_buf)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ _wpas_wsc_ap_send_eap_reqidentity(priv, rx_buf);
+#endif
+}
+
+void wpas_wsc_ap_check_eap_rspidentity(void *priv, u8 *rx_buf)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ _wpas_wsc_ap_check_eap_rspidentity(priv, rx_buf);
+#endif
+}
+
+void wpas_wsc_registrar_send_eap_fail(void *priv)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ _wpas_wsc_registrar_send_eap_fail(priv);
+#endif
+}
+
+void wpas_wsc_registrar_handle_recvd(void *priv, u8 *rx_buf)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ _wpas_wsc_registrar_handle_recvd(priv, rx_buf);
+#endif
+}
+
+void * eap_wsc_server_process_hdl(void *priv, void* req, u8 id)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ return _eap_wsc_server_process_hdl(priv, req, id);
+#else
+ return NULL;
+#endif
+}
+
+void eap_wsc_server_reset(void *priv)
+{
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+ _eap_wsc_server_reset(priv);
+#endif
+}
+
+#if CONFIG_ENABLE_WPS
+xqueue_handle_t queue_for_credential;
+char wps_pin_code[32];
+u16 config_method;
+u8 wps_password_id;
+static TaskHandle_t ap_wps_task = NULL;
+
+void wps_check_and_show_connection_info(void)
+{
+ rtw_wifi_setting_t setting;
+#if CONFIG_LWIP_LAYER
+ /* Start DHCP Client */
+ LwIP_DHCP(0, DHCP_START);
+#endif
+ wifi_get_setting(WLAN0_NAME, &setting);
+ wifi_show_setting(WLAN0_NAME, &setting);
+
+#if CONFIG_INIC_CMD_RSP
+ inic_c2h_wifi_info("ATWW", RTW_SUCCESS);
+#endif
+}
+
+static void wps_config_wifi_setting(rtw_network_info_t *wifi, struct dev_credential *dev_cred)
+{
+ printf("wps_config_wifi_setting\n");
+ //memcpy((void *)wifi->ssid, (void *)dev_cred->ssid, dev_cred->ssid_len);
+ strcpy((char*)wifi->ssid.val, (char*)&dev_cred->ssid[0]);
+ printf("wps_wifi.ssid = %s\n", wifi->ssid.val);
+ wifi->ssid.len = dev_cred->ssid_len;
+ printf("wps_wifi.ssid_len = %d\n", wifi->ssid.len);
+
+ switch(dev_cred->auth_type) {
+ case WPS_AUTH_TYPE_OPEN :
+ case WPS_AUTH_TYPE_SHARED :
+ if(dev_cred->encr_type == WPS_ENCR_TYPE_WEP) {
+ printf("security_type = RTW_SECURITY_WEP_PSK\n");
+ wifi->security_type = RTW_SECURITY_WEP_PSK;
+ wifi->key_id = dev_cred->key_idx - 1;
+ }
+ else {
+ printf("security_type = RTW_SECURITY_OPEN\n");
+ wifi->security_type = RTW_SECURITY_OPEN;
+ }
+ break;
+ case WPS_AUTH_TYPE_WPA_PERSONAL :
+ case WPS_AUTH_TYPE_WPA_ENTERPRISE :
+ printf("security_type = RTW_SECURITY_WPA_AES_PSK\n");
+ wifi->security_type = RTW_SECURITY_WPA_AES_PSK;
+ break;
+ case WPS_AUTH_TYPE_WPA2_PERSONAL :
+ case WPS_AUTH_TYPE_WPA2_ENTERPRISE :
+ printf("security_type = RTW_SECURITY_WPA2_AES_PSK\n");
+ wifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ }
+
+ printf("wps_wifi.security_type = %d\n", wifi->security_type);
+
+ //memcpy(wifi->password, dev_cred->key, dev_cred->key_len);
+ wifi->password = dev_cred->key;
+ printf("wps_wifi.password = %s\n", wifi->password);
+ wifi->password_len = dev_cred->key_len;
+ printf("wps_wifi.password_len = %d", wifi->password_len);
+ //xSemaphoreGive(wps_reconnect_semaphore);
+ //printf("\r\nrelease wps_reconnect_semaphore");
+}
+
+static int wps_connect_to_AP_by_certificate(rtw_network_info_t *wifi)
+{
+#define RETRY_COUNT 3
+ int retry_count = RETRY_COUNT, ret;
+
+ printf("=============== wifi_certificate_info ===============\n");
+ printf("wps_wifi.ssid = %s\n", wifi->ssid.val);
+ printf("security_type = %d\n", wifi->security_type);
+ printf("wps_wifi.password = %s\n", wifi->password);
+ printf("ssid_len = %d\n", wifi->ssid.len);
+ printf("password_len = %d\n", wifi->password_len);
+ while (1) {
+ ret = wifi_connect((char*)wifi->ssid.val,
+ wifi->security_type,
+ (char*)wifi->password,
+ wifi->ssid.len,
+ wifi->password_len,
+ wifi->key_id,
+ NULL);
+ if (ret == RTW_SUCCESS) {
+ if(retry_count == RETRY_COUNT)
+ rtw_msleep_os(1000); //When start wps with OPEN AP, AP will send a disassociate frame after STA connected, need reconnect here.
+ if(RTW_SUCCESS == wifi_is_connected_to_ap( )){
+ //printf("\r\n[WPS]Ready to tranceive!!\n");
+ wps_check_and_show_connection_info();
+ break;
+ }
+ }
+ if (retry_count == 0) {
+ printf("[WPS]Join bss failed\n");
+ ret = -1;
+ break;
+ }
+ retry_count --;
+ }
+ return ret;
+}
+
+static int wps_connect_to_AP_by_open_system(char *target_ssid)
+{
+ int retry_count = 3, ret;
+
+ if (target_ssid != NULL) {
+ rtw_msleep_os(500); //wait scan complete.
+ while (1) {
+ ret = wifi_connect(target_ssid,
+ RTW_SECURITY_OPEN,
+ NULL,
+ strlen(target_ssid),
+ 0,
+ 0,
+ NULL);
+ if (ret == RTW_SUCCESS) {
+ //wps_check_and_show_connection_info();
+ break;
+ }
+ if (retry_count == 0) {
+ printf("[WPS]Join bss failed\n");
+ return -1;
+ }
+ retry_count --;
+ }
+ //
+ } else {
+ printf("[WPS]Target SSID is NULL\n");
+ }
+
+ return 0;
+}
+
+static void process_wps_scan_result( rtw_scan_result_t* record, void * user_data )
+{
+ internal_wps_scan_handler_arg_t *wps_arg = (internal_wps_scan_handler_arg_t *)user_data;
+
+ if (record->wps_type != 0xff) {
+ if (wps_arg->config_method == WPS_CONFIG_PUSHBUTTON) {
+ if (record->wps_type == 0x04) {
+ wps_password_id = record->wps_type;
+ if (++wps_arg->isoverlap == 0) {
+ memcpy(&wps_arg->target_ssid[0], record->SSID.val, record->SSID.len);
+ wps_arg->target_ssid[record->SSID.len] = '\0';
+ printf("[pbc]Record first triger wps AP = %s\n", wps_arg->target_ssid);
+ }
+ }
+ } else if (wps_arg->config_method == WPS_CONFIG_DISPLAY || wps_arg->config_method == WPS_CONFIG_KEYPAD) {
+ if (record->wps_type == 0x00) {
+ wps_arg->isoverlap = 0;
+ wps_password_id = record->wps_type;
+ memcpy(&wps_arg->target_ssid[0], record->SSID.val, record->SSID.len);
+ wps_arg->target_ssid[record->SSID.len] = '\0';
+ printf("[pin]find out first triger wps AP = %s\n", wps_arg->target_ssid);
+ }
+ }
+ }
+}
+
+static rtw_result_t wps_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
+{
+ internal_wps_scan_handler_arg_t *wps_arg = (internal_wps_scan_handler_arg_t *)malloced_scan_result->user_data;
+ if (malloced_scan_result->scan_complete != RTW_TRUE)
+ {
+ rtw_scan_result_t* record = &malloced_scan_result->ap_details;
+ record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
+
+ process_wps_scan_result(record, malloced_scan_result->user_data);
+ }
+ else
+ {
+ printf("WPS scan done!\n");
+ rtw_up_sema(&wps_arg->scan_sema);
+ }
+ return RTW_SUCCESS;
+}
+
+extern void wifi_scan_each_report_hdl( char* buf, int buf_len, int flags, void* userdata);
+extern void wifi_scan_done_hdl( char* buf, int buf_len, int flags, void* userdata);
+
+static int wps_find_out_triger_wps_AP(char *target_ssid, u16 config_method)
+{
+ internal_wps_scan_handler_arg_t wps_arg = {0};
+
+ wps_password_id = 0xFF;
+
+ wps_arg.isoverlap = -1;
+ wps_arg.config_method = config_method;
+ wps_arg.target_ssid = target_ssid;
+ rtw_init_sema(&wps_arg.scan_sema, 0);
+ if(wps_arg.scan_sema == NULL) return RTW_ERROR;
+
+ if(wifi_scan_networks(wps_scan_result_handler, &wps_arg ) != RTW_SUCCESS){
+ printf("ERROR: wifi scan failed\n");
+ goto exit;
+ }
+ if(rtw_down_timeout_sema(&wps_arg.scan_sema, SCAN_LONGEST_WAIT_TIME) == RTW_FALSE){
+ printf("WPS scan done early!\n");
+ }
+ wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl);
+
+exit:
+ rtw_free_sema(&wps_arg.scan_sema);
+
+ return wps_arg.isoverlap;
+}
+
+int wps_start(u16 wps_config, char *pin, u8 channel, char *ssid)
+{
+ struct dev_credential dev_cred;
+ rtw_network_info_t wifi = {0};
+ char target_ssid[64];
+ int is_overlap = -1;
+ u32 start_time = rtw_get_current_time();
+ int ret = 0;
+
+ memset(&dev_cred, 0, sizeof(struct dev_credential));
+ memset(target_ssid, 0, 64);
+ if((wps_config != WPS_CONFIG_PUSHBUTTON)
+ && (wps_config != WPS_CONFIG_DISPLAY)
+ && (wps_config != WPS_CONFIG_KEYPAD)){
+ printf("WPS: Wps method(%d) is wrong. Not triger WPS.\n", wps_config);
+ return -1;
+ }
+ config_method = wps_config;
+
+ if(wps_config == WPS_CONFIG_DISPLAY
+ || wps_config == WPS_CONFIG_KEYPAD) {
+ if(pin)
+ strcpy(wps_pin_code, pin);
+ else{
+ printf("WPS: PIN is NULL. Not triger WPS.\n");
+ return -1;
+ }
+ }
+
+ if(!ssid) {
+ while (1) {
+ unsigned int current_time = rtw_get_current_time();
+ if (rtw_systime_to_sec(current_time - start_time) < 120) {
+ is_overlap = wps_find_out_triger_wps_AP(&target_ssid[0], wps_config);
+ if ((is_overlap == 0) || (is_overlap > 0))
+ break;
+ } else {
+ printf("WPS: WPS Walking Time Out\n");
+ return -2;
+ }
+ }
+
+ if (is_overlap > 0) {
+ printf("WPS: WPS session overlap. Not triger WPS.\n");
+ return -2;
+ }
+ }else{
+ rtw_memcpy(target_ssid, ssid, strlen(ssid));
+ }
+
+ if (queue_for_credential != NULL) {
+ os_xqueue_delete(queue_for_credential);
+ queue_for_credential = NULL;
+ }
+ queue_for_credential = os_xqueue_create(1, sizeof(struct dev_credential));
+ if(!queue_for_credential)
+ return -1;
+
+ wifi_reg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl, NULL);
+
+ wifi_set_wps_phase(ENABLE);
+ ret = wps_connect_to_AP_by_open_system(target_ssid);
+ if(ret < 0){
+ printf("WPS: WPS Fail!!\n");
+ goto exit;
+ }
+ os_xqueue_receive(queue_for_credential, &dev_cred, 120);
+ if (dev_cred.ssid[0] != 0 && dev_cred.ssid_len <= 32) {
+ wps_config_wifi_setting(&wifi, &dev_cred);
+ wifi_set_wps_phase(DISABLE);
+ ret = wps_connect_to_AP_by_certificate(&wifi);
+ goto exit1;
+ } else {
+ printf("WPS: WPS FAIL!!!\n");
+// printf("\n\rWPS: WPS FAIL!!!\n");
+// printf("\n\rWPS: WPS FAIL!!!\n");
+ ret = -1;
+ }
+exit:
+ wifi_set_wps_phase(DISABLE);
+exit1:
+ if (queue_for_credential != NULL) {
+ os_xqueue_delete(queue_for_credential);
+ queue_for_credential = NULL;
+ }
+
+ wifi_unreg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl);
+
+ wpas_wps_deinit();
+ return ret;
+}
+
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+static int ap_wps_start(u16 wps_config, char *pin)
+{
+ u8 authorized_mac[ETH_ALEN];
+ int ret = 0;
+ u32 pin_val = 0;
+
+ if (queue_for_credential != NULL) {
+ os_xqueue_delete(queue_for_credential);
+ queue_for_credential = NULL;
+ }
+
+ queue_for_credential = os_xqueue_create(1, sizeof(authorized_mac));
+ if(!queue_for_credential)
+ return -1;
+
+ wifi_reg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl, NULL);
+
+ wifi_set_wps_phase(ENABLE);
+
+ if(wps_config == WPS_CONFIG_KEYPAD)
+ {
+ pin_val = atoi(pin);
+ if (!wps_pin_valid(pin_val)) {
+ printf("WPS-AP: Enter pin code is unvalid.\n");
+ goto exit;
+ }
+ ret = wpas_wps_registrar_add_pin((unsigned char const*)pin, strlen(pin));
+ }
+ else if(wps_config == WPS_CONFIG_DISPLAY)
+ ret = wpas_wps_registrar_add_pin((unsigned char const*)pin, strlen(pin));
+ else
+ ret = wpas_wps_registrar_button_pushed();
+
+ if(ret<0)
+ goto exit;
+
+ printf("WPS-AP: wait for STA connect!\n");
+ os_xqueue_receive(queue_for_credential, authorized_mac, 120); //max wait 2min
+
+ if(!wpas_wps_registrar_check_done())
+ {
+ ret = -1;
+ wpas_wps_registrar_wps_cancel();
+ }
+
+exit:
+ wifi_set_wps_phase(0);
+ os_xqueue_delete(queue_for_credential);
+ queue_for_credential = NULL;
+ printf("WPS-AP: Finished!\n");
+
+ wifi_unreg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl);
+
+ return ret;
+}
+
+static void wifi_start_ap_wps_thread_hdl( void *param)
+{
+ ap_wps_start(config_method, wps_pin_code); //Not support WPS_CONFIG_KEYPAD
+
+ ap_wps_task = NULL;
+ vTaskDelete(NULL);
+}
+
+void wifi_start_ap_wps_thread(u16 config_methods, char *pin)
+{
+ if((config_methods != WPS_CONFIG_PUSHBUTTON)
+ && (config_methods != WPS_CONFIG_DISPLAY)
+ && (config_methods != WPS_CONFIG_KEYPAD)){
+ printf("WPS-AP: Wps method(%d) is wrong. Not triger WPS.\n", config_methods);
+ return;
+ }
+ config_method = config_methods;
+ if(config_methods == WPS_CONFIG_DISPLAY
+ || config_methods == WPS_CONFIG_KEYPAD) {
+ if(pin)
+ strcpy(wps_pin_code, pin);
+ else{
+ printf("WPS-AP: PIN is NULL. Not triger WPS.\n");
+ return;
+ }
+ }
+ if(ap_wps_task != NULL){ //push item to wait queue to finish last ap_wps task
+ printf("WPS-AP: Wait for last ap_wps task exiting...\n");
+ if(queue_for_credential)
+ os_xqueue_send(queue_for_credential, NULL, 0);
+ while(ap_wps_task != NULL)
+ vTaskDelay(1);
+ vTaskDelay(20);
+ printf("Last ap_wps task completed.\n");
+ }
+ if(xTaskCreate(wifi_start_ap_wps_thread_hdl, ((const char*)"ap_wps"), 256, NULL, tskIDLE_PRIORITY + 3, &ap_wps_task) != pdPASS)
+ printf("%s xTaskCreate(ap_wps thread) failed\n", __FUNCTION__);
+}
+
+#endif //CONFIG_ENABLE_WPS_AP
+
+void wps_judge_staion_disconnect(void)
+{
+ int mode = 0;
+ unsigned char ssid[33];
+
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ switch(mode) {
+ case IW_MODE_MASTER: //In AP mode
+// rltk_wlan_deinit();
+// rltk_wlan_init(0,RTW_MODE_STA);
+// rltk_wlan_start(0);
+ //modified by Chris Yang for iNIC
+ wifi_off();
+ vTaskDelay(20);
+ wifi_on(RTW_MODE_STA);
+ break;
+ case IW_MODE_INFRA: //In STA mode
+ if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
+ wifi_disconnect();
+ }
+}
+
+void cmd_wps(int argc, char **argv)
+{
+ int ret = -1;
+ wps_judge_staion_disconnect();
+
+ if((argc == 2 || argc == 3 ) && (argv[1] != NULL)){
+ if(strcmp(argv[1],"pin") == 0){
+ unsigned int pin_val = 0;
+ /* start pin */
+ if(argc == 2){
+ char device_pin[10];
+ pin_val = wps_generate_pin();
+ sprintf(device_pin, "%08d", pin_val);
+ /* Display PIN 3 times to prevent to be overwritten by logs from other tasks */
+ printf("WPS: Start WPS PIN Display. PIN: [%s]\n", device_pin);
+ printf("WPS: Start WPS PIN Display. PIN: [%s]\n", device_pin);
+ printf("WPS: Start WPS PIN Display. PIN: [%s]\n", device_pin);
+ ret = wps_start(WPS_CONFIG_DISPLAY, (char*)device_pin, 0, NULL);
+ }else{
+ pin_val = atoi(argv[2]);
+ if (!wps_pin_valid(pin_val)) {
+ printf("WPS: Device pin code is invalid. Not triger WPS.\n");
+ goto exit;
+ }
+ printf("WPS: Start WPS PIN Keypad.\n");
+ ret = wps_start(WPS_CONFIG_KEYPAD, argv[2], 0, NULL);
+ }
+ }else if(strcmp(argv[1],"pbc") == 0){
+ /* start pbc */
+ printf("WPS: Start WPS PBC.\n");
+ ret = wps_start(WPS_CONFIG_PUSHBUTTON, NULL, 0, NULL);
+ }else{
+ printf("WPS: Wps Method is wrong. Not triger WPS.\n");
+ goto exit;
+ }
+ }
+exit:
+#if CONFIG_INIC_CMD_RSP
+ if(ret != 0)
+ inic_c2h_msg("ATWW", ret, NULL, 0);
+#endif
+ return;
+}
+
+#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
+/*
+cmd_ap_wps for AP WSC setting. command style:
+cmd_ap_wps pbc or cmd_ap_wps pin 12345678
+*/
+void cmd_ap_wps(int argc, char **argv)
+{
+ int mode = 0;
+ if(rltk_wlan_running(WLAN1_IDX)){
+ printf("Not support con-current softAP WSC!\n");
+ return;
+ }
+ wext_get_mode(WLAN0_NAME, &mode);
+ if(mode != IW_MODE_MASTER){
+ printf("Only valid for IW_MODE_MASTER!\n");
+ return;
+ }
+
+ if((argc == 2 || argc == 3) && (argv[1] != NULL)) {
+ if (strcmp(argv[1],"pin") == 0 ) {
+ unsigned int pin_val = 0;
+ if(argc == 3){
+ pin_val = atoi(argv[2]);
+ if (!wps_pin_valid(pin_val)) {
+ printf("WPS-AP: Device pin code is invalid. Not trigger WPS.\n");
+ return;
+ }
+ printf("WPS-AP: Start AP WPS PIN Keypad.\n");
+ wifi_start_ap_wps_thread(WPS_CONFIG_KEYPAD, argv[2]);
+ }else{
+ char device_pin[10];
+ pin_val = wps_generate_pin();
+ sprintf(device_pin, "%08d", pin_val);
+ printf("WPS: Start WPS PIN Display. PIN: %s\n", device_pin);
+ wifi_start_ap_wps_thread(WPS_CONFIG_DISPLAY, (char*)device_pin);
+ }
+ }else if (strcmp(argv[1],"pbc") == 0) {
+ printf("WPS-AP: Start AP WPS PBC\n");
+ wifi_start_ap_wps_thread(WPS_CONFIG_PUSHBUTTON, NULL);
+ }else{
+ printf("WPS-AP Usage:\"wifi_ap_wps pin [pin_code]\" or \"wifi_ap_wps pbc\"\n");
+ return;
+ }
+ } else {
+ printf("WPS-AP Usage:\"wifi_ap_wps pin [pin_code]\" or \"wifi_ap_wps pbc\"\n");
+ }
+ return;
+}
+#endif //CONFIG_ENABLE_P2P
+#endif //CONFIG_ENABLE_WPS
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.c b/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.c
new file mode 100644
index 0000000..8384624
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.c
@@ -0,0 +1,1981 @@
+//----------------------------------------------------------------------------//
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#include
+#include "main.h"
+#include
+//#include
+#include
+#include
+#include
+#include
+#include "tcpip.h"
+#include
+
+#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
+#include "wlan_fast_connect/example_wlan_fast_connect.h"
+#endif
+#if CONFIG_EXAMPLE_UART_ATCMD
+#include "at_cmd/atcmd_wifi.h"
+#endif
+#if CONFIG_INIC_EN
+extern int inic_start(void);
+extern int inic_stop(void);
+#endif
+
+#if CONFIG_DEBUG_LOG > 0
+ #undef printf
+ #define printf(...) rtl_printf(__VA_ARGS__)
+#else
+ #undef printf
+ #define printf(...)
+#endif
+
+#define SHOW_PRIVATE_OUT 1 // =0 - off, = 1 On
+
+/******************************************************
+ * Constants
+ ******************************************************/
+#define SCAN_USE_SEMAPHORE 0
+
+#define RTW_JOIN_TIMEOUT 15000
+
+#define JOIN_ASSOCIATED (uint32_t)(1 << 0)
+#define JOIN_AUTHENTICATED (uint32_t)(1 << 1)
+#define JOIN_LINK_READY (uint32_t)(1 << 2)
+#define JOIN_SECURITY_COMPLETE (uint32_t)(1 << 3)
+#define JOIN_COMPLETE (uint32_t)(1 << 4)
+#define JOIN_NO_NETWORKS (uint32_t)(1 << 5)
+#define JOIN_WRONG_SECURITY (uint32_t)(1 << 6)
+#define JOIN_HANDSHAKE_DONE (uint32_t)(1 << 7)
+#define JOIN_SIMPLE_CONFIG (uint32_t)(1 << 8)
+#define JOIN_AIRKISS (uint32_t)(1 << 9)
+
+/******************************************************
+ * Type Definitions
+ ******************************************************/
+
+/******************************************************
+ * Variables Declarations
+ ******************************************************/
+
+extern struct netif xnetif[NET_IF_NUM];
+
+/******************************************************
+ * Variables Definitions
+ ******************************************************/
+static internal_scan_handler_t scan_result_handler_ptr = {0, 0, 0, RTW_FALSE, 0, 0, 0, 0, 0};
+static internal_join_result_t* join_user_data;
+extern rtw_mode_t wifi_mode;
+int error_flag = RTW_UNKNOWN;
+uint32_t rtw_join_status;
+#if ATCMD_VER == ATVER_2
+extern unsigned char dhcp_mode_sta;
+#endif
+
+/******************************************************
+ * Variables Definitions
+ ******************************************************/
+
+#ifndef WLAN0_NAME
+ #define WLAN0_NAME "wlan0"
+#endif
+#ifndef WLAN1_NAME
+ #define WLAN1_NAME "wlan1"
+#endif
+/* Give default value if not defined */
+#ifndef NET_IF_NUM
+#ifdef CONFIG_CONCURRENT_MODE
+#define NET_IF_NUM 2
+#else
+#define NET_IF_NUM 1
+#endif
+#endif
+
+/*Static IP ADDRESS*/
+#ifndef IP_ADDR0
+#define IP_ADDR0 192
+#define IP_ADDR1 168
+#define IP_ADDR2 1
+#define IP_ADDR3 80
+#endif
+
+/*NETMASK*/
+#ifndef NETMASK_ADDR0
+#define NETMASK_ADDR0 255
+#define NETMASK_ADDR1 255
+#define NETMASK_ADDR2 255
+#define NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef GW_ADDR0
+#define GW_ADDR0 192
+#define GW_ADDR1 168
+#define GW_ADDR2 1
+#define GW_ADDR3 1
+#endif
+
+/*Static IP ADDRESS*/
+#ifndef AP_IP_ADDR0
+#define AP_IP_ADDR0 192
+#define AP_IP_ADDR1 168
+#define AP_IP_ADDR2 43
+#define AP_IP_ADDR3 1
+#endif
+
+/*NETMASK*/
+#ifndef AP_NETMASK_ADDR0
+#define AP_NETMASK_ADDR0 255
+#define AP_NETMASK_ADDR1 255
+#define AP_NETMASK_ADDR2 255
+#define AP_NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef AP_GW_ADDR0
+#define AP_GW_ADDR0 192
+#define AP_GW_ADDR1 168
+#define AP_GW_ADDR2 43
+#define AP_GW_ADDR3 1
+#endif
+
+/******************************************************
+ * Function Definitions
+ ******************************************************/
+
+#if CONFIG_WLAN
+#define DD_WIFI_CONN 0 // pvvx
+//----------------------------------------------------------------------start-patch//
+#include "freertos/wrapper.h"
+#include "skbuff.h"
+/*
+typedef struct
+{
+ unsigned int rx_packets;
+ unsigned int tx_packets;
+ unsigned int rx_dropped;
+ unsigned int tx_dropped;
+ unsigned int rx_bytes;
+ unsigned int tx_bytes;
+ unsigned int rx_overflow;
+}net_device_stats;
+
+typedef struct net_device
+{
+ char name[16];
+ void *priv;
+ unsigned char dev_addr[6];
+ int (*init)(void);
+ int (*open)(struct net_device *);
+ int (*stop)(struct net_device *);
+ int (*hard_start_xmit)(struct sk_buff *, net_device *);
+ int (*do_ioctl)(struct net_device *, iwreq *, int);
+ net_device_stats *(*get_stats)(net_device *);
+};
+*/
+extern struct net_device *rltk_wlan_info;
+void patch_rltk_wlan_deinit(void)
+{
+ struct net_device *v0; // r6@1
+ int v1; // r5@2
+ char *v4; // r7@3
+
+ v0 = rltk_wlan_info;
+
+ if(rltk_wlan_info->priv != NULL) {
+ v1 = *(u32 *)rltk_wlan_info->priv; /* pointer to private data */
+ *(u8 *)(v1 + 5892) = 1;
+ rtw_wakeup_task(v1 + 5912);
+ while(1) {
+ save_and_cli();
+ *((u8 *)&rltk_wlan_info + 16) = 0;
+ *((u8 *)&rltk_wlan_info + 40) = 0;
+ v4 = &(*(&rltk_wlan_info + 9))->name[(u32)*(&rltk_wlan_info + 2)
+ + (u32)*(&rltk_wlan_info + 3)
+ + (unsigned int)*(&rltk_wlan_info + 8)];
+ restore_flags();
+ if (!v4 ) break;
+ rtl_printf("[%s] Wait for TX/RX Busy (%d)\n", "rltk_wlan_deinit", v4);
+ vTaskDelay(10);
+ }
+ while(1) {
+ if ( !*(u32 *)(v1 + 5916) || *(u8 *)(v1 + 5892) == 2 ) break;
+ rtl_printf("[%s] Wait for RxStop\n", "rltk_wlan_deinit");
+ vTaskDelay(10);
+ }
+ rtw_dev_remove(rltk_wlan_info);
+ rtw_drv_halt();
+ deinit_timer_wrapper();
+ *((u8 *)&rltk_wlan_info + 16) = 0;
+ *((u8 *)&rltk_wlan_info + 40) = 0;
+ *(u64 *)&rltk_wlan_info = 0LL;
+ *((u64 *)&rltk_wlan_info + 1) = 0LL;
+ *((u64 *)&rltk_wlan_info + 3) = 0LL;
+ *((u64 *)&rltk_wlan_info + 4) = 0LL;
+ //deinit_mem_monitor(NULL, NULL);
+ }
+}
+//------------------------------------------------------------------------end-patch//
+static int wifi_connect_local(rtw_network_info_t *pWifi)
+{
+ int ret = 0;
+
+ if(is_promisc_enabled())
+ promisc_set(0, NULL, 0);
+
+ if(!pWifi) return -1;
+ switch(pWifi->security_type){
+ case RTW_SECURITY_OPEN:
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_NONE, NULL, 0, 0, 0, 0, NULL, 0);
+ break;
+ case RTW_SECURITY_WEP_PSK:
+ case RTW_SECURITY_WEP_SHARED:
+ ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_SHARED_KEY);
+ if(ret == 0)
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_WEP, NULL, pWifi->key_id, 1 /* set tx key */, 0, 0, pWifi->password, pWifi->password_len);
+ break;
+ case RTW_SECURITY_WPA_TKIP_PSK:
+ case RTW_SECURITY_WPA2_TKIP_PSK:
+ ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM);
+ if(ret == 0)
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_TKIP, NULL, 0, 0, 0, 0, NULL, 0);
+ if(ret == 0)
+ ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len);
+ break;
+ case RTW_SECURITY_WPA_AES_PSK:
+ case RTW_SECURITY_WPA2_AES_PSK:
+ case RTW_SECURITY_WPA2_MIXED_PSK:
+ case RTW_SECURITY_WPA_WPA2_MIXED:
+ ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM);
+ if(ret == 0)
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0, NULL, 0);
+ if(ret == 0)
+ ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len);
+ break;
+ default:
+ ret = -1;
+ printf("WIFICONF: security type(0x%x) is not supported.\n", pWifi->security_type);
+ break;
+ }
+#if DD_WIFI_CONN // дублирование Ñ wifi_connect_bssid_local()
+ if(ret == 0)
+ ret = wext_set_ssid(WLAN0_NAME, pWifi->ssid.val, pWifi->ssid.len);
+#endif
+ return ret;
+}
+
+#if DD_WIFI_CONN // дублирование Ñ wifi_connect_bssid_local()
+static int wifi_connect_bssid_local(rtw_network_info_t *pWifi)
+{
+ int ret = 0;
+ u8 bssid[12] = {0};
+
+ if(is_promisc_enabled())
+ promisc_set(0, NULL, 0);
+
+ if(!pWifi) return -1;
+ switch(pWifi->security_type){
+ case RTW_SECURITY_OPEN:
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_NONE, NULL, 0, 0, 0, 0, NULL, 0);
+ break;
+ case RTW_SECURITY_WEP_PSK:
+ case RTW_SECURITY_WEP_SHARED:
+ ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_SHARED_KEY);
+ if(ret == 0)
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_WEP, NULL, pWifi->key_id, 1 /* set tx key */, 0, 0, pWifi->password, pWifi->password_len);
+ break;
+ case RTW_SECURITY_WPA_TKIP_PSK:
+ case RTW_SECURITY_WPA2_TKIP_PSK:
+ ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM);
+ if(ret == 0)
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_TKIP, NULL, 0, 0, 0, 0, NULL, 0);
+ if(ret == 0)
+ ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len);
+ break;
+ case RTW_SECURITY_WPA_AES_PSK:
+ case RTW_SECURITY_WPA2_AES_PSK:
+ case RTW_SECURITY_WPA2_MIXED_PSK:
+ ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM);
+ if(ret == 0)
+ ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0, NULL, 0);
+ if(ret == 0)
+ ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len);
+ break;
+ default:
+ ret = -1;
+ printf("WIFICONF: security type(0x%x) is not supported.\n", pWifi->security_type);
+ break;
+ }
+ if(ret == 0){
+ memcpy(bssid, pWifi->bssid.octet, ETH_ALEN);
+ if(pWifi->ssid.len){
+ bssid[ETH_ALEN] = '#';
+ bssid[ETH_ALEN + 1] = '@';
+ memcpy(bssid + ETH_ALEN + 2, &pWifi, sizeof(pWifi));
+ }
+ ret = wext_set_bssid(WLAN0_NAME, bssid);
+ }
+ return ret;
+}
+#endif
+
+void wifi_rx_beacon_hdl( char* buf, int buf_len, int flags, void* userdata) {
+ //printf("Beacon!\n");
+}
+
+
+static void wifi_no_network_hdl(char* buf, int buf_len, int flags, void* userdata)
+{
+ if(join_user_data!=NULL)
+ rtw_join_status = JOIN_NO_NETWORKS;
+}
+
+static void wifi_connected_hdl( char* buf, int buf_len, int flags, void* userdata)
+{
+#ifdef CONFIG_ENABLE_EAP
+ if(get_eap_phase()){
+ rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY;
+ return;
+ }
+#endif /* CONFIG_ENABLE_EAP */
+ if((join_user_data!=NULL)&&((join_user_data->network_info.security_type == RTW_SECURITY_OPEN) ||
+ (join_user_data->network_info.security_type == RTW_SECURITY_WEP_PSK))){
+ rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY;
+ rtw_up_sema(&join_user_data->join_sema);
+ }else if((join_user_data!=NULL)&&((join_user_data->network_info.security_type == RTW_SECURITY_WPA2_AES_PSK) )){
+ rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY;
+ }
+}
+static void wifi_handshake_done_hdl( char* buf, int buf_len, int flags, void* userdata)
+{
+ rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY | JOIN_HANDSHAKE_DONE;
+ if(join_user_data != NULL)
+ rtw_up_sema(&join_user_data->join_sema);
+}
+
+static void wifi_disconn_hdl( char* buf, int buf_len, int flags, void* userdata)
+{
+ if(join_user_data != NULL){
+ if(join_user_data->network_info.security_type == RTW_SECURITY_OPEN){
+
+ if(rtw_join_status == JOIN_NO_NETWORKS)
+ error_flag = RTW_NONE_NETWORK;
+
+ }else if(join_user_data->network_info.security_type == RTW_SECURITY_WEP_PSK){
+
+ if(rtw_join_status == JOIN_NO_NETWORKS)
+ error_flag = RTW_NONE_NETWORK;
+
+ else if(rtw_join_status == 0)
+ error_flag = RTW_CONNECT_FAIL;
+
+ }else if(join_user_data->network_info.security_type == RTW_SECURITY_WPA2_AES_PSK){
+
+ if(rtw_join_status ==JOIN_NO_NETWORKS)
+ error_flag = RTW_NONE_NETWORK;
+
+ else if(rtw_join_status == 0)
+ error_flag = RTW_CONNECT_FAIL;
+
+ else if(rtw_join_status == JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY)
+ error_flag = RTW_WRONG_PASSWORD;
+ }
+
+ }else{
+ if(error_flag == RTW_NO_ERROR) //wifi_disconn_hdl will be dispatched one more time after join_user_data = NULL add by frankie
+ error_flag = RTW_UNKNOWN;
+ }
+
+ if(join_user_data != NULL)
+ rtw_up_sema(&join_user_data->join_sema);
+ //printf("\r\nWiFi Disconnect. Error flag is %d.\n", error_flag);
+}
+
+#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
+#define WLAN0_NAME "wlan0" // ?????
+
+void restore_wifi_info_to_flash()
+{
+ struct wlan_fast_reconnect * data_to_flash;
+ u32 channel = 0;
+ u8 index = 0;
+ u8 *ifname[1] = {WLAN0_NAME};
+ rtw_wifi_setting_t setting;
+ //struct security_priv *psecuritypriv = &padapter->securitypriv;
+ //WLAN_BSSID_EX *pcur_bss = pmlmepriv->cur_network.network;
+
+ data_to_flash = (struct wlan_fast_reconnect *)rtw_zmalloc(sizeof(struct wlan_fast_reconnect));
+
+ if(data_to_flash && p_write_reconnect_ptr){
+ if(wifi_get_setting((const char*)ifname[0],&setting) || setting.mode == RTW_MODE_AP){
+ printf(" %s():wifi_get_setting fail or ap mode\n", __func__);
+ return;
+ }
+ channel = setting.channel;
+
+ rtw_memset(psk_essid[index], 0, sizeof(psk_essid[index]));
+ strncpy(psk_essid[index], setting.ssid, strlen(setting.ssid));
+ switch(setting.security_type){
+ case RTW_SECURITY_OPEN:
+ rtw_memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index]));
+ rtw_memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index]));
+ data_to_flash->security_type = RTW_SECURITY_OPEN;
+ break;
+ case RTW_SECURITY_WEP_PSK:
+ channel |= (setting.key_idx) << 28;
+ rtw_memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index]));
+ rtw_memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index]));
+ rtw_memcpy(psk_passphrase[index], setting.password, sizeof(psk_passphrase[index]));
+ data_to_flash->security_type = RTW_SECURITY_WEP_PSK;
+ break;
+ case RTW_SECURITY_WPA_TKIP_PSK:
+ data_to_flash->security_type = RTW_SECURITY_WPA_TKIP_PSK;
+ break;
+ case RTW_SECURITY_WPA2_AES_PSK:
+ data_to_flash->security_type = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ default:
+ break;
+ }
+
+ memcpy(data_to_flash->psk_essid, psk_essid[index], sizeof(data_to_flash->psk_essid));
+ if (strlen(psk_passphrase64) == 64) {
+ memcpy(data_to_flash->psk_passphrase, psk_passphrase64, sizeof(data_to_flash->psk_passphrase));
+ } else {
+ memcpy(data_to_flash->psk_passphrase, psk_passphrase[index], sizeof(data_to_flash->psk_passphrase));
+ }
+ memcpy(data_to_flash->wpa_global_PSK, wpa_global_PSK[index], sizeof(data_to_flash->wpa_global_PSK));
+ memcpy(&(data_to_flash->channel), &channel, 4);
+
+ //call callback function in user program
+ p_write_reconnect_ptr((u8 *)data_to_flash, sizeof(struct wlan_fast_reconnect));
+
+ }
+ if(data_to_flash)
+ rtw_free(data_to_flash);
+}
+
+#endif
+
+//----------------------------------------------------------------------------//
+int wifi_connect(
+ char *ssid,
+ rtw_security_t security_type,
+ char *password,
+ int ssid_len,
+ int password_len,
+ int key_id,
+ void *semaphore)
+{
+ xSemaphoreHandle join_semaphore;
+ rtw_result_t result = RTW_SUCCESS;
+ u8 wep_hex = 0;
+ u8 wep_pwd[14] = {0};
+
+ if((rtw_join_status & JOIN_SIMPLE_CONFIG) || (rtw_join_status & JOIN_AIRKISS)){
+ return RTW_ERROR;
+ }
+
+ rtw_join_status = 0;//clear for last connect status
+ error_flag = RTW_UNKNOWN ;//clear for last connect status
+ if ( ( ( ( password_len > RTW_MAX_PSK_LEN ) ||
+ ( password_len < RTW_MIN_PSK_LEN ) ) &&
+ ( ( security_type == RTW_SECURITY_WPA_TKIP_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA_AES_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA2_AES_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA2_TKIP_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA2_MIXED_PSK ) ) )) {
+ error_flag = RTW_WRONG_PASSWORD;
+ return RTW_INVALID_KEY;
+ }
+
+ if ((security_type == RTW_SECURITY_WEP_PSK)||
+ (security_type ==RTW_SECURITY_WEP_SHARED)) {
+ if ((password_len != 5) && (password_len != 13) &&
+ (password_len != 10)&& (password_len != 26)) {
+ error_flag = RTW_WRONG_PASSWORD;
+ return RTW_INVALID_KEY;
+ } else {
+
+ if(password_len == 10) {
+
+ u32 p[5] = {0};
+ u8 i = 0;
+ sscanf((const char*)password, "%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4]);
+ for(i=0; i< 5; i++)
+ wep_pwd[i] = (u8)p[i];
+ wep_pwd[5] = '\0';
+ password_len = 5;
+ wep_hex = 1;
+ } else if (password_len == 26) {
+ u32 p[13] = {0};
+ u8 i = 0;
+ sscanf((const char*)password, "%02x%02x%02x%02x%02x%02x%02x"\
+ "%02x%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4],\
+ &p[5], &p[6], &p[7], &p[8], &p[9], &p[10], &p[11], &p[12]);
+ for(i=0; i< 13; i++)
+ wep_pwd[i] = (u8)p[i];
+ wep_pwd[13] = '\0';
+ password_len = 13;
+ wep_hex = 1;
+ }
+ }
+ }
+
+ internal_join_result_t *join_result = (internal_join_result_t *)rtw_zmalloc(sizeof(internal_join_result_t));
+ if(!join_result) {
+ return RTW_NOMEM;
+ }
+
+ join_result->network_info.ssid.len = ssid_len > 32 ? 32 : ssid_len;
+ rtw_memcpy(join_result->network_info.ssid.val, ssid, ssid_len);
+
+ join_result->network_info.password_len = password_len;
+ if(password_len) {
+ /* add \0 to the end */
+ join_result->network_info.password = rtw_zmalloc(password_len + 1);
+ if(!join_result->network_info.password) {
+ result = RTW_NOMEM;
+ goto error;
+ }
+ if (0 == wep_hex)
+ rtw_memcpy(join_result->network_info.password, password, password_len);
+ else
+ rtw_memcpy(join_result->network_info.password, wep_pwd, password_len);
+
+ }
+
+ join_result->network_info.security_type = security_type;
+ join_result->network_info.key_id = key_id;
+
+ if(semaphore == NULL) {
+ rtw_init_sema( &join_result->join_sema, 0 );
+ if(!join_result->join_sema){
+ result = RTW_NORESOURCE;
+ goto error;
+ }
+ join_semaphore = join_result->join_sema;
+ } else {
+ join_result->join_sema = semaphore;
+ }
+ wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl,NULL);
+ wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl, NULL);
+#if DD_WIFI_CONN // дублирование Ñ wifi_connect_bssid_local()
+ wifi_connect_local(&join_result->network_info);
+#else
+ if(wifi_connect_local(&join_result->network_info) == 0)
+ wext_set_ssid(WLAN0_NAME, join_result->network_info.ssid.val, join_result->network_info.ssid.len);
+#endif
+ join_user_data = join_result;
+
+ if(semaphore == NULL) {
+// for eap connection, timeout should be longer (default value in wpa_supplicant: 60s)
+#ifdef CONFIG_ENABLE_EAP
+ if(get_eap_phase()){
+ if(rtw_down_timeout_sema( &join_result->join_sema, 60000 ) == RTW_FALSE) {
+ printf("RTW API: Join bss timeout\n");
+ if(password_len) {
+ rtw_free(join_result->network_info.password);
+ }
+ result = RTW_TIMEOUT;
+ goto error;
+ } else {
+ if(wifi_is_connected_to_ap( ) != RTW_SUCCESS) {
+ result = RTW_ERROR;
+ goto error;
+ }
+ }
+ }
+ else
+#endif
+ if(rtw_down_timeout_sema( &join_result->join_sema, RTW_JOIN_TIMEOUT ) == RTW_FALSE) {
+ printf("RTW API: Join bss timeout\n");
+ if(password_len) {
+ rtw_free(join_result->network_info.password);
+ }
+ result = RTW_TIMEOUT;
+ goto error;
+ } else {
+ if(join_result->network_info.password_len) {
+ rtw_free(join_result->network_info.password);
+ }
+ if(wifi_is_connected_to_ap( ) != RTW_SUCCESS) {
+ result = RTW_ERROR;
+ goto error;
+ }
+ }
+ }
+
+ result = RTW_SUCCESS;
+
+#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
+ restore_wifi_info_to_flash();
+#endif
+
+error:
+ if(semaphore == NULL){
+ rtw_free_sema( &join_semaphore);
+ }
+ join_user_data = NULL;
+ rtw_free((u8*)join_result);
+ wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl);
+ return result;
+}
+
+int wifi_connect_bssid(
+ unsigned char bssid[ETH_ALEN],
+ char *ssid,
+ rtw_security_t security_type,
+ char *password,
+ int bssid_len,
+ int ssid_len,
+ int password_len,
+ int key_id,
+ void *semaphore)
+{
+ xSemaphoreHandle join_semaphore;
+ rtw_result_t result = RTW_SUCCESS;
+
+ if((rtw_join_status & JOIN_SIMPLE_CONFIG) || (rtw_join_status & JOIN_AIRKISS)){
+ return RTW_ERROR;
+ }
+
+ rtw_join_status = 0;//clear for last connect status
+ error_flag = RTW_UNKNOWN;//clear for last connect status
+ internal_join_result_t *join_result = (internal_join_result_t *)rtw_zmalloc(sizeof(internal_join_result_t));
+ if(!join_result) {
+ return RTW_NOMEM;
+ }
+ if(ssid_len && ssid){
+ join_result->network_info.ssid.len = ssid_len > 32 ? 32 : ssid_len;
+ rtw_memcpy(join_result->network_info.ssid.val, ssid, ssid_len);
+ }
+ rtw_memcpy(join_result->network_info.bssid.octet, bssid, bssid_len);
+
+ if ( ( ( ( password_len > RTW_MAX_PSK_LEN ) ||
+ ( password_len < RTW_MIN_PSK_LEN ) ) &&
+ ( ( security_type == RTW_SECURITY_WPA_TKIP_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA_AES_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA2_AES_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA2_TKIP_PSK ) ||
+ ( security_type == RTW_SECURITY_WPA2_MIXED_PSK ) ) )||
+ (((password_len != 5)&& (password_len != 13))&&
+ ((security_type == RTW_SECURITY_WEP_PSK)||
+ (security_type ==RTW_SECURITY_WEP_SHARED ) ))) {
+ return RTW_INVALID_KEY;
+ }
+ join_result->network_info.password_len = password_len;
+ if(password_len) {
+ /* add \0 to the end */
+ join_result->network_info.password = rtw_zmalloc(password_len + 1);
+ if(!join_result->network_info.password) {
+ return RTW_NOMEM;
+ }
+ rtw_memcpy(join_result->network_info.password, password, password_len);
+ }
+
+ join_result->network_info.security_type = security_type;
+ join_result->network_info.key_id = key_id;
+
+ if(semaphore == NULL) {
+ rtw_init_sema( &join_result->join_sema, 0 );
+ if(!join_result->join_sema){
+ return RTW_NORESOURCE;
+ }
+ join_semaphore = join_result->join_sema;
+ } else {
+ join_result->join_sema = semaphore;
+ }
+ wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl,NULL);
+ wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl, NULL);
+#if DD_WIFI_CONN // дублирование Ñ wifi_connect_bssid_local()
+ wifi_connect_bssid_local(&join_result->network_info);
+#else
+ rtw_network_info_t *pWifi = &join_result->network_info;
+ if(wifi_connect_local(pWifi) == 0) {
+ struct{
+ u8 bssid[ETH_ALEN + 2];
+ void * p;
+ } bs = {0};
+ memcpy(bs.bssid, pWifi->bssid.octet, ETH_ALEN);
+ if(pWifi->ssid.len){
+ bs.bssid[ETH_ALEN] = '#';
+ bs.bssid[ETH_ALEN + 1] = '@';
+ bs.p = pWifi;
+ }
+ wext_set_bssid(WLAN0_NAME, bssid);
+ }
+#endif
+
+ join_user_data = join_result;
+
+ if(semaphore == NULL) {
+ if(rtw_down_timeout_sema( &join_result->join_sema, RTW_JOIN_TIMEOUT ) == RTW_FALSE) {
+ printf("RTW API: Join bss timeout\n");
+ if(password_len) {
+ rtw_free(join_result->network_info.password);
+ }
+ rtw_free((u8*)join_result);
+ rtw_free_sema( &join_semaphore);
+ result = RTW_TIMEOUT;
+ goto error;
+ } else {
+ rtw_free_sema( &join_semaphore );
+ if(join_result->network_info.password_len) {
+ rtw_free(join_result->network_info.password);
+ }
+ rtw_free((u8*)join_result);
+ if( wifi_is_connected_to_ap( ) != RTW_SUCCESS) {
+ result = RTW_ERROR;
+ goto error;
+ }
+ }
+ }
+
+ result = RTW_SUCCESS;
+
+#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
+ restore_wifi_info_to_flash();
+#endif
+
+error:
+ join_user_data = NULL;
+ wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl);
+ wifi_unreg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl);
+ return result;
+}
+
+int wifi_disconnect(void)
+{
+ int ret = 0;
+
+ //set MAC address last byte to 1 since driver will filter the mac with all 0x00 or 0xff
+ //add extra 2 zero byte for check of #@ in wext_set_bssid()
+ const __u8 null_bssid[ETH_ALEN + 2] = {0, 0, 0, 0, 0, 1, 0, 0};
+
+ if (wext_set_bssid(WLAN0_NAME, null_bssid) < 0){
+ printf("WEXT: Failed to set bogus BSSID to disconnect\n");
+ ret = -1;
+ }
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_is_connected_to_ap( void )
+{
+ return rltk_wlan_is_connected_to_ap();
+}
+
+//----------------------------------------------------------------------------//
+int wifi_is_up(rtw_interface_t interface)
+{
+ if(interface == RTW_AP_INTERFACE) {
+ if(wifi_mode == RTW_MODE_STA_AP) {
+ return rltk_wlan_running(WLAN1_IDX);
+ }
+ }
+
+ return rltk_wlan_running(WLAN0_IDX);
+}
+
+int wifi_is_ready_to_transceive(rtw_interface_t interface)
+{
+ switch ( interface )
+ {
+ case RTW_AP_INTERFACE:
+ return ( wifi_is_up(interface) == RTW_TRUE ) ? RTW_SUCCESS : RTW_ERROR;
+
+ case RTW_STA_INTERFACE:
+ switch ( error_flag)
+ {
+ case RTW_NO_ERROR:
+ return RTW_SUCCESS;
+
+ default:
+ return RTW_ERROR;
+ }
+ default:
+ return RTW_ERROR;
+ }
+}
+
+//----------------------------------------------------------------------------//
+int wifi_set_mac_address(char * mac)
+{
+ char buf[13+17+1];
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 13+17, "write_mac %s", mac);
+ return wext_private_command(WLAN0_NAME, buf, SHOW_PRIVATE_OUT);
+}
+
+int wifi_get_mac_address(char * mac)
+{
+ int ret = 0;
+ char buf[32];
+ rtw_memset(buf, 0, sizeof(buf));
+ rtw_memcpy(buf, "read_mac", 8);
+ ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 32);
+#if SHOW_PRIVATE_OUT
+ rtl_printf("%s\n", buf);
+#endif
+ strcpy(mac, buf);
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_enable_powersave(void)
+{
+ return wext_enable_powersave(WLAN0_NAME, 1, 1);
+}
+
+int wifi_disable_powersave(void)
+{
+ return wext_disable_powersave(WLAN0_NAME);
+}
+
+#if 1 //Not ready
+//----------------------------------------------------------------------------//
+int wifi_get_txpower(int *poweridx)
+{
+ int ret;
+ char buf[11];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ rtw_memcpy(buf, "txpower", 11);
+ ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 11);
+#if SHOW_PRIVATE_OUT
+ rtl_printf("%s\n", buf);
+#endif
+ sscanf(buf, "%d", poweridx);
+
+ return ret;
+}
+
+int wifi_set_txpower(int poweridx)
+{
+ int ret;
+ char buf[24];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 24, "txpower patha=%d,pathb=%d", poweridx, poweridx); // patha=%d,pathb=%d ?
+ ret = wext_private_command(WLAN0_NAME, buf, SHOW_PRIVATE_OUT);
+
+ return ret;
+}
+#endif
+
+//----------------------------------------------------------------------------//
+int wifi_get_associated_client_list(void * client_list_buffer, uint16_t buffer_length)
+{
+ const char * ifname = WLAN0_NAME;
+ int ret = 0;
+ char buf[25];
+
+ if(wifi_mode == RTW_MODE_STA_AP) {
+ ifname = WLAN1_NAME;
+ }
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 25, "get_client_list %x", client_list_buffer);
+ ret = wext_private_command(ifname, buf, SHOW_PRIVATE_OUT);
+
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security)
+{
+ const char * ifname = WLAN0_NAME;
+ int ret = 0;
+ char buf[24];
+
+ if(wifi_mode == RTW_MODE_STA_AP) {
+ ifname = WLAN1_NAME;
+ }
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 24, "get_ap_info %x", ap_info);
+ ret = wext_private_command(ifname, buf, SHOW_PRIVATE_OUT);
+
+ snprintf(buf, 24, "get_security");
+ ret = wext_private_command_with_retval(ifname, buf, buf, 24);
+#if SHOW_PRIVATE_OUT
+ rtl_printf("%s\n", buf);
+#endif
+ sscanf(buf, "%d", security);
+
+ return ret;
+}
+
+int wifi_get_drv_ability(uint32_t *ability)
+{
+ return wext_get_drv_ability(WLAN0_NAME, ability);
+}
+
+//----------------------------------------------------------------------------//
+int wifi_set_country(rtw_country_code_t country_code)
+{
+ int ret;
+
+ ret = wext_set_country(WLAN0_NAME, country_code);
+
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_set_channel_plan(uint8_t channel_plan)
+{
+ const char * ifname = WLAN0_NAME;
+ int ret = 0;
+ char buf[24];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 24, "set_ch_plan %x", channel_plan);
+ ret = wext_private_command(ifname, buf, SHOW_PRIVATE_OUT);
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_get_rssi(int *pRSSI)
+{
+ return wext_get_rssi(WLAN0_NAME, pRSSI);
+}
+
+//----------------------------------------------------------------------------//
+int wifi_set_channel(int channel)
+{
+ return wext_set_channel(WLAN0_NAME, channel);
+}
+
+int wifi_get_channel(int *channel)
+{
+ return wext_get_channel(WLAN0_NAME, (u8*)channel);
+}
+
+//----------------------------------------------------------------------------//
+int wifi_register_multicast_address(rtw_mac_t *mac)
+{
+ return wext_register_multicast_address(WLAN0_NAME, mac);
+}
+
+int wifi_unregister_multicast_address(rtw_mac_t *mac)
+{
+ return wext_unregister_multicast_address(WLAN0_NAME, mac);
+}
+
+//----------------------------------------------------------------------------//
+void wifi_set_mib(void)
+{
+ // adaptivity
+ wext_set_adaptivity(RTW_ADAPTIVITY_DISABLE);
+}
+
+//----------------------------------------------------------------------------//
+int wifi_rf_on(void)
+{
+ int ret;
+ ret = rltk_wlan_rf_on();
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_rf_off(void)
+{
+ int ret;
+ ret = rltk_wlan_rf_off();
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_on(rtw_mode_t mode)
+{
+ int ret = 1;
+//pvvx int timeout = 20; // 20 sec ??!!
+ int timeout = wifi_test_timeout_ms/wifi_test_timeout_step_ms;
+ int idx;
+ int devnum = 1;
+ static int event_init = 0;
+
+ if(rltk_wlan_running(WLAN0_IDX)) {
+ printf("WIFI is already running\n");
+ return 1;
+ }
+
+ if(event_init == 0){
+ init_event_callback_list();
+ event_init = 1;
+ }
+
+ wifi_mode = mode;
+
+ if(mode == RTW_MODE_STA_AP)
+ devnum = 2;
+
+ // set wifi mib
+ wifi_set_mib();
+ printf("Initializing WIFI ...\n");
+ for(idx=0;idxBSSID.octet, (*result_ptr)->BSSID.octet)){
+ if((*result_ptr)->signal_strength > scan_result_handler_ptr.pap_details[i]->signal_strength){
+ temp = scan_result_handler_ptr.pap_details[i];
+ for(j = i-1; j >= 0; j--){
+ if(scan_result_handler_ptr.pap_details[j]->signal_strength >= (*result_ptr)->signal_strength)
+ break;
+ else
+ scan_result_handler_ptr.pap_details[j+1] = scan_result_handler_ptr.pap_details[j];
+ }
+ scan_result_handler_ptr.pap_details[j+1] = temp;
+ scan_result_handler_ptr.pap_details[j+1]->signal_strength = (*result_ptr)->signal_strength;
+ }
+ memset(*result_ptr, 0, sizeof(rtw_scan_result_t));
+ return;
+ }
+ }
+
+ scan_result_handler_ptr.scan_cnt++;
+
+ if(scan_result_handler_ptr.scan_cnt > scan_result_handler_ptr.max_ap_size){
+ scan_result_handler_ptr.scan_cnt = scan_result_handler_ptr.max_ap_size;
+ if((*result_ptr)->signal_strength > scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size-1]->signal_strength){
+ rtw_memcpy(scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size-1], *result_ptr, sizeof(rtw_scan_result_t));
+ temp = scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size -1];
+ }else
+ return;
+ }else{
+ rtw_memcpy(&scan_result_handler_ptr.ap_details[scan_result_handler_ptr.scan_cnt-1], *result_ptr, sizeof(rtw_scan_result_t));
+ }
+
+ for(i=0; i< scan_result_handler_ptr.scan_cnt-1; i++){
+ if((*result_ptr)->signal_strength > scan_result_handler_ptr.pap_details[i]->signal_strength)
+ break;
+ }
+ insert_pos = i;
+
+ for(i = scan_result_handler_ptr.scan_cnt-1; i>insert_pos; i--)
+ scan_result_handler_ptr.pap_details[i] = scan_result_handler_ptr.pap_details[i-1];
+
+ if(temp != NULL)
+ scan_result_handler_ptr.pap_details[insert_pos] = temp;
+ else
+ scan_result_handler_ptr.pap_details[insert_pos] = &scan_result_handler_ptr.ap_details[scan_result_handler_ptr.scan_cnt-1];
+ rtw_memset(*result_ptr, 0, sizeof(rtw_scan_result_t));
+}
+
+void wifi_scan_done_hdl( char* buf, int buf_len, int flags, void* userdata)
+{
+ int i = 0;
+ rtw_scan_handler_result_t scan_result_report;
+
+ for(i=0; ibuf, pscan_buf->buf_len, flags);
+ }else{
+ wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl, NULL);
+ wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl, NULL);
+ ret = wext_set_scan(WLAN0_NAME, NULL, 0, flags);
+ }
+
+ if(ret == 0) {
+ if(result_ptr != NULL){
+ ret = wext_get_scan(WLAN0_NAME, pscan_buf->buf, pscan_buf->buf_len);
+ }
+ }
+ return ret;
+}
+
+int wifi_scan_networks_with_ssid(int (results_handler)(char*buf, int buflen, char *ssid, void *user_data),
+ OUT void* user_data, IN int scan_buflen, IN char* ssid, IN int ssid_len)
+{
+ int scan_cnt = 0, add_cnt = 0;
+ scan_buf_arg scan_buf;
+ int ret;
+
+ scan_buf.buf_len = scan_buflen;
+ scan_buf.buf = (char*)pvPortMalloc(scan_buf.buf_len);
+ if(!scan_buf.buf){
+ printf("ERROR: Can't malloc memory(%d)\n", scan_buf.buf_len);
+ return RTW_NOMEM;
+ }
+ //set ssid
+ memset(scan_buf.buf, 0, scan_buf.buf_len);
+ memcpy(scan_buf.buf, &ssid_len, sizeof(int));
+ memcpy(scan_buf.buf+sizeof(int), ssid, ssid_len);
+
+ //Scan channel
+ if((scan_cnt = (wifi_scan(RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, &scan_buf))) < 0){
+ printf("ERROR: wifi scan failed\n");
+ ret = RTW_ERROR;
+ }else{
+ if(NULL == results_handler)
+ {
+ int plen = 0;
+ while(plen < scan_buf.buf_len){
+ int len, rssi, ssid_len, i, security_mode;
+ int wps_password_id;
+ char *mac, *ssid;
+ //u8 *security_mode;
+ printf("\n");
+ // len
+ len = (int)*(scan_buf.buf + plen);
+ printf("len = %d,\t", len);
+ // check end
+ if(len == 0) break;
+ // mac
+ mac = scan_buf.buf + plen + 1;
+ printf("mac = ");
+ for(i=0; i<6; i++)
+ printf("%02x ", (u8)*(mac+i));
+ printf(",\t");
+ // rssi
+ rssi = *(int*)(scan_buf.buf + plen + 1 + 6);
+ printf(" rssi = %d,\t", rssi);
+ // security_mode
+ security_mode = (int)*(scan_buf.buf + plen + 1 + 6 + 4);
+ switch (security_mode) {
+ case IW_ENCODE_ALG_NONE:
+ printf("sec = open ,\t");
+ break;
+ case IW_ENCODE_ALG_WEP:
+ printf("sec = wep ,\t");
+ break;
+ case IW_ENCODE_ALG_CCMP:
+ printf("sec = wpa/wpa2,\t");
+ break;
+ }
+ // password id
+ wps_password_id = (int)*(scan_buf.buf + plen + 1 + 6 + 4 + 1);
+ printf("wps password id = %d,\t", wps_password_id);
+
+ printf("channel = %d,\t", *(scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1));
+ // ssid
+ ssid_len = len - 1 - 6 - 4 - 1 - 1 - 1;
+ ssid = scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1 + 1;
+ printf("ssid = ");
+ for(i=0; i 0)
+ {
+ rtw_msleep_os(20);
+ count --;
+ }
+ if(count == 0){
+ printf("[%d]WiFi: Scan is running. Wait 2s timeout.\n", rtw_get_current_time());
+ return RTW_TIMEOUT;
+ }
+ }
+ scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
+ scan_result_handler_ptr.scan_running = 1;
+#endif
+
+ scan_result_handler_ptr.gscan_result_handler = results_handler;
+
+ scan_result_handler_ptr.max_ap_size = max_ap_size;
+ scan_result_handler_ptr.ap_details = (rtw_scan_result_t*)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t));
+ if(scan_result_handler_ptr.ap_details == NULL){
+ goto err_exit;
+ }
+ rtw_memset(scan_result_handler_ptr.ap_details, 0, max_ap_size*sizeof(rtw_scan_result_t));
+
+ scan_result_handler_ptr.pap_details = (rtw_scan_result_t**)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t*));
+ if(scan_result_handler_ptr.pap_details == NULL)
+ goto error2_with_result_ptr;
+ rtw_memset(scan_result_handler_ptr.pap_details, 0, max_ap_size);
+
+ scan_result_handler_ptr.scan_cnt = 0;
+
+ scan_result_handler_ptr.scan_complete = RTW_FALSE;
+ scan_result_handler_ptr.user_data = user_data;
+
+ if (wifi_scan( RTW_SCAN_COMMAMD<<4 | RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, NULL) != RTW_SUCCESS)
+ {
+ goto error1_with_result_ptr;
+ }
+
+ return RTW_SUCCESS;
+
+error1_with_result_ptr:
+ rtw_free((u8*)scan_result_handler_ptr.pap_details);
+ scan_result_handler_ptr.pap_details = NULL;
+
+error2_with_result_ptr:
+ rtw_free((u8*)scan_result_handler_ptr.ap_details);
+ scan_result_handler_ptr.ap_details = NULL;
+
+err_exit:
+ rtw_memset((void *)&scan_result_handler_ptr, 0, sizeof(scan_result_handler_ptr));
+ return RTW_ERROR;
+}
+//----------------------------------------------------------------------------//
+int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length)
+{
+ if(channel_list)
+ return wext_set_pscan_channel(WLAN0_NAME, channel_list, pscan_config, length);
+ else
+ return -1;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_get_setting(const char *ifname, rtw_wifi_setting_t *pSetting)
+{
+ int ret = 0;
+ int mode = 0;
+ unsigned short security = 0;
+
+ memset(pSetting, 0, sizeof(rtw_wifi_setting_t));
+ if(wext_get_mode(ifname, &mode) < 0)
+ ret = -1;
+
+ switch(mode) {
+ case IW_MODE_MASTER:
+ pSetting->mode = RTW_MODE_AP;
+ break;
+ case IW_MODE_INFRA:
+ default:
+ pSetting->mode = RTW_MODE_STA;
+ break;
+ //default:
+ //printf("\r\n%s(): Unknown mode %d\n", __func__, mode);
+ //break;
+ }
+
+ if(wext_get_ssid(ifname, pSetting->ssid) < 0)
+ ret = -1;
+ if(wext_get_channel(ifname, &pSetting->channel) < 0)
+ ret = -1;
+ if(wext_get_enc_ext(ifname, &security, &pSetting->key_idx, pSetting->password) < 0)
+ ret = -1;
+
+ switch(security){
+ case IW_ENCODE_ALG_NONE:
+ pSetting->security_type = RTW_SECURITY_OPEN;
+ break;
+ case IW_ENCODE_ALG_WEP:
+ pSetting->security_type = RTW_SECURITY_WEP_PSK;
+ break;
+ case IW_ENCODE_ALG_TKIP:
+ pSetting->security_type = RTW_SECURITY_WPA_TKIP_PSK;
+ break;
+ case IW_ENCODE_ALG_CCMP:
+ pSetting->security_type = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ default:
+ break;
+ }
+
+ if(security == IW_ENCODE_ALG_TKIP || security == IW_ENCODE_ALG_CCMP)
+ if(wext_get_passphrase(ifname, pSetting->password) < 0)
+ ret = -1;
+
+ return ret;
+}
+//----------------------------------------------------------------------------//
+int wifi_show_setting(const char *ifname, rtw_wifi_setting_t *pSetting)
+{
+ int ret = 0;
+
+ printf("\nWIFI %s Setting:\n==============================\n",ifname);
+
+ switch(pSetting->mode) {
+ case RTW_MODE_AP:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("AP,");
+#endif
+ printf("\tMODE => AP\n");
+ break;
+ case RTW_MODE_STA:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("STA,");
+#endif
+ printf("\tMODE => STATION\n");
+ break;
+ default:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("UNKNOWN,");
+#endif
+ printf("\tMODE => UNKNOWN\n");
+ }
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("%s,%d,", pSetting->ssid, pSetting->channel);
+#endif
+ printf("\tSSID => %s\n", pSetting->ssid);
+ printf("\tCHANNEL => %d\n", pSetting->channel);
+
+ switch(pSetting->security_type) {
+ case RTW_SECURITY_OPEN:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("OPEN,");
+#endif
+ printf("\tSECURITY => OPEN\n");
+ break;
+ case RTW_SECURITY_WEP_PSK:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("WEP,%d,", pSetting->key_idx);
+#endif
+ printf("\tSECURITY => WEP\n");
+ printf("\tKEY INDEX => %d\n", pSetting->key_idx);
+ break;
+ case RTW_SECURITY_WPA_TKIP_PSK:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("TKIP,");
+#endif
+ printf("\tSECURITY => TKIP\n");
+ break;
+ case RTW_SECURITY_WPA2_AES_PSK:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("AES,");
+#endif
+ printf("\tSECURITY => AES\n");
+ break;
+ default:
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("UNKNOWN,");
+#endif
+ printf("\tSECURITY => UNKNOWN\n");
+ }
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+ at_printf("%s,", pSetting->password);
+#endif
+ printf("\tPASSWORD => %s\n", pSetting->password);
+// printf("\n");
+
+ return ret;
+}
+
+//----------------------------------------------------------------------------//
+int wifi_set_network_mode(rtw_network_mode_t mode)
+{
+ if((mode == RTW_NETWORK_B) || (mode == RTW_NETWORK_BG) || (mode == RTW_NETWORK_BGN))
+ return rltk_wlan_wireless_mode((unsigned char) mode);
+
+ return -1;
+}
+
+int wifi_set_wps_phase(unsigned char is_trigger_wps)
+{
+ return rltk_wlan_set_wps_phase(is_trigger_wps);
+}
+
+//----------------------------------------------------------------------------//
+int wifi_set_promisc(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used)
+{
+ return promisc_set(enabled, callback, len_used);
+}
+
+void wifi_enter_promisc_mode(){
+ int mode = 0;
+ unsigned char ssid[33];
+
+ if(wifi_mode == RTW_MODE_STA_AP){
+ wifi_off();
+ vTaskDelay(wifi_test_timeout_step_ms/portTICK_RATE_MS);
+ wifi_on(RTW_MODE_PROMISC);
+ }else{
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ switch(mode) {
+ case IW_MODE_MASTER: //In AP mode
+ //rltk_wlan_deinit();
+ wifi_off();//modified by Chris Yang for iNIC
+ vTaskDelay(wifi_test_timeout_step_ms/portTICK_RATE_MS);
+ //rltk_wlan_init(0, RTW_MODE_PROMISC);
+ //rltk_wlan_start(0);
+ wifi_on(RTW_MODE_PROMISC);
+ break;
+ case IW_MODE_INFRA: //In STA mode
+ if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
+ wifi_disconnect();
+ }
+ }
+}
+
+int wifi_restart_ap(
+ unsigned char *ssid,
+ rtw_security_t security_type,
+ unsigned char *password,
+ int ssid_len,
+ int password_len,
+ int channel)
+{
+ unsigned char idx = 0;
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+ struct netif * pnetif = &xnetif[0];
+#ifdef CONFIG_CONCURRENT_MODE
+ rtw_wifi_setting_t setting;
+ int sta_linked = 0;
+#endif
+
+ if(rltk_wlan_running(WLAN1_IDX)){
+ idx = 1;
+ }
+
+ // stop dhcp server
+ dhcps_deinit();
+
+#ifdef CONFIG_CONCURRENT_MODE
+ if(idx > 0){
+ sta_linked = wifi_get_setting(WLAN0_NAME, &setting);
+ wifi_off();
+ vTaskDelay(wifi_test_timeout_step_ms/portTICK_RATE_MS);
+ wifi_on(RTW_MODE_STA_AP);
+ }
+ else
+#endif
+ {
+ IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
+ wifi_off();
+ vTaskDelay(wifi_test_timeout_step_ms/portTICK_RATE_MS);
+ wifi_on(RTW_MODE_AP);
+ }
+ // start ap
+ if(wifi_start_ap((char*)ssid, security_type, (char*)password, ssid_len, password_len, channel) < 0) {
+ printf("ERROR: Operation failed!\n");
+ return -1;
+ }
+
+#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ printf("WebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL));
+#endif
+#ifdef CONFIG_CONCURRENT_MODE
+ // connect to ap if wlan0 was linked with ap
+ if(idx > 0 && sta_linked == 0){
+ int ret;
+ printf("AP: ssid=%s\n", (char*)setting.ssid);
+ printf("AP: security_type=%d\n", setting.security_type);
+ printf("AP: password=%s\n", (char*)setting.password);
+ printf("AP: key_idx =%d\n", setting.key_idx);
+ ret = wifi_connect((char*)setting.ssid,
+ setting.security_type,
+ (char*)setting.password,
+ strlen((char*)setting.ssid),
+ strlen((char*)setting.password),
+ setting.key_idx,
+ NULL);
+ if(ret == RTW_SUCCESS) {
+#if CONFIG_DHCP_CLIENT
+ /* Start DHCPClient */
+ LwIP_DHCP(0, DHCP_START);
+#endif
+#if CONFIG_WLAN_CONNECT_CB
+ extern void connect_start(void);
+ connect_start();
+#endif
+ }
+ }
+#endif
+#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ printf("WebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL));
+#endif
+ // start dhcp server
+ dhcps_init(&xnetif[idx]);
+
+ return 0;
+}
+
+#if CONFIG_AUTO_RECONNECT
+extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int, int);
+
+struct wifi_autoreconnect_param {
+ rtw_security_t security_type;
+ char *ssid;
+ int ssid_len;
+ char *password;
+ int password_len;
+ int key_id;
+};
+
+static void wifi_autoreconnect_thread(void *param)
+{
+ int ret = RTW_ERROR;
+ struct wifi_autoreconnect_param *reconnect_param = (struct wifi_autoreconnect_param *) param;
+ printf("auto reconnect ...\n");
+ ret = wifi_connect(reconnect_param->ssid, reconnect_param->security_type, reconnect_param->password,
+ reconnect_param->ssid_len, reconnect_param->password_len, reconnect_param->key_id, NULL);
+ if(ret == RTW_SUCCESS) {
+#if CONFIG_LWIP_LAYER
+#if ATCMD_VER == ATVER_2
+ if (dhcp_mode_sta == 2){
+ struct netif * pnetif = &xnetif[0];
+ LwIP_UseStaticIP(pnetif);
+ dhcps_init(pnetif);
+ }
+ else
+#endif
+ {
+ LwIP_DHCP(0, DHCP_START);
+#if LWIP_AUTOIP
+ uint8_t *ip = LwIP_GetIP(&xnetif[0]);
+ if((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) {
+ printf("IPv4 AUTOIP ...\n");
+ LwIP_AUTOIP(&xnetif[0]);
+ }
+#endif
+ }
+#endif //#if CONFIG_LWIP_LAYER
+#if CONFIG_WLAN_CONNECT_CB
+ extern void connect_start(void);
+ connect_start();
+#endif
+ }
+ vTaskDelete(NULL);
+}
+
+void wifi_autoreconnect_hdl(rtw_security_t security_type,
+ char *ssid, int ssid_len,
+ char *password, int password_len,
+ int key_id)
+{
+ static struct wifi_autoreconnect_param param;
+ param.security_type = security_type;
+ param.ssid = ssid;
+ param.ssid_len = ssid_len;
+ param.password = password;
+ param.password_len = password_len;
+ param.key_id = key_id;
+ xTaskCreate(wifi_autoreconnect_thread, (const char *)"wifi_autoreconnect", 512, ¶m, tskIDLE_PRIORITY + 1, NULL);
+}
+
+int wifi_config_autoreconnect(__u8 mode, __u8 retyr_times, __u16 timeout)
+{
+ p_wlan_autoreconnect_hdl = wifi_autoreconnect_hdl;
+ return wext_set_autoreconnect(WLAN0_NAME, mode, retyr_times, timeout);
+}
+
+int wifi_set_autoreconnect(__u8 mode)
+{
+ p_wlan_autoreconnect_hdl = wifi_autoreconnect_hdl;
+ return wifi_config_autoreconnect(mode, 3, 5);//default retry 2 times(limit is 3), timeout 5 seconds
+}
+
+int wifi_get_autoreconnect(__u8 *mode)
+{
+ return wext_get_autoreconnect(WLAN0_NAME, mode);
+}
+#endif
+
+#ifdef CONFIG_CUSTOM_IE
+/*
+ * Example for custom ie
+ *
+ * u8 test_1[] = {221, 2, 2, 2};
+ * u8 test_2[] = {221, 2, 1, 1};
+ * cus_ie buf[2] = {{test_1, PROBE_REQ},
+ * {test_2, PROBE_RSP | BEACON}};
+ * u8 buf_test2[] = {221, 2, 1, 3} ;
+ * cus_ie buf_update = {buf_test2, PROBE_REQ};
+ *
+ * add ie list
+ * static void cmd_add_ie(int argc, char **argv)
+ * {
+ * wifi_add_custom_ie((void *)buf, 2);
+ * }
+ *
+ * update current ie
+ * static void cmd_update_ie(int argc, char **argv)
+ * {
+ * wifi_update_custom_ie(&buf_update, 2);
+ * }
+ *
+ * delete all ie
+ * static void cmd_del_ie(int argc, char **argv)
+ * {
+ * wifi_del_custom_ie();
+ * }
+ */
+
+int wifi_add_custom_ie(void *cus_ie, int ie_num)
+{
+ return wext_add_custom_ie(WLAN0_NAME, cus_ie, ie_num);
+}
+
+
+int wifi_update_custom_ie(void *cus_ie, int ie_index)
+{
+ return wext_update_custom_ie(WLAN0_NAME, cus_ie, ie_index);
+}
+
+int wifi_del_custom_ie()
+{
+ return wext_del_custom_ie(WLAN0_NAME);
+}
+
+#endif
+
+#ifdef CONFIG_PROMISC
+extern void promisc_init_packet_filter(void);
+extern int promisc_add_packet_filter(u8 filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule);
+extern int promisc_enable_packet_filter(u8 filter_id);
+extern int promisc_disable_packet_filter(u8 filter_id);
+extern int promisc_remove_packet_filter(u8 filter_id);
+void wifi_init_packet_filter()
+{
+ promisc_init_packet_filter();
+}
+
+int wifi_add_packet_filter(unsigned char filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule)
+{
+ return promisc_add_packet_filter(filter_id, patt, rule);
+}
+
+int wifi_enable_packet_filter(unsigned char filter_id)
+{
+ return promisc_enable_packet_filter(filter_id);
+}
+
+int wifi_disable_packet_filter(unsigned char filter_id)
+{
+ return promisc_disable_packet_filter(filter_id);
+}
+
+int wifi_remove_packet_filter(unsigned char filter_id)
+{
+ return promisc_remove_packet_filter(filter_id);
+}
+#endif
+
+#ifdef CONFIG_AP_MODE
+int wifi_enable_forwarding(void)
+{
+ return wext_enable_forwarding(WLAN0_NAME);
+}
+
+int wifi_disable_forwarding(void)
+{
+ return wext_disable_forwarding(WLAN0_NAME);
+}
+#endif
+
+/* API to set flag for concurrent mode wlan1 issue_deauth when channel switched by wlan0
+ * usage: wifi_set_ch_deauth(0) -> wlan0 wifi_connect -> wifi_set_ch_deauth(1)
+ */
+#ifdef CONFIG_CONCURRENT_MODE
+int wifi_set_ch_deauth(__u8 enable)
+{
+ return wext_set_ch_deauth(WLAN1_NAME, enable);
+}
+#endif
+
+//----------------------------------------------------------------------------//
+#endif //#if CONFIG_WLAN
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.h b/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.h
new file mode 100644
index 0000000..bcd3786
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.h
@@ -0,0 +1,710 @@
+//----------------------------------------------------------------------------//
+#ifndef __WIFI_API_H
+#define __WIFI_API_H
+
+#include "FreeRTOS.h"
+#include "wifi_constants.h"
+#include "wifi_structures.h"
+#include "wifi_util.h"
+#include "wifi_ind.h"
+#include
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/******************************************************
+ * Macros
+ ******************************************************/
+
+#define RTW_ENABLE_API_INFO
+
+#ifdef RTW_ENABLE_API_INFO
+ #define RTW_API_INFO(args) do {printf args;} while(0)
+#else
+ #define RTW_API_INFO(args)
+#endif
+
+#define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
+#define CMP_MAC( a, b ) (((a[0])==(b[0]))&& \
+ ((a[1])==(b[1]))&& \
+ ((a[2])==(b[2]))&& \
+ ((a[3])==(b[3]))&& \
+ ((a[4])==(b[4]))&& \
+ ((a[5])==(b[5])))
+
+/******************************************************
+ * Constants
+ ******************************************************/
+#define SCAN_LONGEST_WAIT_TIME (4500)
+
+#define wifi_test_timeout_step_ms 20 // ms
+#define wifi_test_timeout_ms 2000 // ms
+
+#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
+
+#define PSCAN_ENABLE 0x01 //enable for partial channel scan
+#define PSCAN_FAST_SURVEY 0x02 //set to select scan time to FAST_SURVEY_TO, otherwise SURVEY_TO
+#define PSCAN_SIMPLE_CONFIG 0x04 //set to select scan time to FAST_SURVEY_TO and resend probe request
+
+/******************************************************
+ * Type Definitions
+ ******************************************************/
+
+/** Scan result callback function pointer type
+ *
+ * @param result_ptr : A pointer to the pointer that indicates where to put the next scan result
+ * @param user_data : User provided data
+ */
+typedef void (*rtw_scan_result_callback_t)( rtw_scan_result_t** result_ptr, void* user_data );
+typedef rtw_result_t (*rtw_scan_result_handler_t)( rtw_scan_handler_result_t* malloced_scan_result );
+
+/******************************************************
+ * Structures
+ ******************************************************/
+typedef struct {
+ char *buf;
+ int buf_len;
+} scan_buf_arg;
+
+/******************************************************
+ * Structures
+ ******************************************************/
+typedef struct internal_scan_handler{
+ rtw_scan_result_t** pap_details;
+ rtw_scan_result_t * ap_details;
+ int scan_cnt;
+ rtw_bool_t scan_complete;
+ unsigned char max_ap_size;
+ rtw_scan_result_handler_t gscan_result_handler;
+#if SCAN_USE_SEMAPHORE
+ void *scan_semaphore;
+#else
+ int scan_running;
+#endif
+ void* user_data;
+ unsigned int scan_start_time;
+} internal_scan_handler_t;
+
+typedef struct {
+ rtw_network_info_t network_info;
+ void *join_sema;
+} internal_join_result_t;
+
+/******************************************************
+ * Function Declarations
+ ******************************************************/
+/**
+ * Initialises Realtek WiFi API System
+ *
+ * - Initialises the required parts of the software platform
+ * i.e. worker, event registering, semaphore, etc.
+ *
+ * - Initialises the RTW API thread which handles the asynchronous event
+ *
+ * @return RTW_SUCCESS if initialization is successful, RTW_ERROR otherwise
+ */
+int wifi_manager_init(void);
+
+/** Joins a Wi-Fi network
+ *
+ * Scans for, associates and authenticates with a Wi-Fi network.
+ * On successful return, the system is ready to send data packets.
+ *
+ * @param[in] ssid : A null terminated string containing the SSID name of the network to join
+ * @param[in] security_type : Authentication type:
+ * - RTW_SECURITY_OPEN - Open Security
+ * - RTW_SECURITY_WEP_PSK - WEP Security with open authentication
+ * - RTW_SECURITY_WEP_SHARED - WEP Security with shared authentication
+ * - RTW_SECURITY_WPA_TKIP_PSK - WPA Security
+ * - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher
+ * - RTW_SECURITY_WPA2_TKIP_PSK - WPA2 Security using TKIP cipher
+ * - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers
+ * @param[in] password : A byte array containing either the
+ * cleartext security key for WPA/WPA2
+ * secured networks, or a pointer to
+ * an array of rtw_wep_key_t
+ * structures for WEP secured networks
+ * @param[in] ssid_len : The length of the SSID in
+ * bytes.
+ * @param[in] password_len : The length of the security_key in
+ * bytes.
+ * @param[in] key_id : The index of the wep key.
+ * @param[in] semaphore : A user provided semaphore that is flagged when the join is complete
+ *
+ * @return RTW_SUCCESS : when the system is joined and ready
+ * to send data packets
+ * RTW_ERROR : if an error occurred
+ */
+int wifi_connect(
+ char *ssid,
+ rtw_security_t security_type,
+ char *password,
+ int ssid_len,
+ int password_len,
+ int key_id,
+ void *semaphore);
+
+int wifi_connect_bssid(
+ unsigned char bssid[ETH_ALEN],
+ char *ssid,
+ rtw_security_t security_type,
+ char *password,
+ int bssid_len,
+ int ssid_len,
+ int password_len,
+ int key_id,
+ void *semaphore);
+
+/** Disassociates from a Wi-Fi network.
+ *
+ * @return RTW_SUCCESS : On successful disassociation from
+ * the AP
+ * RTW_ERROR : If an error occurred
+*/
+int wifi_disconnect(void);
+
+/** Check if the interface specified is up.
+ *
+ * @return RTW_TRUE : If it's up
+ * RTW_FALSE : If it's not
+*/
+int wifi_is_connected_to_ap(void);
+/*check if wifi has connected to AP before dhcp
+*
+* @return RTW_SUCCESS:if conneced
+ RTW_ERROR :if not connect
+*/
+
+
+int wifi_is_up(rtw_interface_t interface);
+
+/** Determines if a particular interface is ready to transceive ethernet packets
+ *
+ * @param Radio interface to check, options are
+ * RTW_STA_INTERFACE, RTW_AP_INTERFACE
+ * @return RTW_SUCCESS : if the interface is ready to
+ * transceive ethernet packets
+ * @return RTW_NOTFOUND : no AP with a matching SSID was
+ * found
+ * @return RTW_NOT_AUTHENTICATED: a matching AP was found but
+ * it won't let you
+ * authenticate. This can
+ * occur if this device is
+ * in the block list on the
+ * AP.
+ * @return RTW_NOT_KEYED: the device has authenticated and
+ * associated but has not completed
+ * the key exchange. This can occur
+ * if the passphrase is incorrect.
+ * @return RTW_ERROR : if the interface is not ready to
+ * transceive ethernet packets
+ */
+int wifi_is_ready_to_transceive(rtw_interface_t interface);
+
+/** ----------------------------------------------------------------------
+ * WARNING : This function is for internal use only!
+ * ----------------------------------------------------------------------
+ * This function sets the current Media Access Control (MAC) address of the
+ * 802.11 device.
+ *
+ * @param[in] mac Wi-Fi MAC address
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_set_mac_address(char * mac);
+
+/** Retrieves the current Media Access Control (MAC) address
+ * (or Ethernet hardware address) of the 802.11 device
+ *
+ * @param mac Pointer to a variable that the current MAC address will be written to
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_get_mac_address(char * mac);
+
+/** Enables powersave mode
+ *
+ * @return @ref rtw_result_t
+ */
+int wifi_enable_powersave(void);
+
+/** Disables 802.11 power save mode
+ *
+ * @return RTW_SUCCESS : if power save mode was successfully
+ * disabled
+ * RTW_ERROR : if power save mode was not successfully
+ * disabled
+ */
+int wifi_disable_powersave(void);
+
+/** Gets the tx power in index units
+ *
+ * @param dbm : The variable to receive the tx power in index.
+ *
+ * @return RTW_SUCCESS : if successful
+ * RTW_ERROR : if not successful
+ */
+int wifi_get_txpower(int *poweridx);
+
+/** Sets the tx power in index units
+ *
+ * @param dbm : The desired tx power in index.
+ *
+ * @return RTW_SUCCESS : if tx power was successfully set
+ * RTW_ERROR : if tx power was not successfully set
+ */
+int wifi_set_txpower(int poweridx);
+
+/** Get the associated clients with SoftAP
+ *
+ * @param client_list_buffer : the location where the client
+ * list will be stored
+ * @param buffer_length : the buffer length.
+ *
+ * @return RTW_SUCCESS : if result was successfully get
+ * RTW_ERROR : if result was not successfully get
+ */
+int wifi_get_associated_client_list(void * client_list_buffer, unsigned short buffer_length);
+
+/** Get the SoftAP information
+ *
+ * @param ap_info : the location where the AP info will be
+ * stored
+ * @param security : the security type.
+ *
+ * @return RTW_SUCCESS : if result was successfully get
+ * RTW_ERROR : if result was not successfully get
+ */
+int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security);
+
+/** Set the country code to driver to determine the channel set
+ *
+ * @param country_code : the country code.
+ *
+ * @return RTW_SUCCESS : if result was successfully set
+ * RTW_ERROR : if result was not successfully set
+ */
+int wifi_set_country(rtw_country_code_t country_code);
+
+/** Retrieve the latest RSSI value
+ *
+ * @param rssi: The location where the RSSI value will be stored
+ *
+ * @return RTW_SUCCESS : if the RSSI was succesfully retrieved
+ * RTW_ERROR : if the RSSI was not retrieved
+ */
+int wifi_get_rssi(int *pRSSI);
+
+/** Set the current channel on STA interface
+ *
+ * @param channel : The desired channel
+ *
+ * @return RTW_SUCCESS : if the channel was successfully set
+ * RTW_ERROR : if the channel was not successfully
+ * set
+ */
+int wifi_set_channel(int channel);
+
+/** Get the current channel on STA interface
+ *
+ * @param channel : A pointer to the variable where the
+ * channel value will be written
+ *
+ * @return RTW_SUCCESS : if the channel was successfully read
+ * RTW_ERROR : if the channel was not successfully
+ * read
+ */
+int wifi_get_channel(int *channel);
+
+/** Registers interest in a multicast address
+ * Once a multicast address has been registered, all packets detected on the
+ * medium destined for that address are forwarded to the host.
+ * Otherwise they are ignored.
+ *
+ * @param mac: Ethernet MAC address
+ *
+ * @return RTW_SUCCESS : if the address was registered
+ * successfully
+ * RTW_ERROR : if the address was not registered
+ */
+int wifi_register_multicast_address(rtw_mac_t *mac);
+
+/** Unregisters interest in a multicast address
+ * Once a multicast address has been unregistered, all packets detected on the
+ * medium destined for that address are ignored.
+ *
+ * @param mac: Ethernet MAC address
+ *
+ * @return RTW_SUCCESS : if the address was unregistered
+ * successfully
+ * RTW_ERROR : if the address was not unregistered
+ */
+int wifi_unregister_multicast_address(rtw_mac_t *mac);
+
+int wifi_rf_on(void);
+int wifi_rf_off(void);
+
+/** Turn on the Wi-Fi device
+ *
+ * - Bring the Wireless interface "Up"
+ * - Initialises the driver thread which arbitrates access
+ * to the SDIO/SPI bus
+ *
+ * @param mode: wifi work mode
+ *
+ * @return RTW_SUCCESS : if the WiFi chip was initialised
+ * successfully
+ * RTW_ERROR : if the WiFi chip was not initialised
+ * successfully
+ */
+int wifi_on(rtw_mode_t mode);
+
+/**
+ * Turn off the Wi-Fi device
+ *
+ * - Bring the Wireless interface "Down"
+ * - De-Initialises the driver thread which arbitrates access
+ * to the SDIO/SPI bus
+ *
+ * @return RTW_SUCCESS if deinitialization is successful,
+ * RTW_ERROR otherwise
+ */
+int wifi_off(void);
+
+/**
+ * Set IPS/LPS mode
+ *
+ * @param[in] ips_mode : The desired IPS mode. It become effective when wlan enter ips.
+ * @param[in] lps_mode : The desired LPS mode. It become effective when wlan enter lps.
+ *
+ * @return RTW_SUCCESS if setting LPS mode successful
+ * RTW_ERROR otherwise
+ */
+int wifi_set_power_mode(unsigned char ips_mode, unsigned char lps_mode);
+
+/**
+ * Set TDMA parameters
+ *
+ * @param[in] slot_period : We separate TBTT into 2 or 3 slots.
+ * If we separate TBTT into 2 slots, then slot_period should be larger or equal to 50ms.
+ * It means 2 slot period is
+ * slot_period, 100-slot_period
+ * If we separate TBTT into 3 slots, then slot_period should be less or equal to 33ms.
+ * It means 3 slot period is
+ * 100 - 2 * slot_period, slot_period, slot_period
+ * @param[in] rfon_period_len_1: rf on period of slot 1
+ * @param[in] rfon_period_len_2: rf on period of slot 2
+ * @param[in] rfon_period_len_3: rf on period of slot 3
+ *
+ * @return RTW_SUCCESS if setting TDMA parameters successful
+ * RTW_ERROR otherwise
+ */
+int wifi_set_tdma_param(unsigned char slot_period, unsigned char rfon_period_len_1, unsigned char rfon_period_len_2, unsigned char rfon_period_len_3);
+
+/**
+ * Set LPS DTIM
+ *
+ * @param[in] dtim : In LPS, the package can be buffered at AP side.
+ * STA leave LPS until dtim count of packages buffered at AP side.
+ *
+ * @return RTW_SUCCESS if setting LPS dtim successful
+ * RTW_ERROR otherwise
+ */
+int wifi_set_lps_dtim(unsigned char dtim);
+
+/**
+ * Get LPS DTIM
+ *
+ * @param[out] dtim : In LPS, the package can be buffered at AP side.
+ * STA leave LPS until dtim count of packages buffered at AP side.
+ *
+ * @return RTW_SUCCESS if getting LPS dtim successful
+ * RTW_ERROR otherwise
+ */
+int wifi_get_lps_dtim(unsigned char *dtim);
+
+/** Starts an infrastructure WiFi network
+ *
+ * @warning If a STA interface is active when this function is called, the softAP will\n
+ * start on the same channel as the STA. It will NOT use the channel provided!
+ *
+ * @param[in] ssid : A null terminated string containing
+ * the SSID name of the network to join
+ * @param[in] security_type : Authentication type: \n
+ * - RTW_SECURITY_OPEN - Open Security \n
+ * - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
+ * - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
+ * - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
+ * - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
+ * @param[in] password : A byte array containing the cleartext
+ * security key for the network
+ * @param[in] ssid_len : The length of the SSID in
+ * bytes.
+ * @param[in] password_len : The length of the security_key in
+ * bytes.
+ * @param[in] channel : 802.11 channel number
+ *
+ * @return RTW_SUCCESS : if successfully creates an AP
+ * RTW_ERROR : if an error occurred
+ */
+int wifi_start_ap(
+ char *ssid,
+ rtw_security_t security_type,
+ char *password,
+ int ssid_len,
+ int password_len,
+ int channel);
+
+/** Starts an infrastructure WiFi network with hidden SSID
+ *
+ * @warning If a STA interface is active when this function is called, the softAP will\n
+ * start on the same channel as the STA. It will NOT use the channel provided!
+ *
+ * @param[in] ssid : A null terminated string containing
+ * the SSID name of the network to join
+ * @param[in] security_type : Authentication type: \n
+ * - RTW_SECURITY_OPEN - Open Security \n
+ * - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
+ * - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
+ * - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
+ * - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
+ * @param[in] password : A byte array containing the cleartext
+ * security key for the network
+ * @param[in] ssid_len : The length of the SSID in
+ * bytes.
+ * @param[in] password_len : The length of the security_key in
+ * bytes.
+ * @param[in] channel : 802.11 channel number
+ *
+ * @return RTW_SUCCESS : if successfully creates an AP
+ * RTW_ERROR : if an error occurred
+ */
+int wifi_start_ap_with_hidden_ssid(
+ char *ssid,
+ rtw_security_t security_type,
+ char *password,
+ int ssid_len,
+ int password_len,
+ int channel);
+
+/** Initiates a scan to search for 802.11 networks.
+ *
+ * The scan progressively accumulates results over time, and
+ * may take between 1 and 3 seconds to complete. The results of
+ * the scan will be individually provided to the callback
+ * function. Note: The callback function will be executed in
+ * the context of the RTW thread.
+ *
+ * @param[in] scan_type : Specifies whether the scan should
+ * be Active, Passive or scan
+ * Prohibited channels
+ * @param[in] bss_type : Specifies whether the scan should
+ * search for Infrastructure
+ * networks (those using an Access
+ * Point), Ad-hoc networks, or both
+ * types.
+ * @param result_ptr[in] : Scan specific ssid. The first 4
+ * bytes is ssid lenth, and ssid name
+ * append after it.
+ * If no specific ssid need to scan,
+ * PLEASE CLEAN result_ptr before pass
+ * it into parameter.
+ * @param result_ptr[out] : a pointer to a pointer to a result
+ * storage structure.
+ *
+ * @note : When scanning specific channels, devices with a
+ * strong signal strength on nearby channels may be
+ * detected
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_scan(rtw_scan_type_t scan_type,
+ rtw_bss_type_t bss_type,
+ void* result_ptr);
+
+/** Initiates a scan to search for 802.11 networks, a higher
+ * level API based on wifi_scan to simplify the scan
+ * operation.
+ *
+ * The scan results will be list by the order of RSSI.
+ * It may demand hundreds bytes memory during scan
+ * processing according to the quantity of AP nearby.
+ *
+ * @param results_handler[in] : the callback function which
+ * will receive and process the result data.
+ * @param user_data[in] : user specific data that will be
+ * passed directly to the callback function
+ *
+ * @note : Callback must not use blocking functions, since it is
+ * called from the context of the RTW thread.
+ * @note : The callback, user_data variables will
+ * be referenced after the function returns. Those
+ * variables must remain valid until the scan is
+ * complete.
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_data);
+int wifi_scan_networks_with_ssid(int (results_handler)(char*, int, char *, void *), void* user_data, int scan_buflen, char* ssid, int ssid_len);
+
+/** Set the partical scan
+ *
+ * @param channel_list[in] : the channel set the scan will
+ * stay on
+ * @param pscan_config[in] : the pscan_config of the channel set
+ *
+ * @param length[in] : the channel list length
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length);
+
+/** Get the network information
+ *
+ * @param ifname[in] : the name of the interface we are care
+ * @param pSetting[in] : the location where the network
+ * information will be stored
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_get_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
+
+/** Show the network information
+ *
+ * @param ifname[in] : the name of the interface we are care
+ * @param pSetting[in] : the location where the network
+ * information was stored
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_show_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
+
+/** Set the network mode according to the data rate it's
+ * supported
+ *
+ * @param mode[in] : the network mode
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_set_network_mode(rtw_network_mode_t mode);
+
+/** Set the chip to worke in the promisc mode
+ *
+ * @param enabled[in] : enabled can be set 0, 1 and 2. if enabled is zero, disable the promisc, else enable the promisc.
+ * 0 means disable the promisc
+ * 1 means enable the promisc
+ * 2 means enable the promisc special for length is used
+ * @param callback[in] : the callback function which will
+ * receive and process the netowork data.
+ * @param len_used[in] : specify if the the promisc length is
+ * used.
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_set_promisc(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used);
+
+/** Set the wps phase
+ *
+ * @param is_trigger_wps[in] : to trigger wps function or not
+ *
+ * @return RTW_SUCCESS or RTW_ERROR
+ */
+int wifi_set_wps_phase(unsigned char is_trigger_wps);
+
+/** Restarts an infrastructure WiFi network
+ *
+ * @warning If a STA interface is active when this function is called, the softAP will\n
+ * start on the same channel as the STA. It will NOT use the channel provided!
+ *
+ * @param[in] ssid : A null terminated string containing
+ * the SSID name of the network to join
+ * @param[in] security_type : Authentication type: \n
+ * - RTW_SECURITY_OPEN - Open Security \n
+ * - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
+ * - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
+ * - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
+ * - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
+ * @param[in] password : A byte array containing the cleartext
+ * security key for the network
+ * @param[in] ssid_len : The length of the SSID in
+ * bytes.
+ * @param[in] password_len : The length of the security_key in
+ * bytes.
+ * @param[in] channel : 802.11 channel number
+ *
+ * @return RTW_SUCCESS : if successfully creates an AP
+ * RTW_ERROR : if an error occurred
+ */
+int wifi_restart_ap(
+ unsigned char *ssid,
+ rtw_security_t security_type,
+ unsigned char *password,
+ int ssid_len,
+ int password_len,
+ int channel);
+
+int wifi_config_autoreconnect(__u8 mode, __u8 retyr_times, __u16 timeout);
+int wifi_set_autoreconnect(__u8 mode);
+int wifi_get_autoreconnect(__u8 *mode);
+int wifi_get_last_error(void);
+/** Present device disconnect reason while connecting
+*
+*@return RTW_NO_ERROR = 0,
+* RTW_NONE_NETWORK = 1,
+* RTW_CONNECT_FAIL = 2,
+* RTW_WRONG_PASSWORD = 3 ,
+* RTW_DHCP_FAIL = 4,
+* RTW_UNKNOWN, initial status
+*/
+
+
+#ifdef CONFIG_CUSTOM_IE
+#ifndef BIT
+#define BIT(x) ((__u32)1 << (x))
+#endif
+
+#ifndef _CUSTOM_IE_TYPE_
+#define _CUSTOM_IE_TYPE_
+enum CUSTOM_IE_TYPE{
+ PROBE_REQ = BIT(0),
+ PROBE_RSP = BIT(1),
+ BEACON = BIT(2),
+};
+#endif /* _CUSTOM_IE_TYPE_ */
+
+/* ie format
+ * +-----------+--------+-----------------------+
+ * |element ID | length | content in length byte|
+ * +-----------+--------+-----------------------+
+ *
+ * type: refer to CUSTOM_IE_TYPE
+ */
+#ifndef _CUS_IE_
+#define _CUS_IE_
+typedef struct _cus_ie{
+ __u8 *ie;
+ __u8 type;
+}cus_ie, *p_cus_ie;
+#endif /* _CUS_IE_ */
+
+int wifi_add_custom_ie(void *cus_ie, int ie_num);
+
+int wifi_update_custom_ie(void *cus_ie, int ie_index);
+
+int wifi_del_custom_ie(void);
+#endif
+
+#ifdef CONFIG_PROMISC
+void wifi_init_packet_filter(void);
+int wifi_add_packet_filter(unsigned char filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule);
+int wifi_enable_packet_filter(unsigned char filter_id);
+int wifi_disable_packet_filter(unsigned char filter_id);
+int wifi_remove_packet_filter(unsigned char filter_id);
+#endif
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif // __WIFI_API_H
+
+//----------------------------------------------------------------------------//
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_ind.c b/RTL00_SDKV35a/component/common/api/wifi/wifi_ind.c
new file mode 100644
index 0000000..febde2c
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_ind.c
@@ -0,0 +1,265 @@
+//----------------------------------------------------------------------------//
+#include "wifi/wifi_ind.h"
+#include "wifi/wifi_conf.h"
+#include "osdep_service.h"
+#include "platform_stdlib.h"
+
+/******************************************************
+ * Constants
+ ******************************************************/
+
+#if CONFIG_DEBUG_LOG > 3
+ #define WIFI_INDICATE_MSG 1
+#else
+ #define WIFI_INDICATE_MSG 0
+#endif
+#define WIFI_MANAGER_STACKSIZE 1300
+#define WIFI_MANAGER_PRIORITY (0) //Actual priority is 4 since calling rtw_create_task
+#define WIFI_MANAGER_Q_SZ 8
+
+#define WIFI_EVENT_MAX_ROW 3
+/******************************************************
+ * Globals
+ ******************************************************/
+
+static event_list_elem_t event_callback_list[WIFI_EVENT_MAX][WIFI_EVENT_MAX_ROW];
+#if CONFIG_WIFI_IND_USE_THREAD
+static rtw_worker_thread_t wifi_worker_thread;
+#endif
+
+//----------------------------------------------------------------------------//
+#if CONFIG_WIFI_IND_USE_THREAD
+static rtw_result_t rtw_send_event_to_worker(int event_cmd, char *buf, int buf_len, int flags)
+{
+ rtw_event_message_t message;
+ int i;
+ rtw_result_t ret = RTW_SUCCESS;
+ char *local_buf = NULL;
+
+ if(event_cmd >= WIFI_EVENT_MAX)
+ return RTW_BADARG;
+
+ for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
+ if(event_callback_list[event_cmd][i].handler == NULL)
+ continue;
+
+ message.function = (event_handler_t)event_callback_list[event_cmd][i].handler;
+ message.buf_len = buf_len;
+ if(buf_len){
+ local_buf = (char*)pvPortMalloc(buf_len);
+ if(local_buf == NULL)
+ return RTW_NOMEM;
+ memcpy(local_buf, buf, buf_len);
+ //printf("\n!!!!!Allocate %p(%d) for evcmd %d\n", local_buf, buf_len, event_cmd);
+ }
+ message.buf = local_buf;
+ message.flags = flags;
+ message.user_data = event_callback_list[event_cmd][i].handler_user_data;
+
+ ret = rtw_push_to_xqueue(&wifi_worker_thread.event_queue, &message, 0);
+ if(ret != RTW_SUCCESS){
+ if(local_buf){
+ printf("rtw_send_event_to_worker: enqueue cmd %d failed and free %p(%d)\n", event_cmd, local_buf, buf_len);
+ vPortFree(local_buf);
+ }
+ break;
+ }
+ }
+ return ret;
+}
+#else
+static rtw_result_t rtw_indicate_event_handle(int event_cmd, char *buf, int buf_len, int flags)
+{
+ rtw_event_handler_t handle = NULL;
+ int i;
+
+ if(event_cmd >= WIFI_EVENT_MAX)
+ return RTW_BADARG;
+
+ for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
+ handle = event_callback_list[event_cmd][i].handler;
+ if(handle == NULL)
+ continue;
+ handle(buf, buf_len, flags, event_callback_list[event_cmd][i].handler_user_data);
+ }
+
+ return RTW_SUCCESS;
+}
+#endif
+
+void wifi_indication( WIFI_EVENT_INDICATE event, char *buf, int buf_len, int flags)
+{
+ //
+ // If upper layer application triggers additional operations on receiving of wext_wlan_indicate,
+ // please strictly check current stack size usage (by using uxTaskGetStackHighWaterMark() )
+ // , and tries not to share the same stack with wlan driver if remaining stack space is
+ // not available for the following operations.
+ // ex: using semaphore to notice another thread.
+ switch(event)
+ {
+ case WIFI_EVENT_DISCONNECT:
+#if(WIFI_INDICATE_MSG>0)
+ printf(" %s():Disconnection indication received\n", __FUNCTION__);
+#endif
+ break;
+ case WIFI_EVENT_CONNECT:
+ // For WPA/WPA2 mode, indication of connection does not mean data can be
+ // correctly transmitted or received. Data can be correctly transmitted or
+ // received only when 4-way handshake is done.
+ // Please check WIFI_EVENT_FOURWAY_HANDSHAKE_DONE event
+#if(WIFI_INDICATE_MSG>0)
+ // Sample: return mac address
+ if(buf != NULL && buf_len == 6)
+ {
+ printf("%s():Connect indication received: %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__,
+ buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
+ }
+#endif
+ break;
+ case WIFI_EVENT_FOURWAY_HANDSHAKE_DONE:
+#if(WIFI_INDICATE_MSG>0)
+ if(buf != NULL)
+ {
+ if(buf_len == strlen(IW_EXT_STR_FOURWAY_DONE))
+ printf("%s():%s\n", __FUNCTION__, buf);
+ }
+#endif
+ break;
+ case WIFI_EVENT_SCAN_RESULT_REPORT:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_SCAN_RESULT_REPORT\n", __func__);
+#endif
+ break;
+ case WIFI_EVENT_SCAN_DONE:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_SCAN_DONE\n", __func__);
+#if CONFIG_DEBUG_LOG > 3
+ printf("Time at start %d ms.\n", xTaskGetTickCount());
+#endif
+#endif
+ break;
+ case WIFI_EVENT_RECONNECTION_FAIL:
+#if(WIFI_INDICATE_MSG>0)
+ if(buf != NULL){
+ if(buf_len == strlen(IW_EXT_STR_RECONNECTION_FAIL))
+ printf("%s\n", buf);
+ }
+#endif
+ break;
+ case WIFI_EVENT_NO_NETWORK:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_NO_NETWORK\n", __func__);
+#endif
+ break;
+#if CONFIG_ENABLE_P2P
+ case WIFI_EVENT_SEND_ACTION_DONE:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_SEND_ACTION_DONE\n", __func__);
+#endif
+ break;
+ case WIFI_EVENT_RX_MGNT:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_RX_MGNT\n", __func__);
+#endif
+ break;
+#endif //CONFIG_ENABLE_P2P
+ case WIFI_EVENT_STA_ASSOC:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_STA_ASSOC\n", __func__);
+#endif
+ break;
+ case WIFI_EVENT_STA_DISASSOC:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_STA_DISASSOC\n", __func__);
+#endif
+ break;
+#ifdef CONFIG_WPS
+ case WIFI_EVENT_STA_WPS_START:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_STA_WPS_START\n", __func__);
+#endif
+ break;
+ case WIFI_EVENT_WPS_FINISH:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_WPS_FINISH\n", __func__);
+#endif
+ break;
+ case WIFI_EVENT_EAPOL_RECVD:
+#if(WIFI_INDICATE_MSG>0)
+ printf("%s(): WIFI_EVENT_EAPOL_RECVD\n", __func__);
+#endif
+ break;
+#endif
+ case WIFI_EVENT_BEACON_AFTER_DHCP:
+#if(WIFI_INDICATE_MSG>1)
+ printf("%s(): WIFI_EVENT_BEACON_AFTER_DHCP\n", __func__);
+#endif
+ break;
+ }
+
+#if CONFIG_INIC_EN
+ inic_indicate_event(event, buf, buf_len, flags);
+#endif//CONFIG_INIC_EN
+
+#if CONFIG_WIFI_IND_USE_THREAD
+ rtw_send_event_to_worker(event, buf, buf_len, flags);
+#else
+ rtw_indicate_event_handle(event, buf, buf_len, flags);
+#endif
+}
+
+void wifi_reg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func, void *handler_user_data)
+{
+ int i = 0, j = 0;
+ if(event_cmds < WIFI_EVENT_MAX){
+ for(i=0; i < WIFI_EVENT_MAX_ROW; i++){
+ if(event_callback_list[event_cmds][i].handler == NULL){
+ for(j=0; j
+
+#ifdef CONFIG_PROMISC
+
+#define _adapter void
+#define recv_frame void
+extern void _promisc_deinit(_adapter *padapter);
+extern int _promisc_recv_func(_adapter *padapter, recv_frame *rframe);
+extern int _promisc_set(rtw_rcr_level_t enabled, void (*callback)(unsigned char *, unsigned int, void *), unsigned char len_used);
+extern unsigned char is_promisc_enabled(void);
+extern int promisc_get_fixed_channel(void *fixed_bssid, unsigned char *ssid, int *ssid_length);
+extern unsigned char is_promisc_enabled(void);
+
+#endif
+
+// Add extra interfaces to make release sdk able to determine promisc API linking
+void promisc_deinit(void *padapter)
+{
+#ifdef CONFIG_PROMISC
+ _promisc_deinit(padapter);
+#endif
+}
+
+int promisc_recv_func(void *padapter, void *rframe)
+{
+ // Never reach here if not define CONFIG_PROMISC
+#ifdef CONFIG_PROMISC
+ return _promisc_recv_func(padapter, rframe);
+#else
+ return 0;
+#endif
+}
+
+int promisc_set(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used)
+{
+#ifdef CONFIG_PROMISC
+ return _promisc_set(enabled, callback, len_used);
+#else
+ return -1;
+#endif
+}
+
+unsigned char is_promisc_enabled(void)
+{
+#ifdef CONFIG_PROMISC
+ return _is_promisc_enabled();
+#else
+ return 0;
+#endif
+}
+
+int promisc_get_fixed_channel(void *fixed_bssid, u8 *ssid, int *ssid_length)
+{
+#ifdef CONFIG_PROMISC
+ return _promisc_get_fixed_channel(fixed_bssid, ssid, ssid_length);
+#else
+ return 0;
+#endif
+}
+// End of Add extra interfaces
+
+struct eth_frame {
+ struct eth_frame *prev;
+ struct eth_frame *next;
+ unsigned char da[6];
+ unsigned char sa[6];
+ unsigned int len;
+ unsigned char type;
+ signed char rssi;
+};
+
+#if CONFIG_INIC_CMD_RSP
+#if defined(__IAR_SYSTEMS_ICC__)
+#pragma pack(1)
+#endif
+struct inic_eth_frame {
+ unsigned char da[6];
+ unsigned char sa[6];
+ unsigned int len;
+ unsigned char type;
+};
+#if defined(__IAR_SYSTEMS_ICC__)
+#pragma pack()
+#endif
+
+static struct inic_eth_frame *inic_frame, *inic_frame_tail = NULL;
+static int inic_frame_cnt = 0;
+#define MAX_INIC_FRAME_NUM 50 //maximum packets for each channel
+extern void inic_c2h_msg(const char *atcmd, char status, char *msg, u16 msg_len);
+#endif
+
+struct eth_buffer {
+ struct eth_frame *head;
+ struct eth_frame *tail;
+};
+
+static struct eth_buffer eth_buffer;
+
+#ifdef CONFIG_PROMISC
+#define MAX_PACKET_FILTER_INFO 5
+#define FILTER_ID_INIT_VALUE 10
+rtw_packet_filter_info_t paff_array[MAX_PACKET_FILTER_INFO]={0, 0, 0, 0, 0};
+static u8 packet_filter_enable_num = 0;
+
+void promisc_init_packet_filter()
+{
+ int i = 0;
+ for(i=0; ioffset;
+ paff_array[i].patt.mask_size = patt->mask_size;
+ paff_array[i].patt.mask = pvPortMalloc(patt->mask_size);
+ memcpy(paff_array[i].patt.mask, patt->mask, patt->mask_size);
+ paff_array[i].patt.pattern= pvPortMalloc(patt->mask_size);
+ memcpy(paff_array[i].patt.pattern, patt->pattern, patt->mask_size);
+
+ paff_array[i].rule = rule;
+ paff_array[i].enable = 0;
+
+ return 0;
+}
+
+int promisc_enable_packet_filter(u8 filter_id)
+{
+ int i = 0;
+ while(i < MAX_PACKET_FILTER_INFO){
+ if(paff_array[i].filter_id == filter_id)
+ break;
+ i++;
+ }
+
+ if(i == MAX_PACKET_FILTER_INFO)
+ return -1;
+
+ paff_array[i].enable = 1;
+ packet_filter_enable_num++;
+ return 0;
+}
+
+int promisc_disable_packet_filter(u8 filter_id)
+{
+ int i = 0;
+ while(i < MAX_PACKET_FILTER_INFO){
+ if(paff_array[i].filter_id == filter_id)
+ break;
+ i++;
+ }
+
+ if(i == MAX_PACKET_FILTER_INFO)
+ return -1;
+
+ paff_array[i].enable = 0;
+ packet_filter_enable_num--;
+ return 0;
+}
+
+int promisc_remove_packet_filter(u8 filter_id)
+{
+ int i = 0;
+ while(i < MAX_PACKET_FILTER_INFO){
+ if(paff_array[i].filter_id == filter_id)
+ break;
+ i++;
+ }
+
+ if(i == MAX_PACKET_FILTER_INFO)
+ return -1;
+
+ paff_array[i].filter_id = FILTER_ID_INIT_VALUE;
+ paff_array[i].enable = 0;
+ paff_array[i].patt.mask_size = 0;
+ paff_array[i].rule = 0;
+ if(paff_array[i].patt.mask){
+ vPortFree(paff_array[i].patt.mask);
+ paff_array[i].patt.mask = NULL;
+ }
+
+ if(paff_array[i].patt.pattern){
+ vPortFree(paff_array[i].patt.pattern);
+ paff_array[i].patt.pattern = NULL;
+ }
+ return 0;
+}
+#endif
+
+/* Make callback simple to prevent latency to wlan rx when promiscuous mode */
+static void promisc_callback(unsigned char *buf, unsigned int len, void* userdata)
+{
+ struct eth_frame *frame = (struct eth_frame *) pvPortMalloc(sizeof(struct eth_frame));
+
+ if(frame) {
+ frame->prev = NULL;
+ frame->next = NULL;
+ memcpy(frame->da, buf, 6);
+ memcpy(frame->sa, buf+6, 6);
+ frame->len = len;
+ frame->rssi = ((ieee80211_frame_info_t *)userdata)->rssi;
+ taskENTER_CRITICAL();
+
+ if(eth_buffer.tail) {
+ eth_buffer.tail->next = frame;
+ frame->prev = eth_buffer.tail;
+ eth_buffer.tail = frame;
+ }
+ else {
+ eth_buffer.head = frame;
+ eth_buffer.tail = frame;
+ }
+
+ taskEXIT_CRITICAL();
+ }
+}
+
+struct eth_frame* retrieve_frame(void)
+{
+ struct eth_frame *frame = NULL;
+
+ taskENTER_CRITICAL();
+
+ if(eth_buffer.head) {
+ frame = eth_buffer.head;
+
+ if(eth_buffer.head->next) {
+ eth_buffer.head = eth_buffer.head->next;
+ eth_buffer.head->prev = NULL;
+ }
+ else {
+ eth_buffer.head = NULL;
+ eth_buffer.tail = NULL;
+ }
+ }
+
+ taskEXIT_CRITICAL();
+
+ return frame;
+}
+
+static void promisc_test(int duration, unsigned char len_used)
+{
+ int ch;
+ unsigned int start_time;
+ struct eth_frame *frame;
+ eth_buffer.head = NULL;
+ eth_buffer.tail = NULL;
+
+ wifi_enter_promisc_mode();
+ wifi_set_promisc(RTW_PROMISC_ENABLE, promisc_callback, len_used);
+
+ for(ch = 1; ch <= 13; ch ++) {
+ if(wifi_set_channel(ch) == 0)
+ printf("\n\n\rSwitch to channel(%d)", ch);
+
+ start_time = xTaskGetTickCount();
+
+ while(1) {
+ unsigned int current_time = xTaskGetTickCount();
+
+ if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
+ frame = retrieve_frame();
+
+ if(frame) {
+ int i;
+ printf("\n\rDA:");
+ for(i = 0; i < 6; i ++)
+ printf(" %02x", frame->da[i]);
+ printf(", SA:");
+ for(i = 0; i < 6; i ++)
+ printf(" %02x", frame->sa[i]);
+ printf(", len=%d", frame->len);
+ printf(", RSSI=%d", frame->rssi);
+#if CONFIG_INIC_CMD_RSP
+ if(inic_frame_tail){
+ if(inic_frame_cnt < MAX_INIC_FRAME_NUM){
+ memcpy(inic_frame_tail->da, frame->da, 6);
+ memcpy(inic_frame_tail->sa, frame->sa, 6);
+ inic_frame_tail->len = frame->len;
+ inic_frame_tail++;
+ inic_frame_cnt++;
+ }
+ }
+#endif
+ vPortFree((void *) frame);
+ }
+ else
+ vTaskDelay(1); //delay 1 tick
+ }
+ else
+ break;
+ }
+#if CONFIG_INIC_CMD_RSP
+ if(inic_frame){
+ inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt);
+ memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
+ inic_frame_tail = inic_frame;
+ inic_frame_cnt = 0;
+ rtw_msleep_os(10);
+ }
+#endif
+ }
+
+ wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
+
+ while((frame = retrieve_frame()) != NULL)
+ vPortFree((void *) frame);
+}
+
+static void promisc_callback_all(unsigned char *buf, unsigned int len, void* userdata)
+{
+ struct eth_frame *frame = (struct eth_frame *) pvPortMalloc(sizeof(struct eth_frame));
+
+ if(frame) {
+ frame->prev = NULL;
+ frame->next = NULL;
+ memcpy(frame->da, buf+4, 6);
+ memcpy(frame->sa, buf+10, 6);
+ frame->len = len;
+ /*
+ * type is the first byte of Frame Control Field of 802.11 frame
+ * If the from/to ds information is needed, type could be reused as follows:
+ * frame->type = ((((ieee80211_frame_info_t *)userdata)->i_fc & 0x0100) == 0x0100) ? 2 : 1;
+ * 1: from ds; 2: to ds
+ */
+ frame->type = *buf;
+ frame->rssi = ((ieee80211_frame_info_t *)userdata)->rssi;
+
+ taskENTER_CRITICAL();
+
+ if(eth_buffer.tail) {
+ eth_buffer.tail->next = frame;
+ frame->prev = eth_buffer.tail;
+ eth_buffer.tail = frame;
+ }
+ else {
+ eth_buffer.head = frame;
+ eth_buffer.tail = frame;
+ }
+
+ taskEXIT_CRITICAL();
+ }
+}
+static void promisc_test_all(int duration, unsigned char len_used)
+{
+ int ch;
+ unsigned int start_time;
+ struct eth_frame *frame;
+ eth_buffer.head = NULL;
+ eth_buffer.tail = NULL;
+
+ wifi_enter_promisc_mode();
+ wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used);
+
+ for(ch = 1; ch <= 13; ch ++) {
+ if(wifi_set_channel(ch) == 0)
+ printf("\n\n\rSwitch to channel(%d)", ch);
+
+ start_time = xTaskGetTickCount();
+
+ while(1) {
+ unsigned int current_time = xTaskGetTickCount();
+
+ if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
+ frame = retrieve_frame();
+
+ if(frame) {
+ int i;
+ printf("\n\rTYPE: 0x%x, ", frame->type);
+ printf("DA:");
+ for(i = 0; i < 6; i ++)
+ printf(" %02x", frame->da[i]);
+ printf(", SA:");
+ for(i = 0; i < 6; i ++)
+ printf(" %02x", frame->sa[i]);
+ printf(", len=%d", frame->len);
+ printf(", RSSI=%d", frame->rssi);
+#if CONFIG_INIC_CMD_RSP
+ if(inic_frame_tail){
+ if(inic_frame_cnt < MAX_INIC_FRAME_NUM){
+ memcpy(inic_frame_tail->da, frame->da, 6);
+ memcpy(inic_frame_tail->sa, frame->sa, 6);
+ inic_frame_tail->len = frame->len;
+ inic_frame_tail->type = frame->type;
+ inic_frame_tail++;
+ inic_frame_cnt++;
+ }
+ }
+#endif
+ vPortFree((void *) frame);
+ }
+ else
+ vTaskDelay(1); //delay 1 tick
+ }
+ else
+ break;
+ }
+#if CONFIG_INIC_CMD_RSP
+ if(inic_frame){
+ inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt);
+ memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
+ inic_frame_tail = inic_frame;
+ inic_frame_cnt = 0;
+ rtw_msleep_os(10);
+ }
+#endif
+ }
+
+ wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
+
+ while((frame = retrieve_frame()) != NULL)
+ vPortFree((void *) frame);
+}
+
+void cmd_promisc(int argc, char **argv)
+{
+ int duration;
+#if CONFIG_INIC_CMD_RSP
+ inic_frame_tail = inic_frame = pvPortMalloc(sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
+ if(inic_frame == NULL){
+ inic_c2h_msg("ATWM", RTW_BUFFER_UNAVAILABLE_TEMPORARY, NULL, 0);
+ return;
+ }
+#endif
+ #ifdef CONFIG_PROMISC
+ wifi_init_packet_filter();
+ #endif
+ if((argc == 2) && ((duration = atoi(argv[1])) > 0))
+ //promisc_test(duration, 0);
+ promisc_test_all(duration, 0);
+ else if((argc == 3) && ((duration = atoi(argv[1])) > 0) && (strcmp(argv[2], "with_len") == 0))
+ promisc_test(duration, 1);
+ else
+ printf("\n\rUsage: %s DURATION_SECONDS [with_len]", argv[0]);
+#if CONFIG_INIC_CMD_RSP
+ if(inic_frame)
+ vPortFree(inic_frame);
+ inic_frame_tail = NULL;
+ inic_frame_cnt = 0;
+#endif
+}
+#endif //#if CONFIG_WLAN
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config.c b/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config.c
new file mode 100644
index 0000000..833b549
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config.c
@@ -0,0 +1,1076 @@
+#include
+#include
+#include
+#include "FreeRTOS.h"
+#include "task.h"
+#include "main.h"
+#include "udp.h"
+#include
+#if LWIP_SOCKET
+#include
+#include
+#include "platform_stdlib.h"
+#include "wifi_simple_config_parser.h"
+#include "wifi_simple_config.h"
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+#include "at_cmd/atcmd_wifi.h"
+#endif
+
+#define STACKSIZE 512
+#define LEAVE_ACK_EARLY 0
+
+#if (CONFIG_LWIP_LAYER == 0)
+extern u32 _ntohl(u32 n);
+#endif
+
+#if CONFIG_WLAN
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+#include "wifi/wifi_conf.h"
+int is_promisc_callback_unlock = 0;
+static int is_fixed_channel;
+int fixed_channel_num;
+unsigned char g_ssid[32];
+int g_ssid_len;
+
+extern int promisc_get_fixed_channel( void *, u8 *, int* );
+struct rtk_test_sc;
+
+#ifdef PACK_STRUCT_USE_INCLUDES
+#include "arch/bpstruct.h"
+#endif
+
+// support scan list function from APP, comment by default
+//#define SC_SCAN_SUPPORT
+
+PACK_STRUCT_BEGIN
+struct ack_msg {
+ PACK_STRUCT_FIELD(u8_t flag);
+ PACK_STRUCT_FIELD(u16_t length);
+ PACK_STRUCT_FIELD(u8_t smac[6]);
+ PACK_STRUCT_FIELD(u8_t status);
+ PACK_STRUCT_FIELD(u16_t device_type);
+ PACK_STRUCT_FIELD(u32_t device_ip);
+ PACK_STRUCT_FIELD(u8_t device_name[64]);
+}__attribute__((packed)); // PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#include "arch/epstruct.h"
+#endif
+
+
+
+#define MULCAST_PORT (8864)
+
+#define SCAN_BUFFER_LENGTH (1024)
+
+#ifndef WLAN0_NAME
+ #define WLAN0_NAME "wlan0"
+#endif
+#define JOIN_SIMPLE_CONFIG (uint32_t)(1 << 8)
+extern uint32_t rtw_join_status;
+char simple_config_terminate = 0;
+
+int simple_config_result;
+static struct ack_msg *ack_content;
+struct rtk_test_sc *backup_sc_ctx;
+extern struct netif xnetif[NET_IF_NUM];
+
+// listen scan command and ACK
+#ifdef SC_SCAN_SUPPORT
+
+static int pin_enable = 0;
+static int scan_start = 0;
+
+#ifdef RTW_PACK_STRUCT_USE_INCLUDES
+#include "pack_begin.h"
+#endif
+RTW_PACK_STRUCT_BEGIN
+struct ack_msg_scan {
+ u8_t flag;
+ u16_t length;
+ u8_t smac[6];
+ u8_t status;
+ u16_t device_type;
+ u32_t device_ip;
+ u8_t device_name[64];
+ u8_t pin_enabled;
+}
+RTW_PACK_STRUCT_STRUCT;
+RTW_PACK_STRUCT_END
+#ifdef RTW_PACK_STRUCT_USE_INCLUDES
+#include "pack_end.h"
+#endif
+
+static void set_device_name(char *device_name)
+{
+ int pos = 0;
+ memcpy(device_name, "ameba_", 6);
+ for(int i = 0; i < 3; i++)
+ {
+ sprintf(device_name + 6 + pos, "%02x", xnetif[0].hwaddr[i + 3]);
+ pos += 2;
+ if(i != 2)
+ device_name[6 + pos++] = ':';
+ }
+ return;
+}
+void SC_scan_thread(void *para)
+{
+ int sockfd_scan;
+ struct sockaddr_in device_addr;
+ unsigned char packet[256];
+ struct sockaddr from;
+ struct sockaddr_in *from_sin = (struct sockaddr_in*) &from;
+ socklen_t fromLen = sizeof(from);
+ struct ack_msg_scan ack_msg;
+
+ #ifdef RTW_PACK_STRUCT_USE_INCLUDES
+ #include "pack_begin.h"
+ #endif
+ RTW_PACK_STRUCT_BEGIN
+ struct scan_msg{
+ unsigned char flag;
+ unsigned short length;
+ unsigned char sec_level;
+ unsigned char nonce[64];
+ unsigned char digest[16];
+ unsigned char smac[6];
+ unsigned short device_type;
+ };
+ RTW_PACK_STRUCT_STRUCT;
+ RTW_PACK_STRUCT_END
+ #ifdef RTW_PACK_STRUCT_USE_INCLUDES
+ #include "pack_end.h"
+ #endif
+
+ struct scan_msg *pMsg;
+
+ if ((sockfd_scan = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+ printf("SC scan socket error\n");
+ return;
+ }
+ memset(&device_addr, 0, sizeof(struct sockaddr_in));
+ device_addr.sin_family = AF_INET;
+ device_addr.sin_port = htons(18864);
+ device_addr.sin_addr.s_addr = INADDR_ANY;
+
+ if (bind(sockfd_scan, (struct sockaddr *)&device_addr, sizeof(struct sockaddr)) == -1)
+ {
+ printf("SC scan bind error\n");
+ close(sockfd_scan);
+ return;
+ }
+ memset(packet, 0, sizeof(packet));
+
+ // for now, no checking for the validity of received data, wf, 0225
+ while(1)
+ {
+ if((recvfrom(sockfd_scan, &packet, sizeof(packet), MSG_DONTWAIT, &from, &fromLen)) >= 0) {
+ uint16_t from_port = ntohs(from_sin->sin_port);
+ //printf("SC_scan: recv %d bytes from %d.%d.%d.%d:%d\n",packetLen, ip[0], ip[1], ip[2], ip[3], from_port);
+
+ from_sin->sin_port = htons(8864);
+ // send ACK for scan
+ pMsg = (struct scan_msg *)packet;
+ if(pMsg->flag == 0x00) // scan flag
+ {
+ ack_msg.flag = 0x21;
+ ack_msg.length = sizeof(struct ack_msg_scan);
+ ack_msg.status = 1;
+ memcpy(ack_msg.smac, xnetif[0].hwaddr, 6);
+
+ ack_msg.device_type = 0;
+ ack_msg.device_ip = xnetif[0].ip_addr.addr;
+ memset(ack_msg.device_name, 0, 64);
+ set_device_name((char*)ack_msg.device_name);
+ // set the device_name to: ameba_xxxxxx(last 3 bytes of MAC)
+ ack_msg.pin_enabled = pin_enable;
+ for(int i = 0; i < 3;i++)
+ {
+ int ret = sendto(sockfd_scan,(unsigned char *)&ack_msg,sizeof(struct ack_msg_scan),0,(struct sockaddr *)&from, fromLen);
+ if(ret < 0)
+ printf("send ACK for scan fail\n");
+ //else
+ //printf("send %d bytes of ACK to scan\n", ret);
+ }
+ }
+ else
+ continue;
+ }
+ vTaskDelay(500);
+ }
+}
+
+void SC_listen_ACK_scan()
+{
+ if(xTaskCreate(SC_scan_thread, ((const char*)"SC_scan_thread"), 512, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
+ printf("%s xTaskCreate(SC_scan_thread) failed\n", __FUNCTION__);
+}
+
+#endif
+
+void SC_set_ack_content()
+{
+ memset(ack_content, 0, sizeof(struct ack_msg));
+ ack_content->flag = 0x20;
+ ack_content->length = htons(sizeof(struct ack_msg)-3);
+ memcpy(ack_content->smac, xnetif[0].hwaddr, 6);
+ ack_content->status = 0;
+ ack_content->device_type = 0;
+ ack_content->device_ip = xnetif[0].ip_addr.addr;
+ memset(ack_content->device_name, 0, 64);
+}
+
+int SC_send_simple_config_ack(u8 round)
+{
+#if CONFIG_LWIP_LAYER
+ int ack_transmit_round, ack_num_each_sec;
+ int ack_socket;
+ //int sended_data = 0;
+ struct sockaddr_in to_addr;
+#if LEAVE_ACK_EARLY
+ u8 check_phone_ack = 0;
+#endif
+ SC_set_ack_content();
+
+ ack_socket = socket(PF_INET, SOCK_DGRAM, IP_PROTO_UDP);
+ if (ack_socket == -1) {
+ return -1;
+ }
+#if LEAVE_ACK_EARLY
+ else {
+ struct sockaddr_in bindAddr;
+ bindAddr.sin_family = AF_INET;
+ bindAddr.sin_port = htons(8864);
+ bindAddr.sin_addr.s_addr = INADDR_ANY;
+ if(bind(ack_socket, (struct sockaddr *) &bindAddr, sizeof(bindAddr)) == 0)
+ check_phone_ack = 1;
+ }
+#endif
+ printf("Sending simple config ack\n");
+ FD_ZERO(&to_addr);
+ to_addr.sin_family = AF_INET;
+ to_addr.sin_port = htons(8864);
+ to_addr.sin_addr.s_addr = (backup_sc_ctx->ip_addr);
+ for (ack_transmit_round = 0;ack_transmit_round < round; ack_transmit_round++) {
+ for (ack_num_each_sec = 0;ack_num_each_sec < 20; ack_num_each_sec++) {
+ //sended_data =
+ sendto(ack_socket, (unsigned char *)ack_content, sizeof(struct ack_msg), 0, (struct sockaddr *) &to_addr, sizeof(struct sockaddr));
+ //printf("\r\nAlready send %d bytes data\n", sended_data);
+ vTaskDelay(50); /* delay 50 ms */
+
+#if LEAVE_ACK_EARLY
+ if(check_phone_ack) {
+ unsigned char packet[100];
+ int packetLen;
+ struct sockaddr from;
+ struct sockaddr_in *from_sin = (struct sockaddr_in*) &from;
+ socklen_t fromLen = sizeof(from);
+
+ if((packetLen = recvfrom(ack_socket, &packet, sizeof(packet), MSG_DONTWAIT, &from, &fromLen)) >= 0) {
+ uint8_t *ip = (uint8_t *) &from_sin->sin_addr.s_addr;
+ uint16_t from_port = ntohs(from_sin->sin_port);
+ printf("recv %d bytes from %d.%d.%d.%d:%d at round=%d, num=%d\n",
+ packetLen, ip[0], ip[1], ip[2], ip[3], from_port,
+ ack_transmit_round, ack_num_each_sec);
+ goto leave_ack;
+ }
+ }
+#endif
+ }
+ }
+
+leave_ack:
+ close(ack_socket);
+#endif
+
+#if CONFIG_INIC_CMD_RSP
+ extern unsigned int inic_sc_ip_addr;
+ inic_sc_ip_addr = backup_sc_ctx->ip_addr;
+ inic_c2h_wifi_info("ATWQ", RTW_SUCCESS);
+#endif
+
+ return 0;
+}
+
+static int SC_check_and_show_connection_info(void)
+{
+ rtw_wifi_setting_t setting;
+ int ret = -1;
+
+#if CONFIG_LWIP_LAYER
+ /* If not rise priority, LwIP DHCP may timeout */
+ vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 3);
+ /* Start DHCP Client */
+ ret = LwIP_DHCP(0, DHCP_START);
+ vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 1);
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD == 0
+ wifi_get_setting(WLAN0_NAME, &setting);
+ wifi_show_setting(WLAN0_NAME, &setting);
+#endif
+
+#if CONFIG_LWIP_LAYER
+ if (ret != DHCP_ADDRESS_ASSIGNED)
+ return SC_DHCP_FAIL;
+ else
+#endif
+ return SC_SUCCESS;
+}
+
+static void check_and_set_security_in_connection(rtw_security_t security_mode, rtw_network_info_t *wifi)
+{
+
+ if (security_mode == RTW_SECURITY_WPA2_AES_PSK) {
+ printf("wifi->security_type = RTW_SECURITY_WPA2_AES_PSK\n");
+ wifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
+ } else if (security_mode == RTW_SECURITY_WEP_PSK) {
+ printf("wifi->security_type = RTW_SECURITY_WEP_PSK\n");
+ wifi->security_type = RTW_SECURITY_WEP_PSK;
+ wifi->key_id = 0;
+ } else if (security_mode == RTW_SECURITY_WPA_AES_PSK) {
+ printf("wifi->security_type = RTW_SECURITY_WPA_AES_PSK\n");
+ wifi->security_type = RTW_SECURITY_WPA_AES_PSK;
+ } else {
+ printf("wifi->security_type = RTW_SECURITY_OPEN\n");
+ wifi->security_type = RTW_SECURITY_OPEN;
+ }
+}
+
+int get_connection_info_from_profile(rtw_security_t security_mode, rtw_network_info_t *wifi)
+{
+
+ printf("======= Connection Information =======\n");
+ check_and_set_security_in_connection(security_mode, wifi);
+
+ wifi->password = backup_sc_ctx->password;
+ wifi->password_len = (int)strlen((char const *)backup_sc_ctx->password);
+
+ /* 1.both scanned g_ssid and ssid from profile are null, return fail */
+ if ((0 == g_ssid_len) && (0 == strlen(backup_sc_ctx->ssid))) {
+ printf("no ssid info found, connect will fail\n");
+ return -1;
+ }
+
+ /* g_ssid and ssid from profile are same, enter connect and retry */
+ if (0 == strcmp(backup_sc_ctx->ssid, g_ssid)) {
+ wifi->ssid.len = strlen(backup_sc_ctx->ssid);
+ rtw_memcpy(wifi->ssid.val, backup_sc_ctx->ssid, wifi->ssid.len);
+ printf("using ssid from profile and scan result\n");
+ goto ssid_set_done;
+ }
+
+ /* if there is profile, but g_ssid and profile are different, using profile to connect and retry */
+ if (strlen(backup_sc_ctx->ssid) > 0) {
+ wifi->ssid.len = strlen(backup_sc_ctx->ssid);
+ rtw_memcpy(wifi->ssid.val, backup_sc_ctx->ssid, wifi->ssid.len);
+ printf("using ssid only from profile\n");
+ goto ssid_set_done;
+
+}
+
+ /* if there is no profile but have scanned ssid, using g_ssid to connect and retry
+ (maybe ssid is right and password is wrong) */
+ if (g_ssid_len > 0) {
+ wifi->ssid.len = g_ssid_len;
+ rtw_memcpy(wifi->ssid.val, g_ssid, wifi->ssid.len);
+ printf("using ssid only from scan result\n");
+ goto ssid_set_done;
+ }
+
+
+ssid_set_done:
+
+
+ if(wifi->security_type == RTW_SECURITY_WEP_PSK)
+ {
+ if(wifi->password_len == 10)
+ {
+ u32 p[5] = {0};
+ u8 pwd[6], i = 0;
+ sscanf((const char*)backup_sc_ctx->password, "%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4]);
+ for(i=0; i< 5; i++)
+ pwd[i] = (u8)p[i];
+ pwd[5] = '\0';
+ memset(backup_sc_ctx->password, 0, 65);
+ strcpy((char*)backup_sc_ctx->password, (char*)pwd);
+ wifi->password_len = 5;
+ }else if(wifi->password_len == 26){
+ u32 p[13] = {0};
+ u8 pwd[14], i = 0;
+ sscanf((const char*)backup_sc_ctx->password, "%02x%02x%02x%02x%02x%02x%02x"\
+ "%02x%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4],\
+ &p[5], &p[6], &p[7], &p[8], &p[9], &p[10], &p[11], &p[12]);
+ for(i=0; i< 13; i++)
+ pwd[i] = (u8)p[i];
+ pwd[13] = '\0';
+ memset(backup_sc_ctx->password, 0, 64);
+ strcpy((char*)backup_sc_ctx->password, (char*)pwd);
+ wifi->password_len = 13;
+ }
+ }
+ printf("wifi.password = %s\n", wifi->password);
+ printf("wifi.password_len = %d\n", wifi->password_len);
+ printf("wifi.ssid = %s\n", wifi->ssid.val);
+ printf("wifi.ssid_len = %d\n", wifi->ssid.len);
+ printf("wifi.channel = %d\n", fixed_channel_num);
+ printf("===== start to connect target AP =====\n");
+ return 0;
+}
+
+
+
+
+#pragma pack(1)
+struct scan_with_ssid_result {
+ u8 len; /* len of a memory area store ap info */
+ u8 mac[ETH_ALEN];
+ int rssi;
+ u8 sec_mode;
+ u8 password_id;
+ u8 channel;
+ //char ssid[65];
+};
+
+
+struct sc_ap_info {
+
+ char *ssid;
+ int ssid_len;
+
+};
+
+
+
+rtw_security_t SC_translate_iw_security_mode(u8 security_type) {
+
+ rtw_security_t security_mode = RTW_SECURITY_UNKNOWN;
+
+
+ switch (security_type) {
+ case IW_ENCODE_ALG_NONE:
+ security_mode = RTW_SECURITY_OPEN;
+ break;
+ case IW_ENCODE_ALG_WEP:
+ security_mode = RTW_SECURITY_WEP_PSK;
+ break;
+ case IW_ENCODE_ALG_CCMP:
+ security_mode = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ default:
+ printf("error: security type not supported\n");
+ break;
+ };
+
+ return security_mode;
+}
+
+/*
+
+ scan buf format:
+
+ len mac rssi sec wps channel ssid
+ 1B 6B 4B 1B 1B 1B (len - 14)B
+
+*/
+enum sc_result SC_parse_scan_result_and_connect(scan_buf_arg* scan_buf, rtw_network_info_t *wifi)
+{
+
+ struct scan_with_ssid_result scan_result;
+
+ char *buf = scan_buf->buf;
+ int buf_len = scan_buf->buf_len;
+ char ssid[65];
+ int ssid_len = 0 ;
+ int parsed_len = 0;
+ u8 scan_channel = 0;
+ int i = 0;
+ int ret = 0;
+ u8 pscan_config = PSCAN_ENABLE | PSCAN_SIMPLE_CONFIG;
+
+ memset((void*)&scan_result, 0, sizeof(struct scan_with_ssid_result));
+
+ /* if wifi_is_connected_to_ap and we run here, ther will be hardfault(caused by auto reconnect) */
+ printf("Scan result got, start to connect AP with scanned bssid\n");
+
+ while (1) {
+
+ memcpy(&scan_result, buf, sizeof(struct scan_with_ssid_result));
+ /* len maybe 3*/
+ if (scan_result.len < sizeof(struct scan_with_ssid_result)) {
+ printf("length = %d, too small!\n",scan_result.len);
+ goto sc_connect_wifi_fail;
+ }
+
+ /* set ssid */
+ memset(ssid, 0, 65);
+
+ ssid_len = scan_result.len - sizeof(struct scan_with_ssid_result);
+
+ memcpy(ssid, buf + sizeof(struct scan_with_ssid_result), ssid_len);
+
+ /* run here means there is a match */
+ if (ssid_len == wifi->ssid.len) {
+ if (memcmp(ssid, wifi->ssid.val, ssid_len) == 0) {
+
+ printf("Connecting to MAC=%02x:%02x:%02x:%02x:%02x:%02x, ssid = %s, SEC=%d\n",
+ scan_result.mac[0], scan_result.mac[1], scan_result.mac[2],
+ scan_result.mac[3], scan_result.mac[4], scan_result.mac[5],
+ ssid, scan_result.sec_mode);
+
+ scan_channel = scan_result.channel;
+
+
+ /* try 3 times to connect */
+ for (i = 0; i < 3; i++) {
+ if(wifi_set_pscan_chan(&scan_channel, &pscan_config, 1) < 0){
+ printf("\n\rERROR: wifi set partial scan channel fail");
+ ret = SC_TARGET_CHANNEL_SCAN_FAIL;
+ goto sc_connect_wifi_fail;
+ }
+ ret = wifi_connect_bssid(scan_result.mac, (char*)wifi->ssid.val, SC_translate_iw_security_mode(scan_result.sec_mode),
+ (char*)wifi->password, ETH_ALEN, wifi->ssid.len, wifi->password_len, 0, NULL);
+ if (ret == RTW_SUCCESS)
+ goto sc_connect_wifi_success;
+ }
+
+ }
+ }
+
+
+ buf = buf + scan_result.len;
+ parsed_len += scan_result.len;
+ if (parsed_len >= buf_len) {
+ printf("parsed=%d, total = %d\n", parsed_len, buf_len);
+ break;
+ }
+
+ }
+
+
+sc_connect_wifi_success:
+ printf("%s success\n", __FUNCTION__);
+ return ret;
+
+sc_connect_wifi_fail:
+ printf("%s fail\n", __FUNCTION__);
+ return ret;
+
+
+}
+
+
+/*
+
+ When BSSID_CHECK_SUPPORT is not set, there will be problems:
+
+ 1.AP1 and AP2 (different SSID) both forward simple config packets,
+ profile is from AP2, but Ameba connect with AP1
+ 2.AP1 and AP2 (same SSID, but different crypto or password), both forward simple config packets,
+ profile is from AP2, but Ameba connect with AP1
+ 3. ...
+
+ fix: using SSID to query matched BSSID(s) in scan result, traverse and connect.
+
+
+ Consideration:
+ 1.Only take ssid and password
+ 2.Assume they have different channel.
+ 3.Assume they have different encrypt methods
+
+*/
+int SC_connect_to_candidate_AP (rtw_network_info_t *wifi){
+
+ int ret;
+
+ scan_buf_arg scan_buf;
+ int scan_cnt = 0;
+ char *ssid = (char*)wifi->ssid.val;
+ int ssid_len = wifi->ssid.len;
+
+
+ printf("Connect with SSID=%s password=%s\n", wifi->ssid.val, wifi->password);
+
+ /* scan buf init */
+ scan_buf.buf_len = 1000;
+ scan_buf.buf = (char*)pvPortMalloc(scan_buf.buf_len);
+ if(!scan_buf.buf){
+ printf("ERROR: Can't malloc memory\n");
+ return RTW_NOMEM;
+ }
+
+ /* set ssid_len, ssid to scan buf */
+ memset(scan_buf.buf, 0, scan_buf.buf_len);
+ if(ssid && ssid_len > 0 && ssid_len <= 32){
+ memcpy(scan_buf.buf, &ssid_len, sizeof(int));
+ memcpy(scan_buf.buf+sizeof(int), ssid, ssid_len);
+ }
+
+ /* call wifi scan to scan */
+ if(scan_cnt = (wifi_scan(RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, &scan_buf)) < 0){
+ printf("ERROR: wifi scan failed\n");
+ ret = RTW_ERROR;
+ }else{
+ ret = SC_parse_scan_result_and_connect(&scan_buf, wifi);
+ }
+
+ if(scan_buf.buf)
+ vPortFree(scan_buf.buf);
+
+ return ret;
+}
+
+
+
+
+rtw_security_t SC_translate_security(u8 security_type)
+{
+
+ rtw_security_t security_mode = RTW_SECURITY_UNKNOWN;
+
+ switch (security_type) {
+ case RTW_ENCRYPTION_OPEN:
+ security_mode = RTW_SECURITY_OPEN;
+ break;
+ case RTW_ENCRYPTION_WEP40:
+ case RTW_ENCRYPTION_WEP104:
+ security_mode = RTW_SECURITY_WEP_PSK;
+ break;
+ case RTW_ENCRYPTION_WPA_TKIP:
+ case RTW_ENCRYPTION_WPA_AES:
+ case RTW_ENCRYPTION_WPA2_TKIP:
+ case RTW_ENCRYPTION_WPA2_AES:
+ case RTW_ENCRYPTION_WPA2_MIXED:
+ security_mode = RTW_SECURITY_WPA2_AES_PSK;
+ break;
+ case RTW_ENCRYPTION_UNKNOWN:
+ case RTW_ENCRYPTION_UNDEF:
+ default:
+ printf( "unknow security mode,connect fail\n");
+ }
+
+ return security_mode;
+
+}
+
+
+enum sc_result SC_connect_to_AP(void)
+{
+ enum sc_result ret = SC_ERROR;
+ u8 scan_channel;
+ u8 pscan_config;
+ int max_retry = 5, retry = 0;
+ rtw_security_t security_mode;
+ rtw_network_info_t wifi = {0};
+ if(!(fixed_channel_num == 0)){
+ scan_channel = fixed_channel_num;
+ }
+ pscan_config = PSCAN_ENABLE | PSCAN_SIMPLE_CONFIG;
+
+ security_mode = SC_translate_security(g_security_mode);
+ g_security_mode = 0xff;//clear it
+
+ if (-1 == get_connection_info_from_profile(security_mode, &wifi)) {
+ ret = SC_CONTROLLER_INFO_PARSE_FAIL;
+ goto wifi_connect_fail;
+ }
+
+#if CONFIG_AUTO_RECONNECT
+ /* disable auto reconnect */
+ wifi_set_autoreconnect(0);
+#endif
+
+#if 1
+ /* optimization: get g_bssid to connect with only pscan */
+ while (1) {
+ if(wifi_set_pscan_chan(&scan_channel, &pscan_config, 1) < 0){
+ printf("ERROR: wifi set partial scan channel fail\n");
+ ret = SC_TARGET_CHANNEL_SCAN_FAIL;
+ goto wifi_connect_fail;
+ }
+ rtw_join_status = 0;//clear simple config status
+ ret = wifi_connect_bssid(g_bssid, (char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password,
+ ETH_ALEN, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
+
+ if (ret == RTW_SUCCESS)
+ goto wifi_connect_success;
+
+ if (retry == max_retry) {
+ printf("connect fail with bssid, try ssid instead\n");
+ break;
+ }
+ retry ++;
+ }
+#endif
+
+#if 1
+ /* when optimization fail: if connect with bssid fail because of we have connect to the wrong AP */
+ ret = SC_connect_to_candidate_AP(&wifi);
+ if (RTW_SUCCESS == ret) {
+ goto wifi_connect_success;
+ } else {
+ ret = SC_JOIN_BSS_FAIL;
+ goto wifi_connect_fail;
+ }
+#endif
+
+
+wifi_connect_success:
+ ret = SC_check_and_show_connection_info();
+ goto wifi_connect_end;
+
+
+wifi_connect_fail:
+ printf("SC_connect_to_AP failed\n");
+ goto wifi_connect_end;
+
+wifi_connect_end:
+#if CONFIG_AUTO_RECONNECT
+ wifi_config_autoreconnect(1, 10, 5);
+#endif
+ return ret;
+
+
+}
+/* Make callback one by one to wlan rx when promiscuous mode */
+
+void simple_config_callback(unsigned char *buf, unsigned int len, void* userdata)
+{
+ unsigned char * da = buf;
+ unsigned char * sa = buf + ETH_ALEN;
+ taskENTER_CRITICAL();
+ if (is_promisc_callback_unlock == 1) {
+ simple_config_result = rtk_start_parse_packet(da, sa, len, userdata, (void *)backup_sc_ctx);
+ //printf("\r\nresult in callback function = %d\n",simple_config_result);
+ }
+ taskEXIT_CRITICAL();
+
+}
+
+static unsigned int simple_config_cmd_start_time;
+static unsigned int simple_config_cmd_current_time;
+extern int simple_config_status;
+extern void rtk_restart_simple_config(void);
+
+
+extern void rtk_sc_deinit(void);
+
+void init_simple_config_lib_config(struct simple_config_lib_config* config)
+{
+ config->free = rtw_mfree;
+ config->malloc = rtw_malloc;
+ config->memcmp = memcmp;
+ config->memcpy = memcpy;
+ config->memset = memset;
+ config->printf = printf;
+ config->strcpy = strcpy;
+ config->strlen = strlen;
+ config->zmalloc = rtw_zmalloc;
+#if CONFIG_LWIP_LAYER
+ config->_ntohl = lwip_ntohl;
+#else
+ config->_ntohl = _ntohl;
+#endif
+ config->is_promisc_callback_unlock = &is_promisc_callback_unlock;
+}
+
+
+int init_test_data(char *custom_pin_code)
+{
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+ is_promisc_callback_unlock = 1;
+ is_fixed_channel = 0;
+ fixed_channel_num = 0;
+ simple_config_result = 0;
+ rtw_memset(g_ssid, 0, 32);
+ g_ssid_len = 0;
+ simple_config_cmd_start_time = xTaskGetTickCount();
+
+ if (ack_content != NULL) {
+ vPortFree(ack_content);
+ ack_content = NULL;
+ }
+ ack_content = pvPortMalloc(sizeof(struct ack_msg));
+ if (!ack_content) {
+ printf("rtk_sc_init fail by allocate ack\n");
+ }
+ memset(ack_content, 0, sizeof(struct ack_msg));
+
+#ifdef SC_SCAN_SUPPORT
+ if(custom_pin_code)
+ pin_enable = 1;
+ else
+ pin_enable = 0;
+#endif
+
+ backup_sc_ctx = pvPortMalloc(sizeof(struct rtk_test_sc));
+ if (!backup_sc_ctx) {
+ printf("[Mem]malloc SC context fail\n");
+ } else {
+ memset(backup_sc_ctx, 0, sizeof(struct rtk_test_sc));
+ struct simple_config_lib_config lib_config;
+ init_simple_config_lib_config(&lib_config);
+ //custom_pin_code can be null
+ if (rtk_sc_init(custom_pin_code, &lib_config) < 0) {
+ printf("Rtk_sc_init fail\n");
+ } else {
+ return 0;
+ }
+ }
+
+#else
+ printf("Platform no include simple config now\n");
+#endif
+ return -1;
+}
+
+void deinit_test_data(){
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+ rtk_sc_deinit();
+ if (backup_sc_ctx != NULL) {
+ vPortFree(backup_sc_ctx);
+ backup_sc_ctx = NULL;
+ }
+ if (ack_content != NULL) {
+ vPortFree(ack_content);
+ ack_content = NULL;
+ }
+ rtw_join_status = 0;//clear simple config status
+#endif
+}
+
+void stop_simple_config()
+{
+ simple_config_terminate = 1;
+}
+
+enum sc_result simple_config_test(rtw_network_info_t *wifi)
+{
+ int channel = 1;
+ enum sc_result ret = SC_SUCCESS;
+ unsigned int start_time;
+ int is_need_connect_to_AP = 0;
+ int fix_channel = 0;
+ int delta_time = 0;
+ wifi_set_promisc(RTW_PROMISC_ENABLE, simple_config_callback, 1);
+ start_time = xTaskGetTickCount();
+ printf("\n");
+ wifi_set_channel(channel);
+ while (simple_config_terminate != 1) {
+ vTaskDelay(50); //delay 0.5s to release CPU usage
+ simple_config_cmd_current_time = xTaskGetTickCount();
+#if CONFIG_GAGENT
+ if (simple_config_cmd_current_time - simple_config_cmd_start_time < ((50 + delta_time)*configTICK_RATE_HZ)) {
+#else
+ if (simple_config_cmd_current_time - simple_config_cmd_start_time < ((120 + delta_time)*configTICK_RATE_HZ)) {
+#endif
+ unsigned int current_time = xTaskGetTickCount();
+ if (((current_time - start_time)*1000 /configTICK_RATE_HZ < 100)
+ || (is_fixed_channel == 1)) {
+ if(is_fixed_channel == 0 && get_channel_flag == 1){
+ fix_channel = promisc_get_fixed_channel(g_bssid,g_ssid,&g_ssid_len);
+ if(fix_channel != 0)
+ {
+ printf("in simple_config_test fix channel = %d ssid: %s\n",fix_channel, g_ssid);
+ is_fixed_channel = 1;
+ fixed_channel_num = fix_channel;
+ wifi_set_channel(fix_channel);
+ }
+ else
+ printf("get channel fail\n");
+ }
+
+ if (simple_config_result == 1) {
+ is_need_connect_to_AP = 1;
+ is_fixed_channel = 0;
+ break;
+ }
+ if (simple_config_result == -1) {
+ printf("simple_config_test restart for result = -1\n");
+ delta_time = 60;
+ wifi_set_channel(1);
+ is_need_connect_to_AP = 0;
+ is_fixed_channel = 0;
+ fixed_channel_num = 0;
+ memset(g_ssid, 0, 32);
+ g_ssid_len = 0;
+ simple_config_result = 0;
+ g_security_mode = 0xff;
+ rtk_restart_simple_config();
+ }
+ if (simple_config_result == -2) {
+ printf("The APP or client must have pin!\n");
+ break;
+ }
+ } else {
+ channel++;
+ if ((1 <= channel) && (channel <= 13)) {
+ if (wifi_set_channel(channel) == 0) {
+ start_time = xTaskGetTickCount();
+ printf("Switch to channel(%d)\n", channel);
+ }
+ } else {
+ channel = 1;
+ if (wifi_set_channel(channel) == 0) {
+ start_time = xTaskGetTickCount();
+ printf("Switch to channel(%d)\n", channel);
+ }
+ }
+
+ }
+ } else {
+ ret = SC_NO_CONTROLLER_FOUND;
+ break;
+ }
+ }
+ wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
+ if (is_need_connect_to_AP == 1) {
+ if(NULL == wifi){
+ int tmp_res = SC_connect_to_AP();
+ if (SC_SUCCESS == tmp_res) {
+ if(-1 == SC_send_simple_config_ack(10))
+ ret = SC_UDP_SOCKET_CREATE_FAIL;
+ #ifdef SC_SCAN_SUPPORT
+ // check whether the thread of listen scan command is already created
+ if(scan_start == 0)
+ {
+ scan_start = 1;
+ SC_listen_ACK_scan();
+ }
+ #endif
+ } else {
+ ret = tmp_res;
+ }
+ }else{
+ if (-1 == get_connection_info_from_profile(wifi->security_type,wifi)) {
+ ret = SC_CONTROLLER_INFO_PARSE_FAIL;
+ }else
+ ret = SC_SUCCESS;
+ }
+ }else{
+ ret = SC_NO_CONTROLLER_FOUND;
+ }
+ return ret;
+}
+
+//Filter packet da[] = {0x01, 0x00, 0x5e}
+//add another filter for bcast, {0xff, 0xff, 0xff, 0xff}
+#define MASK_SIZE 3
+void filter_add_enable(){
+ u8 mask[MASK_SIZE]={0xFF,0xFF,0xFF};
+ u8 pattern[MASK_SIZE]={0x01,0x00,0x5e};
+ u8 pattern_bcast[MASK_SIZE]={0xff,0xff,0xff};
+
+ rtw_packet_filter_pattern_t packet_filter;
+ rtw_packet_filter_pattern_t packet_filter_bcast;
+ rtw_packet_filter_rule_e rule;
+
+ packet_filter.offset = 0;
+ packet_filter.mask_size = 3;
+ packet_filter.mask = mask;
+ packet_filter.pattern = pattern;
+
+ packet_filter_bcast.offset = 0;
+ packet_filter_bcast.mask_size = 3;
+ packet_filter_bcast.mask = mask;
+ packet_filter_bcast.pattern = pattern_bcast;
+
+ rule = RTW_POSITIVE_MATCHING;
+
+ wifi_init_packet_filter();
+ wifi_add_packet_filter(1, &packet_filter,rule);
+ wifi_add_packet_filter(2, &packet_filter_bcast,rule);
+
+ wifi_enable_packet_filter(1);
+ wifi_enable_packet_filter(2);
+}
+
+void remove_filter(){
+ wifi_disable_packet_filter(1);
+ wifi_disable_packet_filter(2);
+ wifi_remove_packet_filter(1);
+ wifi_remove_packet_filter(2);
+}
+
+void print_simple_config_result(enum sc_result sc_code)
+{
+ printf("\n");
+ switch (sc_code) {
+ case SC_NO_CONTROLLER_FOUND:
+ printf("Simple Config timeout!! Can't get Ap profile. Please try again\n");
+ break;
+ case SC_CONTROLLER_INFO_PARSE_FAIL:
+ printf("Simple Config fail, cannot parse target ap info from controller\n");
+ break;
+ case SC_TARGET_CHANNEL_SCAN_FAIL:
+ printf("Simple Config cannot scan the target channel\n");
+ break;
+ case SC_JOIN_BSS_FAIL:
+ printf("Simple Config Join bss failed\n");
+ break;
+ case SC_DHCP_FAIL:
+ printf("Simple Config fail, cannot get dhcp ip address\n");
+ break;
+ case SC_UDP_SOCKET_CREATE_FAIL:
+ printf("Simple Config Ack socket create fail!!!\n");
+ break;
+ case SC_TERMINATE:
+ printf("Simple Config terminate\n");
+ break;
+ case SC_SUCCESS:
+ printf("Simple Config success\n");
+ break;
+
+ case SC_ERROR:
+ default:
+ printf("unknown error when simple config!\n");
+
+ }
+}
+
+#endif //CONFIG_INCLUDE_SIMPLE_CONFIG
+
+void cmd_simple_config(int argc, char **argv){
+#if CONFIG_INCLUDE_SIMPLE_CONFIG
+ char *custom_pin_code = NULL;
+ enum sc_result ret = SC_ERROR;
+
+ if(argc > 2){
+ printf("Input Error!\n");
+ }
+
+ if(argc == 2)
+ custom_pin_code = (argv[1]);
+
+ simple_config_terminate = 0;
+ rtw_join_status |= JOIN_SIMPLE_CONFIG;
+
+ wifi_enter_promisc_mode();
+ if(init_test_data(custom_pin_code) == 0){
+ filter_add_enable();
+ ret = simple_config_test(NULL);
+ deinit_test_data();
+ print_simple_config_result(ret);
+ remove_filter();
+ }
+#if CONFIG_INIC_CMD_RSP
+ if(ret != SC_SUCCESS)
+ inic_c2h_wifi_info("ATWQ", RTW_ERROR);
+#endif
+
+#if CONFIG_EXAMPLE_UART_ATCMD
+ if(ret == SC_SUCCESS){
+ at_printf("\n\r[ATWQ] OK");
+ }else{
+ at_printf("\n\r[ATWQ] ERROR:%d",ret);
+ }
+#endif
+
+#endif
+}
+#endif //#if CONFIG_WLAN
+
+#endif // LWIP_SOCKET
+
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config.h b/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config.h
new file mode 100644
index 0000000..e77972c
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config.h
@@ -0,0 +1,20 @@
+#ifndef __WIFI_SIMPLE_CONFIG_H
+#define __WIFI_SIMPLE_CONFIG_H
+/*****************************wifi_simple_config.h****************************/
+enum sc_result {
+ SC_ERROR = -1, /* default error code*/
+ SC_NO_CONTROLLER_FOUND = 1, /* cannot get sta(controller) in the air which starts a simple config session */
+ SC_CONTROLLER_INFO_PARSE_FAIL, /* cannot parse the sta's info */
+ SC_TARGET_CHANNEL_SCAN_FAIL, /* cannot scan the target channel */
+ SC_JOIN_BSS_FAIL, /* fail to connect to target ap */
+ SC_DHCP_FAIL, /* fail to get ip address from target ap */
+ /* fail to create udp socket to send info to controller. note that client isolation
+ must be turned off in ap. we cannot know if ap has configured this */
+ SC_UDP_SOCKET_CREATE_FAIL,
+ SC_TERMINATE,
+ SC_SUCCESS, /* default success code */
+
+};
+int SC_send_simple_config_ack(u8 round);
+
+#endif //__WIFI_SIMPLE_CONFIG_H
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config_parser.h b/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config_parser.h
new file mode 100644
index 0000000..330ecdb
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_simple_config_parser.h
@@ -0,0 +1,99 @@
+#ifndef __SIMPLE_CONFIG_H__
+#define __SIMPLE_CONFIG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+ /* This macro means user take simple config
+ * lib to another platform such as linux, and
+ * have no rom crypto libs of simple config,
+ * so we take simple_config_crypto as a sw lib
+ * This macro is used by Realtek internal to generate simple config lib
+ * Please delete this macro after generation.
+ */
+#define SIMPLE_CONFIG_PLATFORM_LIB 0
+
+#include "platform_opts.h"
+#include "autoconf.h"
+
+
+
+/* platform related settings */
+#if (defined(CONFIG_PLATFORM_8195A)|| defined(CONFIG_PLATFORM_8711B))
+#undef u32
+#undef s32
+#undef u8
+#undef s8
+#undef u16
+#undef s16
+typedef unsigned int u32;
+typedef signed int s32;
+typedef unsigned char u8;
+typedef char s8;
+typedef unsigned short int u16;
+typedef signed short int s16;
+#else
+#include "osdep_service.h"
+#endif
+
+typedef int (*simple_config_printf_fn) (char const * fmt, ...);
+typedef void* (*simple_config_memset_fn) (u8 *dst0, s32 Val, u32 length);
+typedef void* (*simple_config_memcpy_fn) ( void *s1, const void *s2, u32 n );
+typedef u32 (*simple_config_strlen_fn) (const char *s);
+typedef char * (*simple_config_strcpy_fn) (char *dest, const char *src);
+typedef void (*simple_config_free_fn) (u8 *pbuf, u32 sz);
+typedef u8* (*simple_config_zmalloc_fn) (u32 sz);
+typedef u8* (*simple_config_malloc_fn) (u32 sz);
+typedef int (*simple_config_memcmp_fn) (const void *av, const void *bv, u32 len);
+typedef u32 (*simple_config_ntohl_fn)(u32 x);
+
+
+
+struct simple_config_lib_config {
+ simple_config_printf_fn printf;
+ simple_config_memset_fn memset;
+ simple_config_memcpy_fn memcpy;
+ simple_config_strlen_fn strlen;
+ simple_config_strcpy_fn strcpy;
+ simple_config_free_fn free;
+ simple_config_zmalloc_fn zmalloc;
+ simple_config_malloc_fn malloc;
+ simple_config_memcmp_fn memcmp;
+ simple_config_ntohl_fn _ntohl;
+
+
+ int *is_promisc_callback_unlock;
+
+};
+
+#pragma pack(1)
+struct rtk_test_sc {
+ /* API exposed to user */
+ unsigned char ssid[32];
+ unsigned char password[65];
+ unsigned int ip_addr;
+};
+
+/* expose data */
+extern s32 is_promisc_callback_unlock;
+extern u8 g_bssid[6];
+extern u8 get_channel_flag;
+extern u8 g_security_mode;
+
+/* expose API */
+extern s32 rtk_sc_init(char *custom_pin_code, struct simple_config_lib_config* config);
+extern s32 rtk_start_parse_packet(u8 *da, u8 *sa, s32 len, void * user_data, void *backup_sc);
+extern void rtk_restart_simple_config(void);
+extern void rtk_sc_deinit();
+extern void wifi_enter_promisc_mode();
+extern void whc_fix_channel();
+extern void whc_unfix_channel();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SIMPLE_CONFIG_H__*/
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_util.c b/RTL00_SDKV35a/component/common/api/wifi/wifi_util.c
new file mode 100644
index 0000000..96b8023
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_util.c
@@ -0,0 +1,1342 @@
+#include
+#include
+#include "FreeRTOS.h"
+#include
+#include
+#include
+#include
+
+#if CONFIG_DEBUG_LOG > 0
+ #define wext_printf(...) rtl_printf(__VA_ARGS__)
+#else
+ #define wext_printf(...)
+#endif
+
+
+int iw_ioctl(const char * ifname, unsigned long request, struct iwreq * pwrq)
+{
+ memcpy(pwrq->ifr_name, ifname, 5);
+ return rltk_wlan_control(request, (void *) pwrq);
+}
+
+int wext_get_ssid(const char *ifname, __u8 *ssid)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.essid.pointer = ssid;
+ iwr.u.essid.length = 32;
+
+ if (iw_ioctl(ifname, SIOCGIWESSID, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWESSID] ssid = NULL, not connected\n"); //do not use perror
+ ret = -1;
+ } else {
+ ret = iwr.u.essid.length;
+ if (ret > 32)
+ ret = 32;
+ /* Some drivers include nul termination in the SSID, so let's
+ * remove it here before further processing. WE-21 changes this
+ * to explicitly require the length _not_ to include nul
+ * termination. */
+ if (ret > 0 && ssid[ret - 1] == '\0')
+ ret--;
+ ssid[ret] = '\0';
+ }
+
+ return ret;
+}
+
+int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.essid.pointer = (void *) ssid;
+ iwr.u.essid.length = ssid_len;
+ iwr.u.essid.flags = (ssid_len != 0);
+
+ if (iw_ioctl(ifname, SIOCSIWESSID, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWESSID] error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int wext_set_bssid(const char *ifname, const __u8 *bssid)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.ap_addr.sa_family = ARPHRD_ETHER;
+ memcpy(iwr.u.ap_addr.sa_data, bssid, ETH_ALEN);
+
+ if(bssid[ETH_ALEN]=='#' && bssid[ETH_ALEN + 1]=='@'){
+ memcpy(iwr.u.ap_addr.sa_data + ETH_ALEN, bssid + ETH_ALEN, 6);
+ }
+
+ if (iw_ioctl(ifname, SIOCSIWAP, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWAP] error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int is_broadcast_ether_addr(const unsigned char *addr)
+{
+ return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
+}
+
+int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.param.flags = idx & IW_AUTH_INDEX;
+ iwr.u.param.value = value;
+
+ if (iw_ioctl(ifname, SIOCSIWAUTH, &iwr) < 0) {
+ wext_printf("WEXT: SIOCSIWAUTH(param %d value 0x%x) failed)\n", idx, value);
+ }
+
+ return ret;
+}
+
+int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ struct iw_encode_ext *ext;
+
+ ext = (struct iw_encode_ext *) malloc(sizeof(struct iw_encode_ext) + key_len);
+ if (ext == NULL)
+ return -1;
+ else
+ memset(ext, 0, sizeof(struct iw_encode_ext) + key_len);
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.encoding.flags = key_idx + 1;
+ iwr.u.encoding.flags |= IW_ENCODE_TEMP;
+ iwr.u.encoding.pointer = ext;
+ iwr.u.encoding.length = sizeof(struct iw_encode_ext) + key_len;
+
+ if (alg == IW_ENCODE_DISABLED)
+ iwr.u.encoding.flags |= IW_ENCODE_DISABLED;
+
+ if (addr == NULL || is_broadcast_ether_addr(addr))
+ ext->ext_flags |= IW_ENCODE_EXT_GROUP_KEY;
+
+ if (set_tx)
+ ext->ext_flags |= IW_ENCODE_EXT_SET_TX_KEY;
+
+ ext->addr.sa_family = ARPHRD_ETHER;
+
+ if (addr)
+ memcpy(ext->addr.sa_data, addr, ETH_ALEN);
+ else
+ memset(ext->addr.sa_data, 0xff, ETH_ALEN);
+
+ if (key && key_len) {
+ memcpy(ext->key, key, key_len);
+ ext->key_len = key_len;
+ }
+
+ ext->alg = alg;
+
+ if (seq && seq_len) {
+ ext->ext_flags |= IW_ENCODE_EXT_RX_SEQ_VALID;
+ memcpy(ext->rx_seq, seq, seq_len);
+ }
+
+ if (iw_ioctl(ifname, SIOCSIWENCODEEXT, &iwr) < 0) {
+ ret = -2;
+ wext_printf("ioctl[SIOCSIWENCODEEXT] set key fail\n");
+ }
+
+ free(ext);
+
+ return ret;
+}
+
+int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ struct iw_encode_ext *ext;
+
+ ext = (struct iw_encode_ext *) malloc(sizeof(struct iw_encode_ext) + 16);
+ if (ext == NULL)
+ return -1;
+ else
+ memset(ext, 0, sizeof(struct iw_encode_ext) + 16);
+
+ iwr.u.encoding.pointer = ext;
+
+ if (iw_ioctl(ifname, SIOCGIWENCODEEXT, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWENCODEEXT] error\n");
+ ret = -1;
+ }
+ else
+ {
+ *alg = ext->alg;
+ if(key_idx)
+ *key_idx = (__u8)iwr.u.encoding.flags;
+ if(passphrase)
+ memcpy(passphrase, ext->key, ext->key_len);
+ }
+
+ if(ext != NULL)
+ free(ext);
+
+ return ret;
+}
+
+int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.passphrase.pointer = (void *) passphrase;
+ iwr.u.passphrase.length = passphrase_len;
+ iwr.u.passphrase.flags = (passphrase_len != 0);
+
+ if (iw_ioctl(ifname, SIOCSIWPRIVPASSPHRASE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWESSID+0x1f] error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int wext_get_passphrase(const char *ifname, __u8 *passphrase)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.passphrase.pointer = (void *) passphrase;
+
+ if (iw_ioctl(ifname, SIOCGIWPRIVPASSPHRASE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWPRIVPASSPHRASE] error\n");
+ ret = -1;
+ }
+ else {
+ ret = iwr.u.passphrase.length;
+ passphrase[ret] = '\0';
+ }
+
+ return ret;
+}
+
+#if 0
+int wext_set_mac_address(const char *ifname, char * mac)
+{
+ char buf[13+17+1];
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 13+17, "write_mac %s", mac);
+ return wext_private_command(ifname, buf, 0);
+}
+
+int wext_get_mac_address(const char *ifname, char * mac)
+{
+ int ret = 0;
+ char buf[32];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ rtw_memcpy(buf, "read_mac", 8);
+ ret = wext_private_command_with_retval(ifname, buf, buf, 32);
+ strcpy(mac, buf);
+ return ret;
+}
+#endif
+
+int wext_enable_powersave(const char *ifname, __u8 ips_mode, __u8 lps_mode)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u16 pindex = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("pm_set");
+
+ // Encode parameters as TLV (type, length, value) format
+ para = pvPortMalloc( 7 + (1+1+1) + (1+1+1) );
+ if(para == NULL) return -1;
+
+ snprintf((char*)para, cmd_len, "pm_set");
+ pindex = 7;
+
+ para[pindex++] = 0; // type 0 for ips
+ para[pindex++] = 1;
+ para[pindex++] = ips_mode;
+
+ para[pindex++] = 1; // type 1 for lps
+ para[pindex++] = 1;
+ para[pindex++] = lps_mode;
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = pindex;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVAPESSID] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+}
+
+int wext_disable_powersave(const char *ifname)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u16 pindex = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("pm_set");
+
+ // Encode parameters as TLV (type, length, value) format
+ para = pvPortMalloc( 7 + (1+1+1) + (1+1+1) );
+ if(para == NULL) return -1;
+
+ snprintf((char*)para, cmd_len, "pm_set");
+ pindex = 7;
+
+ para[pindex++] = 0; // type 0 for ips
+ para[pindex++] = 1;
+ para[pindex++] = 0; // ips = 0
+
+ para[pindex++] = 1; // type 1 for lps
+ para[pindex++] = 1;
+ para[pindex++] = 0; // lps = 0
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = pindex;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVAPESSID] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+
+}
+
+int wext_set_tdma_param(const char *ifname, __u8 slot_period, __u8 rfon_period_len_1, __u8 rfon_period_len_2, __u8 rfon_period_len_3)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u16 pindex = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("pm_set");
+
+ // Encode parameters as TLV (type, length, value) format
+ para = pvPortMalloc( 7 + (1+1+4) );
+
+ snprintf((char*)para, cmd_len, "pm_set");
+ pindex = 7;
+
+ para[pindex++] = 2; // type 2 tdma param
+ para[pindex++] = 4;
+ para[pindex++] = slot_period;
+ para[pindex++] = rfon_period_len_1;
+ para[pindex++] = rfon_period_len_2;
+ para[pindex++] = rfon_period_len_3;
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = pindex;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVAPESSID] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+}
+
+int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u16 pindex = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("pm_set");
+
+ // Encode parameters as TLV (type, length, value) format
+ para = pvPortMalloc( 7 + (1+1+1) );
+
+ snprintf((char*)para, cmd_len, "pm_set");
+ pindex = 7;
+
+ para[pindex++] = 3; // type 3 lps dtim
+ para[pindex++] = 1;
+ para[pindex++] = lps_dtim;
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = pindex;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVAPESSID] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+}
+
+int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim)
+{
+
+ struct iwreq iwr;
+ int ret = 0;
+ __u16 pindex = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("pm_get");
+
+ // Encode parameters as TLV (type, length, value) format
+ para = pvPortMalloc( 7 + (1+1+1) );
+
+ snprintf((char*)para, cmd_len, "pm_get");
+ pindex = 7;
+
+ para[pindex++] = 3; // type 3 for lps dtim
+ para[pindex++] = 1;
+ para[pindex++] = 0;
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = pindex;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVAPESSID] error\n");
+ ret = -1;
+ goto exit;
+ }
+
+ //get result at the beginning of iwr.u.data.pointer
+ if((para[0]==3)&&(para[1]==1))
+ *lps_dtim = para[2];
+ else
+ wext_printf("%s error\n", __func__);
+
+exit:
+ vPortFree(para);
+
+ return ret;
+}
+
+int wext_set_tos_value(const char *ifname, __u8 *tos_value)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = sizeof("set_tos_value");
+
+ memset(&iwr, 0, sizeof(iwr));
+
+ para = pvPortMalloc(cmd_len + 4);
+ snprintf((char*)para, cmd_len, "set_tos_value");
+
+ if(*tos_value >= 0 && *tos_value <=32){
+ *(para + cmd_len) = 0x4f;
+ *(para + cmd_len+1) = 0xa4;
+ *(para + cmd_len+2) = 0;
+ *(para + cmd_len+3) = 0;
+ }
+ else if(*tos_value > 32 && *tos_value <=96){
+ *(para + cmd_len) = 0x2b;
+ *(para + cmd_len+1) = 0xa4;
+ *(para + cmd_len+2) = 0;
+ *(para + cmd_len+3) = 0;
+ }
+ else if(*tos_value > 96 && *tos_value <= 160){
+ *(para + cmd_len) = 0x22;
+ *(para + cmd_len+1) = 0x43;
+ *(para + cmd_len+2) = 0x5e;
+ *(para + cmd_len+3) = 0;
+ }
+ else if(*tos_value > 160){
+ *(para + cmd_len) = 0x22;
+ *(para + cmd_len+1) = 0x32;
+ *(para + cmd_len+2) = 0x2f;
+ *(para + cmd_len+3) = 0;
+ }
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = cmd_len + 4;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_set_tos_value():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+}
+
+int wext_get_tx_power(const char *ifname, __u8 *poweridx)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = sizeof("get_tx_power");
+
+ memset(&iwr, 0, sizeof(iwr));
+ //Tx power size : 20 Bytes
+ //CCK 1M,2M,5.5M,11M : 4 Bytes
+ //OFDM 6M, 9M, 12M, 18M, 24M, 36M 48M, 54M : 8 Bytes
+ //MCS 0~7 : 8 Bytes
+ para = pvPortMalloc(cmd_len + 20);
+ if(para != NULL) {
+
+ snprintf((char*)para, cmd_len, "get_tx_power");
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = cmd_len + 20;
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_get_tx_power():ioctl[SIOCDEVPRIVATE] error!\n");
+ ret = -1;
+ }
+
+ memcpy(poweridx,(__u8 *)(iwr.u.data.pointer),20);
+ vPortFree(para);
+ }
+ else {
+ printf("wext_get_tx_power() error alloc!\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+#if 0
+int wext_set_txpower(const char *ifname, int poweridx)
+{
+ int ret;
+ char buf[24];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 24, "txpower patha=%d", poweridx);
+ ret = wext_private_command(ifname, buf, 0);
+
+ return ret;
+}
+
+int wext_get_associated_client_list(const char *ifname, void * client_list_buffer, uint16_t buffer_length)
+{
+ int ret;
+ char buf[25];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 25, "get_client_list %x", client_list_buffer);
+ ret = wext_private_command(ifname, buf, 0);
+
+ return ret;
+}
+
+int wext_get_ap_info(const char *ifname, rtw_bss_info_t * ap_info, rtw_security_t* security)
+{
+ int ret = 0;
+ char buf[24];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 24, "get_ap_info %x", ap_info);
+ ret = wext_private_command(ifname, buf, 0);
+
+ snprintf(buf, 24, "get_security");
+ ret = wext_private_command_with_retval(ifname, buf, buf, 24);
+ sscanf(buf, "%d", security);
+
+ return ret;
+}
+#endif
+
+int wext_set_mode(const char *ifname, int mode)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.mode = mode;
+ if (iw_ioctl(ifname, SIOCSIWMODE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWMODE] error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int wext_get_mode(const char *ifname, int *mode)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+
+ if (iw_ioctl(ifname, SIOCGIWMODE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWMODE] error\n");
+ ret = -1;
+ }
+ else
+ *mode = iwr.u.mode;
+
+ return ret;
+}
+
+int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.essid.pointer = (void *) ssid;
+ iwr.u.essid.length = ssid_len;
+ iwr.u.essid.flags = (ssid_len != 0);
+
+ if (iw_ioctl(ifname, SIOCSIWPRIVAPESSID, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVAPESSID] error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int wext_set_country(const char *ifname, rtw_country_code_t country_code)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+
+ iwr.u.param.value = country_code;
+
+ if (iw_ioctl(ifname, SIOCSIWPRIVCOUNTRY, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWPRIVCOUNTRY] error\n");
+ ret = -1;
+ }
+ return ret;
+}
+
+int wext_get_rssi(const char *ifname, int *rssi)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+
+ if (iw_ioctl(ifname, SIOCGIWSENS, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWSENS] error\n");
+ ret = -1;
+ } else {
+ *rssi = 0 - iwr.u.sens.value;
+ }
+ return ret;
+}
+
+int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config, __u8 length)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int i =0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ //Format of para:function_name num_channel chan1... pscan_config1 ...
+ para = pvPortMalloc((length + length + 1) + 12);//size:num_chan + num_time + length + function_name
+ if(para == NULL) return -1;
+
+ //Cmd
+ snprintf((char*)para, 12, "PartialScan");
+ //length
+ *(para+12) = length;
+ for(i = 0; i < length; i++){
+ *(para + 13 + i)= *(ch + i);
+ *((__u16*) (para + 13 + length + i))= *(pscan_config + i);
+ }
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = (length + length + 1) + 12;
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_set_pscan_channel():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+ vPortFree(para);
+ return ret;
+}
+int wext_set_channel(const char *ifname, __u8 ch)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.freq.m = 0;
+ iwr.u.freq.e = 0;
+ iwr.u.freq.i = ch;
+
+ if (iw_ioctl(ifname, SIOCSIWFREQ, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWFREQ] error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int wext_get_channel(const char *ifname, __u8 *ch)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+
+ if (iw_ioctl(ifname, SIOCGIWFREQ, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWFREQ] error\n");
+ ret = -1;
+ }
+ else
+ *ch = iwr.u.freq.i;
+
+ return ret;
+}
+
+int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac)
+{
+ int ret = 0;
+ char buf[32];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 32, "reg_multicast "MAC_FMT, MAC_ARG(mac->octet));
+ ret = wext_private_command(ifname, buf, 0);
+
+ return ret;
+}
+
+int wext_unregister_multicast_address(const char *ifname, rtw_mac_t *mac)
+{
+ int ret = 0;
+ char buf[35];
+
+ rtw_memset(buf, 0, sizeof(buf));
+ snprintf(buf, 35, "reg_multicast -d "MAC_FMT, MAC_ARG(mac->octet));
+ ret = wext_private_command(ifname, buf, 0);
+
+ return ret;
+}
+
+int wext_set_scan(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+#if 0 //for scan_with_ssid
+ if(buf)
+ memset(buf, 0, buf_len);
+#endif
+ iwr.u.data.pointer = buf;
+ iwr.u.data.flags = flags;
+ iwr.u.data.length = buf_len;
+ if (iw_ioctl(ifname, SIOCSIWSCAN, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWSCAN] error\n");
+ ret = -1;
+ }
+ return ret;
+}
+
+int wext_get_scan(const char *ifname, char *buf, __u16 buf_len)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ iwr.u.data.pointer = buf;
+ iwr.u.data.length = buf_len;
+ if (iw_ioctl(ifname, SIOCGIWSCAN, &iwr) < 0) {
+ wext_printf("ioctl[SIOCGIWSCAN] error\n");
+ ret = -1;
+ }else
+ ret = iwr.u.data.flags;
+ return ret;
+}
+
+int wext_private_command_with_retval(const char *ifname, char *cmd, char *ret_buf, int ret_len)
+{
+ struct iwreq iwr;
+ int ret = 0, buf_size;
+ char *buf;
+
+ buf_size = 128;
+ if(strlen(cmd) >= buf_size)
+ buf_size = strlen(cmd) + 1; // 1 : '\0'
+ buf = (char*)pvPortMalloc(buf_size);
+ if(!buf){
+ wext_printf("WEXT: Can't malloc memory\n");
+ return -1;
+ }
+ memset(buf, 0, buf_size);
+ strcpy(buf, cmd);
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.data.pointer = buf;
+ iwr.u.data.length = buf_size;
+ iwr.u.data.flags = 0;
+
+ if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) {
+ wext_printf("ioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
+ }
+ if(ret_buf){
+ if(ret_len > iwr.u.data.length)
+ ret_len = iwr.u.data.length;
+ rtw_memcpy(ret_buf, (char *) iwr.u.data.pointer, ret_len);
+ }
+ vPortFree(buf);
+ return ret;
+}
+
+int wext_private_command(const char *ifname, char *cmd, int show_msg)
+{
+ struct iwreq iwr;
+ int ret = 0, buf_size;
+ char *buf;
+
+ u8 cmdname[17] = {0}; // IFNAMSIZ+1
+
+ sscanf(cmd, "%16s", cmdname);
+ if((strcmp((const char *)cmdname, "config_get") == 0)
+ || (strcmp((const char *)cmdname, "config_set") == 0)
+ || (strcmp((const char *)cmdname, "efuse_get") == 0)
+ || (strcmp((const char *)cmdname, "efuse_set") == 0)
+ || (strcmp((const char *)cmdname, "mp_psd") == 0))
+ buf_size = 2600;//2600 for config_get rmap,0,512 (or realmap)
+ else
+ buf_size = 512;
+
+ if(strlen(cmd) >= buf_size)
+ buf_size = strlen(cmd) + 1; // 1 : '\0'
+ buf = (char*)pvPortMalloc(buf_size);
+ if(!buf){
+ wext_printf("WEXT: Can't malloc memory\n");
+ return -1;
+ }
+ memset(buf, 0, buf_size);
+ strcpy(buf, cmd);
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.data.pointer = buf;
+ iwr.u.data.length = buf_size;
+ iwr.u.data.flags = 0;
+
+ if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) {
+ wext_printf("ioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
+ }
+ if (show_msg && iwr.u.data.length) {
+ if(iwr.u.data.length > buf_size)
+ wext_printf("WEXT: Malloc memory is not enough\n");
+ wext_printf("Private Message: %s\n", (char *) iwr.u.data.pointer);
+ }
+ vPortFree(buf);
+ return ret;
+}
+
+void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra)
+{
+ unsigned char null_mac[6] = {0};
+
+ switch(cmd)
+ {
+ case SIOCGIWAP:
+ if(wrqu->ap_addr.sa_family == ARPHRD_ETHER)
+ {
+ if(!memcmp(wrqu->ap_addr.sa_data, null_mac, sizeof(null_mac)))
+ wifi_indication(WIFI_EVENT_DISCONNECT, NULL, 0, 0);
+ else
+ wifi_indication(WIFI_EVENT_CONNECT, wrqu->ap_addr.sa_data, sizeof(null_mac), 0);
+ }
+ break;
+
+ case IWEVCUSTOM:
+ if(extra)
+ {
+ if(!memcmp(IW_EXT_STR_FOURWAY_DONE, extra, strlen(IW_EXT_STR_FOURWAY_DONE)))
+ wifi_indication(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, extra, strlen(IW_EXT_STR_FOURWAY_DONE), 0);
+ else if(!memcmp(IW_EXT_STR_RECONNECTION_FAIL, extra, strlen(IW_EXT_STR_RECONNECTION_FAIL)))
+ wifi_indication(WIFI_EVENT_RECONNECTION_FAIL, extra, strlen(IW_EXT_STR_RECONNECTION_FAIL), 0);
+ else if(!memcmp(IW_EVT_STR_NO_NETWORK, extra, strlen(IW_EVT_STR_NO_NETWORK)))
+ wifi_indication(WIFI_EVENT_NO_NETWORK, extra, strlen(IW_EVT_STR_NO_NETWORK), 0);
+#if CONFIG_ENABLE_P2P || defined(CONFIG_AP_MODE)
+ else if(!memcmp(IW_EVT_STR_STA_ASSOC, extra, strlen(IW_EVT_STR_STA_ASSOC)))
+ wifi_indication(WIFI_EVENT_STA_ASSOC, wrqu->data.pointer, wrqu->data.length, 0);
+ else if(!memcmp(IW_EVT_STR_STA_DISASSOC, extra, strlen(IW_EVT_STR_STA_DISASSOC)))
+ wifi_indication(WIFI_EVENT_STA_DISASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0);
+ else if(!memcmp(IW_EVT_STR_SEND_ACTION_DONE, extra, strlen(IW_EVT_STR_SEND_ACTION_DONE)))
+ wifi_indication(WIFI_EVENT_SEND_ACTION_DONE, NULL, 0, wrqu->data.flags);
+#endif
+ }
+ break;
+ case SIOCGIWSCAN:
+ if(wrqu->data.pointer == NULL)
+ wifi_indication(WIFI_EVENT_SCAN_DONE, NULL, 0, 0);
+ else
+ wifi_indication(WIFI_EVENT_SCAN_RESULT_REPORT, wrqu->data.pointer, wrqu->data.length, 0);
+ break;
+#if CONFIG_ENABLE_P2P
+ case IWEVMGNTRECV:
+ wifi_indication(WIFI_EVENT_RX_MGNT, wrqu->data.pointer, wrqu->data.length, wrqu->data.flags);
+ break;
+#endif
+#ifdef REPORT_STA_EVENT
+ case IWEVREGISTERED:
+ if(wrqu->addr.sa_family == ARPHRD_ETHER)
+ wifi_indication(WIFI_EVENT_STA_ASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0);
+ break;
+ case IWEVEXPIRED:
+ if(wrqu->addr.sa_family == ARPHRD_ETHER)
+ wifi_indication(WIFI_EVENT_STA_DISASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0);
+ break;
+#endif
+ default:
+ break;
+
+ }
+
+}
+
+
+int wext_send_eapol(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.data.pointer = buf;
+ iwr.u.data.length = buf_len;
+ iwr.u.data.flags = flags;
+ if (iw_ioctl(ifname, SIOCSIWEAPOLSEND, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWEAPOLSEND] error\n");
+ ret = -1;
+ }
+ return ret;
+}
+
+
+
+#if CONFIG_ENABLE_P2P
+int wext_send_mgnt(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.data.pointer = buf;
+ iwr.u.data.length = buf_len;
+ iwr.u.data.flags = flags;
+ if (iw_ioctl(ifname, SIOCSIWMGNTSEND, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWMGNTSEND] error\n");
+ ret = -1;
+ }
+ return ret;
+}
+#endif
+
+int wext_set_gen_ie(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
+{
+ struct iwreq iwr;
+ int ret = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ iwr.u.data.pointer = buf;
+ iwr.u.data.length = buf_len;
+ iwr.u.data.flags = flags;
+ if (iw_ioctl(ifname, SIOCSIWGENIE, &iwr) < 0) {
+ wext_printf("ioctl[SIOCSIWGENIE] error\n");
+ ret = -1;
+ }
+ return ret;
+}
+
+int wext_set_autoreconnect(const char *ifname, __u8 mode, __u8 retyr_times, __u16 timeout)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("SetAutoRecnt");
+ para = pvPortMalloc((4) + cmd_len);//size:para_len+cmd_len
+ if(para == NULL) return -1;
+
+ //Cmd
+ snprintf((char*)para, cmd_len, "SetAutoRecnt");
+ //length
+ *(para+cmd_len) = mode; //para1
+ *(para+cmd_len+1) = retyr_times; //para2
+ *(para+cmd_len+2) = timeout; //para3
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = (4) + cmd_len;
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_set_autoreconnect():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+ vPortFree(para);
+ return ret;
+}
+
+int wext_get_autoreconnect(const char *ifname, __u8 *mode)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("GetAutoRecnt");
+ para = pvPortMalloc(cmd_len);//size:para_len+cmd_len
+ //Cmd
+ snprintf((char*)para, cmd_len, "GetAutoRecnt");
+ //length
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = cmd_len;
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_get_autoreconnect():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+ *mode = *(__u8 *)(iwr.u.data.pointer);
+ vPortFree(para);
+ return ret;
+}
+
+int wext_get_drv_ability(const char *ifname, __u32 *ability)
+{
+ int ret = 0;
+ char * buf = (char *)rtw_zmalloc(33);
+ if(buf == NULL) return -1;
+
+ snprintf(buf, 33, "get_drv_ability %x", ability);
+ ret = wext_private_command(ifname, buf, 0);
+
+ rtw_free(buf);
+ return ret;
+}
+
+#ifdef CONFIG_CUSTOM_IE
+int wext_add_custom_ie(const char *ifname, void *cus_ie, int ie_num)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+ if(ie_num <= 0 || !cus_ie){
+ wext_printf("wext_add_custom_ie():wrong parameter\n");
+ ret = -1;
+ return ret;
+ }
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("SetCusIE");
+ para = pvPortMalloc((4)* 2 + cmd_len);//size:addr len+cmd_len
+ if(para == NULL) return -1;
+
+ //Cmd
+ snprintf(para, cmd_len, "SetCusIE");
+ //addr length
+ *(__u32 *)(para + cmd_len) = (__u32)cus_ie; //ie addr
+ //ie_num
+ *(__u32 *)(para + cmd_len + 4) = ie_num; //num of ie
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = (4)* 2 + cmd_len;// 2 input
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_add_custom_ie():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+ vPortFree(para);
+
+ return ret;
+}
+
+int wext_update_custom_ie(const char *ifname, void * cus_ie, int ie_index)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+ if(ie_index <= 0 || !cus_ie){
+ wext_printf("wext_update_custom_ie():wrong parameter\n");
+ ret = -1;
+ return ret;
+ }
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("UpdateIE");
+ para = pvPortMalloc((4)* 2 + cmd_len);//size:addr len+cmd_len
+ if(para == NULL) return -1;
+
+ //Cmd
+ snprintf(para, cmd_len, "UpdateIE");
+ //addr length
+ *(__u32 *)(para + cmd_len) = (__u32)cus_ie; //ie addr
+ //ie_index
+ *(__u32 *)(para + cmd_len + 4) = ie_index; //num of ie
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = (4)* 2 + cmd_len;// 2 input
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_update_custom_ie():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+ vPortFree(para);
+
+ return ret;
+
+}
+
+int wext_del_custom_ie(const char *ifname)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("DelIE");
+ para = pvPortMalloc(cmd_len);//size:addr len+cmd_len
+ //Cmd
+ snprintf(para, cmd_len, "DelIE");
+
+ iwr.u.data.pointer = para;
+ iwr.u.data.length = cmd_len;
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_del_custom_ie():ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+ vPortFree(para);
+
+ return ret;
+
+
+}
+
+#endif
+
+#ifdef CONFIG_AP_MODE
+int wext_enable_forwarding(const char *ifname)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("forwarding_set");
+ para = pvPortMalloc(cmd_len + 1);
+ if(para == NULL) return -1;
+
+ // forwarding_set 1
+ snprintf((char *) para, cmd_len, "forwarding_set");
+ *(para + cmd_len) = '1';
+
+ iwr.u.essid.pointer = para;
+ iwr.u.essid.length = cmd_len + 1;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_enable_forwarding(): ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+}
+
+int wext_disable_forwarding(const char *ifname)
+{
+ struct iwreq iwr;
+ int ret = 0;
+ __u8 *para = NULL;
+ int cmd_len = 0;
+
+ memset(&iwr, 0, sizeof(iwr));
+ cmd_len = sizeof("forwarding_set");
+ para = pvPortMalloc(cmd_len + 1);
+ if(para == NULL) return -1;
+
+ // forwarding_set 0
+ snprintf((char *) para, cmd_len, "forwarding_set");
+ *(para + cmd_len) = '0';
+
+ iwr.u.essid.pointer = para;
+ iwr.u.essid.length = cmd_len + 1;
+
+ if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
+ wext_printf("wext_disable_forwarding(): ioctl[SIOCDEVPRIVATE] error\n");
+ ret = -1;
+ }
+
+ vPortFree(para);
+ return ret;
+
+}
+#endif
+
+#ifdef CONFIG_CONCURRENT_MODE
+int wext_set_ch_deauth(const char *ifname, __u8 enable)
+{
+ int ret = 0;
+ char * buf = (char *)rtw_zmalloc(16);
+ if(buf == NULL) return -1;
+
+ snprintf(buf, 16, "SetChDeauth %d", enable);
+ ret = wext_private_command(ifname, buf, 0);
+
+ rtw_free(buf);
+ return ret;
+}
+#endif
+
+int wext_set_adaptivity(rtw_adaptivity_mode_t adaptivity_mode)
+{
+ extern u8 rtw_adaptivity_en;
+ extern u8 rtw_adaptivity_mode;
+
+ switch(adaptivity_mode){
+ case RTW_ADAPTIVITY_NORMAL:
+ rtw_adaptivity_en = 1; // enable adaptivity
+ rtw_adaptivity_mode = RTW_ADAPTIVITY_MODE_NORMAL;
+ break;
+ case RTW_ADAPTIVITY_CARRIER_SENSE:
+ rtw_adaptivity_en = 1; // enable adaptivity
+ rtw_adaptivity_mode = RTW_ADAPTIVITY_MODE_CARRIER_SENSE;
+ break;
+ case RTW_ADAPTIVITY_DISABLE:
+ default:
+ rtw_adaptivity_en = 0; //disable adaptivity
+ break;
+ }
+ return 0;
+}
+
+int wext_set_adaptivity_th_l2h_ini(__u8 l2h_threshold)
+{
+ extern s8 rtw_adaptivity_th_l2h_ini;
+ rtw_adaptivity_th_l2h_ini = (__s8)l2h_threshold;
+ return 0;
+}
+
+extern int rltk_get_auto_chl(const char *ifname, unsigned char *channel_set, int channel_num);
+
+int wext_get_auto_chl(const char *ifname, unsigned char *channel_set, unsigned char channel_num)
+{
+ int ret = -1;
+ int channel = 0;
+ wext_disable_powersave(ifname);
+ if((channel = rltk_get_auto_chl(ifname,channel_set,channel_num)) != 0 )
+ ret = channel ;
+ wext_enable_powersave(ifname, 1, 1);
+ return ret;
+}
+
+extern int rltk_set_sta_num(unsigned char ap_sta_num);
+
+int wext_set_sta_num(unsigned char ap_sta_num)
+{
+ return rltk_set_sta_num(ap_sta_num);
+}
+
+extern int rltk_del_station(const char *ifname, unsigned char *hwaddr);
+
+int wext_del_station(const char *ifname, unsigned char* hwaddr)
+{
+ return rltk_del_station(ifname, hwaddr);
+}
+
+extern struct list_head *mf_list_head;
+int wext_init_mac_filter(void)
+{
+ if(mf_list_head != NULL){
+ return -1;
+ }
+
+ mf_list_head = malloc(sizeof(struct list_head));
+ if(mf_list_head == NULL){
+ wext_printf("ERROR: %s : can't allocate mf_list_head\n",__func__);
+ return -1;
+ }
+
+ INIT_LIST_HEAD(mf_list_head);
+
+ return 0;
+}
+
+int wext_deinit_mac_filter(void)
+{
+ if(mf_list_head == NULL){
+ return -1;
+ }
+ struct list_head *iterator;
+ rtw_mac_filter_list_t *item;
+ list_for_each(iterator, mf_list_head) {
+ item = list_entry(iterator, rtw_mac_filter_list_t, node);
+ list_del(iterator);
+ free(item);
+ item = NULL;
+ iterator = mf_list_head;
+ }
+
+ free(mf_list_head);
+ mf_list_head = NULL;
+ return 0;
+}
+
+int wext_add_mac_filter(unsigned char* hwaddr)
+{
+ if(mf_list_head == NULL){
+ return -1;
+ }
+
+ rtw_mac_filter_list_t *mf_list_new;
+ mf_list_new = malloc(sizeof(rtw_mac_filter_list_t));
+ if(mf_list_new == NULL){
+ wext_printf("ERROR: %s : can't allocate mf_list_new",__func__);
+ return -1;
+ }
+ memcpy(mf_list_new->mac_addr,hwaddr,6);
+ list_add(&(mf_list_new->node), mf_list_head);
+
+ return 0;
+}
+
+int wext_del_mac_filter(unsigned char* hwaddr)
+{
+ if(mf_list_head == NULL){
+ return -1;
+ }
+
+ struct list_head *iterator;
+ rtw_mac_filter_list_t *item;
+ list_for_each(iterator, mf_list_head) {
+ item = list_entry(iterator, rtw_mac_filter_list_t, node);
+ if(memcmp(item->mac_addr,hwaddr,6) == 0){
+ list_del(iterator);
+ free(item);
+ item = NULL;
+ return 0;
+ }
+ }
+ return -1;
+}
diff --git a/RTL00_SDKV35a/component/common/api/wifi/wifi_util.h b/RTL00_SDKV35a/component/common/api/wifi/wifi_util.h
new file mode 100644
index 0000000..aa691d6
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi/wifi_util.h
@@ -0,0 +1,75 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
+#include
+#include
+#include
+#include "wifi_structures.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int wext_get_ssid(const char *ifname, __u8 *ssid);
+int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
+int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value);
+int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len);
+int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase);
+int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len);
+int wext_get_passphrase(const char *ifname, __u8 *passphrase);
+int wext_set_mode(const char *ifname, int mode);
+int wext_get_mode(const char *ifname, int *mode);
+int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
+int wext_set_country(const char *ifname, rtw_country_code_t country_code);
+int wext_get_rssi(const char *ifname, int *rssi);
+int wext_set_channel(const char *ifname, __u8 ch);
+int wext_get_channel(const char *ifname, __u8 *ch);
+int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac);
+int wext_unregister_multicast_address(const char *ifname, rtw_mac_t *mac);
+int wext_set_scan(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
+int wext_get_scan(const char *ifname, char *buf, __u16 buf_len);
+int wext_set_mac_address(const char *ifname, char * mac);
+int wext_get_mac_address(const char *ifname, char * mac);
+int wext_enable_powersave(const char *ifname, __u8 lps_mode, __u8 ips_mode);
+int wext_disable_powersave(const char *ifname);
+int wext_set_tdma_param(const char *ifname, __u8 slot_period, __u8 rfon_period_len_1, __u8 rfon_period_len_2, __u8 rfon_period_len_3);
+int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim);
+int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim);
+int wext_get_tx_power(const char *ifname, __u8 *poweridx);
+int wext_set_txpower(const char *ifname, int poweridx);
+int wext_get_associated_client_list(const char *ifname, void * client_list_buffer, __u16 buffer_length);
+int wext_get_ap_info(const char *ifname, rtw_bss_info_t * ap_info, rtw_security_t* security);
+int wext_mp_command(const char *ifname, char *cmd, int show_msg);
+int wext_private_command(const char *ifname, char *cmd, int show_msg);
+int wext_private_command_with_retval(const char *ifname, char *cmd, char *ret_buf, int ret_len);
+void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra);
+int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config, __u8 length);
+int wext_set_autoreconnect(const char *ifname, __u8 mode, __u8 retyr_times, __u16 timeout);
+int wext_get_autoreconnect(const char *ifname, __u8 *mode);
+int wext_set_adaptivity(rtw_adaptivity_mode_t adaptivity_mode);
+int wext_set_adaptivity_th_l2h_ini(__u8 l2h_threshold);
+int wext_get_auto_chl(const char *ifname, unsigned char *channel_set, unsigned char channel_num);
+int wext_set_sta_num(unsigned char ap_sta_num);
+int wext_del_station(const char *ifname, unsigned char* hwaddr);
+int wext_init_mac_filter(void);
+int wext_deinit_mac_filter(void);
+int wext_add_mac_filter(unsigned char* hwaddr);
+int wext_del_mac_filter(unsigned char* hwaddr);
+int wext_set_tos_value(const char *ifname, __u8 *tos_value);
+#ifdef CONFIG_CUSTOM_IE
+int wext_add_custom_ie(const char *ifname, void * cus_ie, int ie_num);
+int wext_update_custom_ie(const char *ifname, void * cus_ie, int ie_index);
+int wext_del_custom_ie(const char *ifname);
+#endif
+
+#define wext_handshake_done rltk_wlan_handshake_done
+
+int wext_send_mgnt(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
+int wext_send_eapol(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
+int wext_set_gen_ie(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UTIL_H */
diff --git a/RTL00_SDKV35a/component/common/api/wifi_interactive_ext.h b/RTL00_SDKV35a/component/common/api/wifi_interactive_ext.h
new file mode 100644
index 0000000..7f4afc5
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi_interactive_ext.h
@@ -0,0 +1,42 @@
+#define CONFIG_EXTERN_TEST 0
+#define CONFIG_EXTERN_HW 0
+#define CONFIG_EXTERN_CLOUD 0
+#define CONFIG_TTCP 0
+
+/* External Function */
+#if CONFIG_EXTERN_TEST
+extern void cmd_tcpecho(int argc, char **argv);
+#endif
+#if CONFIG_EXTERN_HW
+extern void cmd_led(int argc, char **argv);
+extern void cmd_tmp75(int argc, char **argv);
+#endif
+#if CONFIG_EXTERN_CLOUD
+extern void cmd_cloud(int argc, char **argv);
+extern void cmd_reboot(int argc, char **argv);
+extern void cmd_config(int argc, char **argv);
+#endif
+
+#if CONFIG_TTCP
+extern void cmd_ttcp(int argc, char **argv);
+#endif
+
+
+static const cmd_entry ext_cmd_table[] = {
+#if CONFIG_EXTERN_TEST
+ {"tcpecho", cmd_tcpecho},
+#endif
+#if CONFIG_EXTERN_HW
+ {"led", cmd_led},
+ {"tmp75", cmd_tmp75},
+#endif
+#if CONFIG_EXTERN_CLOUD
+ {"cloud", cmd_cloud},
+ {"reboot", cmd_reboot},
+ {"config", cmd_config},
+#endif
+#if CONFIG_TTCP
+ {"ttcp", cmd_ttcp},
+#endif
+ {"", NULL}
+};
diff --git a/RTL00_SDKV35a/component/common/api/wifi_interactive_mode.c b/RTL00_SDKV35a/component/common/api/wifi_interactive_mode.c
new file mode 100644
index 0000000..45eba1a
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/api/wifi_interactive_mode.c
@@ -0,0 +1,1246 @@
+
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#include "main.h"
+#include
+#include "tcpip.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifndef CONFIG_INTERACTIVE_EXT
+#define CONFIG_INTERACTIVE_EXT 0
+#endif
+#ifndef CONFIG_SSL_CLIENT
+#if defined(CONFIG_PLATFORM_8711B)
+#define CONFIG_SSL_CLIENT 0
+#else
+#define CONFIG_SSL_CLIENT 1
+#endif
+#endif
+
+#ifndef CONFIG_GOOGLENEST
+#define CONFIG_GOOGLENEST 0
+#endif
+#if CONFIG_LWIP_LAYER
+#ifndef CONFIG_WEBSERVER
+#define CONFIG_WEBSERVER 0
+#endif
+#endif
+#ifndef CONFIG_OTA_UPDATE
+#define CONFIG_OTA_UPDATE 0
+#endif
+#ifndef CONFIG_BSD_TCP
+#define CONFIG_BSD_TCP 0
+#endif
+#define CONFIG_JD_SMART 0
+#ifndef CONFIG_ENABLE_P2P
+#define CONFIG_ENABLE_P2P 0
+#endif
+#define SCAN_WITH_SSID 0
+
+#ifdef CONFIG_WPS
+#define STACKSIZE 1280
+#else
+#define STACKSIZE 1024
+#endif
+
+#ifndef WLAN0_NAME
+ #define WLAN0_NAME "wlan0"
+#endif
+#ifndef WLAN1_NAME
+ #define WLAN1_NAME "wlan1"
+#endif
+/* Give default value if not defined */
+#ifndef NET_IF_NUM
+#ifdef CONFIG_CONCURRENT_MODE
+#define NET_IF_NUM 2
+#else
+#define NET_IF_NUM 1
+#endif
+#endif
+
+/*Static IP ADDRESS*/
+#ifndef IP_ADDR0
+#define IP_ADDR0 192
+#define IP_ADDR1 168
+#define IP_ADDR2 1
+#define IP_ADDR3 80
+#endif
+
+/*NETMASK*/
+#ifndef NETMASK_ADDR0
+#define NETMASK_ADDR0 255
+#define NETMASK_ADDR1 255
+#define NETMASK_ADDR2 255
+#define NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef GW_ADDR0
+#define GW_ADDR0 192
+#define GW_ADDR1 168
+#define GW_ADDR2 1
+#define GW_ADDR3 1
+#endif
+
+/*Static IP ADDRESS*/
+#ifndef AP_IP_ADDR0
+#define AP_IP_ADDR0 192
+#define AP_IP_ADDR1 168
+#define AP_IP_ADDR2 43
+#define AP_IP_ADDR3 1
+#endif
+
+/*NETMASK*/
+#ifndef AP_NETMASK_ADDR0
+#define AP_NETMASK_ADDR0 255
+#define AP_NETMASK_ADDR1 255
+#define AP_NETMASK_ADDR2 255
+#define AP_NETMASK_ADDR3 0
+#endif
+
+/*Gateway Address*/
+#ifndef AP_GW_ADDR0
+#define AP_GW_ADDR0 192
+#define AP_GW_ADDR1 168
+#define AP_GW_ADDR2 43
+#define AP_GW_ADDR3 1
+#endif
+
+static void cmd_help(int argc, char **argv);
+#if CONFIG_SSL_CLIENT
+extern void cmd_ssl_client(int argc, char **argv);
+#endif
+
+#if CONFIG_GOOGLENEST
+extern void cmd_googlenest(int argc, char **argv);
+#endif
+#if CONFIG_JD_SMART
+extern void cmd_jd_smart(int argc, char **argv);
+#endif
+#if CONFIG_WLAN
+static void cmd_wifi_on(int argc, char **argv);
+static void cmd_wifi_off(int argc, char **argv);
+static void cmd_wifi_disconnect(int argc, char **argv);
+extern void cmd_promisc(int argc, char **argv);
+extern void cmd_simple_config(int argc, char **argv);
+
+#if CONFIG_OTA_UPDATE
+extern void cmd_update(int argc, char **argv);
+#endif
+#if CONFIG_BSD_TCP
+extern void cmd_tcp(int argc, char **argv);
+extern void cmd_udp(int argc, char **argv);
+#endif
+#if CONFIG_WEBSERVER
+extern void start_web_server(void);
+extern void stop_web_server(void);
+#endif
+extern void cmd_app(int argc, char **argv);
+#ifdef CONFIG_WPS
+#if CONFIG_ENABLE_WPS
+extern void cmd_wps(int argc, char **argv);
+#endif
+#ifdef CONFIG_WPS_AP
+extern void cmd_ap_wps(int argc, char **argv);
+extern int wpas_wps_dev_config(u8 *dev_addr, u8 bregistrar);
+#endif //CONFIG_WPS_AP
+#endif //CONFIG_WPS
+#if CONFIG_ENABLE_P2P
+extern void cmd_wifi_p2p_start(int argc, char **argv);
+extern void cmd_wifi_p2p_stop(int argc, char **argv);
+extern void cmd_p2p_listen(int argc, char **argv);
+extern void cmd_p2p_find(int argc, char **argv);
+extern void cmd_p2p_peers(int argc, char **argv);
+extern void cmd_p2p_info(int argc, char **argv);
+extern void cmd_p2p_disconnect(int argc, char **argv);
+extern void cmd_p2p_connect(int argc, char **argv);
+#endif //CONFIG_ENABLE_P2P
+#if defined(CONFIG_RTL8195A) || defined(CONFIG_RTL8711B)
+extern u32 CmdDumpWord(IN u16 argc, IN u8 *argv[]);
+extern u32 CmdWriteWord(IN u16 argc, IN u8 *argv[]);
+#endif
+#if CONFIG_LWIP_LAYER
+extern struct netif xnetif[NET_IF_NUM];
+#endif
+#ifdef CONFIG_CONCURRENT_MODE
+static void cmd_wifi_sta_and_ap(int argc, char **argv)
+{
+ int timeout = 20;//, mode;
+#if CONFIG_LWIP_LAYER
+ struct netif * pnetiff = (struct netif *)&xnetif[1];
+#endif
+ int channel;
+
+ if((argc != 3) && (argc != 4)) {
+ printf("Usage: wifi_ap SSID CHANNEL [PASSWORD]\n");
+ return;
+ }
+
+ if(atoi((const char *)argv[2]) > 14){
+ printf(" bad channel!Usage: wifi_ap SSID CHANNEL [PASSWORD]\n");
+ return;
+ }
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+
+#if 0
+ //Check mode
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ switch(mode) {
+ case IW_MODE_MASTER: //In AP mode
+ cmd_wifi_off(0, NULL);
+ cmd_wifi_on(0, NULL);
+ break;
+ case IW_MODE_INFRA: //In STA mode
+ if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
+ cmd_wifi_disconnect(0, NULL);
+ }
+#endif
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_STA_AP) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ return;
+ }
+
+ printf("Starting AP ...\n");
+ channel = atoi((const char *)argv[2]);
+ if(channel > 13){
+ printf("Channel is from 1 to 13. Set channel 1 as default!\n");
+ channel = 1;
+ }
+
+ if(argc == 4) {
+ if(wifi_start_ap(argv[1],
+ RTW_SECURITY_WPA2_AES_PSK,
+ argv[3],
+ strlen((const char *)argv[1]),
+ strlen((const char *)argv[3]),
+ channel
+ ) != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n\n");
+ return;
+ }
+ }
+ else {
+ if(wifi_start_ap(argv[1],
+ RTW_SECURITY_OPEN,
+ NULL,
+ strlen((const char *)argv[1]),
+ 0,
+ channel
+ ) != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n");
+ return;
+ }
+ }
+
+ while(1) {
+ char essid[33];
+
+ if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
+ if(strcmp((const char *) essid, (const char *)argv[1]) == 0) {
+ printf("%s started\n", argv[1]);
+ break;
+ }
+ }
+
+ if(timeout == 0) {
+ printf("ERROR: Start AP timeout!\n");
+ break;
+ }
+
+ vTaskDelay(1 * configTICK_RATE_HZ);
+ timeout --;
+ }
+#if CONFIG_LWIP_LAYER
+ LwIP_UseStaticIP(&xnetif[1]);
+#ifdef CONFIG_DONT_CARE_TP
+ pnetiff->flags |= NETIF_FLAG_IPSWITCH;
+#endif
+ dhcps_init(pnetiff);
+#endif
+}
+#endif
+
+static void cmd_wifi_ap(int argc, char **argv)
+{
+ int timeout = 20;
+#if CONFIG_LWIP_LAYER
+ struct ip_addr ipaddr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+ struct netif * pnetif = &xnetif[0];
+#endif
+ int channel;
+
+ if((argc != 3) && (argc != 4)) {
+ printf("Usage: wifi_ap SSID CHANNEL [PASSWORD]\n");
+ return;
+ }
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+ IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
+ IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
+ netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
+#ifdef CONFIG_DONT_CARE_TP
+ pnetif->flags |= NETIF_FLAG_IPSWITCH;
+#endif
+#endif
+#if 0
+ //Check mode
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ switch(mode) {
+ case IW_MODE_MASTER: //In AP mode
+ wifi_off();
+ wifi_on(1);
+ break;
+ case IW_MODE_INFRA: //In STA mode
+ if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
+ cmd_wifi_disconnect(0, NULL);
+ }
+#else
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_AP) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ return;
+ }
+#endif
+
+ printf("Starting AP ...\n");
+ channel = atoi((const char *)argv[2]);
+ if(channel > 13){
+ printf("Channel is from 1 to 13. Set channel 1 as default!\n");
+ channel = 1;
+ }
+#ifdef CONFIG_WPS_AP
+ wpas_wps_dev_config(pnetif->hwaddr, 1);
+#endif
+
+ if(argc == 4) {
+ if(wifi_start_ap(argv[1],
+ RTW_SECURITY_WPA2_AES_PSK,
+ argv[3],
+ strlen((const char *)argv[1]),
+ strlen((const char *)argv[3]),
+ channel
+ ) != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n");
+ return;
+ }
+ }
+ else {
+ if(wifi_start_ap(argv[1],
+ RTW_SECURITY_OPEN,
+ NULL,
+ strlen((const char *)argv[1]),
+ 0,
+ channel
+ ) != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n");
+ return;
+ }
+ }
+
+ while(1) {
+ char essid[33];
+
+ if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) {
+ if(strcmp((const char *) essid, (const char *)argv[1]) == 0) {
+ printf("%s started\n", argv[1]);
+ break;
+ }
+ }
+
+ if(timeout == 0) {
+ printf("ERROR: Start AP timeout!\n");
+ break;
+ }
+
+ vTaskDelay(1 * configTICK_RATE_HZ);
+ timeout --;
+ }
+#if CONFIG_LWIP_LAYER
+ //LwIP_UseStaticIP(pnetif);
+ dhcps_init(pnetif);
+#endif
+}
+
+static void cmd_wifi_connect(int argc, char **argv)
+{
+ int ret = RTW_ERROR;
+ unsigned long tick1 = xTaskGetTickCount();
+ unsigned long tick2, tick3;
+ int mode;
+ char *ssid;
+ rtw_security_t security_type;
+ char *password;
+ int ssid_len;
+ int password_len;
+ int key_id;
+ void *semaphore;
+
+ if((argc != 2) && (argc != 3) && (argc != 4)) {
+ printf("Usage: wifi_connect SSID [WPA PASSWORD / (5 or 13) ASCII WEP KEY] [WEP KEY ID 0/1/2/3]\n");
+ return;
+ }
+
+ //Check if in AP mode
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ if(mode == IW_MODE_MASTER) {
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_STA) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ return;
+ }
+ }
+
+ ssid = argv[1];
+ if(argc == 2){
+ security_type = RTW_SECURITY_OPEN;
+ password = NULL;
+ ssid_len = strlen((const char *)argv[1]);
+ password_len = 0;
+ key_id = 0;
+ semaphore = NULL;
+ }else if(argc ==3){
+ security_type = RTW_SECURITY_WPA2_AES_PSK;
+ password = argv[2];
+ ssid_len = strlen((const char *)argv[1]);
+ password_len = strlen((const char *)argv[2]);
+ key_id = 0;
+ semaphore = NULL;
+ }else{
+ security_type = RTW_SECURITY_WEP_PSK;
+ password = argv[2];
+ ssid_len = strlen((const char *)argv[1]);
+ password_len = strlen((const char *)argv[2]);
+ key_id = atoi(argv[3]);
+ if(( password_len != 5) && (password_len != 13)) {
+ printf("Wrong WEP key length. Must be 5 or 13 ASCII characters.\n");
+ return;
+ }
+ if((key_id < 0) || (key_id > 3)) {
+ printf("Wrong WEP key id. Must be one of 0,1,2, or 3.\n");
+ return;
+ }
+ semaphore = NULL;
+ }
+
+ ret = wifi_connect(ssid,
+ security_type,
+ password,
+ ssid_len,
+ password_len,
+ key_id,
+ semaphore);
+
+ tick2 = xTaskGetTickCount();
+ printf("Connected after %dms.\n", (tick2-tick1));
+ if(ret != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n");
+ return;
+ } else {
+#if CONFIG_LWIP_LAYER
+ /* Start DHCPClient */
+ LwIP_DHCP(0, DHCP_START);
+ tick3 = xTaskGetTickCount();
+ printf("Got IP after %dms.\n", (tick3-tick1));
+#endif
+#if CONFIG_WLAN_CONNECT_CB
+ extern void connect_start(void);
+ connect_start();
+#endif
+ }
+}
+
+static void cmd_wifi_connect_bssid(int argc, char **argv)
+{
+ int ret = RTW_ERROR;
+ unsigned long tick1 = xTaskGetTickCount();
+ unsigned long tick2, tick3;
+ int mode;
+ unsigned char bssid[ETH_ALEN];
+ char *ssid = NULL;
+ rtw_security_t security_type;
+ char *password;
+ int bssid_len;
+ int ssid_len = 0;
+ int password_len;
+ int key_id;
+ void *semaphore;
+ u32 mac[ETH_ALEN];
+ u32 i;
+ u32 index = 0;
+
+ if((argc != 3) && (argc != 4) && (argc != 5) && (argc != 6)) {
+ printf("Usage: wifi_connect_bssid 0/1 [SSID] BSSID / xx:xx:xx:xx:xx:xx [WPA PASSWORD / (5 or 13) ASCII WEP KEY] [WEP KEY ID 0/1/2/3]\n");
+ return;
+ }
+
+ //Check if in AP mode
+ wext_get_mode(WLAN0_NAME, &mode);
+
+ if(mode == IW_MODE_MASTER) {
+#if CONFIG_LWIP_LAYER
+ dhcps_deinit();
+#endif
+ wifi_off();
+ vTaskDelay(20);
+ if (wifi_on(RTW_MODE_STA) < 0){
+ printf("ERROR: Wifi on failed!\n");
+ return;
+ }
+ }
+ //check ssid
+ if(memcmp(argv[1], "0", 1)){
+ index = 1;
+ ssid_len = strlen((const char *)argv[2]);
+ if((ssid_len <= 0) || (ssid_len > 32)) {
+ printf("Wrong ssid. Length must be less than 32.\n");
+ return;
+ }
+ ssid = argv[2];
+ }
+ sscanf(argv[2 + index], MAC_FMT, mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5);
+ for(i=0; i 3)) {
+ printf("Wrong WEP key id. Must be one of 0,1,2, or 3.\n");
+ return;
+ }
+ semaphore = NULL;
+ }
+
+ ret = wifi_connect_bssid(bssid,
+ ssid,
+ security_type,
+ password,
+ bssid_len,
+ ssid_len,
+ password_len,
+ key_id,
+ semaphore);
+
+ tick2 = xTaskGetTickCount();
+ printf("Connected after %dms.\n", (tick2-tick1));
+ if(ret != RTW_SUCCESS) {
+ printf("ERROR: Operation failed!\n");
+ return;
+ } else {
+#if CONFIG_LWIP_LAYER
+ /* Start DHCPClient */
+ LwIP_DHCP(0, DHCP_START);
+#endif
+ }
+ tick3 = xTaskGetTickCount();
+ printf("Got IP after %dms.\n", (tick3-tick1));
+}
+
+static void cmd_wifi_disconnect(int argc, char **argv)
+{
+ int timeout = 20;
+ char essid[33];
+
+ printf("Deassociating AP ...\n");
+
+ if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
+ printf("WIFI disconnected\n");
+ return;
+ }
+
+ if(wifi_disconnect() < 0) {
+ printf("ERROR: Operation failed!\n");
+ return;
+ }
+
+ while(1) {
+ if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
+ printf("WIFI disconnected\n");
+ break;
+ }
+
+ if(timeout == 0) {
+ printf("ERROR: Deassoc timeout!\n");
+ break;
+ }
+
+ vTaskDelay(1 * configTICK_RATE_HZ);
+ timeout --;
+ }
+}
+
+static void cmd_wifi_info(int argc, char **argv)
+{
+ int i = 0;
+#if CONFIG_LWIP_LAYER
+ u8 *mac = LwIP_GetMAC(&xnetif[0]);
+ u8 *ip = LwIP_GetIP(&xnetif[0]);
+ u8 *gw = LwIP_GetGW(&xnetif[0]);
+#endif
+ u8 *ifname[2] = {WLAN0_NAME,WLAN1_NAME};
+#ifdef CONFIG_MEM_MONITOR
+ extern int min_free_heap_size;
+#endif
+
+ rtw_wifi_setting_t setting;
+ for(i=0;i %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ;
+ printf("\tIP => %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ printf("\tGW => %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]);
+#endif
+ if(setting.mode == RTW_MODE_AP || i == 1)
+ {
+ int client_number;
+ struct {
+ int count;
+ rtw_mac_t mac_list[AP_STA_NUM];
+ } client_info;
+
+ client_info.count = AP_STA_NUM;
+ wifi_get_associated_client_list(&client_info, sizeof(client_info));
+
+ printf("Associated Client List:\n==============================\n");
+
+ if(client_info.count == 0)
+ printf("Client Num: 0\n");
+ else
+ {
+ printf("Client Num: %d\n", client_info.count);
+ for( client_number=0; client_number < client_info.count; client_number++ )
+ {
+ printf("Client [%d]:\n", client_number);
+ printf("\tMAC => "MAC_FMT"\n",
+ MAC_ARG(client_info.mac_list[client_number].octet));
+ }
+// printf("\n\r");
+ }
+ }
+
+ {
+ int error = wifi_get_last_error();
+ printf("Last Link Error\n==============================\n");
+ switch(error)
+ {
+ case RTW_NO_ERROR:
+ printf("\tNo Error\n");
+ break;
+ case RTW_NONE_NETWORK:
+ printf("\tTarget AP Not Found\n");
+ break;
+ case RTW_CONNECT_FAIL:
+ printf("\tAssociation Failed\n");
+ break;
+ case RTW_WRONG_PASSWORD:
+ printf("\tWrong Password\n");
+ break;
+ case RTW_DHCP_FAIL:
+ printf("\tDHCP Failed\n");
+ break;
+ default:
+ printf("\tUnknown Error(%d)\n", error);
+ }
+// printf("\n\r");
+ }
+ }
+ }
+
+#if defined(configUSE_TRACE_FACILITY) && (configUSE_TRACE_FACILITY == 1)
+ {
+ signed char pcWriteBuffer[1024];
+ vTaskList((char*)pcWriteBuffer);
+ printf("Task List: \n%s\n", pcWriteBuffer);
+ }
+#endif
+#ifdef CONFIG_MEM_MONITOR
+ printf("Memory Usage\n==============================\n");
+ printf("Min Free Heap Size: %d\n", min_free_heap_size);
+ printf("Cur Free Heap Size: %d\n", xPortGetFreeHeapSize());
+#endif
+}
+
+static void cmd_wifi_on(int argc, char **argv)
+{
+ if(wifi_on(RTW_MODE_STA)<0){
+ printf("ERROR: Wifi on failed!\n");
+ }
+}
+
+static void cmd_wifi_off(int argc, char **argv)
+{
+#if CONFIG_WEBSERVER
+ stop_web_server();
+#endif
+#if CONFIG_ENABLE_P2P
+ cmd_wifi_p2p_stop(0, NULL);
+#else
+ wifi_off();
+#endif
+}
+
+static void print_scan_result( rtw_scan_result_t* record )
+{
+ RTW_API_INFO( ( "%s\t ", ( record->bss_type == RTW_BSS_TYPE_ADHOC ) ? "Adhoc" : "Infra" ) );
+ RTW_API_INFO( ( MAC_FMT, MAC_ARG(record->BSSID.octet) ) );
+ RTW_API_INFO( ( " %d\t ", record->signal_strength ) );
+ RTW_API_INFO( ( " %d\t ", record->channel ) );
+ RTW_API_INFO( ( " %d\t ", record->wps_type ) );
+ RTW_API_INFO( ( "%s\t\t ", ( record->security == RTW_SECURITY_OPEN ) ? "Open" :
+ ( record->security == RTW_SECURITY_WEP_PSK ) ? "WEP" :
+ ( record->security == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
+ ( record->security == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
+ ( record->security == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
+ ( record->security == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
+ ( record->security == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
+ ( record->security == RTW_SECURITY_WPA_WPA2_MIXED ) ? "WPA/WPA2 AES" :
+ "Unknown" ) );
+
+ RTW_API_INFO( ( " %s ", record->SSID.val ) );
+ RTW_API_INFO( ( "\r\n" ) );
+}
+
+static rtw_result_t app_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
+{
+ static int ApNum = 0;
+
+ if (malloced_scan_result->scan_complete != RTW_TRUE) {
+ rtw_scan_result_t* record = &malloced_scan_result->ap_details;
+ record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
+
+ RTW_API_INFO( ( "%d\t ", ++ApNum ) );
+
+ print_scan_result(record);
+ } else{
+ ApNum = 0;
+ }
+ return RTW_SUCCESS;
+}
+#if SCAN_WITH_SSID
+static void cmd_wifi_scan_with_ssid(int argc, char **argv)
+{
+
+ u8 *channel_list = NULL;
+ u8 *pscan_config = NULL;
+
+ char *ssid = NULL;
+ int ssid_len = 0;
+ //Fully scan
+ int scan_buf_len = 500;
+ if(argc == 3 && argv[1] && argv[2]){
+ ssid = argv[1];
+ ssid_len = strlen((const char *)argv[1]);
+ if((ssid_len <= 0) || (ssid_len > 32)) {
+ printf("Wrong ssid. Length must be less than 32.\n");
+ goto exit;
+ }
+ scan_buf_len = atoi(argv[2]);
+ if(scan_buf_len < 36){
+ printf("BUFFER_LENGTH too short\n");
+ goto exit;
+ }
+ }else if(argc > 3){
+ int i = 0;
+ int num_channel = atoi(argv[2]);
+ ssid = argv[1];
+ ssid_len = strlen((const char *)argv[1]);
+ if((ssid_len <= 0) || (ssid_len > 32)) {
+ printf("Wrong ssid. Length must be less than 32.\n");
+ goto exit;
+ }
+ channel_list = (u8*)pvPortMalloc(num_channel);
+ if(!channel_list){
+ printf("ERROR: Can't malloc memory for channel list\n");
+ goto exit;
+ }
+ pscan_config = (u8*)pvPortMalloc(num_channel);
+ if(!pscan_config){
+ printf("ERROR: Can't malloc memory for pscan_config\n");
+ goto exit;
+ }
+ //parse command channel list
+ for(i = 3; i <= argc -1 ; i++){
+ *(channel_list + i - 3) = (u8)atoi(argv[i]);
+ *(pscan_config + i - 3) = PSCAN_ENABLE;
+ }
+ if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){
+ printf("ERROR: wifi set partial scan channel fail\n");
+ goto exit;
+ }
+ }else{
+ printf(" For Scan all channel Usage: wifi_scan_with_ssid ssid BUFFER_LENGTH\n");
+ printf(" For Scan partial channel Usage: wifi_scan_with_ssid ssid num_channels channel_num1 ...\n");
+ return;
+ }
+
+ if(wifi_scan_networks_with_ssid(NULL, &scan_buf_len, ssid, ssid_len) != RTW_SUCCESS){
+ printf("ERROR: wifi scan failed\n");
+ goto exit;
+ }
+
+exit:
+ if(argc > 2 && channel_list)
+ vPortFree(channel_list);
+
+}
+#endif
+static void cmd_wifi_scan(int argc, char **argv)
+{
+
+ u8 *channel_list = NULL;
+ u8 *pscan_config = NULL;
+
+ if(argc > 2){
+ int i = 0;
+ int num_channel = atoi(argv[1]);
+
+ channel_list = (u8*)pvPortMalloc(num_channel);
+ if(!channel_list){
+ printf(" ERROR: Can't malloc memory for channel list\n");
+ goto exit;
+ }
+ pscan_config = (u8*)pvPortMalloc(num_channel);
+ if(!pscan_config){
+ printf(" ERROR: Can't malloc memory for pscan_config\n");
+ goto exit;
+ }
+ //parse command channel list
+ for(i = 2; i <= argc -1 ; i++){
+ *(channel_list + i - 2) = (u8)atoi(argv[i]);
+ *(pscan_config + i - 2) = PSCAN_ENABLE;
+ }
+
+ if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){
+ printf("ERROR: wifi set partial scan channel fail\n");
+ goto exit;
+ }
+
+ }
+
+ if(wifi_scan_networks(app_scan_result_handler, NULL ) != RTW_SUCCESS){
+ printf("ERROR: wifi scan failed\n");
+ goto exit;
+ }
+exit:
+ if(argc > 2 && channel_list)
+ vPortFree(channel_list);
+
+}
+
+#if CONFIG_WEBSERVER
+static void cmd_wifi_start_webserver(int argc, char **argv)
+{
+ start_web_server();
+}
+#endif
+
+static void cmd_wifi_iwpriv(int argc, char **argv)
+{
+ if(argc == 2 && argv[1]) {
+ wext_private_command(WLAN0_NAME, argv[1], 1);
+ }
+ else {
+ printf("Usage: iwpriv COMMAND PARAMETERS\n");
+ }
+}
+#endif //#if CONFIG_WLAN
+
+static void cmd_ping(int argc, char **argv)
+{
+ if(argc == 2) {
+ do_ping_call(argv[1], 0, 5); //Not loop, count=5
+ }
+ else if(argc == 3) {
+ if(strcmp(argv[2], "loop") == 0)
+ do_ping_call(argv[1], 1, 0); //loop, no count
+ else
+ do_ping_call(argv[1], 0, atoi(argv[2])); //Not loop, with count
+ }
+ else {
+ printf("Usage: ping IP [COUNT/loop]\n");
+ }
+}
+#if ( configGENERATE_RUN_TIME_STATS == 1 )
+static char cBuffer[ 512 ];
+static void cmd_cpustat(int argc, char **argv)
+{
+ vTaskGetRunTimeStats( ( char * ) cBuffer );
+ printf( cBuffer );
+}
+#endif
+#if defined(CONFIG_RTL8195A) || defined(CONFIG_RTL8711B)
+static void cmd_dump_reg(int argc, char **argv)
+{
+ CmdDumpWord(argc-1, (u8**)(argv+1));
+}
+static void cmd_edit_reg(int argc, char **argv)
+{
+ CmdWriteWord(argc-1, (u8**)(argv+1));
+}
+#endif
+static void cmd_exit(int argc, char **argv)
+{
+ printf("Leave INTERACTIVE MODE\n");
+ vTaskDelete(NULL);
+}
+
+static void cmd_debug(int argc, char **argv)
+{
+ if(strcmp(argv[1], "ready_trx") == 0) {
+ printf("%d\n", wifi_is_ready_to_transceive((rtw_interface_t)rtw_atoi((u8*)argv[2])));
+ } else if(strcmp(argv[1], "is_up") == 0) {
+ printf("%d\n", wifi_is_up((rtw_interface_t)rtw_atoi((u8*)argv[2])));
+ } else if(strcmp(argv[1], "set_mac") == 0) {
+ printf("%d\n", wifi_set_mac_address(argv[2]));
+ } else if(strcmp(argv[1], "get_mac") == 0) {
+ u8 mac[18] = {0};
+ wifi_get_mac_address((char*)mac);
+ printf("%s\n", mac);
+ } else if(strcmp(argv[1], "ps_on") == 0) {
+ printf("%d\n", wifi_enable_powersave());
+ } else if(strcmp(argv[1], "ps_off") == 0) {
+ printf("%d\n", wifi_disable_powersave());
+#if 0 //TODO
+ } else if(strcmp(argv[1], "get_txpwr") == 0) {
+ int idx;
+ wifi_get_txpower(&idx);
+ printf("%d\n", idx);
+ } else if(strcmp(argv[1], "set_txpwr") == 0) {
+ printf("%d\n", wifi_set_txpower(rtw_atoi((u8*)argv[2])));
+#endif
+ } else if(strcmp(argv[1], "get_clientlist") == 0) {
+ int client_number;
+ struct {
+ int count;
+ rtw_mac_t mac_list[3];
+ } client_info;
+
+ client_info.count = 3;
+
+ printf("%d\n", wifi_get_associated_client_list(&client_info, sizeof(client_info)));
+
+ if( client_info.count == 0 )
+ {
+ RTW_API_INFO(("Clients connected 0..\r\n"));
+ }
+ else
+ {
+ RTW_API_INFO(("Clients connected %d..\r\n", client_info.count));
+ for( client_number=0; client_number < client_info.count; client_number++ )
+ {
+ RTW_API_INFO(("------------------------------------\r\n"));
+ RTW_API_INFO(("| %d | "MAC_FMT" |\r\n",
+ client_number,
+ MAC_ARG(client_info.mac_list[client_number].octet)
+ ));
+ }
+ RTW_API_INFO(("------------------------------------\r\n"));
+ }
+ } else if(strcmp(argv[1], "get_apinfo") == 0) {
+ rtw_bss_info_t ap_info;
+ rtw_security_t sec;
+ if(wifi_get_ap_info(&ap_info, &sec) == RTW_SUCCESS) {
+ RTW_API_INFO( ("\r\nSSID : %s\r\n", (char*)ap_info.SSID ) );
+ RTW_API_INFO( ("BSSID : "MAC_FMT"\r\n", MAC_ARG(ap_info.BSSID.octet)) );
+ RTW_API_INFO( ("RSSI : %d\r\n", ap_info.RSSI) );
+ //RTW_API_INFO( ("SNR : %d\r\n", ap_info.SNR) );
+ RTW_API_INFO( ("Beacon period : %d\r\n", ap_info.beacon_period) );
+ RTW_API_INFO( ( "Security : %s\r\n", ( sec == RTW_SECURITY_OPEN ) ? "Open" :
+ ( sec == RTW_SECURITY_WEP_PSK ) ? "WEP" :
+ ( sec == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
+ ( sec == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
+ ( sec == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
+ ( sec == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
+ ( sec == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
+ "Unknown" ) );
+ }
+ } else if(strcmp(argv[1], "reg_mc") == 0) {
+ rtw_mac_t mac;
+ sscanf(argv[2], MAC_FMT, (int*)(mac.octet+0), (int*)(mac.octet+1), (int*)(mac.octet+2), (int*)(mac.octet+3), (int*)(mac.octet+4), (int*)(mac.octet+5));
+ printf("%d\n", wifi_register_multicast_address(&mac));
+ } else if(strcmp(argv[1], "unreg_mc") == 0) {
+ rtw_mac_t mac;
+ sscanf(argv[2], MAC_FMT, (int*)(mac.octet+0), (int*)(mac.octet+1), (int*)(mac.octet+2), (int*)(mac.octet+3), (int*)(mac.octet+4), (int*)(mac.octet+5));
+ printf("%d\n", wifi_unregister_multicast_address(&mac));
+ } else if(strcmp(argv[1], "get_rssi") == 0) {
+ int rssi = 0;
+ wifi_get_rssi(&rssi);
+ printf("wifi_get_rssi: rssi = %d\n", rssi);
+ } else {
+ printf("Unknown CMD\n");
+ }
+}
+
+typedef struct _cmd_entry {
+ char *command;
+ void (*function)(int, char **);
+} cmd_entry;
+
+static const cmd_entry cmd_table[] = {
+#if CONFIG_WLAN
+ {"wifi_connect", cmd_wifi_connect},
+ {"wifi_connect_bssid", cmd_wifi_connect_bssid},
+ {"wifi_disconnect", cmd_wifi_disconnect},
+ {"wifi_info", cmd_wifi_info},
+ {"wifi_on", cmd_wifi_on},
+ {"wifi_off", cmd_wifi_off},
+ {"wifi_ap", cmd_wifi_ap},
+ {"wifi_scan", cmd_wifi_scan},
+#if SCAN_WITH_SSID
+ {"wifi_scan_with_ssid", cmd_wifi_scan_with_ssid},
+#endif
+ {"iwpriv", cmd_wifi_iwpriv},
+ {"wifi_promisc", cmd_promisc},
+#if CONFIG_OTA_UPDATE
+ {"wifi_update", cmd_update},
+#endif
+#if CONFIG_WEBSERVER
+ {"wifi_start_webserver", cmd_wifi_start_webserver},
+#endif
+#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
+ {"wifi_simple_config", cmd_simple_config},
+#endif
+#ifdef CONFIG_WPS
+#if CONFIG_ENABLE_WPS
+ {"wifi_wps", cmd_wps},
+#endif
+#ifdef CONFIG_WPS_AP
+//pvvx {"wifi_ap_wps", cmd_ap_wps},
+#endif
+#if CONFIG_ENABLE_P2P
+ {"wifi_p2p_start", cmd_wifi_p2p_start},
+ {"wifi_p2p_stop", cmd_wifi_p2p_stop},
+ {"p2p_find", cmd_p2p_find},
+ {"p2p_info", cmd_p2p_info},
+ {"p2p_disconnect", cmd_p2p_disconnect},
+ {"p2p_connect", cmd_p2p_connect},
+#endif
+#endif
+#ifdef CONFIG_CONCURRENT_MODE
+ {"wifi_sta_ap",cmd_wifi_sta_and_ap},
+#endif
+
+#if CONFIG_SSL_CLIENT
+ {"ssl_client", cmd_ssl_client},
+#endif
+#if CONFIG_GOOGLENEST
+ {"gn", cmd_googlenest},
+#endif
+
+#endif
+#if CONFIG_LWIP_LAYER
+// {"app", cmd_app},
+ {"wifi_debug", cmd_debug},
+#if CONFIG_BSD_TCP
+ {"tcp", cmd_tcp},
+ {"udp", cmd_udp},
+#endif
+#if CONFIG_JD_SMART
+ {"jd_smart", cmd_jd_smart},
+#endif
+ {"ping", cmd_ping},
+#endif
+#if ( configGENERATE_RUN_TIME_STATS == 1 )
+ {"cpu", cmd_cpustat},
+#endif
+#if defined(CONFIG_RTL8195A) || defined(CONFIG_RTL8711B)
+ {"dw", cmd_dump_reg},
+ {"ew", cmd_edit_reg},
+#endif
+ {"exit", cmd_exit},
+ {"help", cmd_help}
+};
+
+#if CONFIG_INTERACTIVE_EXT
+/* must include here, ext_cmd_table in wifi_interactive_ext.h uses struct cmd_entry */
+#include
+#endif
+
+static void cmd_help(int argc, char **argv)
+{
+ int i;
+
+ printf("COMMAND LIST:\n");
+ printf("==============================\n");
+
+ for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++)
+ printf("\t%s\n", cmd_table[i].command);
+#if CONFIG_INTERACTIVE_EXT
+ for(i = 0; i < sizeof(ext_cmd_table) / sizeof(ext_cmd_table[0]); i ++)
+ printf("\t%s\n", ext_cmd_table[i].command);
+#endif
+}
+
+#define MAX_ARGC 6
+
+static int parse_cmd(char *buf, char **argv)
+{
+ int argc = 0;
+
+ memset(argv, 0, sizeof(argv)*MAX_ARGC);
+ while((argc < MAX_ARGC) && (*buf != '\0')) {
+ argv[argc] = buf;
+ argc ++;
+ buf ++;
+
+ while((*buf != ' ') && (*buf != '\0'))
+ buf ++;
+
+ while(*buf == ' ') {
+ *buf = '\0';
+ buf ++;
+ }
+ // Don't replace space
+ if(argc == 1){
+ if(strcmp(argv[0], "iwpriv") == 0){
+ if(*buf != '\0'){
+ argv[1] = buf;
+ argc ++;
+ }
+ break;
+ }
+ }
+ }
+
+ return argc;
+}
+
+char uart_buf[64];
+void interactive_mode(void *param)
+{
+ int i, argc;
+ char *argv[MAX_ARGC];
+ extern xSemaphoreHandle uart_rx_interrupt_sema;
+
+ printf("Enter INTERACTIVE MODE\n");
+ printf("\n# ");
+
+ while(1){
+ while(xSemaphoreTake(uart_rx_interrupt_sema, portMAX_DELAY) != pdTRUE);
+
+ if((argc = parse_cmd(uart_buf, argv)) > 0) {
+ int found = 0;
+
+ for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++) {
+ if(strcmp((const char *)argv[0], (const char *)(cmd_table[i].command)) == 0) {
+ cmd_table[i].function(argc, argv);
+ found = 1;
+ break;
+ }
+ }
+#if CONFIG_INTERACTIVE_EXT
+ if(!found) {
+ for(i = 0; i < sizeof(ext_cmd_table) / sizeof(ext_cmd_table[0]); i ++) {
+ if(strcmp(argv[0], ext_cmd_table[i].command) == 0) {
+ ext_cmd_table[i].function(argc, argv);
+ found = 1;
+ break;
+ }
+ }
+ }
+#endif
+ if(!found)
+ printf("unknown command '%s'\n", argv[0]);
+ printf("\n[MEM] After do cmd, available heap %d+%d\n", xPortGetFreeHeapSize(), tcm_heap_freeSpace());
+ }
+
+ printf("\n# ");
+ uart_buf[0] = '\0';
+ }
+}
+
+void start_interactive_mode(void)
+{
+#ifdef SERIAL_DEBUG_RX
+ if(xTaskCreate(interactive_mode, (char const *)"interactive_mode", STACKSIZE, NULL, tskIDLE_PRIORITY + 4, NULL) != pdPASS)
+ printf("%s xTaskCreate failed\n", __FUNCTION__);
+#else
+ printf("ERROR: No SERIAL_DEBUG_RX to support interactive mode!\n");
+#endif
+}
+
+#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
+VOID WlanNormal( IN u16 argc, IN u8 *argv[])
+{
+ u8 i, j= 0;
+ u8* pbuf = (u8*)uart_buf;
+ extern xSemaphoreHandle uart_rx_interrupt_sema;
+
+ memset(uart_buf, 0, sizeof(uart_buf));
+
+ printf("argc=%d\n", argc);
+ for(i = 0 ; i < argc ; i++)
+ {
+ printf("command element [%d] = %s\n", i, argv[i]);
+ for(j = 0; j
+
+/* This include is used to find 8 & 32 bit unsigned integer types */
+#include "rom_wac_brg_types.h"
+
+/* Use AES encrypt/decrypt in wlan ROM codes */
+#include "rom_aes.h"
+extern int aes_set_key( aes_context *ctx, u8 *key, int nbits );
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+#define AES_128 /* if a fast 128 bit key scheduler is needed */
+#define AES_192 /* if a fast 192 bit key scheduler is needed */
+#define AES_256 /* if a fast 256 bit key scheduler is needed */
+#define AES_VAR /* if variable key size scheduler is needed */
+#define AES_MODES /* if support is needed for modes */
+
+/* The following must also be set in assembler files if being used */
+
+#define AES_ENCRYPT /* if support for encryption is needed */
+#define AES_DECRYPT /* if support for decryption is needed */
+#define AES_REV_DKS /* define to reverse decryption key schedule */
+
+#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
+#define N_COLS 4 /* the number of columns in the state */
+
+/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
+/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
+/* or 44, 52 or 60 32-bit words. */
+
+#if defined( AES_VAR ) || defined( AES_256 )
+#define KS_LENGTH 60
+#elif defined( AES_192 )
+#define KS_LENGTH 52
+#else
+#define KS_LENGTH 44
+#endif
+
+#define AES_RETURN INT_RETURN
+
+/* the character array 'inf' in the following structures is used */
+/* to hold AES context information. This AES code uses cx->inf.b[0] */
+/* to hold the number of rounds multiplied by 16. The other three */
+/* elements can be used by code that implements additional modes */
+
+typedef union
+{ uint_32t l;
+ uint_8t b[4];
+} aes_inf;
+
+typedef struct
+{
+#if 0
+ uint_32t ks[KS_LENGTH];
+#else
+ aes_context ctx;
+#endif
+ aes_inf inf;
+} aes_encrypt_ctx;
+
+typedef struct
+{
+#if 0
+ uint_32t ks[KS_LENGTH];
+#else
+ aes_context ctx;
+#endif
+ aes_inf inf;
+} aes_decrypt_ctx;
+
+/* This routine must be called before first use if non-static */
+/* tables are being used */
+
+AES_RETURN aes_init(void);
+
+/* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
+/* those in the range 128 <= key_len <= 256 are given in bits */
+
+#if defined( AES_ENCRYPT )
+
+#if defined( AES_128 ) || defined( AES_VAR)
+AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_192 ) || defined( AES_VAR)
+AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_256 ) || defined( AES_VAR)
+AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_VAR )
+AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]);
+#endif
+
+#if 0
+AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
+#else
+extern void aes_encrypt( aes_context *ctx, u8 input[16], u8 output[16] );
+#endif
+
+#endif
+
+#if defined( AES_DECRYPT )
+
+#if defined( AES_128 ) || defined( AES_VAR)
+AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_192 ) || defined( AES_VAR)
+AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_256 ) || defined( AES_VAR)
+AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_VAR )
+AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]);
+#endif
+
+#if 0
+AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
+#else
+extern void aes_decrypt( aes_context *ctx, u8 input[16], u8 output[16] );
+#endif
+
+#endif
+
+#if defined( AES_MODES )
+
+/* Multiple calls to the following subroutines for multiple block */
+/* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */
+/* long messages incremantally provided that the context AND the iv */
+/* are preserved between all such calls. For the ECB and CBC modes */
+/* each individual call within a series of incremental calls must */
+/* process only full blocks (i.e. len must be a multiple of 16) but */
+/* the CFB, OFB and CTR mode calls can handle multiple incremental */
+/* calls of any length. Each mode is reset when a new AES key is */
+/* set but ECB and CBC operations can be reset without setting a */
+/* new key by setting a new IV value. To reset CFB, OFB and CTR */
+/* without setting the key, aes_mode_reset() must be called and the */
+/* IV must be set. NOTE: All these calls update the IV on exit so */
+/* this has to be reset if a new operation with the same IV as the */
+/* previous one is required (or decryption follows encryption with */
+/* the same IV array). */
+
+AES_RETURN aes_test_alignment_detection(unsigned int n);
+
+AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, const aes_encrypt_ctx cx[1]);
+
+AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, const aes_decrypt_ctx cx[1]);
+
+AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
+
+AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, unsigned char *iv, const aes_decrypt_ctx cx[1]);
+
+AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]);
+
+AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
+
+AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
+
+#define aes_ofb_encrypt aes_ofb_crypt
+#define aes_ofb_decrypt aes_ofb_crypt
+
+AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
+
+typedef void cbuf_inc(unsigned char *cbuf);
+
+#define aes_ctr_encrypt aes_ctr_crypt
+#define aes_ctr_decrypt aes_ctr_crypt
+
+AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
+ int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
+
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/application/apple/WACServer/External/GladmanAES/rom_wac_brg_types.h b/RTL00_SDKV35a/component/common/application/apple/WACServer/External/GladmanAES/rom_wac_brg_types.h
new file mode 100644
index 0000000..e990603
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/apple/WACServer/External/GladmanAES/rom_wac_brg_types.h
@@ -0,0 +1,229 @@
+/*
+---------------------------------------------------------------------------
+Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
+
+The redistribution and use of this software (with or without changes)
+is allowed without the payment of fees or royalties provided that:
+
+ source code distributions include the above copyright notice, this
+ list of conditions and the following disclaimer;
+
+ binary distributions include the above copyright notice, this list
+ of conditions and the following disclaimer in their documentation.
+
+This software is provided 'as is' with no explicit or implied warranties
+in respect of its operation, including, but not limited to, correctness
+and fitness for purpose.
+---------------------------------------------------------------------------
+Issue Date: 20/12/2007
+
+ The unsigned integer types defined here are of the form uint_t where
+ is the length of the type; for example, the unsigned 32-bit type is
+ 'uint_32t'. These are NOT the same as the 'C99 integer types' that are
+ defined in the inttypes.h and stdint.h headers since attempts to use these
+ types have shown that support for them is still highly variable. However,
+ since the latter are of the form uint_t, a regular expression search
+ and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')
+ can be used to convert the types used here to the C99 standard types.
+*/
+
+#ifndef _BRG_TYPES_H
+#define _BRG_TYPES_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#include
+#if 0
+#if defined( _MSC_VER ) && ( _MSC_VER >= 1300 )
+# include
+# define ptrint_t intptr_t
+#elif defined( __ECOS__ )
+# define intptr_t unsigned int
+# define ptrint_t intptr_t
+#elif defined( __GNUC__ ) && ( __GNUC__ >= 3 )
+# include
+# define ptrint_t intptr_t
+#else
+# define ptrint_t int
+#endif
+#else
+# include
+# define ptrint_t intptr_t
+#ifndef u8
+ typedef uint8_t u8;
+#endif
+#ifndef u32
+ typedef uint32_t u32;
+#endif
+#endif
+
+#ifndef BRG_UI8
+# define BRG_UI8
+# if UCHAR_MAX == 255u
+ typedef unsigned char uint_8t;
+# else
+# error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h
+# endif
+#endif
+
+#ifndef BRG_UI16
+# define BRG_UI16
+# if USHRT_MAX == 65535u
+ typedef unsigned short uint_16t;
+# else
+# error Please define uint_16t as a 16-bit unsigned short type in brg_types.h
+# endif
+#endif
+
+#ifndef BRG_UI32
+# define BRG_UI32
+# if UINT_MAX == 4294967295u
+# define li_32(h) 0x##h##u
+ typedef unsigned int uint_32t;
+# elif ULONG_MAX == 4294967295u
+# define li_32(h) 0x##h##ul
+ typedef unsigned long uint_32t;
+# elif defined( _CRAY )
+# error This code needs 32-bit data types, which Cray machines do not provide
+# else
+# error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h
+# endif
+#endif
+
+#ifndef BRG_UI64
+# if defined( __BORLANDC__ ) && !defined( __MSDOS__ )
+# define BRG_UI64
+# define li_64(h) 0x##h##ui64
+ typedef unsigned __int64 uint_64t;
+# elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */
+# define BRG_UI64
+# define li_64(h) 0x##h##ui64
+ typedef unsigned __int64 uint_64t;
+# elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful
+# define BRG_UI64
+# define li_64(h) 0x##h##ull
+ typedef unsigned long long uint_64t;
+# elif defined( __MVS__ )
+# define BRG_UI64
+# define li_64(h) 0x##h##ull
+ typedef unsigned int long long uint_64t;
+# elif defined( UINT_MAX ) && UINT_MAX > 4294967295u
+# if UINT_MAX == 18446744073709551615u
+# define BRG_UI64
+# define li_64(h) 0x##h##u
+ typedef unsigned int uint_64t;
+# endif
+# elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u
+# if ULONG_MAX == 18446744073709551615ul
+# define BRG_UI64
+# define li_64(h) 0x##h##ul
+ typedef unsigned long uint_64t;
+# endif
+# elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u
+# if ULLONG_MAX == 18446744073709551615ull
+# define BRG_UI64
+# define li_64(h) 0x##h##ull
+ typedef unsigned long long uint_64t;
+# endif
+# elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u
+# if ULONG_LONG_MAX == 18446744073709551615ull
+# define BRG_UI64
+# define li_64(h) 0x##h##ull
+ typedef unsigned long long uint_64t;
+# endif
+# endif
+#endif
+
+#if !defined( BRG_UI64 )
+# if defined( NEED_UINT_64T )
+# error Please define uint_64t as an unsigned 64 bit type in brg_types.h
+# endif
+#endif
+
+#ifndef RETURN_VALUES
+# define RETURN_VALUES
+# if defined( DLL_EXPORT )
+# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
+# define VOID_RETURN __declspec( dllexport ) void __stdcall
+# define INT_RETURN __declspec( dllexport ) int __stdcall
+# elif defined( __GNUC__ )
+# define VOID_RETURN __declspec( __dllexport__ ) void
+# define INT_RETURN __declspec( __dllexport__ ) int
+# else
+# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
+# endif
+# elif defined( DLL_IMPORT )
+# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
+# define VOID_RETURN __declspec( dllimport ) void __stdcall
+# define INT_RETURN __declspec( dllimport ) int __stdcall
+# elif defined( __GNUC__ )
+# define VOID_RETURN __declspec( __dllimport__ ) void
+# define INT_RETURN __declspec( __dllimport__ ) int
+# else
+# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
+# endif
+# elif defined( __WATCOMC__ )
+# define VOID_RETURN void __cdecl
+# define INT_RETURN int __cdecl
+# else
+# define VOID_RETURN void
+# define INT_RETURN int
+# endif
+#endif
+
+/* These defines are used to detect and set the memory alignment of pointers.
+ Note that offsets are in bytes.
+
+ ALIGN_OFFSET(x,n) return the positive or zero offset of
+ the memory addressed by the pointer 'x'
+ from an address that is aligned on an
+ 'n' byte boundary ('n' is a power of 2)
+
+ ALIGN_FLOOR(x,n) return a pointer that points to memory
+ that is aligned on an 'n' byte boundary
+ and is not higher than the memory address
+ pointed to by 'x' ('n' is a power of 2)
+
+ ALIGN_CEIL(x,n) return a pointer that points to memory
+ that is aligned on an 'n' byte boundary
+ and is not lower than the memory address
+ pointed to by 'x' ('n' is a power of 2)
+*/
+
+#define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1))
+#define ALIGN_FLOOR(x,n) ((uint_8t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1)))
+#define ALIGN_CEIL(x,n) ((uint_8t*)(x) + (-((ptrint_t)(x)) & ((n) - 1)))
+
+/* These defines are used to declare buffers in a way that allows
+ faster operations on longer variables to be used. In all these
+ defines 'size' must be a power of 2 and >= 8. NOTE that the
+ buffer size is in bytes but the type length is in bits
+
+ UNIT_TYPEDEF(x,size) declares a variable 'x' of length
+ 'size' bits
+
+ BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize'
+ bytes defined as an array of variables
+ each of 'size' bits (bsize must be a
+ multiple of size / 8)
+
+ UNIT_CAST(x,size) casts a variable to a type of
+ length 'size' bits
+
+ UPTR_CAST(x,size) casts a pointer to a pointer to a
+ varaiable of length 'size' bits
+*/
+
+#define UI_TYPE(size) uint_##size##t
+#define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x
+#define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)]
+#define UNIT_CAST(x,size) ((UI_TYPE(size) )(x))
+#define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x))
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/application/google/google_nest.h b/RTL00_SDKV35a/component/common/application/google/google_nest.h
new file mode 100644
index 0000000..c98e612
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/google/google_nest.h
@@ -0,0 +1,23 @@
+#ifndef GOOGLENEST_H
+#define GOOGLENEST_H
+
+#include
+
+typedef struct {
+ int socket;
+ char *host;
+ ssl_context ssl;
+} googlenest_context;
+
+int gn_connect(googlenest_context *googlenest, char *host, int port);
+void gn_close(googlenest_context *googlenest);
+int gn_put(googlenest_context *googlenest, char *uri, char *content);
+int gn_patch(googlenest_context *googlenest, char *uri, char *content);
+int gn_post(googlenest_context *googlenest, char *uri, char *content, unsigned char *out_buffer, size_t out_len);
+int gn_get(googlenest_context *googlenest, char *uri, unsigned char *out_buffer, size_t out_len);
+int gn_delete(googlenest_context *googlenest, char *uri);
+int gn_stream(googlenest_context *googlenest, char *uri);
+void google_retrieve_data_hook_callback(void (*callback)(char *));
+
+#endif
+
diff --git a/RTL00_SDKV35a/component/common/application/uart_adapter/uart_adapter.c b/RTL00_SDKV35a/component/common/application/uart_adapter/uart_adapter.c
new file mode 100644
index 0000000..c69c4a6
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/uart_adapter/uart_adapter.c
@@ -0,0 +1,2250 @@
+#include "FreeRTOS.h"
+#include "task.h"
+#include "main.h"
+#include
+#include
+#include
+#include "serial_api.h"
+#include "serial_ex_api.h"
+#include "uart_adapter.h"
+#include "wifi_conf.h"
+#include "gpio_api.h" // mbed
+#include "gpio_irq_api.h" // mbed
+#include "osdep_service.h"
+#include "flash_api.h"
+#include "device_lock.h"
+//#include
+#include
+#include
+
+#if CONFIG_UART_SOCKET
+
+/***********************************************************************
+ * Macros *
+ ***********************************************************************/
+
+/***********************************************************************
+ * Variables Declarations *
+ ***********************************************************************/
+char ua_tcp_server_ip[16];
+
+_Sema ua_exception_sema;
+_Sema ua_print_sema;
+
+int ua_gpio_irq_happen = 0;
+int ua_debug_print_en = 0;
+int ua_wifi_connected = 0;
+int ua_reconnect_started = 0;
+int ua_reconnect_ip_change = 0;
+
+ua_socket_t *ua_global_socket = NULL;
+gpio_irq_t gpio_rx_wake;
+
+/************************************************************************
+ * extern variables *
+ ************************************************************************/
+extern struct netif xnetif[NET_IF_NUM];
+
+extern unsigned char psk_essid[NET_IF_NUM][NDIS_802_11_LENGTH_SSID+4];
+extern unsigned char psk_passphrase[NET_IF_NUM][IW_PASSPHRASE_MAX_SIZE + 1];
+extern unsigned char wpa_global_PSK[NET_IF_NUM][A_SHA_DIGEST_LEN * 2];
+
+extern wlan_init_done_ptr p_wlan_uart_adapter_callback;
+/************************************************************************
+ * extern funtions *
+ ************************************************************************/
+#if CONFIG_INCLUDE_SIMPLE_CONFIG
+extern enum sc_result simple_config_test(rtw_network_info_t *);
+extern int init_test_data(char *custom_pin_code);
+extern void deinit_test_data(void);
+extern void filter_add_enable();
+extern void remove_filter();
+extern void wifi_enter_promisc_mode();
+#endif
+
+/*************************************************************************
+* uart releated *
+*************************************************************************/
+#define ____________UART__RELATED____________________
+static void uartadapter_uart_irq(uint32_t id, SerialIrq event)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)id;
+
+ if(event == RxIrq) {
+ ua_socket->uart.recv_buf[ua_socket->uart.pwrite++] = serial_getc(&ua_socket->uart.uart_sobj);
+ RtlUpSemaFromISR(&ua_socket->uart.action_sema); //up action semaphore
+
+ if(ua_socket->uart.pwrite > (UA_UART_RECV_BUFFER_LEN -1)){ //restart from head if reach tail
+ ua_socket->uart.pwrite = 0;
+ ua_socket->uart.overlap = 1;
+ }
+
+ if(ua_socket->uart.overlap && (ua_socket->uart.pwrite > ua_socket->uart.pread) ){
+ ua_socket->uart.miss_cnt ++;
+ ua_socket->uart.pread = ua_socket->uart.pwrite; //if pwrite overhead pread ,pread is always flow rwrite
+ }
+ ua_socket->uart.tick_last_update = xTaskGetTickCountFromISR(); // update tick everytime recved data
+ ua_socket->uart.rx_cnt ++;
+ }
+}
+
+static int uartadapter_uart_recv_data(ua_socket_t *ua_socket)
+{
+ int uart_recv_len = 0;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ ua_socket->uart.tick_current = xTaskGetTickCount();
+ while((ua_socket->uart.tick_current -ua_socket->uart.tick_last_update) < (UA_UART_MAX_DELAY_TIME/portTICK_RATE_MS)
+ || ua_socket->uart.tick_current <= ua_socket->uart.tick_last_update){
+ if(!ua_socket->uart.overlap){
+ uart_recv_len = ua_socket->uart.pwrite - ua_socket->uart.pread;
+ }else{
+ uart_recv_len = (UA_UART_RECV_BUFFER_LEN - ua_socket->uart.pread) + ua_socket->uart.pwrite;
+ }
+
+ if(uart_recv_len >= UA_UART_FRAME_LEN){
+ return 2;
+ }
+ //vTaskDelay(10);
+ ua_socket->uart.tick_current = xTaskGetTickCount();
+ }
+
+ return 1;
+}
+
+int uartadapter_uart_read(ua_socket_t *ua_socket, void *read_buf, size_t size)
+{
+ int ret = 0;
+ int read_bytes;
+ int pread_local,pwrite_local;
+ char *ptr;
+
+ ua_printf(UA_DEBUG, "==>uart adapter read uart");
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ if(!size || !read_buf){
+ ua_printf(UA_ERROR, "inpua error,size should not be null");
+ ret = -1;
+ return ret;
+ }
+
+ pread_local = ua_socket->uart.pread;
+ pwrite_local = ua_socket->uart.pwrite;
+ ptr = (char *)read_buf;
+
+ /*calculate how much data not read */
+ if(!ua_socket->uart.overlap){
+ ua_socket->uart.recv_bytes = pwrite_local - pread_local;
+ }else{
+ ua_socket->uart.recv_bytes = (UA_UART_RECV_BUFFER_LEN - pread_local) + pwrite_local;
+ }
+
+ /*decide how much data shoule copy to application*/
+ if(size >= ua_socket->uart.recv_bytes ){
+ read_bytes = ua_socket->uart.recv_bytes;
+ ret = ua_socket->uart.recv_bytes;
+ }else{
+ read_bytes = size;
+ ret = size;
+ }
+
+ if(!ua_socket->uart.overlap){
+ memcpy(ptr, (ua_socket->uart.recv_buf+ pread_local), read_bytes );
+ }else {
+ ua_printf(UA_DEBUG, "uart recv buf is write overlap!!");
+ if((pread_local + read_bytes) > UA_UART_RECV_BUFFER_LEN){
+ memcpy(ptr,(ua_socket->uart.recv_buf+ pread_local),(UA_UART_RECV_BUFFER_LEN-pread_local));
+ memcpy(ptr+(UA_UART_RECV_BUFFER_LEN-pread_local), ua_socket->uart.recv_buf,read_bytes-(UA_UART_RECV_BUFFER_LEN- pread_local));
+ }else{
+ memcpy(ptr,(ua_socket->uart.recv_buf+ pread_local),read_bytes);
+ }
+ }
+
+ ua_socket->uart.recv_bytes = 0;
+ if((pread_local + read_bytes) >= UA_UART_RECV_BUFFER_LEN){ //update pread
+ ua_socket->uart.pread = (pread_local + read_bytes) - UA_UART_RECV_BUFFER_LEN;
+ ua_socket->uart.overlap = 0; //clean overlap flags
+ }else{
+ ua_socket->uart.pread = pread_local + read_bytes;
+ }
+
+ return ret;
+}
+
+int uartadapter_uart_write(ua_socket_t *ua_socket, char *pbuf, size_t size)
+{
+ int ret = -1;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ if(!size || !pbuf) {
+ ret = -1;
+ return ret;
+ }
+
+ while(RtlDownSema(&ua_socket->uart.dma_tx) == pdTRUE){
+ ret = serial_send_stream_dma(&ua_socket->uart.uart_sobj, pbuf, size);
+ if(ret != HAL_OK){
+ ua_printf(UA_ERROR, "uart dma tx error %d!!", ret);
+ RtlUpSema(&ua_socket->uart.dma_tx);
+ return -1;
+ }else{
+ return 0;
+ }
+ }
+
+ return ret;
+}
+
+void uartadapter_uart_send_stream_done(uint32_t id)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)id;
+
+ RtlUpSemaFromISR(&ua_socket->uart.dma_tx);
+}
+
+static void uartadapter_uart_rx_thread(void* param)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+ char *rxbuf = NULL;
+ int ret =0;
+ int read_len = 0;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ rxbuf = pvPortMalloc(UA_UART_FRAME_LEN);
+ if(NULL == rxbuf){
+ ua_printf(UA_ERROR, "TCP: Allocate rx buffer failed.\n");
+ return;
+ }
+
+
+ while(1){
+ if(RtlDownSemaWithTimeout(&ua_socket->uart.action_sema, 1000) == pdTRUE){
+ ret = uartadapter_uart_recv_data(ua_socket);
+ if(ret == -1){
+ ua_printf(UA_ERROR, "uart recv data error!");
+ }else{
+ read_len = uartadapter_uart_read(ua_socket, rxbuf, UA_UART_FRAME_LEN);
+ if(read_len > 0){
+ uartadapter_tcp_send_data(ua_socket, rxbuf, read_len);
+ }else if(read_len < 0){
+ ua_printf(UA_ERROR, "tcp send read_len = %d", read_len);
+ }
+ }
+ }
+#if UA_PS_ENABLE
+ else{
+ ua_socket->uart.uart_ps_cnt++;
+ if(ua_socket->uart.uart_ps_cnt >5){
+ ua_socket->uart.uart_ps_cnt = 5;
+ ua_socket->uart.uart_ps = 1;
+ if(ua_socket->uart.uart_ps && ua_socket->tcp.tcp_ps){
+ release_wakelock(UA_WAKELOCK);
+ }
+ }
+ }
+#endif
+ }
+
+}
+
+void uartadapter_uart_gpio_wakeup_callback (uint32_t id, gpio_irq_event event) {
+ acquire_wakelock(UA_WAKELOCK);
+ ua_socket_t *ua_socket = (ua_socket_t *)id;
+ ua_socket->uart.uart_ps = 0;
+ ua_socket->uart.uart_ps_cnt = 0;
+}
+
+int uartadapter_uart_open(ua_socket_t *ua_socket, ua_uart_set_str *puartpara)
+{
+ PinName uart_tx,uart_rx;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ uart_tx = UA_UART_TX_PIN;
+ uart_rx = UA_UART_RX_PIN;
+ ua_socket->uart.uart_param.BaudRate = puartpara->BaudRate;
+ ua_socket->uart.uart_param.FlowControl = puartpara->FlowControl;
+ ua_socket->uart.uart_param.WordLen = puartpara->number;
+ ua_socket->uart.uart_param.Parity = puartpara->parity;
+ ua_socket->uart.uart_param.StopBit = puartpara->StopBits;
+
+ /*initial uart */
+ serial_init(&ua_socket->uart.uart_sobj, uart_tx, uart_rx);
+ serial_baud(&ua_socket->uart.uart_sobj,puartpara->BaudRate);
+ serial_format(&ua_socket->uart.uart_sobj, puartpara->number, (SerialParity)puartpara->parity, puartpara->StopBits);
+// serial_format(&at_cmd_sobj, uartconf.DataBits, (SerialParity)uartconf.Parity, uartconf.StopBits);
+ serial_rx_fifo_level(&ua_socket->uart.uart_sobj, FifoLvHalf);
+
+ //---------------------------- add Flow
+ #define rxflow UA_UART_RTS_PIN
+ #define txflow UA_UART_CTS_PIN
+ if(puartpara->FlowControl){
+ pin_mode(txflow, PullDown); // init CTS in low
+ serial_set_flow_control(&ua_socket->uart.uart_sobj, FlowControlRTSCTS, rxflow, txflow);
+ }
+ else
+ serial_set_flow_control(&ua_socket->uart.uart_sobj, FlowControlNone, rxflow, txflow);
+ //---------------------------- add Flow
+
+ /*uart irq handle*/
+ serial_irq_handler(&ua_socket->uart.uart_sobj, uartadapter_uart_irq, (uint32_t)ua_socket);
+ serial_irq_set(&ua_socket->uart.uart_sobj, RxIrq, 1);
+ serial_irq_set(&ua_socket->uart.uart_sobj, TxIrq, 1);
+
+ serial_send_comp_handler(&ua_socket->uart.uart_sobj, (void*)uartadapter_uart_send_stream_done, (uint32_t)ua_socket);
+
+#if UA_PS_ENABLE
+ //config uart rx as gpio wakeup pin
+ gpio_irq_t gpio_rx_wake;
+ gpio_irq_init(&gpio_rx_wake, UA_GPIO_WAKEUP_PIN, uartadapter_uart_gpio_wakeup_callback, (uint32_t)ua_socket);
+ gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1); // Falling Edge Trigger
+ gpio_irq_enable(&gpio_rx_wake);
+#endif
+
+ return 0;
+}
+
+int uartadapter_uart_baud(ua_socket_t *ua_socket, int baud_rate)
+{
+ int ret = 0;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ ua_socket->uart.uart_param.BaudRate = baud_rate;
+
+ serial_baud(&ua_socket->uart.uart_sobj, baud_rate);
+
+ return ret;
+}
+
+int uartadapter_uart_para(ua_socket_t *ua_socket, int word_len, int parity, int stop_bits)
+{
+ int ret = 0;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ ua_socket->uart.uart_param.WordLen = word_len;
+ ua_socket->uart.uart_param.Parity = parity;
+ ua_socket->uart.uart_param.StopBit = stop_bits;
+
+ serial_format(&ua_socket->uart.uart_sobj, word_len, (SerialParity)parity, stop_bits);
+
+ return ret;
+}
+
+int uartadapter_uart_getpara(ua_socket_t *ua_socket, ua_uart_get_str *uart_para)
+{
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ uart_para->BaudRate = ua_socket->uart.uart_param.BaudRate;
+ uart_para->FlowControl = ua_socket->uart.uart_param.FlowControl;
+ uart_para->number = ua_socket->uart.uart_param.WordLen;
+ uart_para->parity = ua_socket->uart.uart_param.Parity;
+ uart_para->StopBits = ua_socket->uart.uart_param.StopBit;
+
+ return 0;
+}
+
+void uartadapter_uart_init(ua_socket_t *ua_socket)
+{
+ ua_uart_set_str uartset;
+ ua_uart_get_str uartget;
+ char uarttest[]="uart0";
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ uartset.BaudRate = 9600;
+ uartset.number = 8;
+ uartset.StopBits = 1;
+ uartset.FlowControl = 3;
+ uartset.parity = 0;
+ strcpy(uartset.UartName,uarttest);
+
+ uartadapter_uart_open(ua_socket, &uartset);
+
+ if(uartadapter_uart_getpara(ua_socket, &uartget))
+ ua_printf(UA_ERROR, "get uart failed!");
+ else
+ ua_printf(UA_DEBUG,"uart pata:\r\n"\
+ "uart->BaudRate = %d\r\n"\
+ "uart->number = %d\r\n"\
+ "uart->FlowControl = %d\r\n"\
+ "uart->parity = %d\r\n"\
+ "uart->StopBits = %d\r\n"\
+ "\r\n",\
+ uartget.BaudRate,\
+ uartget.number,\
+ uartget.FlowControl,\
+ uartget.parity,\
+ uartget.StopBits\
+ );
+}
+
+#define _________FLASH___RELATED________________________
+int uartadapter_flashread(int flashadd, char *pbuf, int len)
+{
+ int ret = 0;
+ flash_t flash;
+
+ if( len == 0){
+ ua_printf(UA_ERROR, "input error,data length should not be null!");
+ ret = -1;
+ return ret;
+ }else //as 8711am only canbe r/w in words.so make len is 4-bytes aligmented.
+ len += 4 - ((len%4)==0 ? 4 : (len%4));
+
+ while(len){
+ if(flash_read_word(&flash, flashadd, (unsigned int *)pbuf) !=1 ){
+ ua_printf(UA_ERROR, "read flash error!");
+ ret = -1;
+ return ret;
+ }
+ len -= 4;
+ pbuf += 4;
+ flashadd += 4;
+ }
+
+ return len;
+}
+
+int uartadapter_flashwrite(int flashadd, char *pbuf, int len)
+{
+ int ret = 0;
+ flash_t flash;
+
+ if( len == 0){
+ ua_printf(UA_ERROR, "input error,data length should not be null!");
+ ret = -1;
+ return ret;
+ }
+ else //as 8711am only canbe r/w in words.so make len is 4-bytes aligmented.
+ len += 4 - ((len%4)==0 ? 4 : (len%4));
+
+ while(len){
+ if(flash_write_word(&flash, flashadd, *(unsigned int *)pbuf) !=1 ){
+ ua_printf(UA_ERROR, "write flash error!");
+ ret = -1;
+ return ret;
+ }
+ len -= 4;
+ pbuf += 4;
+ flashadd += 4;
+ }
+
+ return ret;
+}
+
+int uartadapter_flasherase(int flashadd, int erase_bytelen)
+{
+ int ret = 0;
+ flash_t flash;
+ device_mutex_lock(RT_DEV_LOCK_FLASH);
+ flash_erase_sector(&flash, flashadd);
+ device_mutex_unlock(RT_DEV_LOCK_FLASH);
+ return ret;
+}
+
+#define _________GPIO___RELATED________________________
+void uartadapter_systemreload(void)
+{
+ // Cortex-M3 SCB->AIRCR
+ HAL_WRITE32(0xE000ED00, 0x0C, (0x5FA << 16) | // VECTKEY
+ (HAL_READ32(0xE000ED00, 0x0C) & (7 << 8)) | // PRIGROUP
+ (1 << 2)); // SYSRESETREQ
+}
+
+void uartadapter_gpio_irq (uint32_t id, gpio_irq_event event)
+{
+ ua_printf(UA_DEBUG, "GPIO push button!!");
+
+ ua_gpio_irq_happen = 1;
+ RtlUpSemaFromISR(&ua_exception_sema);
+}
+
+void uartadapter_gtimer_timeout_handler(uint32_t id)
+{
+ gpio_t *gpio_led = (gpio_t *)id;
+
+ gpio_write(gpio_led, !gpio_read(gpio_led));
+}
+
+void uartadapter_gpio_init(ua_socket_t *ua_socket)
+{
+ gpio_init(&ua_socket->gpio.gpio_led, UA_GPIO_LED_PIN);
+ gpio_dir(&ua_socket->gpio.gpio_led, PIN_OUTPUT); // Direction: Output
+ gpio_mode(&ua_socket->gpio.gpio_led, PullNone); // No pull
+
+ gpio_init(&ua_socket->gpio.gpio_btn, UA_GPIO_IRQ_PIN);
+ gpio_dir(&ua_socket->gpio.gpio_btn, PIN_INPUT); // Direction: Output
+ gpio_mode(&ua_socket->gpio.gpio_btn, PullNone); // No pull
+
+ gpio_irq_init(&ua_socket->gpio.gpio_btn_irq, UA_GPIO_IRQ_PIN, uartadapter_gpio_irq, (uint32_t)(&ua_socket->gpio.gpio_btn));
+ gpio_irq_set(&ua_socket->gpio.gpio_btn_irq, IRQ_FALL, 1); // Falling Edge Trigger
+ gpio_irq_enable(&ua_socket->gpio.gpio_btn_irq);
+
+ // Initial a periodical timer
+ gtimer_init(&ua_socket->gpio.gpio_timer, TIMER0);
+ //gtimer_start_periodical(&ua_socket->gpio.gpio_timer, 100000, (void*)timer_timeout_handler, (uint32_t)&ua_socket->gpio.gpio_led);
+}
+
+void uartadapter_gpio_led_mode(ua_socket_t *ua_socket, ua_led_mode_t mode)
+{
+ gtimer_stop(&ua_socket->gpio.gpio_timer);
+ switch(mode){
+ case UART_ADAPTER_LED_ON:
+ gpio_write(&ua_socket->gpio.gpio_led, 1);
+ break;
+ case UART_ADAPTER_LED_OFF:
+ gpio_write(&ua_socket->gpio.gpio_led, 0);
+ break;
+ case UART_ADAPTER_LED_FAST_TWINKLE:
+ gtimer_start_periodical(&ua_socket->gpio.gpio_timer, 100000,
+ (void*)uartadapter_gtimer_timeout_handler, (uint32_t)&ua_socket->gpio.gpio_led);
+ break;
+ case UART_ADAPTER_LED_SLOW_TWINKLE:
+ gtimer_start_periodical(&ua_socket->gpio.gpio_timer, 2000000,
+ (void*)uartadapter_gtimer_timeout_handler, (uint32_t)&ua_socket->gpio.gpio_led);
+ break;
+ default:
+ ua_printf(UA_ERROR, "Unknown GPIO LED mode!!");
+ break;
+ }
+}
+
+#define _________CONTROL__DATA__RELATED________________________
+int uartadapter_strncmp(char *cs, char *ct, size_t count)
+{
+ unsigned char c1, c2;
+
+ while (count) {
+ c1 = *cs++;
+ c2 = *ct++;
+ if (c1 != c2)
+ return c1 < c2 ? -1 : 1;
+ if (!c1)
+ break;
+ count--;
+ }
+
+ return 0;
+}
+
+int uartadapter_control_write_tcp_info_into_flash(ua_socket_t *ua_socket)
+{
+ int ret;
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ ua_printf(UA_INFO, "\r\nWrite Uart Adapter tcp connection new profile to flash");
+
+ uartadapter_flasherase(UA_FAST_RECONNECT_TCP_DATA, 0x1000);
+ ret = uartadapter_flashwrite(UA_FAST_RECONNECT_TCP_DATA, (char *)&ua_socket->tcp, sizeof(ua_tcp_socket_t));
+ return ret;
+}
+
+int uartadapter_control_read_tcp_info_and_connect(ua_socket_t *ua_socket)
+{
+ int ret = 0;
+ ua_tcp_socket_t tcp = {0};
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ ua_printf(UA_INFO, "\r\nRead Uart Adapter tcp connection profile from flash");
+
+ uartadapter_flashread(UA_FAST_RECONNECT_TCP_DATA, (u8*)&tcp, sizeof(ua_tcp_socket_t));
+ if(tcp.group_id != ~0x0){
+ if(tcp.group_id){
+ ua_socket->tcp.group_id = tcp.group_id;
+ ua_socket->tcp.server_port = tcp.server_port;
+ ua_socket->tcp.client_port = tcp.client_port;
+ memcpy(ua_socket->tcp.client_ip, tcp.client_ip, 16);
+
+ if(xTaskCreate(uartadapter_tcp_transmit_server_thread, ((const char*)"tserver"), 256, (void *)ua_socket->tcp.server_port, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(tcp server) failed", __FUNCTION__);
+
+ strncpy(ua_tcp_server_ip, ua_socket->tcp.client_ip, 16);
+ if(xTaskCreate(uartadapter_tcp_transmit_client_forever_thread, ((const char*)"tclient"), 256, (void *)ua_socket->tcp.client_port, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(tcp client) failed", __FUNCTION__);
+ }
+ }
+ return 0;
+}
+
+int uartadapter_control_set_req_handle(ua_socket_t *ua_socket, u8 *pbuf, u32 sz)
+{
+ u8 *p = pbuf;
+ u8 len = 0;
+ u16 type = 0;
+ u32 port = 0;
+ u32 server_ip = 0;
+ int ret = 0;
+ struct sockaddr_in server_addr;
+ int server_addr_len = sizeof(server_addr);
+ TXTRecordRef txtRecord;
+ unsigned char txt_buf[100] = {0}; // use fixed buffer for text record to prevent malloc/free
+ unsigned char txt_buf2[100] = {0}; // use fixed buffer for text record to prevent malloc/free
+
+
+ ua_printf(UA_DEBUG, "\n===>uartadapter_control_set_req_handle()");
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ UA_PRINT_DATA(pbuf, sz);
+
+ while(p < (pbuf+sz)){
+ type = (*p)<<8 | *(p+1);
+ p = p + 2;
+ len = *p++;
+ ua_printf(UA_DEBUG, "type=%d len=%d\n", type, len);
+ switch(type)
+ {
+ case UART_CTRL_TYPE_BAUD_RATE:
+ ua_socket->uart.uart_param.BaudRate = *(u32 *)p;
+ ua_printf(UA_INFO, "SET UART BAUD_RATE to %d.\n", ua_socket->uart.uart_param.BaudRate);
+ serial_baud(&ua_socket->uart.uart_sobj, ua_socket->uart.uart_param.BaudRate);
+ break;
+ case UART_CTRL_TYPE_WORD_LEN:
+ ua_socket->uart.uart_param.WordLen = *p;
+ ua_printf(UA_INFO, "SET UART WORD_LEN to %d.\n", ua_socket->uart.uart_param.WordLen);
+ serial_format(&ua_socket->uart.uart_sobj,
+ ua_socket->uart.uart_param.WordLen,
+ (SerialParity)ua_socket->uart.uart_param.Parity,
+ ua_socket->uart.uart_param.StopBit);
+ break;
+ case UART_CTRL_TYPE_PARITY:
+ ua_socket->uart.uart_param.Parity = *p;
+ ua_printf(UA_INFO, "SET UART PARITY to %d.\n", ua_socket->uart.uart_param.Parity);
+ serial_format(&ua_socket->uart.uart_sobj,
+ ua_socket->uart.uart_param.WordLen,
+ (SerialParity)ua_socket->uart.uart_param.Parity,
+ ua_socket->uart.uart_param.StopBit);
+ break;
+ case UART_CTRL_TYPE_STOP_BIT:
+ ua_socket->uart.uart_param.StopBit = *p;
+ ua_printf(UA_INFO, "SET UART STOP_BIT to %d.\n", ua_socket->uart.uart_param.StopBit);
+ serial_format(&ua_socket->uart.uart_sobj,
+ ua_socket->uart.uart_param.WordLen,
+ (SerialParity)ua_socket->uart.uart_param.Parity,
+ ua_socket->uart.uart_param.StopBit);
+ break;
+ case UART_CTRL_TYPE_TCP_SERVER_CREATE:
+ port = (*p)<<8 | *(p+1);
+
+ if(ua_socket->tcp.transmit_server_listen_socket != -1){
+ ua_printf(UA_INFO, "Close old transmit server socket %d", ua_socket->tcp.transmit_server_listen_socket);
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ }
+ if(xTaskCreate(uartadapter_tcp_transmit_server_thread, ((const char*)"tserver"), 256, (void *)port, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(tcp server) failed", __FUNCTION__);
+ ua_socket->tcp.server_port = port;
+ uartadapter_control_write_tcp_info_into_flash(ua_socket);
+ vTaskDelay(50);
+ ua_printf(UA_DEBUG, "CREATE TCP SERVER WITH PORT %d.\n", port);
+ //TODO
+ break;
+ case UART_CTRL_TYPE_TCP_SERVER_DELETE:
+ port = (*p)<<8 | *(p+1);
+
+ if(ua_socket->tcp.transmit_server_listen_socket != -1){
+ getsockname (ua_socket->tcp.transmit_server_listen_socket, (struct sockaddr *)&server_addr, &server_addr_len);
+ if(server_addr.sin_port == ntohs((u16)port)){
+ ua_printf(UA_INFO,"uart tcp transmit server socket %d closed by control socket!", ua_socket->tcp.transmit_server_listen_socket);
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ ua_socket->tcp.transmit_server_listen_socket = -1;
+ if(ua_socket->tcp.transmit_recv_socket != -1){
+ ua_printf(UA_INFO,"uart tcp transmit receive socket %d closed by control socket!", ua_socket->tcp.transmit_recv_socket);
+ close(ua_socket->tcp.transmit_recv_socket);
+ ua_socket->tcp.transmit_recv_socket = -1;
+ }
+
+ if(ua_socket->tcp.transmit_send_socket != -1){
+ ua_printf(UA_INFO,"uart tcp transmit send socket %d closed by control socket!", ua_socket->tcp.transmit_send_socket);
+ close(ua_socket->tcp.transmit_send_socket);
+ ua_socket->tcp.transmit_send_socket = -1;
+ ua_printf(UA_INFO, "DISCONNECT FROM TCP SERVER.\n");
+ memset(ua_socket->tcp.client_ip, 0, 16);
+ ua_socket->tcp.client_port = 0;
+ }
+ ua_printf(UA_INFO, "DELETE TCP SERVER \n");
+ ua_socket->tcp.server_port = 0;
+ uartadapter_control_write_tcp_info_into_flash(ua_socket);
+ }else{
+ ua_printf(UA_INFO, "DELETE TCP SERVER FAILED: port not match\n");
+ return -1;
+ }
+ }else{
+ ua_printf(UA_INFO, "DELETE TCP SERVER FAILED: server not exist\n");
+ return -1;
+ }
+
+ break;
+ case UART_CTRL_TYPE_TCP_CLIENT_CONNECT:
+ server_ip = (*(p+3))<<24 | (*(p+2))<<16 | (*(p+1))<<8 | *p;
+ p = p + 4;
+ memcpy(ua_tcp_server_ip, inet_ntoa(server_ip), 16);
+ port = (*p)<<8 | *(p+1);
+ ret = uartadapter_tcpclient(ua_socket, ua_tcp_server_ip, (unsigned short)port);
+ if(ret == 0){
+ ua_printf(UA_INFO, "CONNECT TO TCP SERVER, IP %s PORT %d Success.\n", ua_tcp_server_ip, port);
+ }else{
+ ua_printf(UA_INFO, "CONNECT TO TCP SERVER, IP %s PORT %d Failed.\n", ua_tcp_server_ip, port);
+ return -1;
+ }
+ memcpy(ua_socket->tcp.client_ip, ua_tcp_server_ip, 16);
+ ua_socket->tcp.client_port = port;
+ uartadapter_control_write_tcp_info_into_flash(ua_socket);
+ break;
+ case UART_CTRL_TYPE_TCP_CLIENT_DISCONNECT:
+ server_ip = (*(p+3))<<24 | (*(p+2))<<16 | (*(p+1))<<8 | *p;
+ p = p + 4;
+ memcpy(ua_tcp_server_ip, inet_ntoa(server_ip), 16);
+ port = (*p)<<8 | *(p+1);
+
+ if(ua_socket->tcp.transmit_send_socket != -1){
+ getpeername(ua_socket->tcp.transmit_send_socket, (struct sockaddr *)&server_addr, &server_addr_len);
+ if(server_addr.sin_port == ntohs((u16)port) && server_addr.sin_addr.s_addr == server_ip){
+ ua_printf(UA_INFO,"uart tcp transmit send socket %d closed by control socket!", ua_socket->tcp.transmit_send_socket);
+ close(ua_socket->tcp.transmit_send_socket);
+ ua_socket->tcp.transmit_send_socket = -1;
+ ua_printf(UA_INFO, "DISCONNECT FROM TCP SERVER.\n");
+ memset(ua_socket->tcp.client_ip, 0, 16);
+ ua_socket->tcp.client_port = 0;
+ uartadapter_control_write_tcp_info_into_flash(ua_socket);
+ }else{
+ ua_printf(UA_INFO, "DISCONNECT FROM TCP SERVER FAILED: port or IP not match.\n");
+ return -1;
+ }
+ }else{
+ ua_printf(UA_INFO, "DISCONNECT FROM TCP SERVER FAILED: connection not exist\n");
+ return -1;
+ }
+ break;
+ case UART_CTRL_TYPE_TCP_GROUP_ID:
+ ua_socket->tcp.group_id = *p;
+ ua_printf(UA_INFO,"SET TCP GROUP ID to %d!", *p);
+#ifdef MDNS_LIB_EN
+ sprintf(txt_buf2, "groupid:%d, tcpserver:%d", ua_socket->tcp.group_id, ua_socket->tcp.server_port);
+ TXTRecordCreate(&txtRecord, sizeof(txt_buf), txt_buf);
+ TXTRecordSetValue(&txtRecord, "groupid", strlen(txt_buf2), txt_buf2);
+ mDNSUpdateService(ua_socket->dnsServiceRef, &txtRecord, 0);
+ mDNSUpdateService(ua_socket->dnsServiceRef2, &txtRecord, 0); */
+#endif
+
+ uartadapter_control_write_tcp_info_into_flash(ua_socket);
+
+ break;
+ default:
+ ua_printf(UA_DEBUG, "Unknown Type, just skip\n");
+ break;
+
+ }
+ p += len;
+ }
+ return 0;
+}
+
+int uartadapter_control_get_req_handle(ua_socket_t *ua_socket, u16 type, u8 *prsp, u32 *sz)
+{
+ u8 *p = prsp;
+
+ ua_printf(UA_DEBUG, "===>uartadapter_control_get_req_handle()");
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ sprintf((char *)p, UA_CONTROL_PREFIX);
+ p += strlen(UA_CONTROL_PREFIX);
+ *p++ = UART_CTRL_MODE_GET_RSP;
+
+ if(type & UART_CTRL_TYPE_BAUD_RATE){
+ *p++ = 0;
+ *p++ = UART_CTRL_TYPE_BAUD_RATE;
+ *p++ = 4;
+ *(u32*)p = ua_socket->uart.uart_param.BaudRate;
+ p += 4;
+ }
+ if(type & UART_CTRL_TYPE_WORD_LEN){
+ *p++ = 0;
+ *p++ = UART_CTRL_TYPE_WORD_LEN;
+ *p++ = 1;
+ *p = ua_socket->uart.uart_param.WordLen;
+ p += 1;
+ }
+ if(type & UART_CTRL_TYPE_PARITY){
+ *p++ = 0;
+ *p++ = UART_CTRL_TYPE_PARITY;
+ *p++ = 1;
+ *p = ua_socket->uart.uart_param.Parity;
+ p += 1;
+ }
+ if(type & UART_CTRL_TYPE_STOP_BIT){
+ *p++ = 0;
+ *p++ = UART_CTRL_TYPE_STOP_BIT;
+ *p++ = 1;
+ *p = ua_socket->uart.uart_param.StopBit;
+ p += 1;
+ }
+#if 0
+ if(type & UART_CTRL_TYPE_FLOW_CTRL){
+ *p++ = UART_CTRL_TYPE_FLOW_CTRL;
+ *p++ = 1;
+ *p = ua_socket->uart.uart_param.FlowControl;
+ p += 1;
+ }
+#endif
+ *sz = p - prsp;
+
+ UA_PRINT_DATA(prsp, *sz);
+ return 0;
+}
+
+int uartadapter_control_process(ua_socket_t *ua_socket, char *pbuf, size_t size)
+{
+ /*the same as socket*/
+ int ret = 0;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ if(!size || !pbuf){
+ //ua_printf(UA_ERROR, "control data input error,please check!");
+ ret = -1;
+ return ret;
+ }
+
+ UA_PRINT_DATA(pbuf, size);
+ if (size <= strlen(UA_CONTROL_PREFIX)) {
+ ua_printf(UA_ERROR, "no control data prefix!");
+ return -1;
+ }
+
+ if(uartadapter_strncmp(pbuf, UA_CONTROL_PREFIX, 10) != 0)
+ {
+ ua_printf(UA_ERROR, "control data prefix wrong!");
+ return -1;
+ }
+ else
+ {
+ u8 *p = (u8*)pbuf + strlen(UA_CONTROL_PREFIX);
+ u8 mode = *p++;
+ switch(mode)
+ {
+ case UART_CTRL_MODE_SET_REQ: //AMEBA_UART-MODE-TYPE-LEN-VAL-TYPE-LEN-VAL...
+ {
+ char rsp[32] = {0}; //AMEBA_UART-MODE
+ u32 sz = strlen(UA_CONTROL_PREFIX);
+ ret = uartadapter_control_set_req_handle(ua_socket, p, (size - strlen(UA_CONTROL_PREFIX) - 1));
+ if(0 == ret){
+ sprintf(rsp, UA_CONTROL_PREFIX);
+ *(rsp + sz) = UART_CTRL_MODE_SET_RSP;
+ sz ++;
+ sprintf(rsp + sz, "\n");
+ sz ++;
+ vTaskDelay(100);
+ uartadapter_tcp_send_control(ua_socket, rsp, sz);
+ }
+ break;
+ }
+ case UART_CTRL_MODE_GET_REQ: //AMEBA_UART-MODE-TYPE
+ {
+ char rsp[128] = {0};
+ u32 sz = 0;
+ u16 type = (*p)<<8 | *(p+1);
+ uartadapter_control_get_req_handle(ua_socket, type, (u8*)rsp, &sz);
+ sprintf(rsp + sz, "\n");
+ sz ++;
+ vTaskDelay(100);
+ uartadapter_tcp_send_control(ua_socket, rsp, sz);
+ break;
+ }
+ default:
+ ua_printf(UA_ERROR, UA_CONTROL_PREFIX": Mode (%d) not support!", mode);
+ break;
+ }
+ }
+ return 0;
+}
+
+#define _________TCP__RELATED________________________
+int uartadapter_tcpclient(ua_socket_t *ua_socket, const char *host_ip, unsigned short usPort)
+{
+ int iAddrSize;
+ int iSockFD = -1;
+ int iStatus;
+ int enable = 1;
+ struct sockaddr_in sAddr;
+ int send_timeout = 3000;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ FD_ZERO(&sAddr);
+ sAddr.sin_family = AF_INET;
+ sAddr.sin_port = htons(usPort);
+ sAddr.sin_addr.s_addr = inet_addr(host_ip);
+
+ iAddrSize = sizeof(struct sockaddr_in);
+
+ iSockFD = socket(AF_INET, SOCK_STREAM, 0);
+ if( iSockFD < 0 ) {
+ ua_printf(UA_ERROR, "TCP ERROR: create tcp client socket fd error!");
+ return -1;
+ }
+
+ ua_printf(UA_DEBUG, "TCP: ServerIP=%s port=%d.", host_ip, usPort);
+ ua_printf(UA_DEBUG, "TCP: Create socket %d.", iSockFD);
+ // connecting to TCP server
+ iStatus = connect(iSockFD, (struct sockaddr *)&sAddr, iAddrSize);
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client connect server error %d!", iStatus);
+ goto Exit;
+ }
+
+ iStatus = setsockopt(iSockFD, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set TCP_NODELAY error! ");
+ goto Exit;
+ }
+
+ iStatus = setsockopt(iSockFD, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set SO_KEEPALIVE error! ");
+ goto Exit;
+ }
+
+#if LWIP_SO_SNDTIMEO
+ iStatus = setsockopt(iSockFD, SOL_SOCKET, SO_SNDTIMEO, &send_timeout, sizeof(int));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set SO_SNDTIMEO error! ");
+ goto Exit;
+ }
+#endif
+
+#if LWIP_SO_RCVTIMEO
+ iStatus = setsockopt(iSockFD, SOL_SOCKET, SO_RCVTIMEO, &send_timeout, sizeof(int));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set SO_RCVTIMEO error! ");
+ goto Exit;
+ }
+#endif
+
+ if(ua_socket->tcp.transmit_send_socket != -1){
+ close(ua_socket->tcp.transmit_send_socket);
+ ua_printf(UA_INFO, "Close old transmit send socket %d.", ua_socket->tcp.transmit_send_socket);
+ }
+
+ ua_printf(UA_INFO, "Connect to transmit server successfully.");
+ ua_socket->tcp.transmit_send_socket = iSockFD;
+
+ return 0;
+
+Exit:
+ close(iSockFD);
+ return -1;
+}
+
+int uartadapter_tcpserver(ua_socket_t *ua_socket, unsigned short usPort, u8 socket_type)
+{
+ struct sockaddr_in sLocalAddr;
+ int iAddrSize;
+ int iSockFD;
+ int iStatus;
+ int enable = 1;
+
+ UA_SOCKET_CHECK_2(ua_socket);
+
+ iSockFD = socket(AF_INET, SOCK_STREAM, 0);
+ if( iSockFD < 0 ) {
+ ua_printf(UA_ERROR, "create server_socket error!");
+ goto Exit;
+ }
+
+ iStatus = setsockopt( iSockFD, SOL_SOCKET, SO_REUSEADDR,
+ (const char *) &enable, sizeof( enable ) );
+ if( iStatus < 0 ) {
+ ua_printf(UA_ERROR, "set tcp server socket SO_REUSEADDR error %d! ", iStatus);
+ goto Exit;
+ }
+
+ ua_printf(UA_DEBUG, "TCP: Create Tcp server socket %d", iSockFD);
+
+ //filling the TCP server socket address
+ memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
+ sLocalAddr.sin_family = AF_INET;
+ sLocalAddr.sin_len = sizeof(sLocalAddr);
+ sLocalAddr.sin_port = htons(usPort);
+ sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ iAddrSize = sizeof(sLocalAddr);
+
+ iStatus = bind(iSockFD, (struct sockaddr *)&sLocalAddr, iAddrSize);
+ if( iStatus < 0 ) {
+ ua_printf(UA_ERROR, "bind tcp server socket fd error %d! ", iStatus);
+ goto Exit;
+ }
+ ua_printf(UA_DEBUG, "TCP: Bind successfully.");
+
+ iStatus = listen(iSockFD, 10);
+ if( iStatus != 0 ) {
+ ua_printf(UA_ERROR, "listen tcp server socket fd error %d!", iStatus);
+ goto Exit;
+ }
+
+ if(0 == socket_type){
+ ua_socket->tcp.chat_server_listen_socket = iSockFD;
+ ua_printf(UA_INFO, "TCP Chat Server: Listen on port %d", usPort);
+ }else if(1 == socket_type){
+ ua_socket->tcp.control_server_listen_socket = iSockFD;
+ ua_printf(UA_INFO, "TCP Control Server: Listen on port %d", usPort);
+ }else{
+ ua_socket->tcp.transmit_server_listen_socket = iSockFD;
+ ua_printf(UA_INFO, "TCP Transmit Server: Listen on port %d", usPort);
+ }
+
+ return 0;
+
+Exit:
+ close(iSockFD);
+ ua_printf(UA_DEBUG, "Tcp server listen on port %d closed!", usPort);
+ return 0;
+}
+
+void uartadapter_tcp_chat_server_thread(void *param)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+ unsigned short port = UA_CHAT_SOCKET_PORT;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_printf(UA_DEBUG, "Uart Adapter: Start Tcp Data Server!");
+ uartadapter_tcpserver(ua_socket, port, 0);
+
+#if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ ua_printf(UA_DEBUG, "Min available stack size of %s = %d * %d bytes\n\r", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE));
+#endif
+ ua_printf(UA_DEBUG, "TCP: Tcp data server stopped!");
+ vTaskDelete(NULL);
+}
+
+void uartadapter_tcp_control_server_thread(void *param)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+ unsigned short port = UA_CONTROL_SOCKET_PORT;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_printf(UA_DEBUG, "Uart Adapter: Start Tcp Control Server!");
+ uartadapter_tcpserver(ua_socket, port, 1);
+
+#if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ ua_printf(UA_DEBUG, "Min available stack size of %s = %d * %d bytes", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE));
+#endif
+ ua_printf(UA_DEBUG, "TCP: Tcp control server stopped!");
+ vTaskDelete(NULL);
+}
+
+void uartadapter_tcp_transmit_server_thread(void *param)
+{
+ ua_socket_t *ua_socket = ua_global_socket;
+ unsigned short port = (int)param;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_printf(UA_DEBUG, "Uart Adapter: Start Tcp Transmit Server!");
+ uartadapter_tcpserver(ua_socket, port, 2);
+
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_SLOW_TWINKLE);
+
+#if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ ua_printf(UA_DEBUG, "Min available stack size of %s = %d * %d bytes", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE));
+#endif
+ ua_printf(UA_DEBUG, "TCP: Tcp transmit server thread delete!");
+ vTaskDelete(NULL);
+}
+
+void uartadapter_tcp_transmit_client_thread(void *param)
+{
+ ua_socket_t *ua_socket = ua_global_socket;
+ unsigned short port = (int)param;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_printf(UA_DEBUG, "Uart Adapter: Start Tcp Data Client!");
+ uartadapter_tcpclient(ua_socket, ua_tcp_server_ip, port);
+
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_SLOW_TWINKLE);
+
+#if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ ua_printf(UA_DEBUG, "Min available stack size of %s = %d * %d bytes\n\r", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE));
+#endif
+ ua_printf(UA_DEBUG, "TCP: Tcp transmit client thread delete!");
+ vTaskDelete(NULL);
+}
+
+void uartadapter_tcp_transmit_client_forever_thread(void *param)
+{
+ ua_socket_t *ua_socket = ua_global_socket;
+ unsigned short port = (int)param;
+ int ret = 0;
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_printf(UA_DEBUG, "Uart Adapter: Start Tcp Transmit Client forever thread!");
+
+ do{
+ ret = uartadapter_tcpclient(ua_socket, ua_tcp_server_ip, port);
+ if(ret != 0){
+ ua_printf(UA_INFO, "Uart Adapter: Try to connect to TCP server again");
+ vTaskDelay(3000);
+ }
+ }while(ret != 0);
+
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_SLOW_TWINKLE);
+
+#if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1)
+ ua_printf(UA_DEBUG, "Min available stack size of %s = %d * %d bytes\n\r", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE));
+#endif
+ ua_printf(UA_DEBUG, "TCP: Tcp transmit client thread delete!");
+ vTaskDelete(NULL);
+}
+
+void uartadapter_tcp_send_data(ua_socket_t *ua_socket, char *buffer, int size)
+{
+ int iStatus;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ if(ua_socket->tcp.chat_socket != -1){
+ ua_socket->tcp.send_flag = 1;
+ RtlDownSema(&ua_socket->uart.tcp_tx_rx_sema);
+ iStatus = send(ua_socket->tcp.chat_socket, buffer, size, 0 );
+ RtlUpSema(&ua_socket->uart.tcp_tx_rx_sema);
+ ua_socket->tcp.send_flag = 0;
+ if( iStatus <= 0 ){
+ ua_printf(UA_ERROR, "tcp chat socket send data error! iStatus:%d!", iStatus);
+ }else{
+ ua_socket->tcp.tx_cnt += iStatus;
+ }
+ }
+
+ if(ua_socket->tcp.transmit_send_socket != -1){
+ ua_socket->tcp.send_flag = 1;
+ iStatus = send(ua_socket->tcp.transmit_send_socket, buffer, size, 0 );
+ ua_socket->tcp.send_flag = 0;
+ if( iStatus <= 0 ){
+ ua_printf(UA_ERROR, "tcp transmit send socket send data error! iStatus:%d!", iStatus);
+ }else{
+ ua_socket->tcp.tx_cnt += iStatus;
+ }
+ }
+
+ return;
+}
+
+void uartadapter_tcp_send_control(ua_socket_t *ua_socket, char *buffer, int size)
+{
+ int iStatus;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ if(ua_socket->tcp.control_socket != -1){
+ ua_socket->tcp.send_flag = 1;
+ iStatus = send(ua_socket->tcp.control_socket, buffer, size, 0 );
+ ua_socket->tcp.send_flag = 0;
+ if( iStatus <= 0 ){
+ ua_printf(UA_ERROR,"tcp control socket send data error! iStatus:%d!", iStatus);
+ }
+
+ if(ua_debug_print_en){
+ ua_printf(UA_INFO,"uart tcp control socket send %d bytes, ret %d!", size, iStatus);
+ }
+ }
+
+ return;
+}
+
+void uartadapter_tcp_except_handler(ua_socket_t *ua_socket, fd_set *exceptfds)
+{
+ if(ua_socket->tcp.chat_socket != -1 && FD_ISSET(ua_socket->tcp.chat_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp chat socket %d exception happen, need to close!", ua_socket->tcp.chat_socket);
+ close(ua_socket->tcp.chat_socket);
+ ua_socket->tcp.chat_socket = -1;
+ }
+
+ if(ua_socket->tcp.control_socket != -1 && FD_ISSET(ua_socket->tcp.control_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp control socket %d exception happen, need to close!", ua_socket->tcp.control_socket);
+ close(ua_socket->tcp.control_socket);
+ ua_socket->tcp.control_socket = -1;
+ }
+
+ if(ua_socket->tcp.transmit_recv_socket != -1 && FD_ISSET(ua_socket->tcp.transmit_recv_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp transmit recv socket %d exception happen, need to close!", ua_socket->tcp.transmit_recv_socket);
+ close(ua_socket->tcp.transmit_recv_socket);
+ ua_socket->tcp.transmit_recv_socket = -1;
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+#if 0
+ if(ua_socket->tcp.transmit_server_listen_socket != -1){
+ ua_printf(UA_INFO,"uart tcp transmit server socket %d exception happen, need to close!", ua_socket->tcp.transmit_server_listen_socket);
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ ua_socket->tcp.transmit_server_listen_socket = -1;
+ }
+#endif
+ }
+
+ if(ua_socket->tcp.transmit_send_socket != -1 && FD_ISSET(ua_socket->tcp.transmit_send_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp transmit send socket %d exception happen, need to close!", ua_socket->tcp.transmit_send_socket);
+ close(ua_socket->tcp.transmit_send_socket);
+ ua_socket->tcp.transmit_send_socket = -1;
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+
+ strncpy(ua_tcp_server_ip, ua_socket->tcp.client_ip, 16);
+ if(xTaskCreate(uartadapter_tcp_transmit_client_forever_thread, ((const char*)"tclient"), 256, (void *)ua_socket->tcp.client_port, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(tcp client) failed", __FUNCTION__);
+ }
+
+ if(ua_socket->tcp.chat_server_listen_socket != -1 && FD_ISSET(ua_socket->tcp.chat_server_listen_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp chat server socket %d exception happen, need to restart!", ua_socket->tcp.chat_server_listen_socket);
+ close(ua_socket->tcp.chat_server_listen_socket);
+ ua_socket->tcp.chat_server_listen_socket = -1;
+ uartadapter_tcpserver(ua_socket, UA_CHAT_SOCKET_PORT, 0);
+ }
+
+ if(ua_socket->tcp.control_server_listen_socket != -1 && FD_ISSET(ua_socket->tcp.control_server_listen_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp control server socket %d exception happen, need to restart!", ua_socket->tcp.control_server_listen_socket);
+ close(ua_socket->tcp.control_server_listen_socket);
+ ua_socket->tcp.control_server_listen_socket = -1;
+ uartadapter_tcpserver(ua_socket, UA_CONTROL_SOCKET_PORT, 1);
+ }
+
+ if(ua_socket->tcp.transmit_server_listen_socket != -1 && FD_ISSET(ua_socket->tcp.transmit_server_listen_socket, exceptfds)){
+ ua_printf(UA_INFO,"uart tcp transmit server socket %d exception happen, need to close!", ua_socket->tcp.transmit_server_listen_socket);
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ ua_socket->tcp.transmit_server_listen_socket = -1;
+ //uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+ uartadapter_tcpserver(ua_socket, ua_socket->tcp.server_port, 2);
+ }
+
+}
+
+void uartadapter_tcp_chat_socket_handler(ua_socket_t *ua_socket, char *tcp_rxbuf)
+{
+ int recv_len;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_socket->tcp.recv_flag = 1;
+ RtlDownSema(&ua_socket->uart.tcp_tx_rx_sema);
+ recv_len = recv(ua_socket->tcp.chat_socket, tcp_rxbuf, UA_UART_FRAME_LEN, MSG_DONTWAIT);
+ RtlUpSema(&ua_socket->uart.tcp_tx_rx_sema);
+ ua_socket->tcp.recv_flag = 0;
+ if(recv_len < 0){
+ ua_printf(UA_ERROR, "Tcp Chat Socket %d Recv Error, ret = %d", ua_socket->tcp.chat_socket, recv_len);
+ }else if(recv_len == 0){
+ ua_printf(UA_INFO, "Tcp Chat Socket %d closed", ua_socket->tcp.chat_socket);
+ close(ua_socket->tcp.chat_socket);
+ ua_socket->tcp.chat_socket = -1;
+ }else{
+ ua_printf(UA_DEBUG, "Tcp Chat Socket %d Recv %d Data", ua_socket->tcp.chat_socket, recv_len);
+ uartadapter_uart_write(ua_socket, tcp_rxbuf, recv_len);
+ ua_socket->tcp.rx_cnt += recv_len;
+ }
+
+ return;
+}
+
+void uartadapter_tcp_control_socket_handler(ua_socket_t *ua_socket)
+{
+ char tcp_rxbuf[UA_UART_FRAME_LEN];
+ int recv_len;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ recv_len = recv(ua_socket->tcp.control_socket, tcp_rxbuf, UA_UART_FRAME_LEN, MSG_DONTWAIT); //MSG_DONTWAIT MSG_WAITALL
+ if(recv_len<0){
+ ua_printf(UA_ERROR, "Tcp Control Socket %d Recv Error", ua_socket->tcp.control_socket);
+ }else if(recv_len == 0){
+ ua_printf(UA_INFO, "Tcp Control Socket %d closed", ua_socket->tcp.control_socket);
+ close(ua_socket->tcp.control_socket);
+ ua_socket->tcp.control_socket = -1;
+ }else{
+ ua_printf(UA_DEBUG, "Tcp Control Socket %d Recv %d Data", ua_socket->tcp.control_socket, recv_len);
+ uartadapter_control_process(ua_socket, (void*)tcp_rxbuf, recv_len);
+ }
+
+ return;
+}
+
+void uartadapter_tcp_transmit_socket_handler(ua_socket_t *ua_socket, char *tcp_rxbuf)
+{
+ int recv_len;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_socket->tcp.recv_flag = 1;
+ recv_len = recv(ua_socket->tcp.transmit_recv_socket, tcp_rxbuf, UA_UART_FRAME_LEN, MSG_DONTWAIT);
+ ua_socket->tcp.recv_flag = 0;
+ if(recv_len < 0){
+ ua_printf(UA_ERROR, "Tcp Transmit Recv Socket %d Recv Error, ret = %d", ua_socket->tcp.transmit_recv_socket, recv_len);
+ }else if(recv_len == 0){
+ ua_printf(UA_INFO, "Tcp Transmit Recv Socket %d closed", ua_socket->tcp.transmit_recv_socket);
+ close(ua_socket->tcp.transmit_recv_socket);
+ ua_socket->tcp.transmit_recv_socket = -1;
+#if 0
+ if(ua_socket->tcp.transmit_server_listen_socket != -1){
+ ua_printf(UA_INFO, "Tcp Transmit Server Socket %d closed", ua_socket->tcp.transmit_server_listen_socket);
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ ua_socket->tcp.transmit_server_listen_socket = -1;
+ }
+#endif
+ }else{
+ uartadapter_uart_write(ua_socket, tcp_rxbuf, recv_len);
+ ua_socket->tcp.rx_cnt += recv_len;
+ }
+
+ return;
+}
+
+void uartadapter_tcp_chat_listen_socket_handler(ua_socket_t *ua_socket)
+{
+ int old_chat_socket;
+ struct sockaddr_in sAddr;
+ int addrlen = sizeof(sAddr);
+ int iStatus;
+ int enable = 1;
+ int send_timeout = 3000;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ old_chat_socket = ua_socket->tcp.chat_socket;
+
+ ua_socket->tcp.chat_socket = accept(ua_socket->tcp.chat_server_listen_socket, (struct sockaddr *)&sAddr, (socklen_t*)&addrlen);
+ if( ua_socket->tcp.chat_socket< 0 ) {
+ ua_printf(UA_ERROR, "Accept tcp chat socket error");
+ goto EXIT;
+ }
+
+ iStatus = setsockopt(ua_socket->tcp.chat_socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp chat socket set opt TCP_NODELAY error! ");
+ goto EXIT;
+ }
+
+ iStatus = setsockopt(ua_socket->tcp.chat_socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp chat socket set opt SO_KEEPALIVE error! ");
+ goto EXIT;
+ }
+
+#if LWIP_SO_SNDTIMEO
+ iStatus = setsockopt(ua_socket->tcp.chat_socket, SOL_SOCKET, SO_SNDTIMEO, &send_timeout, sizeof(send_timeout));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set opt error! ");
+ goto EXIT;
+ }
+#endif
+
+#if LWIP_SO_RCVTIMEO
+ iStatus = setsockopt(ua_socket->tcp.chat_socket, SOL_SOCKET, SO_RCVTIMEO, &send_timeout, sizeof(send_timeout));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set opt error! ");
+ goto EXIT;
+ }
+#endif
+
+ ua_printf(UA_INFO, "Accept new chat socket %d on port %d successfully.", ua_socket->tcp.chat_socket, htons(sAddr.sin_port));
+ if(old_chat_socket != -1)
+ {
+ close(old_chat_socket);
+ ua_printf(UA_INFO, "Close old chat socket %d.", old_chat_socket);
+ }
+
+ return;
+
+EXIT:
+ if(ua_socket->tcp.chat_server_listen_socket != -1){
+ close(ua_socket->tcp.chat_server_listen_socket);
+ ua_socket->tcp.chat_server_listen_socket = -1;
+ }
+}
+
+void uartadapter_tcp_control_listen_socket_handler(ua_socket_t *ua_socket)
+{
+ int old_control_socket;
+ struct sockaddr_in sAddr;
+ int addrlen = sizeof(sAddr);
+ int iStatus;
+ int enable = 1;
+ int send_timeout = 3000;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ old_control_socket = ua_socket->tcp.control_socket;
+
+ ua_socket->tcp.control_socket = accept(ua_socket->tcp.control_server_listen_socket, (struct sockaddr *)&sAddr, (socklen_t*)&addrlen);
+ if( ua_socket->tcp.control_socket< 0 ) {
+ ua_printf(UA_ERROR, "Accept tcp control socket error");
+ goto EXIT;
+ }
+
+ iStatus = setsockopt(ua_socket->tcp.control_socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp chat socket set opt TCP_NODELAY error! ");
+ goto EXIT;
+ }
+
+ iStatus = setsockopt(ua_socket->tcp.control_socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp chat socket set opt SO_KEEPALIVE error! ");
+ goto EXIT;
+ }
+
+#if LWIP_SO_SNDTIMEO
+ iStatus = setsockopt(ua_socket->tcp.control_socket, SOL_SOCKET, SO_SNDTIMEO, &send_timeout, sizeof(send_timeout));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set opt error! ");
+ goto EXIT;
+ }
+#endif
+
+#if LWIP_SO_RCVTIMEO
+ iStatus = setsockopt(ua_socket->tcp.control_socket, SOL_SOCKET, SO_RCVTIMEO, &send_timeout, sizeof(send_timeout));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set opt error! ");
+ goto EXIT;
+ }
+#endif
+
+ ua_printf(UA_INFO, "Accept new control socket %d on port %d successfully.", ua_socket->tcp.control_socket, htons(sAddr.sin_port));
+ if(old_control_socket != -1)
+ {
+ close(old_control_socket);
+ ua_printf(UA_INFO, "Close old control socket %d.", old_control_socket);
+ }
+
+ return;
+
+EXIT:
+ if(ua_socket->tcp.control_server_listen_socket!= -1){
+ close(ua_socket->tcp.control_server_listen_socket);
+ ua_socket->tcp.control_server_listen_socket= -1;
+ }
+}
+
+void uartadapter_tcp_transmit_listen_socket_handler(ua_socket_t *ua_socket)
+{
+ int old_transmit_recv_socket;
+ struct sockaddr_in sAddr;
+ int addrlen = sizeof(sAddr);
+ int iStatus;
+ int enable = 1;
+ int send_timeout = 3000;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ old_transmit_recv_socket = ua_socket->tcp.transmit_recv_socket;
+
+ ua_socket->tcp.transmit_recv_socket = accept(ua_socket->tcp.transmit_server_listen_socket, (struct sockaddr *)&sAddr, (socklen_t*)&addrlen);
+ if( ua_socket->tcp.transmit_recv_socket < 0 ) {
+ ua_printf(UA_ERROR, "Accept tcp control socket error");
+ goto EXIT;
+ }
+
+ iStatus = setsockopt(ua_socket->tcp.transmit_recv_socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp transmit recv socket set opt TCP_NODELAY error! ");
+ goto EXIT;
+ }
+
+ iStatus = setsockopt(ua_socket->tcp.transmit_recv_socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp transmit recv socket set opt SO_KEEPALIVE error! ");
+ goto EXIT;
+ }
+
+#if LWIP_SO_SNDTIMEO
+ iStatus = setsockopt(ua_socket->tcp.transmit_recv_socket, SOL_SOCKET, SO_SNDTIMEO, &send_timeout, sizeof(send_timeout));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set opt error! ");
+ goto EXIT;
+ }
+#endif
+
+#if LWIP_SO_RCVTIMEO
+ iStatus = setsockopt(ua_socket->tcp.transmit_recv_socket, SOL_SOCKET, SO_RCVTIMEO, &send_timeout, sizeof(send_timeout));
+ if (iStatus < 0) {
+ ua_printf(UA_ERROR, "tcp client socket set opt error! ");
+ goto EXIT;
+ }
+#endif
+
+ ua_printf(UA_INFO, "Accept new transmit recv socket %d on port %d successfully.", ua_socket->tcp.transmit_recv_socket, htons(sAddr.sin_port));
+ if(old_transmit_recv_socket != -1)
+ {
+ close(old_transmit_recv_socket);
+ ua_printf(UA_INFO, "Close old transmit recv socket %d.", old_transmit_recv_socket);
+ }
+
+ return;
+
+EXIT:
+ if(ua_socket->tcp.transmit_server_listen_socket!= -1){
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ ua_socket->tcp.transmit_server_listen_socket= -1;
+ }
+}
+
+void uartadapter_tcp_select_restart_handler(ua_socket_t *ua_socket)
+{
+ if(ua_socket->tcp.chat_socket != -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp chat socket %d need to close!", ua_socket->tcp.chat_socket);
+ close(ua_socket->tcp.chat_socket);
+ ua_socket->tcp.chat_socket = -1;
+ }
+
+ if(ua_socket->tcp.control_socket != -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp control socket %d need to close!", ua_socket->tcp.control_socket);
+ close(ua_socket->tcp.control_socket);
+ ua_socket->tcp.control_socket = -1;
+ }
+
+ if(ua_socket->tcp.transmit_recv_socket != -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp transmit recv socket %d need to close!", ua_socket->tcp.transmit_recv_socket);
+ close(ua_socket->tcp.transmit_recv_socket);
+ ua_socket->tcp.transmit_recv_socket = -1;
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+ }
+
+ if(ua_socket->tcp.transmit_send_socket != -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp transmit send socket %d need to close!", ua_socket->tcp.transmit_send_socket);
+ close(ua_socket->tcp.transmit_send_socket);
+ ua_socket->tcp.transmit_send_socket = -1;
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+ }
+
+ if(ua_socket->tcp.chat_server_listen_socket!= -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp chat server socket %d need to restart!", ua_socket->tcp.chat_server_listen_socket);
+ close(ua_socket->tcp.chat_server_listen_socket);
+ ua_socket->tcp.chat_server_listen_socket = -1;
+ uartadapter_tcpserver(ua_socket, UA_CHAT_SOCKET_PORT, 0);
+ }
+
+ if(ua_socket->tcp.control_server_listen_socket!= -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp control server socket %d need to restart!", ua_socket->tcp.control_server_listen_socket);
+ close(ua_socket->tcp.control_server_listen_socket);
+ ua_socket->tcp.control_server_listen_socket = -1;
+ uartadapter_tcpserver(ua_socket, UA_CONTROL_SOCKET_PORT, 1);
+ }
+
+ if(ua_socket->tcp.transmit_server_listen_socket!= -1){
+ ua_printf(UA_INFO,"IP changed, uart tcp transmit server socket %d need to close!", ua_socket->tcp.transmit_server_listen_socket);
+ close(ua_socket->tcp.transmit_server_listen_socket);
+ ua_socket->tcp.transmit_server_listen_socket = -1;
+ uartadapter_gpio_led_mode(ua_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+ }
+
+}
+
+void uartadapter_tcp_select_thread(void *param)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+ int max_fd;
+ struct timeval tv;
+ fd_set readfds;
+ fd_set exceptfds;
+ int ret = 0;
+ char *tcp_rxbuf;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ tcp_rxbuf = pvPortMalloc(UA_UART_FRAME_LEN);
+ if(NULL == tcp_rxbuf){
+ ua_printf(UA_ERROR, "Allocate select buffer failed.\n");
+ return;
+ }
+
+ while(1){
+ if(ua_reconnect_ip_change){
+ uartadapter_tcp_select_restart_handler(ua_socket);
+ ua_reconnect_ip_change = 0;
+ }
+
+ FD_ZERO(&readfds);
+ FD_ZERO(&exceptfds);
+ max_fd = -1;
+
+ if(ua_socket->tcp.chat_socket != -1){
+ FD_SET(ua_socket->tcp.chat_socket, &readfds);
+ FD_SET(ua_socket->tcp.chat_socket, &exceptfds);
+ if(ua_socket->tcp.chat_socket > max_fd)
+ max_fd = ua_socket->tcp.chat_socket;
+ }
+
+ if(ua_socket->tcp.control_socket != -1){
+ FD_SET(ua_socket->tcp.control_socket, &readfds);
+ FD_SET(ua_socket->tcp.control_socket, &exceptfds);
+ if(ua_socket->tcp.control_socket > max_fd)
+ max_fd = ua_socket->tcp.control_socket;
+ }
+
+ if(ua_socket->tcp.control_server_listen_socket != -1){
+ FD_SET(ua_socket->tcp.control_server_listen_socket, &readfds);
+ FD_SET(ua_socket->tcp.control_server_listen_socket, &exceptfds);
+ if(ua_socket->tcp.control_server_listen_socket > max_fd)
+ max_fd = ua_socket->tcp.control_server_listen_socket;
+ }
+
+ if(ua_socket->tcp.chat_server_listen_socket != -1){
+ FD_SET(ua_socket->tcp.chat_server_listen_socket, &readfds);
+ FD_SET(ua_socket->tcp.chat_server_listen_socket, &exceptfds);
+ if(ua_socket->tcp.chat_server_listen_socket > max_fd)
+ max_fd = ua_socket->tcp.chat_server_listen_socket;
+ }
+
+ if(ua_socket->tcp.transmit_recv_socket != -1){
+ FD_SET(ua_socket->tcp.transmit_recv_socket, &readfds);
+ FD_SET(ua_socket->tcp.transmit_recv_socket, &exceptfds);
+ if(ua_socket->tcp.transmit_recv_socket > max_fd)
+ max_fd = ua_socket->tcp.transmit_recv_socket;
+ }
+
+ if(ua_socket->tcp.transmit_send_socket != -1){
+ FD_SET(ua_socket->tcp.transmit_send_socket, &exceptfds);
+ if(ua_socket->tcp.transmit_send_socket > max_fd)
+ max_fd = ua_socket->tcp.transmit_send_socket;
+ }
+
+ if(ua_socket->tcp.transmit_server_listen_socket != -1){
+ FD_SET(ua_socket->tcp.transmit_server_listen_socket, &readfds);
+ FD_SET(ua_socket->tcp.transmit_server_listen_socket, &exceptfds);
+ if(ua_socket->tcp.transmit_server_listen_socket> max_fd)
+ max_fd = ua_socket->tcp.transmit_server_listen_socket;
+ }
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+
+ ret = select(max_fd + 1, &readfds, NULL, &exceptfds, &tv);
+
+ if(ua_debug_print_en){
+ ua_printf(UA_INFO, "uart adapter test select ret = %x",ret);
+ }
+ if(ret > 0){
+#if UA_PS_ENABLE
+ //printf("select get lock \r\n");
+ acquire_wakelock(UA_WAKELOCK);
+ ua_socket->tcp.tcp_ps = 0;
+ ua_socket->tcp.tcp_ps_cnt = 0;
+#endif
+
+ uartadapter_tcp_except_handler(ua_socket, &exceptfds);
+
+ if(ua_socket->tcp.chat_socket != -1 && FD_ISSET(ua_socket->tcp.chat_socket, &readfds)){
+ uartadapter_tcp_chat_socket_handler(ua_socket, tcp_rxbuf);
+ }
+
+ if(ua_socket->tcp.control_socket != -1 && FD_ISSET(ua_socket->tcp.control_socket, &readfds)){
+ uartadapter_tcp_control_socket_handler(ua_socket);
+ }
+
+ if(ua_socket->tcp.transmit_recv_socket != -1 && FD_ISSET(ua_socket->tcp.transmit_recv_socket, &readfds)){
+ uartadapter_tcp_transmit_socket_handler(ua_socket, tcp_rxbuf);
+ }
+
+ if(ua_socket->tcp.chat_server_listen_socket!= -1 && FD_ISSET(ua_socket->tcp.chat_server_listen_socket, &readfds)){
+ uartadapter_tcp_chat_listen_socket_handler(ua_socket);
+ }
+
+ if(ua_socket->tcp.control_server_listen_socket!= -1 && FD_ISSET(ua_socket->tcp.control_server_listen_socket, &readfds)){
+ uartadapter_tcp_control_listen_socket_handler(ua_socket);
+ }
+
+ if(ua_socket->tcp.transmit_server_listen_socket!= -1 && FD_ISSET(ua_socket->tcp.transmit_server_listen_socket, &readfds)){
+ uartadapter_tcp_transmit_listen_socket_handler(ua_socket);
+ }
+
+
+ }
+#if UA_PS_ENABLE
+ else{
+ ua_socket->tcp.tcp_ps_cnt++;
+ if(ua_socket->tcp.tcp_ps_cnt > 5){
+ ua_socket->tcp.tcp_ps_cnt = 5;
+ ua_socket->tcp.tcp_ps = 1;
+ if(ua_socket->uart.uart_ps && ua_socket->tcp.tcp_ps){
+ release_wakelock(UA_WAKELOCK);
+ }
+ }
+ }
+#endif
+ }
+
+ //vTaskDelete(NULL);
+}
+
+#define _________WIFI__RELATED________________________
+
+int uartadapter_connect_wifi(rtw_network_info_t *p_wifi, uint32_t channel, uint8_t pscan_config)
+{
+ int retry = 3;
+ rtw_wifi_setting_t setting;
+ int ret;
+ while (1) {
+ if(wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1) < 0){
+ ua_printf(UA_ERROR, "wifi set partial scan channel fail");
+ ret = SC_TARGET_CHANNEL_SCAN_FAIL;
+ return ret;
+ }
+
+ ret = wifi_connect((char*)p_wifi->ssid.val,
+ p_wifi->security_type,
+ (char*)p_wifi->password,
+ p_wifi->ssid.len,
+ p_wifi->password_len,
+ p_wifi->key_id,
+ NULL);
+
+ if (ret == RTW_SUCCESS) {
+ ret = LwIP_DHCP(0, DHCP_START);
+ wifi_get_setting(WLAN0_NAME, &setting);
+ wifi_show_setting(WLAN0_NAME, &setting);
+ if (ret == DHCP_ADDRESS_ASSIGNED)
+ return SC_SUCCESS;
+ else
+ return SC_DHCP_FAIL;
+ }
+
+ if (retry == 0) {
+ ret = SC_JOIN_BSS_FAIL;
+ break;
+ }
+ retry --;
+ }
+
+ return ret;
+}
+
+
+static int uartadapter_load_wifi_config()
+{
+ flash_t flash;
+ struct wlan_fast_reconnect *data;
+ uint32_t channel;
+ uint8_t pscan_config;
+ char key_id;
+ rtw_network_info_t wifi = {0};
+ int ret = SC_SUCCESS;
+
+
+ data = (struct wlan_fast_reconnect *)rtw_zmalloc(sizeof(struct wlan_fast_reconnect));
+ device_mutex_lock(RT_DEV_LOCK_FLASH);
+ flash_stream_read(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (uint8_t *)data);
+ device_mutex_unlock(RT_DEV_LOCK_FLASH);
+ if(*((uint32_t *) data) != ~0x0){
+ memcpy(psk_essid, data->psk_essid, sizeof(data->psk_essid));
+ memcpy(psk_passphrase, data->psk_passphrase, sizeof(data->psk_passphrase));
+ memcpy(wpa_global_PSK, data->wpa_global_PSK, sizeof(data->wpa_global_PSK));
+ memcpy(&channel, &(data->channel), 4);
+ sprintf(&key_id,"%d",(channel >> 28));
+ channel &= 0xff;
+ pscan_config = PSCAN_ENABLE | PSCAN_FAST_SURVEY;
+ //set partial scan for entering to listen beacon quickly
+ //wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1);
+
+ //set wifi connect
+ wifi.ssid.len = (int)strlen((char*)psk_essid);
+ memcpy(wifi.ssid.val, psk_essid, wifi.ssid.len);
+ wifi.key_id = key_id;
+
+ //open mode
+ if(!strlen((char*)psk_passphrase)){
+ wifi.security_type = RTW_SECURITY_OPEN;
+ }
+ //wep mode
+ else if( strlen((char*)psk_passphrase) == 5 || strlen((char*)psk_passphrase) == 13){
+ wifi.security_type = RTW_SECURITY_WEP_PSK;
+ wifi.password = (unsigned char *)psk_passphrase;
+ wifi.password_len = (int)strlen((char const *)psk_passphrase);
+ }
+ //WPA/WPA2
+ else{
+ wifi.security_type = RTW_SECURITY_WPA2_AES_PSK;
+ wifi.password = (unsigned char *)psk_passphrase;
+ wifi.password_len = (int)strlen((char const *)psk_passphrase);
+ }
+
+ ret = uartadapter_connect_wifi(&wifi, channel, pscan_config);
+
+ //print_simple_config_result((enum ua_sc_result)ret);
+
+ if(data)
+ rtw_mfree((u8*)data, sizeof(sizeof(struct wlan_fast_reconnect)));
+
+ if(ret == SC_SUCCESS)
+ return RTW_SUCCESS;
+ else
+ return RTW_ERROR;
+ }else{
+ ua_printf(UA_INFO, "No AP Profile read from FLASH, start simple configure");
+
+ if(data)
+ rtw_mfree((u8*)data, sizeof(sizeof(struct wlan_fast_reconnect)));
+
+ return RTW_ERROR;
+ }
+}
+
+#if CONFIG_INCLUDE_SIMPLE_CONFIG
+int uartadapter_simple_config(char *pin_code){
+
+ enum sc_result ret = SC_ERROR;
+ wifi_enter_promisc_mode();
+ if(init_test_data(pin_code) == 0){
+ filter_add_enable();
+ ret = simple_config_test(NULL);
+ //print_simple_config_result(ret);
+ remove_filter();
+ if(ret == SC_SUCCESS)
+ return RTW_SUCCESS;
+ else
+ return RTW_ERROR;
+ }else{
+ return RTW_ERROR;
+ }
+}
+#endif
+
+#ifdef MDNS_LIB_EN
+#define _________MDNS__RELATED________________________
+static void uartadapter_mdns_start(ua_socket_t *ua_socket, int is_restart)
+{
+ TXTRecordRef txtRecord;
+ unsigned char txt_buf[100] = {0}; // use fixed buffer for text record to prevent malloc/free
+ unsigned char txt_buf2[100] = {0}; // use fixed buffer for text record to prevent malloc/free
+ struct sockaddr_in server_addr;
+ int server_addr_len = sizeof(server_addr);
+
+ struct netif * pnetif = &xnetif[0];
+
+ if(is_restart){
+ ua_printf(UA_INFO, "Uart Adapter mDNS Restart");
+ mDNSResponderDeinit();
+ vTaskDelay(1000);
+ }
+
+ ua_printf(UA_DEBUG, "Uart Adapter mDNS Init");
+
+ if(mDNSResponderInit() == 0) {
+ ua_printf(UA_INFO, "mDNS Register service");
+ char hostname[32] = {0}; //AMEBA_UART-MODE
+ u32 prefix_len = strlen("AMEBA_");
+ sprintf(hostname, "AMEBA_");
+ sprintf(hostname+prefix_len, "%02x%02x%02x%02x%02x%02x",
+ pnetif->hwaddr[0], pnetif->hwaddr[1], pnetif->hwaddr[2],
+ pnetif->hwaddr[3], pnetif->hwaddr[4], pnetif->hwaddr[5]);
+
+ sprintf(txt_buf2, "groupid:%d, tcpserver:%d", ua_socket->tcp.group_id, ua_socket->tcp.server_port);
+ TXTRecordCreate(&txtRecord, sizeof(txt_buf), txt_buf);
+ TXTRecordSetValue(&txtRecord, "groupid", strlen(txt_buf2), txt_buf2);
+
+ ua_socket->dnsServiceRef = mDNSRegisterService(hostname, "_uart_data._tcp", "local", 5001, &txtRecord);
+ if(ua_socket->dnsServiceRef == NULL)
+ ua_printf(UA_ERROR, "mdns data service register failed!");
+ ua_socket->dnsServiceRef2 = mDNSRegisterService(hostname, "_uart_control._tcp", "local", 6001, &txtRecord);
+ if(ua_socket->dnsServiceRef2 == NULL)
+ ua_printf(UA_ERROR, "mdns control service register failed!");
+ TXTRecordDeallocate(&txtRecord);
+
+ }else{
+ ua_printf(UA_INFO, "mDNS Init Failed");
+ }
+
+ //vTaskDelete(NULL);
+}
+#endif
+
+
+#define _________INIT__RELATED________________________
+static void uartadapter_auto_reconnect(void* param)
+{
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+ uint32_t IPaddress, IPaddress2;
+ uint8_t iptab[4], iptab2[4];
+ //int ret = 0;
+
+ ua_reconnect_started = 1;
+
+#if CONFIG_AUTO_RECONNECT
+ wifi_set_autoreconnect(0);
+#endif
+ vTaskDelay(1000);
+ while(uartadapter_load_wifi_config() != RTW_SUCCESS){
+ vTaskDelay(2000);
+ }
+#if CONFIG_AUTO_RECONNECT
+ wifi_set_autoreconnect(1);
+#endif
+
+ ua_printf(UA_INFO, "uart adapter reconnect successful");
+ //uartadapter_gpio_led_mode(ua_global_socket, UART_ADAPTER_LED_OFF);
+
+ if(0 == memcmp(&ua_socket->ip, &xnetif[0].ip_addr, sizeof(ip_addr_t))){
+ IPaddress = ua_socket->ip.addr;
+ iptab[0] = (uint8_t)(IPaddress >> 24);
+ iptab[1] = (uint8_t)(IPaddress >> 16);
+ iptab[2] = (uint8_t)(IPaddress >> 8);
+ iptab[3] = (uint8_t)(IPaddress);
+ ua_printf(UA_INFO, "reconnect IP address no change, %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);
+ }else{
+ IPaddress = ua_socket->ip.addr;
+ iptab[0] = (uint8_t)(IPaddress >> 24);
+ iptab[1] = (uint8_t)(IPaddress >> 16);
+ iptab[2] = (uint8_t)(IPaddress >> 8);
+ iptab[3] = (uint8_t)(IPaddress);
+ IPaddress2 = xnetif[0].ip_addr.addr;
+ iptab2[0] = (uint8_t)(IPaddress2 >> 24);
+ iptab2[1] = (uint8_t)(IPaddress2 >> 16);
+ iptab2[2] = (uint8_t)(IPaddress2 >> 8);
+ iptab2[3] = (uint8_t)(IPaddress2);
+ ua_printf(UA_INFO, "reconnect IP address changed from %d.%d.%d.%d to %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0], iptab2[3], iptab2[2], iptab2[1], iptab2[0]);
+ memcpy(&ua_socket->ip, &xnetif[0].ip_addr, sizeof(ip_addr_t));
+ ua_reconnect_ip_change = 1;
+
+ ua_printf(UA_INFO,"IP changed, remove TCP information in FLASH!");
+ ua_socket->tcp.group_id = 0;
+ ua_socket->tcp.client_port = 0;
+ ua_socket->tcp.server_port = 0;
+ memset(ua_socket->tcp.client_ip, 0, 16);
+
+#ifdef MDNS_LIB_EN
+ uartadapter_mdns_start(ua_socket, 1);
+#endif
+ }
+
+
+ ua_reconnect_started = 0;
+ vTaskDelete(NULL);
+}
+
+void uartadapter_auto_connect(void *param)
+{
+ int ret = 0;
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+
+ UA_SOCKET_CHECK(ua_socket);
+
+ if(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) == RTW_SUCCESS) {
+ ua_printf(UA_INFO, "wifi connect successfully!");
+ }else{
+#if CONFIG_AUTO_RECONNECT
+ wifi_set_autoreconnect(0);
+#endif
+RETRY:
+ vTaskDelay(2000);
+ ret = uartadapter_load_wifi_config();
+ if(ret != RTW_SUCCESS){
+ vTaskDelay(2000);
+#if CONFIG_INCLUDE_SIMPLE_CONFIG
+ ret = uartadapter_simple_config(NULL);
+ if(ret != RTW_SUCCESS){
+ ua_printf(UA_INFO, "Simple configure connect failed, try again!");
+ goto RETRY;
+ }
+#endif
+ }
+#if CONFIG_AUTO_RECONNECT
+ wifi_set_autoreconnect(1);
+#endif
+ }
+
+ ua_wifi_connected = 1;
+ //uartadapter_gpio_led_mode(ua_global_socket, UART_ADAPTER_LED_OFF);
+
+ memcpy(&ua_socket->ip, &xnetif[0].ip_addr, sizeof(ip_addr_t));
+
+ if(!sys_thread_new("tcp data server", uartadapter_tcp_chat_server_thread, (void *)ua_socket, 256, UA_UART_THREAD_PRIORITY))
+ ua_printf(UA_ERROR, "%s sys_thread_new data server failed\n", __FUNCTION__);
+
+ vTaskDelay(50);
+ if(!sys_thread_new("tcp control server", uartadapter_tcp_control_server_thread, (void *)ua_socket, 256, UA_UART_THREAD_PRIORITY))
+ ua_printf(UA_ERROR, "%s sys_thread_new control server failed\n", __FUNCTION__);
+
+ vTaskDelay(50);
+
+ if(!sys_thread_new("tcp select", uartadapter_tcp_select_thread, (void *)ua_socket, 768, UA_UART_THREAD_PRIORITY))
+ ua_printf(UA_ERROR, "%s sys_thread_new tcp select failed\n", __FUNCTION__);
+
+ vTaskDelay(50);
+
+ uartadapter_control_read_tcp_info_and_connect(ua_socket);
+
+ vTaskDelay(50);
+#ifdef MDNS_LIB_EN
+ uartadapter_mdns_start(ua_socket, 0);
+
+ vTaskDelay(50);
+#endif
+
+ ua_printf(UA_INFO, "[MEM] After auao connect, available heap %d", xPortGetFreeHeapSize());
+
+ /* Kill init thread after all init tasks done */
+ vTaskDelete(NULL);
+}
+
+void uartadapter_exception_thread(void *param)
+{
+ int ret = 0;
+ unsigned int tick_start;
+ unsigned int tick_current;
+ int pin_high = 0;
+ int address = FAST_RECONNECT_DATA;
+
+ ua_socket_t *ua_socket = (ua_socket_t *)param;
+
+ while(RtlDownSema(&ua_exception_sema) == pdTRUE){
+ if(ua_gpio_irq_happen){
+ pin_high = 0;
+ tick_start = xTaskGetTickCount();
+ tick_current = xTaskGetTickCount();
+ while(tick_current - tick_start < 3000){
+ if (gpio_read(&ua_socket->gpio.gpio_btn)){
+ pin_high = 1;
+ break;
+ }else{
+ tick_current = xTaskGetTickCount();
+ }
+ vTaskDelay(10);
+ }
+
+ ua_gpio_irq_happen = 0;
+ if(!pin_high){
+ ret = uartadapter_flasherase(address, sizeof(rtw_wifi_config_t));
+ if(ret < 0){
+ ua_printf(UA_ERROR, "flash erase error!");
+ }
+
+ ret = uartadapter_flasherase(UA_FAST_RECONNECT_TCP_DATA, sizeof(ua_tcp_socket_t));
+ if(ret < 0){
+ ua_printf(UA_ERROR, "flash erase error!");
+ }
+
+ uartadapter_systemreload();
+ }
+ }
+ }
+
+ vTaskDelete(NULL);
+}
+
+ua_socket_t* uartadapter_socket_init()
+{
+ ua_socket_t* ua_socket = NULL;
+ //int ret = 0;
+
+ ua_socket = pvPortMalloc(sizeof(ua_socket_t));
+
+ if(NULL == ua_socket){
+ ua_printf(UA_ERROR, "Allocate uart adapter socket failed.");
+ goto Exit2;
+ }
+
+ ua_socket->uart.rcv_ch = 0;
+ ua_socket->uart.overlap = 0;
+ ua_socket->uart.recv_bytes = 0;
+ ua_socket->uart.pread = 0;
+ ua_socket->uart.pwrite = 0;
+ ua_socket->uart.tick_last_update = 0;
+ ua_socket->uart.tick_current = 0;
+ ua_socket->uart.rx_cnt = 0;
+ ua_socket->uart.miss_cnt = 0;
+ ua_socket->uart.tx_busy = 0;
+ RtlInitSema(&ua_socket->uart.action_sema, 0);
+ RtlInitSema(&ua_socket->uart.tcp_tx_rx_sema, 1);
+ RtlInitSema(&ua_socket->uart.dma_tx, 1);
+
+ ua_socket->tcp.chat_socket= -1;
+ ua_socket->tcp.control_socket= -1;
+ ua_socket->tcp.chat_server_listen_socket= -1;
+ ua_socket->tcp.control_server_listen_socket= -1;
+
+ ua_socket->tcp.transmit_recv_socket = -1;
+ ua_socket->tcp.transmit_send_socket = -1;
+ ua_socket->tcp.transmit_server_listen_socket = -1;
+
+ ua_socket->tcp.group_id = 0;
+ ua_socket->tcp.server_port = 0;
+ ua_socket->tcp.client_port = 0;
+ memset(ua_socket->tcp.client_ip, 0, 16);
+
+ ua_socket->tcp.send_flag = 0;
+ ua_socket->tcp.recv_flag = 0;
+ ua_socket->tcp.rx_cnt = 0;
+ ua_socket->tcp.tx_cnt = 0;
+
+ ua_socket->uart.uart_ps = 0;
+ ua_socket->uart.uart_ps_cnt = 0;
+ ua_socket->tcp.tcp_ps = 0;
+ ua_socket->tcp.tcp_ps_cnt = 0;
+
+ ua_socket->dnsServiceRef = NULL;
+ ua_socket->dnsServiceRef2 = NULL;
+
+ return ua_socket;
+
+Exit2:
+ return NULL;
+
+}
+
+void uartadapter_disconnect_handler(char *buf, int buf_len, int flags, void *userdata)
+{
+ if(!ua_wifi_connected || ua_reconnect_started)
+ return;
+
+ ua_printf(UA_DEBUG, "start uart adapter reconnect thread\r\n");
+ //uartadapter_gpio_led_mode(ua_global_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+
+ if(xTaskCreate(uartadapter_auto_reconnect, ((const char*)"reconnect"), 512, (void *)ua_global_socket, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(uart_rx) failed", __FUNCTION__);
+
+}
+
+int uartadapter_init()
+{
+ int ret = 0;
+
+ RtlInitSema(&ua_print_sema, 1);
+
+ ua_printf(UA_INFO, "==============>%s()\n", __func__);
+
+ ua_global_socket = uartadapter_socket_init();
+ if(ua_global_socket == NULL){
+ ua_printf(UA_ERROR, "ua_socket init failed");
+ ret = -1;
+ goto Exit;
+ }
+
+#if !UA_PS_ENABLE
+ acquire_wakelock(UA_WAKELOCK);
+#endif
+
+ RtlInitSema(&ua_exception_sema, 0);
+
+ uartadapter_uart_init(ua_global_socket);
+
+ uartadapter_gpio_init(ua_global_socket);
+ //uartadapter_gpio_led_mode(ua_global_socket, UART_ADAPTER_LED_FAST_TWINKLE);
+
+ wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, uartadapter_disconnect_handler, NULL);
+
+ if(xTaskCreate(uartadapter_uart_rx_thread, ((const char*)"uart_rx"), 256, (void *)ua_global_socket, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(uart_rx) failed", __FUNCTION__);
+
+ vTaskDelay(50);
+
+ if(xTaskCreate(uartadapter_auto_connect, ((const char*)"auto connnect"), 1024, (void *)ua_global_socket, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(auao connnect) failed", __FUNCTION__);
+
+ vTaskDelay(50);
+
+ if(xTaskCreate(uartadapter_exception_thread, ((const char*)"uart main"), 128, (void *)ua_global_socket, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(auao connnect) failed", __FUNCTION__);
+
+ return 0;
+Exit:
+ ua_printf(UA_ERROR, "%s(): Initialization failed!", __func__);
+ return ret;
+}
+
+void example_uart_adapter_init()
+{
+ // Call back from wlan driver after wlan init done
+ p_wlan_uart_adapter_callback = uartadapter_init;
+}
+
+#define _________CMD__RELATED________________________
+void uartadapter_print_irq_rx_count(ua_socket_t *ua_socket)
+{
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_printf(UA_INFO, "ua_tick_last_update: %d!\n", ua_socket->uart.tick_last_update);
+ ua_printf(UA_INFO, "ua_tick_current: %d!\n", ua_socket->uart.tick_current);
+ ua_printf(UA_INFO, "ua current tick: %d!\n", xTaskGetTickCount());
+ ua_printf(UA_INFO, "ua_pwrite: %d!\n", ua_socket->uart.pwrite);
+ ua_printf(UA_INFO, "ua_pread: %d!\n", ua_socket->uart.pread);
+ ua_printf(UA_INFO, "ua_overlap: %d!\n", ua_socket->uart.overlap);
+ ua_printf(UA_INFO, "ua_rcv_ch: %d!\n", ua_socket->uart.rcv_ch);
+ ua_printf(UA_INFO, "ua_uart_recv_bytes: %d!\n", ua_socket->uart.recv_bytes);
+ ua_printf(UA_INFO, "irq_rx_cnt: %d!\n", ua_socket->uart.rx_cnt);
+ ua_printf(UA_INFO, "irq_miss_cnt: %d!\n", ua_socket->uart.miss_cnt);
+ ua_printf(UA_INFO, "tcp_tx_cnt: %d!\n", ua_socket->tcp.tx_cnt);
+ ua_printf(UA_INFO, "tcp_rx_cnt: %d!\n", ua_socket->tcp.rx_cnt);
+ ua_printf(UA_INFO, "tcp_send_flag: %d!\n", ua_socket->tcp.send_flag);
+ ua_printf(UA_INFO, "tcp_recv_flag: %d!\n", ua_socket->tcp.recv_flag);
+ ua_printf(UA_INFO, "tcp_chat_socket: %d!\n", ua_socket->tcp.chat_socket);
+ ua_printf(UA_INFO, "tcp_control_socket: %d!\n", ua_socket->tcp.control_socket);
+ ua_printf(UA_INFO, "tcp_transmit_recv_socket: %d!\n", ua_socket->tcp.transmit_recv_socket);
+ ua_printf(UA_INFO, "tcp_transmit_send_socket: %d!\n", ua_socket->tcp.transmit_send_socket);
+ ua_printf(UA_INFO, "tcp_chat_server_listen_socket: %d!\n", ua_socket->tcp.chat_server_listen_socket);
+ ua_printf(UA_INFO, "tcp_control_server_listen_socket: %d!\n", ua_socket->tcp.control_server_listen_socket);
+ ua_printf(UA_INFO, "tcp_transmit_server_listen_socket: %d!\n", ua_socket->tcp.transmit_server_listen_socket);
+
+}
+
+void uartadapter_reset_irq_rx_count(ua_socket_t *ua_socket)
+{
+ UA_SOCKET_CHECK(ua_socket);
+
+ ua_socket->uart.rx_cnt = 0;
+ ua_socket->uart.miss_cnt = 0;
+ ua_socket->tcp.rx_cnt = 0;
+ ua_socket->tcp.tx_cnt = 0;
+}
+
+void uartadapter_set_debug_print(bool enable)
+{
+ ua_debug_print_en = enable;
+}
+
+void cmd_uart_adapter(int argc, char **argv)
+{
+ if(argc < 2) {
+ printf(" input error\n");
+ return;
+ }
+
+ if(strcmp(argv[1], "help") == 0){
+ printf("UART THROUGH COMMAND LIST:\n");
+ printf("==============================\n");
+ printf("tuart_baud\n");
+ printf("\n");
+ }else if(strcmp(argv[1], "irq_rx_get") == 0){
+ uartadapter_print_irq_rx_count(ua_global_socket);
+ }else if(strcmp(argv[1], "debug_print_en") == 0){
+ uartadapter_set_debug_print(TRUE);
+ }else if(strcmp(argv[1], "debug_print_dis") == 0){
+ uartadapter_set_debug_print(FALSE);
+ }else if(strcmp(argv[1], "irq_rx_reset") == 0){
+ uartadapter_reset_irq_rx_count(ua_global_socket);
+ }else if(strcmp(argv[1], "tcp") == 0){
+ unsigned int port;
+ if(strcmp(argv[2], "-c") == 0 || strcmp(argv[2], "c") == 0){
+ strncpy(ua_tcp_server_ip, argv[3], (strlen(argv[3])>16)?16:strlen(argv[3]));
+ port = atoi(argv[4]);
+ if(xTaskCreate(uartadapter_tcp_transmit_client_thread, ((const char*)"tclient"), 256, (void *)port, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(tcp client) failed", __FUNCTION__);
+ }else if(strcmp(argv[2], "-s") == 0 || strcmp(argv[2], "s") == 0){
+ port = atoi(argv[3]);
+ if(xTaskCreate(uartadapter_tcp_transmit_server_thread, ((const char*)"tserver"), 256, (void *)port, UA_UART_THREAD_PRIORITY, NULL) != pdPASS)
+ ua_printf(UA_ERROR, "%s xTaskCreate(tcp server) failed", __FUNCTION__);
+ }
+ }else if(strcmp(argv[1], "uart_baud") == 0){
+ uartadapter_uart_baud(ua_global_socket, atoi(argv[2]));
+ }else if(strcmp(argv[1], "uart_para") == 0){
+ uartadapter_uart_para(ua_global_socket, atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
+ }else if(strcmp(argv[1], "led") == 0){
+ //uartadapter_gpio_led_mode(ua_global_socket, atoi(argv[2]));
+ }else{
+ printf("Can not find the input command!\n");
+ }
+}
+
+#endif // #if CONFIG_UART_SOCKET
diff --git a/RTL00_SDKV35a/component/common/application/uart_adapter/uart_adapter.h b/RTL00_SDKV35a/component/common/application/uart_adapter/uart_adapter.h
new file mode 100644
index 0000000..89f526f
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/uart_adapter/uart_adapter.h
@@ -0,0 +1,272 @@
+#include "osdep_api.h"
+#include "serial_api.h"
+#include
+#include "freertos_pmu.h"
+#include
+
+#if CONFIG_UART_SOCKET
+
+/******************************************************
+ * Macros
+ ******************************************************/
+#define UA_ERROR 0
+#define UA_WARNING 1
+#define UA_INFO 2
+#define UA_DEBUG 2 //pvvx! было 3
+#define UA_NONE 0xFF
+#define UA_DEBUG_LEVEL UA_INFO
+
+#define UA_UART_THREAD_PRIORITY 5
+#define UA_UART_THREAD_STACKSIZE 512
+
+#define UA_TCP_SERVER_FD_NUM 1
+#define UA_TCP_CLIENT_FD_NUM 1
+
+#define UA_UART_RECV_BUFFER_LEN 8196
+#define UA_UART_FRAME_LEN 1400
+#define UA_UART_MAX_DELAY_TIME 100
+
+#define UA_CHAT_SOCKET_PORT 5001
+#define UA_CONTROL_SOCKET_PORT 6001
+
+#define UA_UART_TX_PIN PA_4
+#define UA_UART_RX_PIN PA_0
+#define UA_UART_RTS_PIN PA_2
+#define UA_UART_CTS_PIN PA_1
+
+#define UA_GPIO_LED_PIN PC_5
+#define UA_GPIO_IRQ_PIN PC_4
+
+#define UA_CONTROL_PREFIX "AMEBA_UART"
+
+#define UA_PS_ENABLE 0
+#define UA_GPIO_WAKEUP_PIN PC_3
+#define UA_WAKELOCK WAKELOCK_USER_BASE
+
+#define UA_FAST_RECONNECT_TCP_DATA (0x80000 - 0x2000)
+
+
+#if (UA_DEBUG_LEVEL== UA_NONE)
+#define ua_printf(level, fmt, arg...)
+#else
+#define ua_printf(level, fmt, arg...) \
+do {\
+ if (level <= UA_DEBUG_LEVEL) {\
+ if (level <= UA_ERROR) {\
+ RtlDownSema(&ua_print_sema);\
+ printf("\r\nERROR: " fmt, ##arg);\
+ RtlUpSema(&ua_print_sema);\
+ } \
+ else {\
+ RtlDownSema(&ua_print_sema);\
+ printf("\r\n"fmt, ##arg);\
+ RtlUpSema(&ua_print_sema);\
+ } \
+ }\
+}while(0)
+#endif
+
+#define UA_PRINT_DATA(_HexData, _HexDataLen) \
+ if(UA_DEBUG_LEVEL == UA_DEBUG) \
+ { \
+ int __i; \
+ u8 *ptr = (u8 *)_HexData; \
+ printf("--------Len=%d\n\r", _HexDataLen); \
+ for( __i=0; __i<(int)_HexDataLen; __i++ ) \
+ { \
+ printf("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" "); \
+ if (((__i + 1) % 16) == 0) printf("\n\r"); \
+ } \
+ printf("\n\r"); \
+ }
+
+#define UA_SOCKET_CHECK(_ua_socket) \
+ if(_ua_socket == NULL) \
+ { \
+ printf("ERROR: ua_socket = NULL\n\r"); \
+ return; \
+ }
+
+#define UA_SOCKET_CHECK_2(_ua_socket) \
+ if(_ua_socket == NULL) \
+ { \
+ printf("ERROR: ua_socket = NULL\n\r"); \
+ return -1; \
+ }
+
+/******************************************************
+ * Constants
+ ******************************************************/
+typedef enum
+{
+ UART_ADAPTER_LED_ON = 0,
+ UART_ADAPTER_LED_OFF = 1,
+ UART_ADAPTER_LED_FAST_TWINKLE = 2,
+ UART_ADAPTER_LED_SLOW_TWINKLE = 3,
+}ua_led_mode_t;
+
+typedef enum
+{
+ UART_CTRL_MODE_SET_REQ = 0,
+ UART_CTRL_MODE_SET_RSP = 1,
+ UART_CTRL_MODE_GET_REQ = 2,
+ UART_CTRL_MODE_GET_RSP = 3,
+}ua_ctrl_mode_t;
+
+typedef enum
+{
+ UART_CTRL_TYPE_BAUD_RATE = 0x01,
+ UART_CTRL_TYPE_WORD_LEN = 0x02,
+ UART_CTRL_TYPE_PARITY = 0x04,
+ UART_CTRL_TYPE_STOP_BIT = 0x08,
+ UART_CTRL_TYPE_TCP_SERVER_CREATE = 0x10,
+ UART_CTRL_TYPE_TCP_SERVER_DELETE = 0x20,
+ UART_CTRL_TYPE_TCP_CLIENT_CONNECT = 0x40,
+ UART_CTRL_TYPE_TCP_CLIENT_DISCONNECT = 0x80,
+ UART_CTRL_TYPE_TCP_GROUP_ID = 0x100,
+}ua_ctrl_type_t;
+
+enum sc_result {
+ SC_ERROR = -1, /* default error code*/
+ SC_NO_CONTROLLER_FOUND = 1, /* cannot get sta(controller) in the air which starts a simple config session */
+ SC_CONTROLLER_INFO_PARSE_FAIL, /* cannot parse the sta's info */
+ SC_TARGET_CHANNEL_SCAN_FAIL, /* cannot scan the target channel */
+ SC_JOIN_BSS_FAIL, /* fail to connect to target ap */
+ SC_DHCP_FAIL, /* fail to get ip address from target ap */
+ /* fail to create udp socket to send info to controller. note that client isolation
+ must be turned off in ap. we cannot know if ap has configured this */
+ SC_UDP_SOCKET_CREATE_FAIL,
+ SC_SUCCESS, /* default success code */
+};
+
+
+/******************************************************
+ * Structures
+ ******************************************************/
+ typedef struct _ua_uart_param_t
+{
+ u8 WordLen;
+ u8 Parity;
+ u8 StopBit;
+ u8 FlowControl;
+ int BaudRate;
+}ua_uart_param_t;
+
+
+typedef struct _ua_uart_socket_t
+{
+ int fd;
+ char rcv_ch;
+ volatile char overlap;
+ int recv_bytes;
+ volatile int pread;
+ volatile int pwrite;
+
+ volatile unsigned int tick_last_update;
+ unsigned int tick_current;
+
+ volatile int tx_busy;
+
+ volatile int uart_ps;
+ volatile int uart_ps_cnt;
+
+ char recv_buf[UA_UART_RECV_BUFFER_LEN];
+
+ long rx_cnt;
+ long miss_cnt;
+
+ serial_t uart_sobj;
+ ua_uart_param_t uart_param;
+
+ _Sema action_sema;
+ _Sema tcp_tx_rx_sema;
+ _Sema dma_tx;
+}ua_uart_socket_t;
+
+typedef struct _ua_tcp_socket_t
+{
+ int chat_socket;
+ int control_socket;
+ int chat_server_listen_socket;
+ int control_server_listen_socket;
+
+ int transmit_recv_socket;
+ int transmit_send_socket;
+ int transmit_server_listen_socket;
+
+ int group_id;
+ u32 server_port;
+ u32 client_port;
+ char client_ip[16];
+
+
+ int send_flag;
+ int recv_flag;
+ long rx_cnt;
+ long tx_cnt;
+
+ volatile int tcp_ps;
+ volatile int tcp_ps_cnt;
+}ua_tcp_socket_t;
+
+typedef struct _ua_gpio_t
+{
+ gpio_t gpio_led;
+ gpio_t gpio_btn;
+ gpio_irq_t gpio_btn_irq;
+ gtimer_t gpio_timer;
+}ua_gpio_t;
+
+typedef struct _ua_socket_t
+{
+ ua_uart_socket_t uart;
+ ua_tcp_socket_t tcp;
+ ua_gpio_t gpio;
+ ip_addr_t ip;
+ DNSServiceRef dnsServiceRef;
+ DNSServiceRef dnsServiceRef2;
+}ua_socket_t;
+
+typedef struct _ua_mbox_buffer
+{
+ char data[UA_UART_FRAME_LEN];
+ int data_len;
+}ua_mbox_buffer_t;
+
+//Save Uart Settings when get uart information
+typedef struct _ua_uart_get_str
+{
+ int BaudRate; //The baud rate
+ char number; //The number of data bits
+ char parity; //The parity(0: none, 1:odd, 2:evn, default:0)
+ char StopBits; //The number of stop bits
+ char FlowControl; //support flow control is 1
+}ua_uart_get_str;
+
+//Uart Setting information
+typedef struct _ua_uart_set_str
+{
+ char UartName[8]; // the name of uart
+ int BaudRate; //The baud rate
+ char number; //The number of data bits
+ char parity; //The parity(default NONE)
+ char StopBits; //The number of stop bits
+ char FlowControl; //support flow control is 1
+}ua_uart_set_str;
+
+
+int uartadapter_init();
+void uartadapter_tcp_send_data(ua_socket_t *ua_socket, char *buffer, int size);
+void uartadapter_tcp_send_control(ua_socket_t *ua_socket, char *buffer, int size);
+void uartadapter_tcp_transmit_server_thread(void *param);
+void uartadapter_tcp_transmit_client_thread(void *param);
+int uartadapter_tcpclient(ua_socket_t *ua_socket, const char *host_ip, unsigned short usPort);
+void uartadapter_tcp_transmit_client_forever_thread(void *param);
+
+
+void example_uart_adapter_init();
+void cmd_uart_adapter(int argc, char **argv);
+
+void uartadapter_tcp_transmit_socket_handler(ua_socket_t *ua_socket, char *tcp_rxbuf);
+
+#endif // CONFIG_UART_SOCKET
diff --git a/RTL00_SDKV35a/component/common/application/wigadget/cloud_link.c b/RTL00_SDKV35a/component/common/application/wigadget/cloud_link.c
new file mode 100644
index 0000000..3de0239
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/wigadget/cloud_link.c
@@ -0,0 +1,83 @@
+#include "FreeRTOS.h"
+#include "task.h"
+#include "wifi_conf.h"
+#include "wifi_ind.h"
+#include "google_nest.h"
+#include "flash_api.h"
+#include "wigadget.h"
+#include
+#include "lwip_netconf.h"
+#include "shtc1.h"
+
+#define CLOUD_PORT 443
+extern struct netif xnetif[NET_IF_NUM];
+
+void cloud_link_task(void *param){
+ googlenest_context googlenest;
+ unsigned char URI[64];
+ unsigned char data[97] = {0};
+ unsigned char host_addr[64] = {0};
+ flash_t cloud_flash;
+ u8 *mac = (u8 *)LwIP_GetMAC(&xnetif[0]);
+ char i[16], j[16];
+ float temperature = 1.123f;
+ float humidity = 2.456f;
+ int ret = 0;
+
+ vTaskDelay(2000);
+
+
+ sprintf(URI, "ht_sensor/%02x%02x%02x%02x%02x%02x.json", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+ memset(host_addr, 0, sizeof(host_addr));
+ if(flash_stream_read(&cloud_flash, FLASH_IOT_DATA, 97, (uint8_t *) data) == 1){
+
+ memset(host_addr, 0 , 64);
+ memcpy(host_addr, data+33, 64);
+ while(1) {
+ printf("\n=====>START CLOUD LINKING\n");
+ memset(i, 0, 16);
+ memset(j, 0, 16);
+#if PSEUDO_DATA
+ sprintf(i,"%.2f", temperature++);
+ sprintf(j, "%.2f", humidity++);
+ if(temperature > 60)
+ temperature = 1.123f;
+ if(humidity > 98)
+ humidity = 2.456f;
+#else
+ ret = SHTC_GetTempAndHumi(&temperature, &humidity);
+ sprintf(i,"%.2f", temperature);
+ sprintf(j, "%.2f", humidity);
+#endif
+ if(ret < 0)
+ printf("\n<-----LOCAL LINK FAILED!!(get infor failed)\n");
+ else{
+ gen_json_data(i,j, data);
+ printf("\nCLOUD-LINK--Sending data : \n%s\n", data);
+ memset(&googlenest, 0, sizeof(googlenest_context));
+ if(gn_connect(&googlenest, host_addr, CLOUD_PORT) == 0) {
+ if(gn_put(&googlenest, URI, data) != 0)
+ printf("PUT data failed!\n");
+ gn_close(&googlenest);
+ printf("\n<=====CLOUD LINK OK!!\n");
+ }
+ else{
+ printf("\n<=====CLOUD LINK FAILED!!(google nest connecting)\n");
+ }
+ free(data);
+ vTaskDelay(10000);
+ }
+ }
+
+ }
+ else
+ printf("\n<=====CLOUD LINK FAILED!!(flash reading)\n");
+
+}
+
+void start_cloud_link(void)
+{
+if(xTaskCreate(cloud_link_task, ((const char*)"cloud_link_task"), 3584, NULL, tskIDLE_PRIORITY + 4, NULL) != pdPASS)
+ printf("%s xTaskCreate failed\n", __FUNCTION__);
+}
diff --git a/RTL00_SDKV35a/component/common/application/wigadget/cloud_link.h b/RTL00_SDKV35a/component/common/application/wigadget/cloud_link.h
new file mode 100644
index 0000000..650c1f6
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/wigadget/cloud_link.h
@@ -0,0 +1,11 @@
+#ifndef CLOUD_LINK_H
+#define CLOUD_LINK_THREAD_H
+
+#include "wigadget.h"
+
+void start_cloud_link(void);
+void cloud_link_task(void *param);
+
+
+#endif
+
diff --git a/RTL00_SDKV35a/component/common/application/wigadget/shtc1.c b/RTL00_SDKV35a/component/common/application/wigadget/shtc1.c
new file mode 100644
index 0000000..8965c99
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/wigadget/shtc1.c
@@ -0,0 +1,186 @@
+#include "device.h"
+#include "PinNames.h"
+#include "osdep_api.h"
+#include "i2c_api.h"
+#include "pinmap.h"
+#include "shtc1.h"
+#include "platform_stdlib.h"
+
+#ifdef CONFIG_I2C_EN
+
+#define MBED_I2C_MTR_SDA PB_3
+#define MBED_I2C_MTR_SCL PB_2
+
+#define MBED_I2C_SLAVE_ADDR0 0x70
+#define POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 + 1 = 100110001
+
+#define MBED_I2C_BUS_CLK 100000 //hz
+#define I2C_DATA_MAX_LENGTH 16
+
+static uint8_t i2cdata_write[I2C_DATA_MAX_LENGTH];
+static uint8_t i2cdata_read[I2C_DATA_MAX_LENGTH];
+static int i2cdata_read_pos;
+
+static i2c_t i2cmaster;
+
+// Sensor Commands
+#define READ_ID 0xEFC8 // command: read ID register
+#define SOFT_RESET 0x805D // soft resetSample Code for SHTC1
+#define MEAS_T_RH_POLLING 0x7866 // meas. read T first, clock stretching disabled
+#define MEAS_T_RH_CLOCKSTR 0x7CA2 // meas. read T first, clock stretching enabled
+#define MEAS_RH_T_POLLING 0x58E0 // meas. read RH first, clock stretching disabled
+#define MEAS_RH_T_CLOCKSTR 0x5C24 // meas. read RH first, clock stretching enabled
+
+
+static int SHTC1_GetID(uint16_t *id);
+static void SHTC1_WriteCommand(uint16_t cmd);
+static int SHTC1_Read2BytesAndCrc(uint16_t *data);
+static int SHTC1_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);
+static float SHTC1_CalcTemperature(uint16_t rawValue);
+static float SHTC1_CalcHumidity(uint16_t rawValue);
+
+
+int SHTC_Init(uint16_t *pID)
+{
+ int error = NO_ERROR;
+
+ DiagPrintf("SHTC1_Init\n");
+
+ i2c_init((i2c_t*)&i2cmaster, MBED_I2C_MTR_SDA ,MBED_I2C_MTR_SCL);
+ i2c_frequency((i2c_t*)&i2cmaster,MBED_I2C_BUS_CLK);
+
+ if (pID == NULL )
+ return NULL_ERROR;
+ error = SHTC1_GetID(pID);
+
+ return error;
+}
+
+static int SHTC1_GetID(uint16_t *id)
+{
+ int error = NO_ERROR;
+ uint8_t bytes[2];
+ uint8_t checksum;
+
+ SHTC1_WriteCommand(READ_ID);
+
+ i2c_read((i2c_t*)&i2cmaster, MBED_I2C_SLAVE_ADDR0, (char*)&i2cdata_read[0], 3, 1);
+ i2cdata_read_pos = 0;
+ error = SHTC1_Read2BytesAndCrc(id);
+
+ return error;
+}
+
+static int SHTC1_Read2BytesAndCrc(uint16_t *data)
+{
+ int error;
+ int readed;
+ uint8_t bytes[2];
+ uint8_t checksum;
+
+ bytes[0] = i2cdata_read[i2cdata_read_pos++];
+ bytes[1] = i2cdata_read[i2cdata_read_pos++];
+ checksum = i2cdata_read[i2cdata_read_pos++];
+
+ error = SHTC1_CheckCrc(bytes, 2, checksum);
+ *data = (bytes[0] << 8) | bytes[1];
+
+ return error;
+}
+
+static int SHTC1_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum)
+{
+ uint8_t bit; // bit mask
+ uint8_t crc = 0xFF; // calculated checksum
+ uint8_t byteCtr; // byte counter
+
+ for(byteCtr = 0; byteCtr < nbrOfBytes; byteCtr++){
+ crc ^= (data[byteCtr]);
+ for(bit = 8; bit > 0; --bit){
+ if(crc & 0x80)
+ crc = (crc << 1) ^ POLYNOMIAL;
+ else
+ crc = (crc << 1);
+ }
+ }
+
+ if(crc != checksum)
+ return CHECKSUM_ERROR;
+ else
+ return NO_ERROR;
+}
+
+static void SHTC1_WriteCommand(uint16_t cmd)
+{
+ int writebytes;
+
+ i2cdata_write[0] = (uint8_t)(cmd >>8);
+ i2cdata_write[1] = (uint8_t)(cmd&0xFF);
+ i2c_write((i2c_t*)&i2cmaster, MBED_I2C_SLAVE_ADDR0, &i2cdata_write[0], 2, 1);
+}
+
+static float SHTC1_CalcTemperature(uint16_t rawValue)
+{
+ return 175.0 * (float)rawValue / 65536.0 - 45.0;
+}
+
+static float SHTC1_CalcHumidity(uint16_t rawValue)
+{
+ return 100.0 * (float)rawValue / 65536.0;
+}
+
+int SHTC_GetTempAndHumi(float *temp, float *humi)
+{
+ int error;
+ uint16_t rawValueTemp;
+ uint16_t rawValueHumi;
+
+ SHTC1_WriteCommand(MEAS_T_RH_CLOCKSTR);
+
+ i2c_read((i2c_t*)&i2cmaster, MBED_I2C_SLAVE_ADDR0, (char*)&i2cdata_read[0], 6, 1);
+ i2cdata_read_pos = 0;
+ error = NO_ERROR;
+ error |= SHTC1_Read2BytesAndCrc(&rawValueTemp);
+ error |= SHTC1_Read2BytesAndCrc(&rawValueHumi);
+
+ if ( error == NO_ERROR ) {
+ *temp = SHTC1_CalcTemperature(rawValueTemp);
+ *humi = SHTC1_CalcHumidity(rawValueHumi);
+ }
+
+ return error;
+}
+
+static void example_shtc1_thread(void *param)
+{
+ int error;
+ uint16_t shtc1_id;
+ float temperature = 1.123f;
+ float humidity = 2.456f;
+
+ DBG_8195A("sleep 10 sec. to wait for UART console\n");
+ RtlMsleepOS(10000);
+ DBG_8195A("start i2c example - SHTC1\n");
+
+ error = SHTC_Init(&shtc1_id);
+ if ( error == NO_ERROR )
+ DiagPrintf("SHTC1 init ok, id=0x%x\n", shtc1_id);
+ else {
+ DiagPrintf("SHTC1 init FAILED!\n");
+ for(;;);
+ }
+
+ while(1){
+ error = SHTC_GetTempAndHumi(&temperature, &humidity);
+ rtl_printf("temp=%f, humidity=%f, error=%d\n", temperature, humidity, error);
+ RtlMsleepOS(1000);
+ }
+}
+
+void example_shtc1(void)
+{
+ if(xTaskCreate(example_shtc1_thread, ((const char*)"example_shtc1_thread"), 512, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
+ printf("%s xTaskCreate(init_thread) failed\n", __FUNCTION__);
+}
+
+#endif //#ifdef CONFIG_I2C_EN
diff --git a/RTL00_SDKV35a/component/common/application/wigadget/shtc1.h b/RTL00_SDKV35a/component/common/application/wigadget/shtc1.h
new file mode 100644
index 0000000..f5259dc
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/wigadget/shtc1.h
@@ -0,0 +1,13 @@
+#ifndef SHTC1_H
+#define SHTC1_H
+
+#define NO_ERROR 0x00
+#define ACK_ERROR 0x01
+#define CHECKSUM_ERROR 0x02
+#define NULL_ERROR 0x03
+
+int SHTC_GetTempAndHumi(float *temp, float *humi);
+int SHTC_Init(uint16_t *pID);
+void example_shtc1(void);
+
+#endif
diff --git a/RTL00_SDKV35a/component/common/application/wigadget/wigadget.c b/RTL00_SDKV35a/component/common/application/wigadget/wigadget.c
new file mode 100644
index 0000000..b050517
--- /dev/null
+++ b/RTL00_SDKV35a/component/common/application/wigadget/wigadget.c
@@ -0,0 +1,743 @@
+#include "FreeRTOS.h"
+#include "task.h"
+#include "wifi_conf.h"
+#include "wifi_ind.h"
+#include "sockets.h"
+#include
+#include
+#include