通过dbus接口使用wpa_supplicant创建接入点

时间:2016-01-08 10:52:35

标签: linux dbus wpa-supplicant

有人告诉我,可以通过其dbus接口创建一个带wpa_supplicant的接入点。我在Google上找到的所有内容都是this forum thread,尽管标题完全相同,但对我来说信息量不大。

这是否可以通过wpa_supplicant dbus接口执行此操作,以及使用自定义参数(如频率等)创建一个具体步骤是什么?

1 个答案:

答案 0 :(得分:2)

毕竟,我找到了一种用wpa_supplicant的dbus接口启动接入点的方法。

下面是非常自我解释的python代码,它试图用它找到的第一个接口(适配器)启动AP。

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)

请注意,毕竟,我发现wpa_supplicant对我的需求不太可靠(在我的特定情况下,我无法启动5GHz AP)并且已经切换到使用不同的配置文件启动hostapd。