[rdkb][common][conf][Add filogic830 onewifi build support]

[Description]
Add filogic830 onewifi build support

[Release-log]

Change-Id: I5db0bc298ecfbc84c4338bf6dac77a15ddd3474e
diff --git a/recipes-ccsp/ccsp/ccsp-common-library.bbappend b/recipes-ccsp/ccsp/ccsp-common-library.bbappend
index 801ad2a..932e45d 100644
--- a/recipes-ccsp/ccsp/ccsp-common-library.bbappend
+++ b/recipes-ccsp/ccsp/ccsp-common-library.bbappend
@@ -19,12 +19,11 @@
     file://utopia.service \
 "
 
-SRC_URI_remove = "file://0001-DBusLoop-SSL_state-TLS_ST_OK.patch"
+SRC_URI_remove_dunfell = "file://0001-DBusLoop-SSL_state-TLS_ST_OK.patch"
 
 SRC_URI += "file://0003-add-dependency-to-pandm.patch;apply=no"
-SRC_URI += "file://0004-fix-out-of-array-access.patch;apply=no"
 
-SRC_URI_append = " file://0001-DBusLoop-SSL_state-TLS_ST_OK.patch;apply=no"
+SRC_URI_append_dunfell = " file://0001-DBusLoop-SSL_state-TLS_ST_OK.patch;apply=no"
 
 
 # we need to patch to code for Filogic
@@ -33,10 +32,11 @@
     if [ ! -e patch_applied ]; then
         bbnote "Patching 0003-add-dependency-to-pandm.patch"
         patch -p1 < ${WORKDIR}/0003-add-dependency-to-pandm.patch
-        patch -p1 < ${WORKDIR}/0004-fix-out-of-array-access.patch
-        bbnote "Patching 0001-DBusLoop-SSL_state-TLS_ST_OK.patch"
-        patch -p1 < ${WORKDIR}/0001-DBusLoop-SSL_state-TLS_ST_OK.patch
+        if [ "${@bb.utils.contains('DISTRO_CODENAME', 'dunfell', 'dunfell', '', d)}" = "dunfell" ] ; then
+            bbnote "Patching 0001-DBusLoop-SSL_state-TLS_ST_OK.patch"
+            patch -p1 < ${WORKDIR}/0001-DBusLoop-SSL_state-TLS_ST_OK.patch
 
+        fi
        touch patch_applied
     fi
 }
@@ -73,9 +73,8 @@
     install -D -m 0644 ${S}/systemd_units/CcspLMLite.service ${D}${systemd_unitdir}/system/CcspLMLite.service
     install -D -m 0644 ${S}/systemd_units/CcspTr069PaSsp.service ${D}${systemd_unitdir}/system/CcspTr069PaSsp.service
     install -D -m 0644 ${S}/systemd_units/snmpSubAgent.service ${D}${systemd_unitdir}/system/snmpSubAgent.service
-    install -D -m 0644 ${S}/systemd_units/snmpSubAgent.service ${D}${systemd_unitdir}/system/snmpSubAgent.service
     install -D -m 0644 ${S}/systemd_units/CcspEthAgent.service ${D}${systemd_unitdir}/system/CcspEthAgent.service
-
+    install -D -m 0644 ${S}/systemd_units/CcspTelemetry.service ${D}${systemd_unitdir}/system/CcspTelemetry.service
     #rfc service file
     install -D -m 0644 ${S}/systemd_units/rfc.service ${D}${systemd_unitdir}/system/rfc.service
 
@@ -109,6 +108,13 @@
     #change for Filogic
     sed -i 's/PIDFile/#&/' ${D}${systemd_unitdir}/system/CcspPandMSsp.service 
 
