Re: Question: is it possible to start dormant hostapd?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Arturs,
On 12/8/21 17:40, Arturs Laizans wrote:
> Hi list,
> 
> Tl;dr: Is it possible to start hostapd without opening an AP and then
> later start AP through ctrl interface?
> 
> We are developing a demon that would control wpa_supplicant and
> hostapd. Currently, it is easily possible to start wpa_supplcant that
> has no network configuration and later add networks through ctrl
> interface. However, it seems that for hostapd it is not possible, or
> is it? We would like to eventually start a hostapd service that does
> nothing to interface (wlan0) until it gets settings from ctrl
> interface. Afterward, also disable AP through ctrl interface.

Yes, it's possible to run hostapd without any configuration file. Try this:

hostapd -g /var/run/hostapd/global

You can then add and remove interfaces via wpa_ctrl. Here are some 
examples using hostapd_cli, but you can achieve the same thing 
programmatically with the wpa_ctrl interface. Note that at least with 
the version I am using (2.9), one has to use the 'raw' hostapd_cli 
command to add and remove interfaces. When using 'raw', the arguments 
are case sensitive, so 'ADD' will work but 'add' will fail.

### add the interface uap0

# hostapd_cli raw ADD uap0 /var/run/hostapd nl80211
Selected interface 'global'
OK
# hostapd_cli -i uap0 status
state=UNINITIALIZED
phy=
freq=0
num_sta_non_erp=0
num_sta_no_short_slot_time=0
num_sta_no_short_preamble=0
olbc=0
num_sta_ht_no_gf=0
num_sta_no_ht=0
num_sta_ht_20_mhz=0
num_sta_ht40_intolerant=0
olbc_ht=0
ht_op_mode=0x0
cac_time_seconds=0
cac_time_left_seconds=N/A
channel=0
secondary_channel=0
ieee80211n=0
ieee80211ac=0
ieee80211ax=0
beacon_int=100
dtim_period=2
bss[0]=uap0
bssid[0]=00:00:00:00:00:00
ssid[0]=
num_sta[0]=0

### set up an AP on uap0

# hostapd_cli -i uap0 set ssid test
OK
# hostapd_cli -i uap0 set channel 1
OK
# hostapd_cli -i uap0 set hw_mode b
OK
# hostapd_cli -i uap0 enable
OK
# hostapd_cli -i uap0 status
state=ENABLED
phy=phy0
freq=2412
num_sta_non_erp=0
num_sta_no_short_slot_time=0
num_sta_no_short_preamble=0
olbc=0
num_sta_ht_no_gf=0
num_sta_no_ht=0
num_sta_ht_20_mhz=0
num_sta_ht40_intolerant=0
olbc_ht=0
ht_op_mode=0x0
cac_time_seconds=0
cac_time_left_seconds=N/A
channel=1
secondary_channel=0
ieee80211n=0
ieee80211ac=0
ieee80211ax=0
beacon_int=100
dtim_period=2
supported_rates=02 04 0b 16
max_txpower=20
bss[0]=uap0
bssid[0]=00:09:a7:xx:xx:xx
ssid[0]=test
num_sta[0]=0

### temporarily disable AP on uap0

# hostapd_cli -i uap0 disable
OK
# hostapd_cli -i uap0 status
state=DISABLED
phy=phy0
freq=2412
num_sta_non_erp=0
num_sta_no_short_slot_time=0
num_sta_no_short_preamble=0
olbc=0
num_sta_ht_no_gf=0
num_sta_no_ht=0
num_sta_ht_20_mhz=0
num_sta_ht40_intolerant=0
olbc_ht=0
ht_op_mode=0x0
cac_time_seconds=0
cac_time_left_seconds=N/A
channel=1
secondary_channel=0
ieee80211n=0
ieee80211ac=0
ieee80211ax=0
beacon_int=100
dtim_period=2
bss[0]=uap0
bssid[0]=00:09:a7:xx:xx:xx
ssid[0]=test
num_sta[0]=0

### remove interface uap0 (note: use -iglobal to access the global 
wpa_ctrl interface, otherwise hostapd_cli might pick another interface 
to use and the ADD command will fail)

# hostapd_cli raw REMOVE uap0
Selected interface 'uap0'
UNKNOWN COMMAND
# hostapd_cli -iglobal raw REMOVE uap0
OK
# hostapd_cli -i uap0 status
Failed to connect to hostapd - wpa_ctrl_open: No such file or directory

### other tips

You can disable an interface and then reconfigure it on the fly like 
above, e.g. to change SSID. Note that this usage of hostapd is not very 
well documented, so some things may not behave as you expect. You 
cannot, for example, just do `hostapd_cli -i uap0 channel 6` and expect 
the AP to switch channel while the AP is enabled. But if you 
disable/enable it then the channel will change. However, if your driver 
supports it, you can use the chan_switch command.

Another tip is to use the configuration 'ssid2' rather than 'ssid' if 
you want to be confident that your SSID is exactly as you intended, 
since the wpa_ctrl interface parsing can screw it up sometimes. 'ssid2' 
takes a hex-formatted argument like '616263' for an SSID 'ABC'.

Hope that helps!

Kind regards,

	Alvin
_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux