Skip to contentSkip to conversation

Hostapd doesn't like crda

DISCUSSION Michael Buesch 5 participants 11 messages Dec 27, 2008 – Dec 29, 2008

lore
Share & tools
lore
#0 lore raw

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.
So hostapd does set the channel before regulatory stuff is uploaded by CRDA to the kernel. That fails, if we use channel 13, which is allowed in DE, but not in the default regulatory settings.

On the second attempt to start hostapd it works fine, of course, because the regulatory tables are already uploaded.

Any ideas?

Signature · 1 line
Greetings, Michael.
#1 lore raw
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Unfortunately, I don't see an easy fix for this. cfg80211 would somehow need to block sending of the NL80211_CMD_REQ_SET_REG response until CRDA has completed doing whatever it is going to do (is that even something that cfg80211 knows when the final step was completed?).. I haven't taken a look at all the details, but I've asked for this kind of wait in the past and at least it did not seem to be trivial to add since this has not been fixed yet ;-).

Signature · 1 line
Jouni Malinen                                            PGP id EFC895FA
#2 lore raw
Quoted 17 lines · On Saturday 27 December 2008 23:08:14 Jouni Malinen wrote:
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Quoted 7 lines

Unfortunately, I don't see an easy fix for this. cfg80211 would somehow need to block sending of the NL80211_CMD_REQ_SET_REG response until CRDA has completed doing whatever it is going to do (is that even something that cfg80211 knows when the final step was completed?).. I haven't taken a look at all the details, but I've asked for this kind of wait in the past and at least it did not seem to be trivial to add since this has not been fixed yet ;-).

Ok, thanks for the explanation. For now I added a workaround to the initscript that starts hostapd which sets the regulatory and waits a seconds before starting hostapd.

iw reg set DE
sleep 1
# start hostapd...

Signature · 1 line
Greetings, Michael.
#3 lore raw
In reply to Jouni Malinen
Quoted 17 lines · Jouni Malinen
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Quoted 1 line

Unfortunately, I don't see an easy fix for this.

This sounds like it's broken by design. Hostapd should not send NL80211_CMD_REQ_SET_REG if it is unable to evaluate the result. If it's necessary to do "iw reg set foobar" in a script prior to invoking hostapd, then why does hostapd even bother?

Signature · 2 lines
http://www.fastmail.fm - Accessible with your email software
                          or over the web
#4 lore raw
Quoted 19 lines · On Monday 29 December 2008 04:45:22 Dan E wrote:
Quoted 17 lines · Jouni Malinen
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Quoted 7 lines
Quoted 1 line

Unfortunately, I don't see an easy fix for this.

This sounds like it's broken by design. Hostapd should not send NL80211_CMD_REQ_SET_REG if it is unable to evaluate the result. If it's necessary to do "iw reg set foobar" in a script prior to invoking hostapd, then why does hostapd even bother?

hostapd isn't broken. The CMD_REQ_SET_REG should block until regulatory settings are done. It currently doesn't, because that's hard to implement (probably by design).

Signature · 1 line
Greetings, Michael.
#5 lore raw
Quoted 28 lines · Michael Buesch
Quoted 19 lines · On Monday 29 December 2008 04:45:22 Dan E wrote:
Quoted 17 lines · Jouni Malinen
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Quoted 7 lines
Quoted 1 line

Unfortunately, I don't see an easy fix for this.

This sounds like it's broken by design. Hostapd should not send NL80211_CMD_REQ_SET_REG if it is unable to evaluate the result. If it's necessary to do "iw reg set foobar" in a script prior to invoking hostapd, then why does hostapd even bother?

Quoted 3 lines

hostapd isn't broken. The CMD_REQ_SET_REG should block until regulatory settings are done. It currently doesn't, because that's hard to implement (probably by design).

It means adding a timer and picking a reasonable value for the timeout, then waiting for a response through nl80211 and disabling the timer from there and then finally sending the reply back. This seems rather hackish but we can implement if its desirable. I suppose the worst case scenerio would be CRDA and the regulatory db in an NFS mount or something like that.

