blob: 56c99ad26cb28ec40e5ec3276cdfd43283f981cd [file] [log] [blame]
developer2bf53a92022-06-06 12:08:58 +08001diff --git a/kconfig/Kconfig.platform b/kconfig/Kconfig.platform
2new file mode 100644
3index 0000000..4a045b2
4--- /dev/null
5+++ b/kconfig/Kconfig.platform
6@@ -0,0 +1,15 @@
7+menuconfig PLATFORM_IS_RDK
8+ bool "RDK"
9+ help
10+ Support for RDK-based platforms
11+
12+
13+if PLATFORM_IS_RDK
14+
15+config RDK_EXTENDER
16+ bool "RDK Extender device (EXPERIMENTAL)"
17+ default n
18+
19+
20+endif
21+
22diff --git a/src/lib/osn/override.mk b/src/lib/osn/override.mk
23index bf128b7..ff210ed 100644
24--- a/src/lib/osn/override.mk
25+++ b/src/lib/osn/override.mk
26@@ -33,11 +33,22 @@ UNIT_EXPORT_CFLAGS := -I$(UNIT_PATH)/inc
27 UNIT_SRC := src/osn_inet.c
28 UNIT_SRC += src/osn_types.c
29
30+#if extender
31+ifeq ($(CONFIG_RDK_EXTENDER),y)
32+UNIT_SRC += src/osn_dnsmasq.c
33+UNIT_SRC += src/osn_udhcpc.c
34+UNIT_SRC += src/osn_route.c
35+endif
36+
37 UNIT_SRC_DIR := $(OVERRIDE_DIR)/src
38 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_upnpd.c
39+
40+ifneq ($(CONFIG_RDK_EXTENDER),y)
41 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_dhcpc.c
42 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_route.c
43 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_dhcps.c
44+endif
45+
46 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_dhcps6.c
47 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_odhcp6c.c
48 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/osn_inet6.c
49diff --git a/src/lib/osn/src/osn_dhcps.c b/src/lib/osn/src/osn_dhcps.c
50index d183172..f2885fd 100644
51--- a/src/lib/osn/src/osn_dhcps.c
52+++ b/src/lib/osn/src/osn_dhcps.c
53@@ -284,11 +284,13 @@ static bool dhcp_server_init(osn_dhcp_server_t *self, const char *ifname)
54 return false;
55 }
56
57+#ifndef CONFIG_RDK_EXTENDER
58 if (!sync_init(SYNC_MGR_NM))
59 {
60 LOGE("Cannot init sync manager for NM");
61 return false;
62 }
63+#endif
64
65 /* Initialize this instance */
66 memset(self, 0 ,sizeof(*self));
67diff --git a/src/lib/osync_hal/src/inet.c b/src/lib/osync_hal/src/inet.c
68index b221667..580ff83 100644
69--- a/src/lib/osync_hal/src/inet.c
70+++ b/src/lib/osync_hal/src/inet.c
71@@ -304,7 +304,11 @@ osync_hal_return_t osync_hal_inet_add_to_bridge(
72
73 memset(cmd, 0, sizeof(cmd));
74
75+#ifdef CONFIG_RDK_EXTENDER
76+ snprintf(cmd, sizeof(cmd), "ovs-vsctl add-port %s %s", br_name, if_name);
77+#else
78 snprintf(cmd, sizeof(cmd), "brctl addif %s %s", br_name, if_name);
79+#endif
80 LOGD("%s: Adding to bridge with \"%s\"", if_name, cmd);
81 rc = system(cmd);
82 if (!WIFEXITED(rc) || WEXITSTATUS(rc) != 0)
83diff --git a/src/lib/target/inc/target_internal.h b/src/lib/target/inc/target_internal.h
84index 1608b03..61f0f06 100644
85--- a/src/lib/target/inc/target_internal.h
86+++ b/src/lib/target/inc/target_internal.h
87@@ -35,7 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88 #include "osync_hal.h"
89 #include "osn_dhcp.h"
90
91+#if !defined(CONFIG_RDK_EXTENDER)
92 #include <mesh/meshsync_msgs.h> // needed only by sync_send_security_change()
93+#endif
94
95 #ifndef __WIFI_HAL_H__
96 #include "ccsp/wifi_hal.h"
97@@ -182,12 +184,15 @@ bool sync_init(sync_mgr_t mgr);
98 bool sync_cleanup(void);
99 bool sync_send_ssid_change(INT ssid_index, const char *ssid_ifname,
100 const char *new_ssid);
101+#if !defined(CONFIG_RDK_EXTENDER)
102 bool sync_send_security_change(INT ssid_index, const char *ssid_ifname,
103 MeshWifiAPSecurity *sec);
104+#endif
105 bool sync_send_status(radio_cloud_mode_t mode);
106
107 bool vif_state_update(INT ssidIndex);
108 bool vif_state_get(INT ssidIndex, struct schema_Wifi_VIF_State *vstate);
109+bool vif_state_sta_get(INT ssidIndex, struct schema_Wifi_VIF_State *vstate);
110 bool vif_copy_to_config(INT ssidIndex, struct schema_Wifi_VIF_State *vstate,
111 struct schema_Wifi_VIF_Config *vconf);
112 struct target_radio_ops;
113diff --git a/src/lib/target/override.mk b/src/lib/target/override.mk
114index 8c37835..369d2a5 100644
115--- a/src/lib/target/override.mk
116+++ b/src/lib/target/override.mk
117@@ -44,7 +44,11 @@ UNIT_SRC_TOP += $(UNIT_SRC_DIR)/radio.c
118 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/vif.c
119 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/stats.c
120 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/log.c
121+
122+ifneq ($(CONFIG_RDK_EXTENDER),y)
123 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/sync.c
124+endif
125+
126 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/maclearn.c
127 UNIT_SRC_TOP += $(UNIT_SRC_DIR)/bsal.c
128
129@@ -53,6 +57,8 @@ UNIT_CFLAGS += -DENABLE_MESH_SOCKETS
130
131 UNIT_DEPS := $(PLATFORM_DIR)/src/lib/devinfo
132 UNIT_DEPS += $(PLATFORM_DIR)/src/lib/osync_hal
133+
134+#UNIT_DEPS += src/lib/kconfig
135 UNIT_DEPS += src/lib/evsched
136 UNIT_DEPS += src/lib/schema
137 UNIT_DEPS += src/lib/const
138@@ -66,6 +72,7 @@ endif
139
140 UNIT_LDFLAGS := $(SDK_LIB_DIR) -lhal_wifi -lrt
141 UNIT_CFLAGS += -DCONTROLLER_ADDR="\"$(shell echo -n $(CONTROLLER_ADDR))\""
142+UNIT_CFLAGS += -include "$(KCONFIG_WORK).h"
143
144 UNIT_EXPORT_CFLAGS := $(UNIT_CFLAGS)
145 UNIT_EXPORT_LDFLAGS := $(UNIT_LDFLAGS)
146diff --git a/src/lib/target/src/radio.c b/src/lib/target/src/radio.c
147index 9bedd00..33a2032 100644
148--- a/src/lib/target/src/radio.c
149+++ b/src/lib/target/src/radio.c
150@@ -72,6 +72,7 @@ static c_item_t map_country_str[] =
151 {
152 C_ITEM_STR_STR("826", "UK"), // ISO 3166-1
153 C_ITEM_STR_STR("840", "US"),
154+ C_ITEM_STR_STR("705", "SI"), // (non-standard)
155 C_ITEM_STR_STR("841", "US"), // (non-standard)
156 };
157
158@@ -620,6 +621,62 @@ bool target_radio_config_init2()
159 g_rops.op_vconf(&vconfig, rconfig.if_name);
160 g_rops.op_vstate(&vstate);
161 }
162+#ifdef CONFIG_RDK_EXTENDER
163+ /* CLIENT-API */
164+ ret = wifi_getSTANumberOfEntries(&snum);
165+ if (ret != RETURN_OK)
166+ {
167+ LOGE("%s: failed to get SSID count", __func__);
168+ return false;
169+ }
170+
171+ for (s = 0; s < snum; s++)
172+ {
173+ memset(ssid_ifname, 0, sizeof(ssid_ifname));
174+ ret = wifi_getSTAName(s, ssid_ifname);
175+ if (ret != RETURN_OK)
176+ {
177+ LOGW("%s: failed to get STA name for index %lu. Skipping.\n", __func__, s);
178+ continue;
179+ }
180+ // Filter SSID's that we don't have mappings for
181+ if (!target_unmap_ifname_exists(ssid_ifname))
182+ {
183+ LOGW("%s: STA %s not in map. Skipping.\n", __func__, ssid_ifname);
184+ continue;
185+ }
186+
187+ ret = wifi_getSTARadioIndex(s, &ssid_radio_idx);
188+ if (ret != RETURN_OK)
189+ {
190+ LOGW("Cannot get radio index for SSID %lu", s);
191+ continue;
192+ }
193+
194+ if ((ULONG)ssid_radio_idx != r)
195+ {
196+ continue;
197+ }
198+
199+ LOGI("Found STA index %lu: %s", s, ssid_ifname);
200+ if (!vif_state_sta_get(s, &vstate))
201+ {
202+ LOGE("%s: cannot get vif state for STA index %lu", __func__, s);
203+ continue;
204+ }
205+ if (!vif_copy_to_config(s, &vstate, &vconfig))
206+ {
207+ LOGE("%s: cannot copy VIF state to config for STA index %lu", __func__, s);
208+ continue;
209+ }
210+ g_rops.op_vconf(&vconfig, rconfig.if_name);
211+ g_rops.op_vstate(&vstate);
212+
213+
214+ }
215+
216+ /* END CLIENT-API */
217+#endif
218
219 }
220
221@@ -807,6 +864,9 @@ bool
222 radio_cloud_mode_set(radio_cloud_mode_t mode)
223 {
224 radio_cloud_mode = mode;
225-
226+#ifdef CONFIG_RDK_EXTENDER
227+ return true;
228+#else
229 return sync_send_status(radio_cloud_mode);
230+#endif
231 }
232diff --git a/src/lib/target/src/sync.c b/src/lib/target/src/sync.c
233index 5b4337d..b8dfc17 100644
234--- a/src/lib/target/src/sync.c
235+++ b/src/lib/target/src/sync.c
236@@ -43,7 +43,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237 #include <sys/socket.h>
238 #include <sys/un.h>
239
240+#ifndef CONFIG_RDK_EXTENDER
241 #include <mesh/meshsync_msgs.h> // this file is included by vendor
242+#endif
243
244 #include "os.h"
245 #include "log.h"
246@@ -146,6 +148,7 @@ static char* sync_iface_name(int iface_type)
247 return tmp;
248 }
249
250+#ifndef CONFIG_RDK_EXTENDER
251 static int wiifhal_sync_iface_mltype(int iface_type)
252 {
253 c_item_t *citem;
254@@ -157,7 +160,7 @@ static int wiifhal_sync_iface_mltype(int iface_type)
255
256 return -1;
257 }
258-
259+#endif
260 static void sync_process_msg(MeshSync *mp)
261 {
262 radio_cloud_mode_t cloud_mode;
263diff --git a/src/lib/target/src/target.c b/src/lib/target/src/target.c
264index ffaaf6a..ef20eda 100644
265--- a/src/lib/target/src/target.c
266+++ b/src/lib/target/src/target.c
267@@ -281,12 +281,13 @@ bool target_init(target_init_opt_t opt, struct ev_loop *loop)
268 "(Failed to initialize EVSCHED)");
269 return -1;
270 }
271-
272+ #ifndef CONFIG_RDK_EXTENDER
273 if (!sync_init(SYNC_MGR_WM))
274 {
275 // It reports the error
276 return false;
277 }
278+ #endif
279 if (!set_deauth_and_scan_filter_flags())
280 {
281 LOGE("Failed to set csa_deauth and scan filter flags");
282@@ -296,11 +297,13 @@ bool target_init(target_init_opt_t opt, struct ev_loop *loop)
283 break;
284
285 case TARGET_INIT_MGR_CM:
286+ #ifndef CONFIG_RDK_EXTENDER
287 if (!sync_init(SYNC_MGR_CM))
288 {
289 // It reports the error
290 return false;
291 }
292+ #endif
293 break;
294
295 case TARGET_INIT_MGR_BM:
296@@ -323,7 +326,9 @@ bool target_close(target_init_opt_t opt, struct ev_loop *loop)
297 switch (opt)
298 {
299 case TARGET_INIT_MGR_WM:
300+ #ifndef CONFIG_RDK_EXTENDER
301 sync_cleanup();
302+ #endif
303 /* fall through */
304
305 case TARGET_INIT_MGR_SM:
306diff --git a/src/lib/target/src/vif.c b/src/lib/target/src/vif.c
307index aaecbf9..a987aa3 100644
308--- a/src/lib/target/src/vif.c
309+++ b/src/lib/target/src/vif.c
310@@ -262,7 +262,8 @@ static bool acl_apply(
311
312 return true;
313 }
314-
315+//FIXME: is this needed only for mesh something?
316+#if !defined(CONFIG_RDK_EXTENDER)
317 static const char* security_conf_find_by_key(
318 const struct schema_Wifi_VIF_Config *vconf,
319 char *key)
320@@ -279,6 +280,7 @@ static const char* security_conf_find_by_key(
321
322 return NULL;
323 }
324+#endif
325
326 static bool security_to_state(
327 INT ssid_index,
328@@ -449,7 +451,7 @@ static bool security_to_state(
329 vstate->security_len = n;
330 return true;
331 }
332-
333+#if !defined(CONFIG_RDK_EXTENDER)
334 static bool security_to_syncmsg(
335 const struct schema_Wifi_VIF_Config *vconf,
336 MeshWifiAPSecurity *dest)
337@@ -527,7 +529,7 @@ static bool security_to_syncmsg(
338
339 return true;
340 }
341-
342+#endif
343 static bool vif_is_enabled(INT ssid_index)
344 {
345 BOOL enabled = false;
346@@ -602,10 +604,177 @@ bool vif_copy_to_config(
347 STRSCPY(vconf->mac_list[i], vstate->mac_list[i]);
348 }
349 vconf->mac_list_len = vstate->mac_list_len;
350+ /* CLIENT-API */
351+ SCHEMA_SET_STR(vconf->parent, vstate->parent);
352+ LOGT("vconf->parent = %s", vconf->parent);
353+ SCHEMA_SET_INT(vconf->uapsd_enable, vstate->uapsd_enable);
354+ LOGT("vconf->uapsd_enable = %d", vconf->uapsd_enable);
355+
356
357 return true;
358 }
359
360+#if defined(CONFIG_RDK_EXTENDER)
361+/* CLIENT-API */
362+
363+bool vif_state_sta_get(INT ssidIndex, struct schema_Wifi_VIF_State *vstate)
364+{
365+ CHAR buf[WIFIHAL_MAX_BUFFER];
366+ INT ret;
367+ char ssid_ifname[128];
368+ hw_mode_t min_hw_mode;
369+ INT radio_idx;
370+ char band[128];
371+ BOOL gOnly, nOnly, acOnly;
372+ char *str;
373+ ULONG lval;
374+ int n = 0;
375+
376+ memset(vstate, 0, sizeof(*vstate));
377+ schema_Wifi_VIF_State_mark_all_present(vstate);
378+ vstate->_partial_update = true;
379+ vstate->associated_clients_present = false;
380+ vstate->vif_config_present = false;
381+ memset(ssid_ifname, 0, sizeof(ssid_ifname));
382+
383+ ret = wifi_getSTAName(ssidIndex, ssid_ifname);
384+ if (ret != RETURN_OK)
385+ {
386+ LOGE("%s: cannot get sta name for index %d", __func__, ssidIndex);
387+ return false;
388+ }
389+
390+ SCHEMA_SET_STR(vstate->if_name, target_unmap_ifname(ssid_ifname));
391+
392+ SCHEMA_SET_STR(vstate->mode, "sta");
393+ SCHEMA_SET_INT(vstate->enabled, true);
394+ SCHEMA_SET_INT(vstate->uapsd_enable, false);
395+ SCHEMA_SET_INT(vstate->vif_radio_idx, target_map_ifname_to_vif_radio_idx(vstate->if_name));
396+
397+ // mac (w/ exists)
398+ memset(buf, 0, sizeof(buf));
399+ ret = wifi_getSTAMAC(ssidIndex, buf);
400+ if (ret != RETURN_OK)
401+ {
402+ LOGW("%s: Failed to get STA (mac)", ssid_ifname);
403+ }
404+ else
405+ {
406+ SCHEMA_SET_STR(vstate->mac, buf);
407+ }
408+
409+ // mac (w/ exists)
410+ memset(buf, 0, sizeof(buf));
411+ ret = wifi_getSTABSSID(ssidIndex, buf);
412+ if (ret != RETURN_OK)
413+ {
414+ LOGW("%s: Failed to get STA (parent)", ssid_ifname);
415+ }
416+ else
417+ {
418+ SCHEMA_SET_STR(vstate->parent, buf);
419+ }
420+
421+
422+ ret = wifi_getSSIDRadioIndex(ssidIndex, &radio_idx);
423+ if (ret != RETURN_OK)
424+ {
425+ LOGE("%s: cannot get radio idx for SSID %s\n", __func__, ssid_ifname);
426+ return false;
427+ }
428+
429+
430+ memset(band, 0, sizeof(band));
431+ ret = wifi_getRadioOperatingFrequencyBand(radio_idx, band);
432+ if (ret != RETURN_OK)
433+ {
434+ LOGE("%s: cannot get radio band for idx %d", __func__, radio_idx);
435+ return false;
436+ }
437+
438+
439+ // min_hw_mode (w/ exists)
440+ if (band[0] == '5')
441+ {
442+ min_hw_mode = HW_MODE_11A;
443+ } else
444+ {
445+ min_hw_mode = HW_MODE_11B;
446+ }
447+ ret = wifi_getRadioStandard(radio_idx, buf, &gOnly, &nOnly, &acOnly);
448+ if (ret != RETURN_OK)
449+ {
450+ LOGW("%s: Failed to get min_hw_mode from %d", ssid_ifname, radio_idx);
451+ }
452+ else
453+ {
454+ if (gOnly)
455+ {
456+ min_hw_mode = HW_MODE_11G;
457+ }
458+ else if (nOnly)
459+ {
460+ min_hw_mode = HW_MODE_11N;
461+ }
462+ else if (acOnly)
463+ {
464+ min_hw_mode = HW_MODE_11AC;
465+ }
466+ }
467+
468+ str = c_get_str_by_key(map_hw_mode, min_hw_mode);
469+ if (strlen(str) == 0)
470+ {
471+ LOGW("%s: failed to encode min_hw_mode (%d)",
472+ ssid_ifname, min_hw_mode);
473+ }
474+ else
475+ {
476+ SCHEMA_SET_STR(vstate->min_hw_mode, str);
477+ }
478+ // channel (w/ exists)
479+ ret = wifi_getRadioChannel(radio_idx, &lval);
480+ if (ret != RETURN_OK)
481+ {
482+ LOGW("%s: Failed to get channel from radio idx %d", ssid_ifname, radio_idx);
483+ }
484+ else
485+ {
486+ SCHEMA_SET_INT(vstate->channel, lval);
487+ }
488+
489+
490+ SCHEMA_SET_STR(vstate->ssid_broadcast, "disabled");
491+ SCHEMA_SET_STR(vstate->mac_list_type, "none");
492+ SCHEMA_SET_INT(vstate->btm, 0);
493+ SCHEMA_SET_INT(vstate->rrm, 0);
494+ SCHEMA_SET_INT(vstate->wds, 0);
495+ SCHEMA_SET_INT(vstate->ap_bridge, false);
496+ //Wifi credentials
497+ SCHEMA_SET_STR(vstate->ssid, "opensync.onboard");
498+
499+ strncpy(vstate->security_keys[n],
500+ OVSDB_SECURITY_ENCRYPTION,
501+ sizeof(vstate->security_keys[n]) - 1);
502+
503+ strncpy(vstate->security[n],
504+ OVSDB_SECURITY_ENCRYPTION_WPA_PSK,
505+ sizeof(vstate->security[n]) - 1);
506+ n++;
507+ strncpy(vstate->security_keys[n],
508+ OVSDB_SECURITY_KEY,
509+ sizeof(vstate->security_keys[n]) - 1);
510+ strncpy(vstate->security[n],
511+ "7eCyoqETHiJzKBBALPFP9X8mVy4dwCga",
512+ sizeof(vstate->security[n]) - 1);
513+
514+ n++;
515+ vstate->security_len = n;
516+ return true;
517+
518+}
519+#endif
520+
521 bool vif_state_get(INT ssidIndex, struct schema_Wifi_VIF_State *vstate)
522 {
523 ULONG lval;
524@@ -888,7 +1055,9 @@ bool target_vif_config_set2(
525 INT ret;
526 c_item_t *citem;
527 char tmp[256];
528+#if !defined(CONFIG_RDK_EXTENDER)
529 MeshWifiAPSecurity sec;
530+#endif
531 const char *ssid_ifname = target_map_ifname((char *)vconf->if_name);
532
533 if (!vif_ifname_to_idx(ssid_ifname, &ssid_index))
534@@ -966,10 +1135,12 @@ bool target_vif_config_set2(
535 else
536 {
537 LOGI("%s: SSID updated to '%s'", ssid_ifname, tmp);
538+ #if !defined(CONFIG_RDK_EXTENDER)
539 if (!sync_send_ssid_change(ssid_index, ssid_ifname, vconf->ssid))
540 {
541 LOGE("%s: Failed to sync SSID change to '%s'", ssid_ifname, vconf->ssid);
542 }
543+ #endif
544 }
545 }
546 }
547@@ -977,6 +1148,8 @@ bool target_vif_config_set2(
548
549 if (changed->security && vconf->security_len)
550 {
551+ //TODO: add proper WA
552+ #if !defined(CONFIG_RDK_EXTENDER)
553 memset(&sec, 0, sizeof(sec));
554 if (!security_to_syncmsg(vconf, &sec))
555 {
556@@ -1018,6 +1191,7 @@ bool target_vif_config_set2(
557 }
558 }
559 }
560+ #endif
561 }
562
563