@@ -12,7 +12,7 @@ static int wifi_gen_config(const char *ifname, const char *ssid, const char *cou
1212 char * encryption_str ;
1313 int rc = SR_ERR_OK ;
1414
15- if (!secret || ! ssid || ! country || ! encryption ) {
15+ if (!secret && ( ssid && country && encryption ) ) {
1616 /* Not an error, updated from two ways, interface cb and keystore cb. */
1717 return 0 ;
1818 }
@@ -24,15 +24,26 @@ static int wifi_gen_config(const char *ifname, const char *ssid, const char *cou
2424 }
2525
2626 fprintf (wpa , "# Generated by Infix confd\n" );
27+
28+ fprintf (wpa , "if [ -f '/etc/finit.d/enabled/wifi@%s.conf' ];then\n" , ifname );
29+ fprintf (wpa , "initctl -bfqn touch wifi@%s\n" , ifname );
30+ fprintf (wpa , "else\n" );
2731 fprintf (wpa , "initctl -bfqn enable wifi@%s\n" , ifname );
32+ fprintf (wpa , "fi\n" );
2833 fclose (wpa );
2934
3035 wpa_supplicant = fopenf ("w" , WPA_SUPPLICANT_CONF , ifname );
3136 if (!wpa_supplicant ) {
3237 rc = SR_ERR_INTERNAL ;
3338 goto out ;
3439 }
35- if (ssid ) {
40+
41+ if (!secret || !ssid || !country || !encryption ) {
42+ fprintf (wpa_supplicant ,
43+ "ctrl_interface=/run/wpa_supplicant\n"
44+ "autoscan=periodic:10\n"
45+ "ap_scan=1\n" );
46+ } else {
3647 if (!strcmp (encryption , "disabled" )) {
3748 asprintf (& encryption_str , "key_mgmt=NONE" );
3849 } else {
@@ -48,14 +59,7 @@ static int wifi_gen_config(const char *ifname, const char *ssid, const char *cou
4859 "ssid=\"%s\"\n"
4960 "%s\n"
5061 "}\n" , country , ssid , encryption_str );
51- free (encryption_str );
52- } else {
53- fprintf (wpa_supplicant ,
54- "ctrl_interface=/run/wpa_supplicant\n"
55- "autoscan=periodic:10\n"
56- "ap_scan=1\n" );
57-
58-
62+ free (encryption_str );
5963 }
6064 fclose (wpa_supplicant );
6165
@@ -75,11 +79,6 @@ int wifi_gen(struct lyd_node *dif, struct lyd_node *cif, struct dagger *net)
7579 return wifi_gen_config (ifname , NULL , NULL , NULL , NULL , net );
7680 }
7781
78- if (dif && !lydx_get_child (dif , "wifi" )) {
79- return SR_ERR_OK ;
80- }
81-
82-
8382 enabled = lydx_get_bool (cif , "enabled" );
8483 wifi = lydx_get_child (cif , "wifi" );
8584
0 commit comments