@@ -144,14 +144,23 @@ def to_netjson_loop(self, block, result, index):
144144 interface = self .__get_netjson_interface (block )
145145 if not interface :
146146 is_new = True
147- interface = {'name' : block ['ifname' ], 'type' : 'wireless' }
147+ ifname = self .__netjson_wifi_get_ifname (block )
148+ interface = {'name' : ifname , 'type' : 'wireless' }
148149 wifi = self .__netjson_wifi (block , interface )
149150 interface ['wireless' ] = wifi
150151 if is_new :
151152 result .setdefault ('interfaces' , [])
152153 result ['interfaces' ].append (interface )
153154 return result
154155
156+ def __netjson_wifi_get_ifname (self , block ):
157+ """
158+ returns the ifname or alternatively returns
159+ the UCI block name as interface name
160+ (because ifname in wifi devices is optional)
161+ """
162+ return block .get ('ifname' , block ['.name' ].replace ('wifi_' , '' ))
163+
155164 def __netjson_wifi (self , wifi , interface ):
156165 _name = wifi .pop ('.name' )
157166 if _name != self .__get_auto_name (interface ):
@@ -177,7 +186,7 @@ def __netjson_wifi(self, wifi, interface):
177186 if uci_key not in wifi :
178187 continue
179188 wifi [netjson_key ] = int (wifi .pop (uci_key ))
180- ifname = wifi .pop ('ifname' , None )
189+ ifname = wifi .pop ('ifname' , interface [ 'name' ] )
181190 if 'network' in wifi :
182191 if wifi ['network' ] in [ifname , interface .get ('network' )]:
183192 del wifi ['network' ]
@@ -309,7 +318,8 @@ def __netjson_encryption_typecast(self, encryption):
309318
310319 def __get_netjson_interface (self , wifi ):
311320 for interface in self .netjson .get ('interfaces' , []):
312- if interface ['name' ] == wifi ['ifname' ]:
321+ ifname = self .__netjson_wifi_get_ifname (wifi )
322+ if interface ['name' ] == ifname :
313323 interface ['type' ] = 'wireless'
314324 return interface
315325
0 commit comments