+    #Telemetry support
+     sed -i "/Type=oneshot/a EnvironmentFile=\/etc/\device.properties" ${D}${systemd_unitdir}/system/CcspTelemetry.service
+     sed -i "/EnvironmentFile=\/etc\/device.properties/a EnvironmentFile=\/etc\/dcm.properties" ${D}${systemd_unitdir}/system/CcspTelemetry.service
+     sed -i "/EnvironmentFile=\/etc\/dcm.properties/a ExecStartPre=\/bin\/sh -c '\/bin\/touch \/rdklogs\/logs\/dcmscript.log'" ${D}${systemd_unitdir}/system/CcspTelemetry.service
+     sed -i "s/ExecStart=\/bin\/sh -c '\/lib\/rdk\/dcm.service \&'/ExecStart=\/bin\/sh -c '\/lib\/rdk\/StartDCM.sh \>\> \/rdklogs\/logs\/telemetry.log \&'/g" ${D}${systemd_unitdir}/system/CcspTelemetry.service
+     sed -i "s/wan-initialized.target/multi-user.target/g" ${D}${systemd_unitdir}/system/CcspTelemetry.service
+
     #WanManager - RdkWanManager.service
      DISTRO_WAN_ENABLED="${@bb.utils.contains('DISTRO_FEATURES','rdkb_wan_manager','true','false',d)}"
      if [ $DISTRO_WAN_ENABLED = 'true' ]; then
@@ -119,7 +125,6 @@
      install -D -m 0644 ${WORKDIR}/utopia.service ${D}${systemd_unitdir}/system/utopia.service
      install -D -m 0644 ${S}/systemd_units/RdkTelcoVoiceManager.service ${D}${systemd_unitdir}/system/RdkTelcoVoiceManager.service
      install -D -m 0644 ${S}/systemd_units/RdkVlanManager.service ${D}${systemd_unitdir}/system/RdkVlanManager.service
-     sed -i "s/After=CcspCrSsp.service/After=CcspCrSsp.service utopia.service PsmSsp.service CcspEthAgent.service/g" ${D}${systemd_unitdir}/system/RdkVlanManager.service
     fi
 
      DISTRO_FW_ENABLED="${@bb.utils.contains('DISTRO_FEATURES','fwupgrade_manager','true','false',d)}"
@@ -133,6 +138,16 @@
 ethtool -s erouter0 speed 1000 \
 fi' ${D}/usr/ccsp/ccspPAMCPCheck.sh
 
+     DISTRO_OneWiFi_ENABLED="${@bb.utils.contains('DISTRO_FEATURES','OneWifi','true','false',d)}"
+     if [ $DISTRO_OneWiFi_ENABLED = 'true' ]; then
+         install -D -m 0644 ${S}/systemd_units/onewifi.service ${D}${systemd_unitdir}/system/onewifi.service
+         sed -i "s/Unit=ccspwifiagent.service/Unit=onewifi.service/g"  ${D}${systemd_unitdir}/system/filogicwifiinitialized.path
+         sed -i "/OSW_DRV_TARGET_DISABLED=1/a ExecStartPre=\/bin\/sh \/usr\/ccsp\/wifi\/onewifi_pre_start.sh"  ${D}${systemd_unitdir}/system/onewifi.service
+     fi
+
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'webconfig_bin', 'true', 'false', d)}; then
+        install -D -m 0644 ${S}/systemd_units/webconfig.service ${D}${systemd_unitdir}/system/webconfig.service
+    fi
 }
 
 do_install_append_dunfell_class-target () {
@@ -140,7 +155,6 @@
     sed -i '/CcspCrSsp.service/c After=CcspCrSsp.service gwprovethwan.service' ${D}${systemd_unitdir}/system/PsmSsp.service
 }
 
-SYSTEMD_SERVICE_${PN} += "ccspwifiagent.service"
 SYSTEMD_SERVICE_${PN} += "CcspCrSsp.service"
 SYSTEMD_SERVICE_${PN} += "CcspPandMSsp.service"
 SYSTEMD_SERVICE_${PN} += "PsmSsp.service"