An alternative would be for us to add a netlink event once the regultory rule is set in place. If the first approach is the better path to take then this secondary netlink event can be sent anyway as informational.

Thoughts?

Luis

#6 lore raw
Quoted 33 lines · On Monday 29 December 2008 16:56:13 Luis R. Rodriguez wrote:
Quoted 28 lines · Michael Buesch
Quoted 19 lines · On Monday 29 December 2008 04:45:22 Dan E wrote:
Quoted 17 lines · Jouni Malinen
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Quoted 7 lines
Quoted 1 line

Unfortunately, I don't see an easy fix for this.

This sounds like it's broken by design. Hostapd should not send NL80211_CMD_REQ_SET_REG if it is unable to evaluate the result. If it's necessary to do "iw reg set foobar" in a script prior to invoking hostapd, then why does hostapd even bother?

Quoted 3 lines

hostapd isn't broken. The CMD_REQ_SET_REG should block until regulatory settings are done. It currently doesn't, because that's hard to implement (probably by design).

Quoted 5 lines

It means adding a timer and picking a reasonable value for the timeout, then waiting for a response through nl80211 and disabling the timer from there and then finally sending the reply back. This seems rather hackish but we can implement if its desirable. I suppose the worst case scenerio would be CRDA and the regulatory db in an NFS mount or something like that.

I think this wouldn't be hackish, but do we actually _know_ when crda has finished uploading regulatory information? Does it do it all in one step?

Quoted 3 lines

An alternative would be for us to add a netlink event once the regultory rule is set in place. If the first approach is the better path to take then this secondary netlink event can be sent anyway as informational.

Would also be OK, but would also require knowledge about "did we finish already". Do we have this knowledge?

Signature · 1 line
Greetings, Michael.
#7 lore raw
Quoted 34 lines · Michael Buesch
Quoted 33 lines · On Monday 29 December 2008 16:56:13 Luis R. Rodriguez wrote:
Quoted 31 lines · Michael Buesch
Quoted 19 lines · On Monday 29 December 2008 04:45:22 Dan E wrote:
Quoted 17 lines · Jouni Malinen
Quoted 7 lines · Michael Buesch

Please take a look at the following log:
http://bu3sch.de/misc/crda.JPG

Note the ordering of the events.
Hostapd starts up and tells the kernel what country we're in. Then the kernel calls CRDA, _but_ hostapd goes on with its business before CRDA has finished its work.

Yes, because the netlink message was completed and hostapd assumes everything is ready at that point. Ignoring the complexity in the kernel (+ CRDA as a helper), this looks like reasonable expectation to make for NL80211_CMD_REQ_SET_REG operation. There is no other mechanism that would notify hostapd (or any other program setting country for that matter) when the operation was actually fully completed and polling for channel changes up to a timeout is not very appealing either.

Quoted 7 lines
Quoted 1 line

Unfortunately, I don't see an easy fix for this.

This sounds like it's broken by design. Hostapd should not send NL80211_CMD_REQ_SET_REG if it is unable to evaluate the result. If it's necessary to do "iw reg set foobar" in a script prior to invoking hostapd, then why does hostapd even bother?

hostapd isn't broken. The CMD_REQ_SET_REG should block until regulatory settings are done. It currently doesn't, because that's hard to implement (probably by design).

Quoted 8 lines
Quoted 5 lines

It means adding a timer and picking a reasonable value for the timeout, then waiting for a response through nl80211 and disabling the timer from there and then finally sending the reply back. This seems rather hackish but we can implement if its desirable. I suppose the worst case scenerio would be CRDA and the regulatory db in an NFS mount or something like that.

I think this wouldn't be hackish, but do we actually _know_ when crda has finished uploading regulatory information? Does it do it all in one step?

It would go in through another nl80211 command, NL80211_CMD_SET_REG. nl80211 eventually calls set_regdom() and this will set it, so if all goes well we can remove the timer at the end if its active (other means can call CRDA like for 802.11d or the wireless core upon initialization).

Quoted 6 lines
Quoted 3 lines

