[rdkb][common][bsp][Refactor ucode related parts]

[Description]
Refactor ucode related parts

[Release-log]

Change-Id: I76db3a59ea1a2c92441829e5911d078d6fab72a1
diff --git a/recipes-wifi/hostapd/files/hostapd.uc b/recipes-wifi/hostapd/files/hostapd.uc
index 593840c..163d619 100644
--- a/recipes-wifi/hostapd/files/hostapd.uc
+++ b/recipes-wifi/hostapd/files/hostapd.uc
@@ -60,6 +60,7 @@
 function iface_freq_info(iface, config, params)
 {
 	let freq = params.frequency;
+	let bw320_offset = params.bw320_offset;
 	if (!freq)
 		return null;
 
@@ -68,25 +69,29 @@
 		sec_offset = 0;
 
 	let width = 0;
-	for (let line in config.radio.data) {
-		if (!sec_offset && match(line, /^ht_capab=.*HT40/)) {
-			sec_offset = null; // auto-detect
-			continue;
-		}
+	if (params.ch_width >= 0){
+		width = params.ch_width;
+	} else {
+		for (let line in config.radio.data) {
+			if (!sec_offset && match(line, /^ht_capab=.*HT40/)) {
+				sec_offset = null; // auto-detect
+				continue;
+			}
 
-		let val = match(line, /^(vht_oper_chwidth|he_oper_chwidth)=(\d+)/);
-		if (!val)
-			continue;
+			let val = match(line, /^(vht_oper_chwidth|he_oper_chwidth|eht_oper_chwidth)=(\d+)/);
+			if (!val)
+				continue;
 
-		val = int(val[2]);
-		if (val > width)
-			width = val;
+			val = int(val[2]);
+			if (val > width)
+				width = val;
+		}
 	}
 
 	if (freq < 4000)
 		width = 0;
 
-	return hostapd.freq_info(freq, sec_offset, width);
+	return hostapd.freq_info(freq, sec_offset, width, bw320_offset);
 }
 
 function iface_add(phy, config, phy_status)
@@ -278,12 +283,12 @@
 		return false;
 
 	let iface = hostapd.interfaces[phy];
+	let iface_name = old_config.bss[0].ifname;
 	if (!iface) {
 		hostapd.printf(`Could not find previous interface ${iface_name}`);
 		return false;
 	}
 
-	let iface_name = old_config.bss[0].ifname;
 	let first_bss = hostapd.bss[iface_name];
 	if (!first_bss) {
 		hostapd.printf(`Could not find bss of previous interface ${iface_name}`);
@@ -658,6 +663,8 @@
 			up: true,
 			frequency: 0,
 			sec_chan_offset: 0,
+			ch_width: -1,
+			bw320_offset: 1,
 			csa: true,
 			csa_count: 0,
 		},
@@ -665,6 +672,15 @@
 			if (req.args.up == null || !req.args.phy)
 				return libubus.STATUS_INVALID_ARGUMENT;
 
+			hostapd.printf(`ucode: mtk: apsta state update`);
+			hostapd.printf(`    * phy: ${req.args.phy}`);
+			hostapd.printf(`    * up: ${req.args.up}`);
+			hostapd.printf(`    * freqeuncy: ${req.args.frequency}`);
+			hostapd.printf(`    * sec_chan_offset: ${req.args.sec_chan_offset}`);
+			hostapd.printf(`    * ch_width: ${req.args.ch_width}`);
+			hostapd.printf(`    * bw320_offset: ${req.args.bw320_offset}`);
+			hostapd.printf(`    * csa: ${req.args.csa}`);
+
 			let phy = req.args.phy;
 			let config = hostapd.data.config[phy];
 			if (!config || !config.bss || !config.bss[0] || !config.bss[0].ifname)
@@ -784,6 +800,7 @@
 
 hostapd.data.ubus = ubus;
 hostapd.data.obj = ubus.publish("hostapd", main_obj);
+hostapd.udebug_set("hostapd", hostapd.data.ubus);
 
 function bss_event(type, name, data) {
 	let ubus = hostapd.data.ubus;
@@ -798,6 +815,7 @@
 	shutdown: function() {
 		for (let phy in hostapd.data.config)
 			iface_set_config(phy, null);
+		hostapd.udebug_set(null);
 		hostapd.ubus.disconnect();
 	},
 	bss_add: function(name, obj) {