Search code examples
linuxdbuswpa-supplicant

Creating an access point with wpa_supplicant via dbus interface


I was told that it's possible to create an access point with wpa_supplicant over its dbus interface. All I found with a google is this forum thread, which, despite having exact same title, isn't much informative to me.

Is it possible to do this via wpa_supplicant dbus interface and what exact steps does it take to create one with custom parameters (like frequency, etc.)?


Solution

  • After all, I've found a way to launch access point with wpa_supplicant's dbus inteface.

    Below is pretty self explanatory python code that's is trying to launch AP with the first interface (adapter) it have found.

    import dbus
    import sys
    
    ssid = "TEST_WPA_DBUS_HOTSPOT"
    frequency = 2412
    
    bus = dbus.SystemBus()
    wpa_sup_obj = bus.get_object('fi.w1.wpa_supplicant1', '/fi/w1/wpa_supplicant1')
    props_iface = dbus.Interface(wpa_sup_obj, "org.freedesktop.DBus.Properties")
    
    interfaces = props_iface.Get('fi.w1.wpa_supplicant1', "Interfaces")
    
    try:
        interface = interfaces[0]
    except IndexError:
        sys.exit("No interfaces availible")
    
    
    print "Creating ap with %s" % (interface)
    
    interface_obj = bus.get_object('fi.w1.wpa_supplicant1', interface)
    interface_interface_props = dbus.Interface(interface_obj, "org.freedesktop.DBus.Properties")
    interface_interface = dbus.Interface(interface_obj, "fi.w1.wpa_supplicant1.Interface")
    adapters_name = interface_interface_props.Get("fi.w1.wpa_supplicant1.Interface", "Ifname")
    
    print "Interface's name is %s" % adapters_name
    
    
    key_mgmt = "NONE"
    args = dbus.Dictionary({
        'ssid': ssid,
        'key_mgmt': key_mgmt,
        'mode': 2,
        'frequency': frequency
        }, signature='sv')
    
    netw = interface_interface.AddNetwork(args)
    interface_interface.SelectNetwork(netw)
    
    
    print "AP %s with frequency %i created with adapter %s" % ( ssid, frequency, adapters_name)
    

    Note, that, after all, I've found wpa_supplicant not quite reliable for my needs (in my particular case, I wasn't able to launch 5GHz AP) and have switched to launching hostapd with different configuration files.