diff --git a/src/confd/src/if-wifi.c b/src/confd/src/if-wifi.c index f6f54a88..84081f12 100644 --- a/src/confd/src/if-wifi.c +++ b/src/confd/src/if-wifi.c @@ -203,6 +203,18 @@ int wifi_add_iface(struct lyd_node *cif, struct dagger *net) fprintf(iw, " timeout=$((timeout - 1))\n"); fprintf(iw, "done\n"); } + + /* + * If radio doesn't exist, create a dummy interface as placeholder. This allows all + * downstream config (IP addresses, etc.) to work. User must reboot when radio becomes + * available. + */ + fprintf(iw, "if ! iw phy %s info >/dev/null 2>&1; then\n", radio); + fprintf(iw, " logger -t wifi \"%s: radio %s not available, creating dummy placeholder\"\n", ifname, radio); + fprintf(iw, " ip link add %s type dummy\n", ifname); + fprintf(iw, " exit 0\n"); + fprintf(iw, "fi\n\n"); + switch(mode) { case wifi_station: fprintf(iw, "iw phy %s interface add %s type managed\n", radio, ifname); @@ -241,16 +253,15 @@ int wifi_del_iface(struct lyd_node *dif, struct dagger *net) } fprintf(iw, "# Generated by Infix confd - WiFi Interface Deletion\n"); - fprintf(iw, "ip link set %s down\n", ifname); /* Required to change modes. */ - fprintf(iw, "iw dev %s disconnect\n", ifname); - fprintf(iw, "iw dev %s del\n", ifname); + fprintf(iw, "ip link set %s down\n", ifname); + fprintf(iw, "iw dev %s disconnect 2>/dev/null\n", ifname); + fprintf(iw, "iw dev %s del 2>/dev/null || ip link del %s 2>/dev/null || true\n", ifname, ifname); wifi = lydx_get_child(dif, "wifi"); - if (wifi && wifi_get_mode(wifi) == wifi_ap) { /* if not station or scanning mode */ + if (wifi && wifi_get_mode(wifi) != wifi_ap) { erasef(WPA_SUPPLICANT_CONF, ifname); fprintf(iw, "initctl -bfq disable wifi@%s\n", ifname); } - fclose(iw); return SR_ERR_OK;