def kernelEvent(data): type, dir = data.split("@", 1) if not "/net/" in dir: return device = dir.split("/net/")[-1] new = True if type == "add": # Get device information ifc = netutils.IF(device) device_id = ifc.deviceUID() if not ifc.isWireless(): return # Notify clients notify("Network.Link", "deviceChanged", ("add", "wifi", device_id, netutils.deviceName(device_id))) # Bring related connection up for pn in listProfiles(): profile = Profile(pn) if profile.info.get("device", None) == device_id: new = False if profile.info.get("state", "down").startswith("unplugged"): setState(pn, "up") break # Notify clients if device has no connections if new: notify("Network.Link", "deviceChanged", ("new", "wifi", device_id, netutils.deviceName(device_id))) elif type == "remove": # Bring related connection down for pn in listProfiles(): profile = Profile(pn) if profile.info.get("device", "").split(":")[-1].split("_")[-1] == device: if profile.info.get("state", "down").startswith("up"): # Stop ifplug daemon plugService(device, "down", wireless=True) setState(pn, "unplugged") break # Notify clients notify("Network.Link", "deviceChanged", ("removed", "wifi", device, ""))
def connections(): return listProfiles()