def kernelEvent(data): type, dir = data.split("@", 1) if not dir.startswith("/class/net/"): return devname = dir[11:] flag = 1 ifc = network.IF(devname) if type == "add": if not ifc.isWireless(): return devuid = ifc.deviceUID() notify("Net.Link.deviceChanged", "added wifi %s %s" % (devuid, network.deviceName(devuid))) conns = instances("name") for conn in conns: dev = Dev(conn) if dev.ifc and dev.ifc.name == devname: if dev.state == "up": dev.up() return flag = 0 if flag: notify("Net.Link.deviceChanged", "new wifi %s %s" % (devuid, network.deviceName(devuid))) elif type == "remove": conns = instances("name") for conn in conns: dev = Dev(conn) # FIXME: ifc is not enough here :( if dev.ifc and dev.ifc.name == devname: if dev.state == "up": notify("Net.Link.stateChanged", dev.name + "\ninaccessible " + "Device removed") notify("Net.Link.deviceChanged", "removed wifi %s" % devname)
#!/usr/bin/python import os from comar import network action = os.environ.get("ACTION", None) devpath = os.environ.get("DEVPATH", None) if action == "add": ifc = network.IF(devpath.split("/")[-1]) if ifc.isWireless(): os.system( '/usr/bin/hav event Net.Link kernelEvent wireless-tools "add@%s"' % devpath) elif action == "remove": #FIXME: need to keep some state about add events, or we cant get actual #connection name or device type pass