@@ -105,15 +105,13 @@ int wifi_gen(struct lyd_node *dif, struct lyd_node *cif, struct dagger *net) {
105105 return SR_ERR_OK ;
106106 cmode = lydx_get_child (cwifi , "mode" );
107107
108- ERROR ("NOW GENERATE WIFI" );
109108 fp = dagger_fopen_net_init (net , ifname , NETDAG_INIT_POST , "disable-wifi.sh" );
110109 if (dif ) {
111110 dwifi = lydx_get_child (dif , "wifi" );
112111 if (dwifi )
113112 dmode = lydx_get_child (dwifi , "mode" );
114113 }
115114 if (!lydx_get_cattr (cif , "enabled" )) {
116- ERROR ("INTERFACE DISSABLED" );
117115 if (dwifi ) {
118116 if (dmode && !strcmp (lyd_get_value (dmode ), "accesspoint" ))
119117 disable_wifi_ap (ifname , fp );
@@ -124,13 +122,11 @@ int wifi_gen(struct lyd_node *dif, struct lyd_node *cif, struct dagger *net) {
124122 }
125123
126124 if (cmode && !strcmp (lyd_get_value (cmode ), "accesspoint" )) {
127- ERROR ("Should now configure AP" );
128125 if (dmode && strcmp (lyd_get_value (dmode ), "accesspoint" ))
129126 disable_wifi_station (ifname , fp );
130127 wifi_ap_gen (cif , net );
131128
132129 } else {
133- ERROR ("Should now configure station" );
134130 if (dmode && strcmp (lyd_get_value (dmode ), "station" ))
135131 disable_wifi_ap (ifname , fp );
136132 /* Client */
@@ -149,7 +145,6 @@ int wifi_station_gen(struct lyd_node *cif, struct dagger *net)
149145 int counter = 0 ;
150146 FILE * fp ;
151147
152- ERROR ("GENERATE STATION" );
153148 ifname = lydx_get_cattr (cif , "name" );
154149 fp = dagger_fopen_net_init (net , ifname , NETDAG_INIT_POST , "disable-wifi.sh" );
155150
@@ -203,61 +198,33 @@ int wifi_station_gen(struct lyd_node *cif, struct dagger *net)
203198
204199int wifi_ap_del_iface (struct lyd_node * cif ,struct dagger * net )
205200{
206- const char * ifname , * radio ;
207- struct lyd_node * wifi ;
208- struct ly_set * remaining_aps = NULL ;
209- bool is_last_ap = false;
201+ const char * ifname ;
210202 FILE * iw ;
211- int rc ;
212203
213204 ifname = lydx_get_cattr (cif , "name" );
214- wifi = lydx_get_child (cif , "wifi" );
215-
216- if (wifi ) {
217- radio = lydx_get_cattr (wifi , "radio" );
218-
219- /* Check if this is the last AP interface for this radio */
220- if (radio ) {
221- rc = lyd_find_xpath (cif , "../interface[derived-from-or-self(type, 'infix-if-type:wifi-ap') and wifi/radio = current()/wifi/radio and name != current()/name]" , & remaining_aps );
222- if (rc != LY_SUCCESS || !remaining_aps || remaining_aps -> count == 0 ) {
223- is_last_ap = true;
224- ERROR ("Interface %s is the last AP for radio %s - will restore radio name" , ifname , radio );
225- } else {
226- ERROR ("Interface %s removal leaves %d other APs for radio %s" , ifname , remaining_aps -> count , radio );
227- }
228-
229- if (remaining_aps )
230- ly_set_free (remaining_aps , NULL );
231- }
232- }
233-
234205 iw = dagger_fopen_net_exit (net , ifname , NETDAG_EXIT , "exit-iw.sh" );
235206
236- if ( is_last_ap && radio ) {
237- /* Last AP interface: restore original radio name */
238- fprintf (iw , "# Restore radio name from %s back to %s \n" , ifname , radio );
239- fprintf (iw , "ip link set dev %s name %s \n" , ifname , radio );
240- fprintf (iw , "ip link property del dev %s altname %s\ n" , radio , radio );
241- } else {
242- /* Virtual AP interface: delete it */
243- fprintf (iw , "# Delete virtual AP interface %s \n" , ifname );
244- fprintf (iw , "iw dev %s del\n" , ifname );
245- }
207+ fprintf ( iw , "# Check if interface has altname, if so restore it, else delete interface\n" );
208+ fprintf ( iw , "ALTNAME=$(ip -j link show dev %s | jq -r '.[0].altnames[0] // empty')\n" , ifname );
209+ fprintf (iw , "if [ -n \"$ALTNAME\" ]; then \n" );
210+ fprintf (iw , " # Restore original radio name \n" );
211+ fprintf (iw , " ip link set dev %s name \"$ALTNAME\"\ n" , ifname );
212+ fprintf ( iw , " ip link property del dev \"$ALTNAME\" altname \"$ALTNAME\"\n" );
213+ fprintf ( iw , "else\n" );
214+ fprintf (iw , " # Delete virtual AP interface\n" );
215+ fprintf (iw , " iw dev %s del\n" , ifname );
216+ fprintf ( iw , "fi\n" );
246217
247218 fclose (iw );
248219
249220 return 0 ;
250221}
251222
252-
253223int wifi_ap_add_iface (struct lyd_node * cif ,struct dagger * net )
254224{
255225 const char * ifname , * radio ;
256226 struct lyd_node * wifi ;
257- struct ly_set * existing_aps = NULL ;
258- bool is_first_ap = false;
259227 FILE * iw ;
260- int rc ;
261228
262229 ifname = lydx_get_cattr (cif , "name" );
263230
@@ -273,39 +240,22 @@ int wifi_ap_add_iface(struct lyd_node *cif,struct dagger *net)
273240 return SR_ERR_INVAL_ARG ;
274241 }
275242
276- /* Check if this is the first AP interface for this radio by finding all APs for this radio */
277- rc = lyd_find_xpath (cif , "../interface[derived-from-or-self(type, 'infix-if-type:wifi-ap') and wifi/radio = current()/wifi/radio]" , & existing_aps );
278- if (rc == LY_SUCCESS && existing_aps && existing_aps -> count > 0 ) {
279- /* Check if current interface is the first one in the list */
280- const char * first_ap_name = lydx_get_cattr (existing_aps -> dnodes [0 ], "name" );
281- if (!strcmp (ifname , first_ap_name )) {
282- is_first_ap = true;
283- ERROR ("Interface %s is the first AP for radio %s - will rename radio" , ifname , radio );
284- } else {
285- ERROR ("Interface %s is additional AP for radio %s - will create virtual interface" , ifname , radio );
286- }
287- } else {
288- /* Fallback: if we can't determine, assume first */
289- is_first_ap = true;
290- ERROR ("Interface %s assumed to be first AP for radio %s" , ifname , radio );
291- }
292-
293- if (existing_aps )
294- ly_set_free (existing_aps , NULL );
295-
296243 dagger_add_dep (& confd .netdag , ifname , radio );
297244 iw = dagger_fopen_net_init (net , ifname , NETDAG_INIT_PRE , "init-iw.sh" );
298245
299- if (is_first_ap ) {
300- /* First AP interface: rename radio interface to AP name */
301- fprintf (iw , "# Rename radio %s to first AP interface %s\n" , radio , ifname );
302- fprintf (iw , "ip link set dev %s name %s\n" , radio , ifname );
303- fprintf (iw , "ip link property add dev %s altname %s\n" , ifname , radio );
304- } else {
305- /* Additional AP interfaces: create virtual interface as before */
306- fprintf (iw , "# Create virtual AP interface %s on radio %s\n" , ifname , radio );
307- fprintf (iw , "iw dev %s interface add %s type __ap\n" , radio , ifname );
308- }
246+ fprintf (iw , "# Check if radio has altname, if so create virtual interface, else rename radio\n" );
247+ fprintf (iw , "ALTNAME=$(ip -j link show dev %s | jq -r '.[0].altnames[0] // empty')\n" , radio );
248+ fprintf (iw , "if [ -n \"$ALTNAME\" ]; then\n" );
249+ fprintf (iw , " # Radio already renamed, create virtual AP interface\n" );
250+ fprintf (iw , " logger -t confd -p daemon.info \"Creating virtual AP interface %s on radio %s\"\n" , ifname , radio );
251+ fprintf (iw , " iw dev %s interface add %s type __ap\n" , radio , ifname );
252+ fprintf (iw , "else\n" );
253+ fprintf (iw , " # First AP interface, rename radio to AP name\n" );
254+ fprintf (iw , " logger -t confd -p daemon.info \"Renaming radio %s to AP interface %s\"\n" , radio , ifname );
255+ fprintf (iw , " ip link set dev %s down\n" , radio );
256+ fprintf (iw , " ip link set dev %s name %s\n" , radio , ifname );
257+ fprintf (iw , " ip link property add dev %s altname %s\n" , ifname , radio );
258+ fprintf (iw , "fi\n" );
309259
310260 fclose (iw );
311261
@@ -348,6 +298,7 @@ int wifi_ap_gen(struct lyd_node *cif, struct dagger *net)
348298 if (!channel || !strcmp (channel , "auto" ))
349299 channel = freq_24GHz ? "6" : "149" ;
350300
301+ ERROR ("Searching radio" );
351302 /* Find all wifi-ap interfaces that reference this radio */
352303 rc = lyd_find_xpath (cif , "../interface[derived-from-or-self(type, 'infix-if-type:wifi-ap') and wifi/radio = current()/name]" , & ap_interfaces );
353304 if (rc != LY_SUCCESS || !ap_interfaces || ap_interfaces -> count == 0 ) {
0 commit comments