diff --git a/src/config.c b/src/config.c index 19087d12b64d599669e06634476b65b767604fb8..7c8f7cd66e8098bee17215797d36c62b4cf3812a 100644 --- a/src/config.c +++ b/src/config.c @@ -278,6 +278,51 @@ out_pkg: } +/* buf must be allocated buffer of len size, len must be greater than 0 */ +int wifi_get_section_option(const char *package, const char *sec_type, + const char *sec_key, const char *sec_value, + const char *get_key, char *buf, int len) +{ + struct uci_context *ctx = NULL; + struct uci_package *pkg; + struct uci_section *section; + struct uci_ptr ptr = {0}; + int ret = -1; + + pkg = uci_load_pkg(&ctx, package); + if (!pkg) + return ret; + + section = config_get_section(ctx, pkg, sec_type, sec_key, sec_value); + if (!section) + goto out_pkg; + + ptr.p = pkg; + ptr.s = section; + ptr.option = get_key; + ptr.target = UCI_TYPE_OPTION; + + ret = uci_lookup_ptr(ctx, &ptr, NULL, false); + if (ret != UCI_OK || !(ptr.flags & UCI_LOOKUP_DONE)) { + goto out_pkg; + } + + /* only return 0 if option is found */ + ret = -1; + + if (ptr.flags & UCI_LOOKUP_COMPLETE) { + /* option found */ + strncpy(buf, ptr.o->v.string, len - 1); + ret = 0; + } + +out_pkg: + uci_unload(ctx, pkg); + uci_free_context(ctx); + return ret; +} + + int wifi_set_iface_bssid(struct netif_bk *bk, uint8_t *bssid) { struct uci_context *ctx = NULL; @@ -1227,6 +1272,23 @@ int uci_apply_m2(struct agent_config *cfg, char *interface_name, char *device, interface_name, "wps_serial_number", out->serial_number); } + do { + char buf[2] = {0}; + + if (wifi_get_section_option(UCI_WIRELESS, UCI_WLAN_IFACE, + "ifname", interface_name, + "multicast_to_unicast", buf, + sizeof(buf))) { + /* if option was not found */ + uci_set_wireless_interface_option(UCI_WIRELESS, + UCI_WLAN_IFACE, + "ifname", + interface_name, + "multicast_to_unicast", + "1"); + } + } while(0); + dbg("|%s:%d| Enabled interface %s\n", __func__, __LINE__, interface_name); diff --git a/src/config.h b/src/config.h index 7451b85ca40dc5d563f20ba5ab1b0f0815941530..c86cb4d7526fdcf951e3950b197533bea101fed8 100644 --- a/src/config.h +++ b/src/config.h @@ -270,7 +270,9 @@ bool uci_set_wireless_interface_option(char *package_name, bool uci_add_wireless_iface_sec(char *package_name, char *interface_name, char *section_type, char *section_name); int agent_init_wsc_attributes(struct agent *a); - +int wifi_get_section_option(const char *package, const char *sec_type, + const char *sec_key, const char *sec_value, + const char *get_key, char *buf, int len); void clean_bk(struct netif_bkcfg *p); int clean_all_bk(struct agent_config *cfg); void clean_fh(struct netif_fhcfg *p);