An alternative would be for us to add a netlink event once the regultory rule is set in place. If the first approach is the better path to take then this secondary netlink event can be sent anyway as informational.

Would also be OK, but would also require knowledge about "did we finish already". Do we have this knowledge?

During set_regdom() we can always inspect last_request which tells us the details of who last set the regulatory domain, and at the end of set_regdom() it can be assumed it did so successfully, right after update_all_wiphy_regulatory().

Luis

#8 lore raw
Quoted 7 lines · Luis R. Rodriguez
Quoted 2 lines

I think this wouldn't be hackish, but do we actually _know_ when crda has finished uploading regulatory information? Does it do it all in one step?

It would go in through another nl80211 command, NL80211_CMD_SET_REG. nl80211 eventually calls set_regdom() and this will set it, so if all goes well we can remove the timer at the end if its active (other means can call CRDA like for 802.11d or the wireless core upon initialization).

Can we have a command to _get_ regulatory settings? I think it would be useful. Then hostapd could wait until the correct settings are active. If it doesn't happen after some time, hostapd should exit with an error.

It would be even better if hostapd could wait for an event notifying of the regulatory settings change.

Signature · 2 lines
Regards,
Pavel Roskin
#9 lore raw
Quoted 4 lines · Pavel Roskin
Quoted 3 lines · Luis R. Rodriguez
Quoted 2 lines

I think this wouldn't be hackish, but do we actually _know_ when crda has finished uploading regulatory information? Does it do it all in one step?

Quoted 8 lines
Quoted 4 lines

It would go in through another nl80211 command, NL80211_CMD_SET_REG. nl80211 eventually calls set_regdom() and this will set it, so if all goes well we can remove the timer at the end if its active (other means can call CRDA like for 802.11d or the wireless core upon initialization).

Can we have a command to _get_ regulatory settings? I think it would be useful. Then hostapd could wait until the correct settings are active. If it doesn't happen after some time, hostapd should exit with an error.

Yeah, I've been meaning to get to that but haven't yet, we should have a nl80211 command which lets userspace get the entire rd structure, and maybe some info from last_request.

Quoted 2 lines

It would be even better if hostapd could wait for an event notifying of the regulatory settings change.

Whatever works. But as can be seen this just requires a bit of work.

Luis

#10 lore raw
In reply to Pavel Roskin
Quoted 9 lines · Pavel Roskin
Quoted 7 lines · Luis R. Rodriguez
Quoted 2 lines

I think this wouldn't be hackish, but do we actually _know_ when crda has finished uploading regulatory information? Does it do it all in one step?

It would go in through another nl80211 command, NL80211_CMD_SET_REG. nl80211 eventually calls set_regdom() and this will set it, so if all goes well we can remove the timer at the end if its active (other means can call CRDA like for 802.11d or the wireless core upon initialization).

Quoted 6 lines

Can we have a command to _get_ regulatory settings? I think it would be useful. Then hostapd could wait until the correct settings are active. If it doesn't happen after some time, hostapd should exit with an error.

It would be even better if hostapd could wait for an event notifying of the regulatory settings change.

While I could make hostapd poll for the change (either with get or by waiting in a local loop waiting for the event; both are about equally horrible hacks), I would really prefer this to be done by blocking the response message in the kernel rather than requiring all user space apps (or scripts, for that matter) from having to do this. This is just likely to result in silly "sleep 1" everywhere and hoping that it is always long enough wait..

I might even be tempted to just push that out from hostapd and leave it to be a somebody else's problem (that silly shell script with sleep 1) if the needed mechanism would mean that restarting hostapd takes extra time). A command for querying the current country would get rid of the extra penalty on restarts, so I would probably prefer it if these two options were the only available choices.

Either way, the main problems I see here is to figure out when exactly the CRDA processing has been completed and to make sure that userspace apps will somehow know when that happened (i.e., get country better not return the new country code before all CRDA parameters have been configured and available for the following set_freq command).

Signature · 1 line
Jouni Malinen                                            PGP id EFC895FA