@@ -159,8 +173,11 @@
 SYSTEMD_SERVICE_${PN} += "ProcessResetDetect.path"
 SYSTEMD_SERVICE_${PN} += "ProcessResetDetect.service"
 SYSTEMD_SERVICE_${PN} += "rfc.service"
+SYSTEMD_SERVICE_${PN} += "CcspTelemetry.service"
 SYSTEMD_SERVICE_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'rdkb_wan_manager', 'RdkWanManager.service utopia.service RdkVlanManager.service ', '', d)}"
 SYSTEMD_SERVICE_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'fwupgrade_manager', 'RdkFwUpgradeManager.service ', '', d)}"
+SYSTEMD_SERVICE_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'OneWifi', 'onewifi.service ', 'ccspwifiagent.service', d)}"
+SYSTEMD_SERVICE_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'webconfig_bin', 'webconfig.service', '', d)}"
 
 FILES_${PN}_append = " \
     /usr/ccsp/ccspSysConfigEarly.sh \
@@ -168,7 +185,6 @@
     /usr/ccsp/utopiaInitCheck.sh \
     /usr/ccsp/ccspPAMCPCheck.sh \
     /usr/ccsp/ProcessResetCheck.sh \
-    ${systemd_unitdir}/system/ccspwifiagent.service \
     ${systemd_unitdir}/system/CcspCrSsp.service \
     ${systemd_unitdir}/system/CcspPandMSsp.service \
     ${systemd_unitdir}/system/PsmSsp.service \
@@ -187,6 +203,8 @@
     ${systemd_unitdir}/system/ProcessResetDetect.path \
     ${systemd_unitdir}/system/ProcessResetDetect.service \
     ${systemd_unitdir}/system/rfc.service \
+    ${systemd_unitdir}/system/CcspTelemetry.service \
 "
 FILES_${PN}_append = "${@bb.utils.contains('DISTRO_FEATURES', 'rdkb_wan_manager', ' ${systemd_unitdir}/system/RdkWanManager.service ${systemd_unitdir}/system/utopia.service ${systemd_unitdir}/system/RdkVlanManager.service ${systemd_unitdir}/system/RdkTelcoVoiceManager.service ', '', d)}"
-FILES_${PN}_append = "${@bb.utils.contains('DISTRO_FEATURES', 'fwupgrade_manager', ' ${systemd_unitdir}/system/RdkFwUpgradeManager.service ', '', d)}"
\ No newline at end of file
+FILES_${PN}_append = "${@bb.utils.contains('DISTRO_FEATURES', 'fwupgrade_manager', ' ${systemd_unitdir}/system/RdkFwUpgradeManager.service ', '', d)}"
+FILES_${PN}_append = "${@bb.utils.contains('DISTRO_FEATURES', 'OneWifi', ' ${systemd_unitdir}/system/onewifi.service ', '  ${systemd_unitdir}/system/ccspwifiagent.service ', d)}"
\ No newline at end of file
diff --git a/recipes-ccsp/ccsp/ccsp-one-wifi.bbappend b/recipes-ccsp/ccsp/ccsp-one-wifi.bbappend
new file mode 100644
index 0000000..95e2050
--- /dev/null
+++ b/recipes-ccsp/ccsp/ccsp-one-wifi.bbappend
@@ -0,0 +1,40 @@
+require ccsp_common_filogic.inc
+
+FILESEXTRAPATHS_prepend := "${THISDIR}/ccsp-wifi-agent:${THISDIR}/files:"
+
+DEPENDS_remove = " opensync-2.4.1"
+DEPENDS_append = " opensync mesh-agent"
+
+CFLAGS_append = " -DWIFI_HAL_VERSION_3 -Wno-unused-function -DCONFIG_MBO"
+LDFLAGS_append = " -ldl "
+CFLAGS_remove = " -Wno-mismatched-dealloc -Wno-enum-conversion "
+CFLAGS_append_aarch64 = " -Wno-error "
+
+SRC_URI += " \
+    file://checkonewifi.sh \
+    file://bridge_mode.sh \
+    file://onewifi_pre_start.sh \
+    file://mac80211.sh \
+    file://init-uci-config.service \
+"
+#SYSTEMD_AUTO_ENABLE_${PN} = "enable"
+SYSTEMD_SERVICE_${PN} += " init-uci-config.service"
+
+do_install_append(){
+    install -m 777 ${WORKDIR}/checkonewifi.sh ${D}/usr/ccsp/wifi/checkwifi.sh
+    install -m 777 ${WORKDIR}/bridge_mode.sh ${D}/usr/ccsp/wifi/
+    install -m 777 ${WORKDIR}/onewifi_pre_start.sh ${D}/usr/ccsp/wifi/
+    install -d ${D}${systemd_unitdir}/system/
+    install -m 0644 ${WORKDIR}/init-uci-config.service ${D}${systemd_unitdir}/system
+    install -m 777 ${WORKDIR}/mac80211.sh ${D}/usr/ccsp/wifi/
+}
+
+FILES_${PN} += " \
+    ${prefix}/ccsp/wifi/checkwifi.sh \
+    ${prefix}/ccsp/wifi/bridge_mode.sh \
+    ${prefix}/ccsp/wifi/onewifi_pre_start.sh \
+    ${prefix}/ccsp/wifi/mac80211.sh \
+    ${systemd_unitdir}/system/init-uci-config.service \
+    /usr/bin/wifi_events_consumer \
+"
+
diff --git a/recipes-ccsp/ccsp/ccsp-wifi-agent/bridge_mode.sh b/recipes-ccsp/ccsp/ccsp-wifi-agent/bridge_mode.sh
new file mode 100644
index 0000000..6534722
--- /dev/null
+++ b/recipes-ccsp/ccsp/ccsp-wifi-agent/bridge_mode.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+########################### FOR BRIDGE MODE SET UP ##############################
+
+sleep 5
+
+BRIDGE_MODE=`dmcli eRT getv Device.X_CISCO_COM_DeviceControl.LanManagementEntry.1.LanMode | grep value | cut -d ':' -f3 | cut -d ' ' -f2`
+PRIVATE_WIFI_2G=`cat /nvram/hostapd0.conf | grep interface= | head -n1 | cut -d '=' -f2`
+PRIVATE_WIFI_5G=`cat /nvram/hostapd1.conf | grep interface= | head -n1 | cut -d '=' -f2`
+echo "BRIDGE MODE is $BRIDGE_MODE"
+if [ "$BRIDGE_MODE" = "bridge-static" ] ; then
+	sysevent set lan-stop
+        hostapd_cli -i$PRIVATE_WIFI_2G disable
+	hostapd_cli -i$PRIVATE_WIFI_5G disable
+	ps aux | grep hostapd1 | grep -v grep | awk '{print $1}' | xargs kill -9
+	ps aux | grep hostapd0 | grep -v grep | awk '{print $1}' | xargs kill -9
+else
+	echo "Running in Router Mode"
+fi
+
+################# Make Persistent after reboot ################
+        
+        
+######## SSID status
+pri_2g=`cat /var/Get2gssidEnable.txt`
+pri_5g=`cat /var/Get5gssidEnable.txt`
+pub_2g=`cat /var/GetPub2gssidEnable.txt`
+pub_5g=`cat /var/GetPub5gssidEnable.txt`
+                                        
+######## Radio Status
+Rad_2g=`cat /var/Get2gRadioEnable.txt`
+Rad_5g=`cat /var/Get5gRadioEnable.txt`
+                                      
+######### Current Wireless interfaces names
+pri_wifi_2g=`grep interface= /nvram/hostapd0.conf | cut -d '=' -f2 | head -n 1`
+pri_wifi_5g=`grep interface= /nvram/hostapd1.conf | cut -d '=' -f2 | head -n 1`
+pub_wifi_2g=`grep interface= /nvram/hostapd4.conf | cut -d '=' -f2 | head -n 1`
+pub_wifi_5g=`grep interface= /nvram/hostapd5.conf | cut -d '=' -f2 | head -n 1`
+                                                                               
+echo "wireless interface names : $pri_wifi_2g $pri_wifi_5g $pub_wifi_2g $pub_wifi_5g"
+                                                                                     
+Disable_WiFi ()
+{              
+         wifi_status=`ifconfig $1 | grep RUNNING  | wc -l`
+         if  [ $wifi_status == 1 ] ; then
+             hostapd_cli -i$1 disable               
+         fi    
+}          
+
+if [ $Rad_2g == 0 ] ; then                   
+         Disable_WiFi $pri_wifi_2g 
+         Disable_WiFi $pub_wifi_2g 
+else                                            
+        if [ $pub_2g == 0 ] ; then           
+                Disable_WiFi $pub_wifi_2g 
+        fi                                      
+        if [ $pri_2g == 0 ] ; then           
+                Disable_WiFi $pri_wifi_2g 
+        fi                                                                     
+fi                                                                             
+                                                                               
+if [ $Rad_5g == 0 ] ; then                   
+         Disable_WiFi $pri_wifi_5g                                            
+         Disable_WiFi $pub_wifi_5g 
+else                                            
+        if [ $pri_5g == 0 ] ; then           
+                Disable_WiFi $pri_wifi_5g 
+        fi                                      
+        if [ $pub_5g == 0 ] ; then           
+                Disable_WiFi $pub_wifi_5g
+        fi                  
+fi           
+
+##Added workaround fix for LAN connection issue
+
+ETH_INTERFACE=`ifconfig eth0 | grep eth0 | wc -l`
+if [ $ETH_INTERFACE == 1 ] ; then
+      ifconfig eth0 down
+      ip link set dev eth0 name eth1
+fi
+
+ETH_INTERFACE=`ifconfig eth1 | grep eth1 | wc -l`                               
+if [ $ETH_INTERFACE == 1 ] ; then
+      ifconfig eth1 up
+      brctl addif brlan0 eth1
+fi   
diff --git a/recipes-ccsp/ccsp/ccsp-wifi-agent/checkonewifi.sh b/recipes-ccsp/ccsp/ccsp-wifi-agent/checkonewifi.sh
new file mode 100644
index 0000000..ae00a02
--- /dev/null
+++ b/recipes-ccsp/ccsp/ccsp-wifi-agent/checkonewifi.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+wifi_wlan0=`iwconfig wlan0|grep IEEE\ 802.11 | wc -l`
+wifi_wlan1=`iwconfig wlan1|grep IEEE\ 802.11 | wc -l`
+wifi_wlan2=`iwconfig wlan2|grep IEEE\ 802.11 | wc -l`
+wifi_wlan3=`iwconfig wlan3|grep IEEE\ 802.11 | wc -l`
+
+if [ $wifi_wlan0 == "1" ] ; then
+        flag=wlan0 
+        wlan0=$(iwconfig wlan0|grep IEEE\ 802.11)
+elif [ $wifi_wlan1 == "1" ]; then
+        flag=wlan1 
+        wlan0=$(iwconfig wlan1|grep IEEE\ 802.11)
+elif [ $wifi_wlan2 == "1" ]; then 
+        flag=wlan2 
+        wlan0=$(iwconfig wlan2|grep IEEE\ 802.11)
+elif [ $wifi_wlan3 == "1" ]; then 
+        flag=wlan3 
+        wlan0=$(iwconfig wlan3|grep IEEE\ 802.11) 
+fi 
+
+wifi_driver_init=${#wlan0}
+check_dual_band=1
+if [ $wifi_driver_init != 0 ]; then
+	echo "Wifi (single band) driver is initialized"
+        while [ $check_dual_band -le 5 ]
+        do
+           echo "checking for dual band support:$check_dual_band"
+	   if [ $flag == "wlan0" ]; then
+		wifi_dual_band=1
+	   elif [ $flag == "wlan1" ]; then
+		wifi_dual_band=1
+	   elif [ $flag == "wlan2" ]; then
+		wifi_dual_band=1
+	   elif [ $flag == "wlan3" ]; then
+		wifi_dual_band=1
+	   fi 
+	   echo "$wifi_dual_band"
+           if [ $wifi_dual_band == 1 ]; then
+               break
+           fi
+           check_dual_band=`expr $check_dual_band + 1`
+           sleep 1;
+        done
+	sleep 1;
+	touch /tmp/wifi_driver_initialized
+else
+	echo "Wifi driver is not initialized"
+fi
diff --git a/recipes-ccsp/ccsp/ccsp_common_filogic.inc b/recipes-ccsp/ccsp/ccsp_common_filogic.inc
index c2e0619..88eb483 100644
--- a/recipes-ccsp/ccsp/ccsp_common_filogic.inc
+++ b/recipes-ccsp/ccsp/ccsp_common_filogic.inc
@@ -10,5 +10,7 @@
 
 CFLAGS_append_aarch64 = " -D_64BIT_ARCH_SUPPORT_ "
 
+LDFLAGS_append = " -lpthread -lcrypto"
+
 DEPENDS += "breakpad-wrapper"
 LDFLAGS += "-lbreakpadwrapper"
diff --git a/recipes-ccsp/ccsp/files/init-uci-config.service b/recipes-ccsp/ccsp/files/init-uci-config.service
new file mode 100644
index 0000000..c8e732d
--- /dev/null
+++ b/recipes-ccsp/ccsp/files/init-uci-config.service
@@ -0,0 +1,14 @@
+[Unit]

+Description=Init UCI wireless config

+DefaultDependencies=no

+Before=onewifi.service

+After=CcspPandMSsp.service

+

+[Service]

+Type=oneshot

+ExecStart=/bin/sh /usr/ccsp/wifi/mac80211.sh

+RemainAfterExit=yes

+

+[Install]

+WantedBy=multi-user.target

+

diff --git a/recipes-ccsp/ccsp/files/mac80211.sh b/recipes-ccsp/ccsp/files/mac80211.sh
new file mode 100644
index 0000000..6449516
--- /dev/null
+++ b/recipes-ccsp/ccsp/files/mac80211.sh
@@ -0,0 +1,238 @@
+#!/bin/sh
+
+#append DRIVERS "mac80211"
+
+lookup_phy() {
+	[ -n "$phy" ] && {
+		[ -d /sys/class/ieee80211/$phy ] && return
+	}
+
+	local devpath
+	config_get devpath "$device" path
+	[ -n "$devpath" ] && {
+		phy="$(iwinfo nl80211 phyname "path=$devpath")"
+		[ -n "$phy" ] && return
+	}
+
+	local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
+	[ -n "$macaddr" ] && {
+		for _phy in /sys/class/ieee80211/*; do
+			[ -e "$_phy" ] || continue
+
+			[ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
+			phy="${_phy##*/}"
+			return
+		done
+	}
+	phy=
+	return
+}
+
+find_mac80211_phy() {
+	local device="$1"
+
+	config_get phy "$device" phy
+	lookup_phy
+	[ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
+		echo "PHY for wifi device $1 not found"
+		return 1
+	}
+	config_set "$device" phy "$phy"
+
+	config_get macaddr "$device" macaddr
+	[ -z "$macaddr" ] && {
+		config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
+	}
+
+	return 0
+}
+
+check_mac80211_device() {
+	config_get phy "$1" phy
+	[ -z "$phy" ] && {
+		find_mac80211_phy "$1" >/dev/null || return 0
+		config_get phy "$1" phy
+	}
+	[ "$phy" = "$dev" ] && found=1
+}
+
+
+__get_band_defaults() {
+	local phy="$1"
+
+	( iw phy "$phy" info; echo ) | awk '
+BEGIN {
+        bands = ""
+}
+
+($1 == "Band" || $1 == "") && band {
+        if (channel) {
+		mode="NOHT"
+		if (ht) mode="HT20"
+		if (vht && band != "1:") mode="VHT80"
+		if (he) mode="HE80"
+		if (he && band == "1:") mode="HE20"
+                sub("\\[", "", channel)
+                sub("\\]", "", channel)
+                bands = bands band channel ":" mode " "
+        }
+        band=""
+}
+
+$1 == "Band" {
+        band = $2
+        channel = ""
+	vht = ""
+	ht = ""
+	he = ""
+}
+
+$0 ~ "Capabilities:" {
+	ht=1
+}
+
+$0 ~ "VHT Capabilities" {
+	vht=1
+}
+
+$0 ~ "HE Iftypes" {
+	he=1
+}
+
+$1 == "*" && $3 == "MHz" && $0 !~ /disabled/ && band && !channel {
+        channel = $4
+}
+
+END {
+        print bands
+}'
+}
+
+get_band_defaults() {
+	local phy="$1"
+
+	for c in $(__get_band_defaults "$phy"); do
+		local band="${c%%:*}"
+		c="${c#*:}"
+		local chan="${c%%:*}"
+		c="${c#*:}"
+		local mode="${c%%:*}"
+
+		case "$band" in
+			1) band=2g;;
+			2) band=5g;;
+			3) band=60g;;
+			4) band=6g;;
+			*) band="";;
+		esac
+
+		[ -n "$band" ] || continue
+		[ -n "$mode_band" -a "$band" = "6g" ] && return
+
+		mode_band="$band"
+		channel="$chan"
+		htmode="$mode"
+		if [ "$band" = "6g" ]
+		then
+			encryption=sae
+			key=12345678
+		else
+			encryption=none
+		fi
+	done
+}
+
+detect_mac80211() {
+	devidx=0
+	#config_load wireless
+	while :; do
+		#config_get type "radio$devidx" type
+		[ -n "$type" ] || break
+		devidx=$(($devidx + 1))
+	done
+
+	if [ ! -f /etc/config/wireless ]; then
+		mkdir -p /etc/config
+		echo -n > /etc/config/wireless
+	fi
+
+	pcieCheck="$(uci get wireless.radio1.path)"
+	checkpath="$(realpath /sys/class/ieee80211/phy1/device | cut -d/ -f4-)"
+
+	if [[ "$pcieCheck"* != "$checkpath"* ]]; then
+		echo -n > /etc/config/wireless
+		rm /nvram/hostapd*
+	fi
+
+	old_path=""
+	for _dev in /sys/class/ieee80211/*; do
+		[ -e "$_dev" ] || continue
+
+		dev="${_dev##*/}"
+
+		found="$(uci get wireless.radio${devidx})"
+
+
+		if [ "$found" == "wifi-device" ]; then
+			devidx=$(($devidx + 1))
+			continue
+		fi
+
+		mode_band=""
+		channel=""
+		htmode=""
+		ht_capab=""
+		
+
+		get_band_defaults "$dev"
+
+		path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)"
+		if [ -n "$path" ]; then
+			if [ "$path" == "$old_path" ]; then
+				dev_id="set wireless.radio${devidx}.path='$path'+1"
+			else
+				dev_id="set wireless.radio${devidx}.path='$path'"
+			fi	
+		else
+			dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
+		fi
+
+		if [ "$(cat /sys/class/ieee80211/"$dev"/device/device)" == "0x7906" ]; then
+			isMerlin=1
+		fi
+
+		if [ "$mode_band" = "6g" ]; then
+			channel="37"
+		fi
+		setdisable="set wireless.radio${devidx}.disabled=0"
+
+
+		if [ "$isMerlin" == "1" ] && [ "$devidx" == "2" ] && [ "$mode_band" == "2g" ]; then
+			setdisable="set wireless.radio${devidx}.disabled=1"
+		fi
+	
+		uci -q batch <<-EOF
+			set wireless.radio${devidx}=wifi-device
+			set wireless.radio${devidx}.type=mac80211
+			${dev_id}
+			set wireless.radio${devidx}.channel=${channel}
+			set wireless.radio${devidx}.band=${mode_band}
+			set wireless.radio${devidx}.htmode=$htmode
+			${setdisable}
+			set wireless.default_radio${devidx}=wifi-iface
+			set wireless.default_radio${devidx}.device=radio${devidx}
+			set wireless.default_radio${devidx}.network=lan
+			set wireless.default_radio${devidx}.mode=ap
+			set wireless.default_radio${devidx}.ssid=Filogic_${mode_band}
+			set wireless.default_radio${devidx}.encryption=${encryption}
+EOF
+		[ -n "$key" ] && {
+			uci -q set wireless.default_radio${devidx}.key=${key}
+		}
+		uci -q commit wireless
+
+		devidx=$(($devidx + 1))
+		old_path=$path
+	done
+}
+detect_mac80211
\ No newline at end of file
diff --git a/recipes-ccsp/ccsp/files/onewifi_pre_start.sh b/recipes-ccsp/ccsp/files/onewifi_pre_start.sh
new file mode 100644
index 0000000..2d5290b
--- /dev/null
+++ b/recipes-ccsp/ccsp/files/onewifi_pre_start.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+create_hostapdConf() {
+	devidx=0
+	phyidx=0
+	old_path=""
+	pcie7915count=0
+    vap_per_radio=8
+    radio_num="$(iw list | grep Wiphy | wc -l)"
+
+    for _dev in /sys/class/ieee80211/*; do
+		[ -e "$_dev" ] || continue
+
+		dev="${_dev##*/}"
+
+        band="$(uci get wireless.radio${phyidx}.band)"
+        channel="$(uci get wireless.radio${phyidx}.channel)"
+        # Use random MAC to prevent use the same MAC address
+        rand="$(hexdump -C /dev/urandom | head -n 1 | awk '{printf ""$3":"$4""}' &)"
+        killall hexdump
+        MAC="00:0${devidx}:12:34:${rand}"
+        chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
+
+        if [ $chip == "0x7915" ]; then
+            path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)"
+            if [ -n "$path" ]; then
+                if [ "$path" == "$old_path" ] || [ "$old_path" == "" ]; then
+                    pcie7915count="1"
+                else
+                    pcie7915count="2"    
+                fi
+            fi
+            old_path=$path
+        fi
+
+        if [ -e /sys/class/net/wlan$phyidx ]; then
+            iw wlan$phyidx del > /dev/null
+        fi
+
+        if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then
+            phyidx=$(($phyidx + 1))
+			continue
+        fi
+        if [ "$band" == "2g" ]; then
+            iw phy phy$phyidx interface add wifi0 type __ap > /dev/null
+        fi
+        if [ "$band" == "5g" ]; then
+            iw phy phy$phyidx interface add wifi1 type __ap > /dev/null
+        fi
+        if [ "$band" == "6g" ]; then
+            iw phy phy$phyidx interface add wifi2 type __ap > /dev/null
+        fi
+        #iw phy phy$phyidx interface add wifi$devidx type __ap > /dev/null
+        #touch /tmp/$dev-wifi$devidx
+        devidx=$(($devidx + 1))
+        phyidx=$(($phyidx + 1))
+		
+	done
+}
+#Creating files for tracking AssociatedDevices
+touch /tmp/AllAssociated_Devices_2G.txt
+touch /tmp/AllAssociated_Devices_5G.txt
+
+#Create wps pin request log file
+touch /var/run/hostapd_wps_pin_requests.log
+
+
+create_hostapdConf
+
+exit 0