hwsim: don't print on when send frame fails
James Prestwood
PATCH 1/3 hwsim: don't print on when send frame fails
This happens quite often and spams the console with this error.
--- tools/hwsim.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
tools/hwsim.c +1 -5
@@ -1336,11 +1336,7 @@ static void send_frame_callback(struct l_genl_msg *msg, void *user_data) {struct send_frame_info *info = user_data; -if (l_genl_msg_get_error (msg) <0 ) -/* Radio address or frequency didn't match */ -l_debug ("HWSIM_CMD_FRAME failed for destination %s" , -util_address_to_string (info->radio->addrs[0 ])); -else { +if (l_genl_msg_get_error (msg) ==0 ) { info->frame->acked = true; info->frame->ack_radio = info->radio; }
Signature · 1 line
2.34.1
James Prestwood
PATCH 2/3 hwsim: allow concurrent radio creations
Currently CreateRadio only allows a single outstanding DBus message until the radio is fully created. 99% of the time this is just fine but in order to test dual phy cards there needs to be support for phy's appearing at the same time.
This required storing the pending DBus message inside the radio object rather than a single static variable.
--- tools/hwsim.c | 77 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 36 deletions(-)
tools/hwsim.c +41 -36
@@ -415,6 +415,7 @@ struct radio_info_rec {uint8_t addrs[2 ][ETH_ALEN ];char *name;bool ap_only; +struct l_dbus_message *pending; };struct interface_info_rec {
@@ -428,13 +429,13 @@ struct interface_info_rec {static struct l_queue *radio_info;static struct l_queue *interface_info; -static struct l_dbus_message *pending_create_msg; -static uint32_t pending_create_radio_id; -static void radio_free (void *user_data) {struct radio_info_rec *rec = user_data; +if (rec->pending) +l_dbus_message_unref (rec->pending); +l_free (rec->name);l_free (rec); }
@@ -512,12 +513,6 @@ static const char *interface_get_path(const struct interface_info_rec *rec)return path; } -static struct l_dbus_message *dbus_error_busy (struct l_dbus_message *msg) -{ -return l_dbus_message_new_error (msg,HWSIM_SERVICE ".InProgress" , -"Operation already in progress" ); -} -static struct l_dbus_message *dbus_error_failed (struct l_dbus_message *msg) { return l_dbus_message_new_error(msg, HWSIM_SERVICE ".Failed",
@@ -610,7 +605,7 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data)uint8_t file_buffer[128 ];int bytes, consumed;unsigned int uintval; -bool old; +bool old = false;struct radio_info_rec prev_rec;bool name_change = false;const char *path;
@@ -637,8 +632,15 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data)if (!id || !name)return ; +/* +* If the radio info exists without a pending dbus message this is a +* name change. If the radio info exists with a pending message a +* minimal radio was created in order to save the DBus message. This +* can be handled nearly identical to if 'rec' is NULL by initializing +* the object now. +*/ rec =l_queue_find (radio_info, radio_info_match_id,L_UINT_TO_PTR (*id)); -if (rec) { +if (rec && !rec->pending) { old = true;memcpy (&prev_rec, rec,sizeof (prev_rec));
@@ -647,8 +649,7 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data) name_change = true;l_free (rec->name); - }else { - old = false; + }else if (!rec) { rec = l_new(struct radio_info_rec, 1); rec->id = *id; }
@@ -758,12 +759,12 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data) }/* Send pending CreateRadio reply */ -if (pending_create_msg && pending_create_radio_id == rec->id) { +if (rec->pending) {struct l_dbus_message *reply = -l_dbus_message_new_method_return (pending_create_msg); +l_dbus_message_new_method_return (rec->pending);l_dbus_message_set_arguments (reply,"o" , path); -dbus_pending_reply (&pending_create_msg, reply); +dbus_pending_reply (&rec->pending, reply); }return ;
@@ -772,9 +773,9 @@ err_free_radio:if (!old)radio_free (rec); -if (pending_create_msg && pending_create_radio_id == *id) -dbus_pending_reply (&pending_create_msg, -dbus_error_failed (pending_create_msg)); +if (rec->pending) +dbus_pending_reply (&rec->pending, +dbus_error_failed (rec->pending)); }static bool radio_ap_only (struct radio_info_rec *rec)
@@ -1642,6 +1643,7 @@ static void unicast_handler(struct l_genl_msg *msg, void *user_data)static void radio_manager_create_callback (struct l_genl_msg *msg,void *user_data) { +struct l_dbus_message *message = user_data;struct l_dbus_message *reply;struct l_genl_attr attr;struct radio_info_rec *radio;
@@ -1658,28 +1660,38 @@ static void radio_manager_create_callback(struct l_genl_msg *msg,if (err <0 ) goto error; - pending_create_radio_id = err; -/* * If the NEW_RADIO event has been received we'll have added the * radio to radio_info already but we can send the method return * only now that we know the ID returned by our command. */ radio =l_queue_find (radio_info, radio_info_match_id, -L_UINT_TO_PTR (pending_create_radio_id)); -if (radio && pending_create_msg) { +L_UINT_TO_PTR (err)); +if (radio) {const char *path =radio_get_path (radio); - reply =l_dbus_message_new_method_return (pending_create_msg); + reply =l_dbus_message_new_method_return (message);l_dbus_message_set_arguments (reply,"o" , path); -dbus_pending_reply (&pending_create_msg, reply); +dbus_pending_reply (&message, reply); + }else { +/* +* NEW_RADIO has not happened but in order to allow concurrent +* radio creations we must save away the message now. This means +* creating this minimal radio object in order to look up in +* the NEW_RADIO callback and reply. +*/ + radio = l_new(struct radio_info_rec, 1); + radio->id = err; + radio->pending = message; + +l_queue_push_tail (radio_info, radio); }return ; error: - reply =dbus_error_failed (pending_create_msg); -dbus_pending_reply (&pending_create_msg, reply); + reply =dbus_error_failed (message); +dbus_pending_reply (&message, reply); } static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,
@@ -1695,9 +1707,6 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,const char *disabled_iftypes =NULL ;const char *disabled_ciphers =NULL ; -if (pending_create_msg) -return dbus_error_busy (message); -if (!l_dbus_message_get_arguments (message,"a{sv}" , &dict)) goto invalid;
@@ -1753,10 +1762,9 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus, }l_genl_family_send (hwsim, new_msg, radio_manager_create_callback, - pending_create_msg,NULL ); + message,NULL ); - pending_create_msg =l_dbus_message_ref (message); - pending_create_radio_id =0 ; +l_dbus_message_ref (message);return NULL ;
@@ -3088,9 +3096,6 @@ int main(int argc, char *argv[])l_genl_family_free (nl80211);l_genl_unref (genl); -if (pending_create_msg) -l_dbus_message_unref (pending_create_msg); -l_dbus_destroy (dbus);hwsim_radio_cache_cleanup ();l_queue_destroy (rules, l_free);
Signature · 1 line
2.34.1
Denis Kenzior
Re: [PATCH 2/3] hwsim: allow concurrent radio creations
Hi James,
Quoted 160 lines · James Prestwood
Currently CreateRadio only allows a single outstanding DBus message until the radio is fully created. 99% of the time this is just fine but in order to test dual phy cards there needs to be support for phy's appearing at the same time.
This required storing the pending DBus message inside the radio object rather than a single static variable.
--- tools/hwsim.c | 77 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 36 deletions(-)tools/hwsim.c +36
-25@@ -415,6 +415,7 @@ struct radio_info_rec {uint8_t addrs[2 ][ETH_ALEN ];char *name;bool ap_only; +struct l_dbus_message *pending; };struct interface_info_rec {@@ -428,13 +429,13 @@ struct interface_info_rec {static struct l_queue *radio_info;static struct l_queue *interface_info; -static struct l_dbus_message *pending_create_msg; -static uint32_t pending_create_radio_id; -static void radio_free (void *user_data) {struct radio_info_rec *rec = user_data; +if (rec->pending) +l_dbus_message_unref (rec->pending); +l_free (rec->name);l_free (rec); }@@ -512,12 +513,6 @@ static const char *interface_get_path(const struct interface_info_rec *rec)return path; } -static struct l_dbus_message *dbus_error_busy (struct l_dbus_message *msg) -{ -return l_dbus_message_new_error (msg,HWSIM_SERVICE ".InProgress" , -"Operation already in progress" ); -} -static struct l_dbus_message *dbus_error_failed (struct l_dbus_message *msg) { return l_dbus_message_new_error(msg, HWSIM_SERVICE ".Failed",@@ -610,7 +605,7 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data)uint8_t file_buffer[128 ];int bytes, consumed;unsigned int uintval; -bool old; +bool old = false;struct radio_info_rec prev_rec;bool name_change = false;const char *path;@@ -637,8 +632,15 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data)if (!id || !name)return ; +/* +* If the radio info exists without a pending dbus message this is a +* name change. If the radio info exists with a pending message a +* minimal radio was created in order to save the DBus message. This +* can be handled nearly identical to if 'rec' is NULL by initializing +* the object now. +*/ rec =l_queue_find (radio_info, radio_info_match_id,L_UINT_TO_PTR (*id)); -if (rec) { +if (rec && !rec->pending) { old = true;memcpy (&prev_rec, rec,sizeof (prev_rec));@@ -647,8 +649,7 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data) name_change = true;l_free (rec->name); - }else { - old = false; + }else if (!rec) { rec = l_new(struct radio_info_rec, 1); rec->id = *id; }@@ -758,12 +759,12 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data) }/* Send pending CreateRadio reply */ -if (pending_create_msg && pending_create_radio_id == rec->id) { +if (rec->pending) {struct l_dbus_message *reply = -l_dbus_message_new_method_return (pending_create_msg); +l_dbus_message_new_method_return (rec->pending);l_dbus_message_set_arguments (reply,"o" , path); -dbus_pending_reply (&pending_create_msg, reply); +dbus_pending_reply (&rec->pending, reply); }return ;@@ -772,9 +773,9 @@ err_free_radio:if (!old)radio_free (rec); -if (pending_create_msg && pending_create_radio_id == *id) -dbus_pending_reply (&pending_create_msg, -dbus_error_failed (pending_create_msg)); +if (rec->pending) +dbus_pending_reply (&rec->pending, +dbus_error_failed (rec->pending)); }static bool radio_ap_only (struct radio_info_rec *rec)@@ -1642,6 +1643,7 @@ static void unicast_handler(struct l_genl_msg *msg, void *user_data)static void radio_manager_create_callback (struct l_genl_msg *msg,void *user_data) { +struct l_dbus_message *message = user_data;struct l_dbus_message *reply;struct l_genl_attr attr;struct radio_info_rec *radio;@@ -1658,28 +1660,38 @@ static void radio_manager_create_callback(struct l_genl_msg *msg,if (err <0 ) goto error; - pending_create_radio_id = err; -/* * If the NEW_RADIO event has been received we'll have added the * radio to radio_info already but we can send the method return * only now that we know the ID returned by our command. */ radio =l_queue_find (radio_info, radio_info_match_id, -L_UINT_TO_PTR (pending_create_radio_id)); -if (radio && pending_create_msg) { +L_UINT_TO_PTR (err)); +if (radio) {const char *path =radio_get_path (radio); - reply =l_dbus_message_new_method_return (pending_create_msg); + reply =l_dbus_message_new_method_return (message);l_dbus_message_set_arguments (reply,"o" , path); -dbus_pending_reply (&pending_create_msg, reply); +dbus_pending_reply (&message, reply); + }else { +/* +* NEW_RADIO has not happened but in order to allow concurrent +* radio creations we must save away the message now. This means +* creating this minimal radio object in order to look up in +* the NEW_RADIO callback and reply. +*/ + radio = l_new(struct radio_info_rec, 1); + radio->id = err; + radio->pending = message; +
tools/hwsim.c static void radio_manager_create_callback(struct l_genl_msg *msg, · line 1694
Quoted 10 lines
tools/hwsim.c +3
-2+l_queue_push_tail (radio_info, radio); }return ; error: - reply =dbus_error_failed (pending_create_msg); -dbus_pending_reply (&pending_create_msg, reply); + reply =dbus_error_failed (message); +dbus_pending_reply (&message, reply);
This all seems even messier than before. Maybe we should just always create the radio info structure in radio_manager_create and just set the pending_genl_cmd_id and dbus_message accordingly? That way you're not creating the structure all over the place.
Quoted 3 lines
tools/hwsim.c +0
-0} static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,
<snip>
tools/hwsim.c static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus, · line 1765
Quoted 6 lines
tools/hwsim.c +1
-1@@ -1753,10 +1762,9 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus, }l_genl_family_send (hwsim, new_msg, radio_manager_create_callback, - pending_create_msg,NULL ); + message,NULL );
Nit: You probably should be using the destroy callback here. Otherwise the messages won't be cleaned up properly.
tools/hwsim.c static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus, · line 1770
Quoted 7 lines
tools/hwsim.c +1
-2- pending_create_msg =l_dbus_message_ref (message); - pending_create_radio_id =0 ; +l_dbus_message_ref (message);return NULL ;
<snip>
Regards,
-Denis
James Prestwood
PATCH 3/3 auto-t: hwsim.py: support async radio creation
In reply to James PrestwoodAdds a new wait argument which, if false, will call the DBus method and return immediately. This allows the caller to create multiple radios very quickly, simulating (as close as we can) a wifi card with dual phy's which appear in the kernel simultaneously.
--- autotests/util/hwsim.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
autotests/util/hwsim.py +12 -1
@@ -310,7 +310,7 @@ class RadioList(collections.Mapping): del _dict[path] def create(self, name=None, p2p_device=False, iftype_disable=None, - cipher_disable=None): + cipher_disable=None, wait=False): args = dbus.Dictionary({ 'P2P': p2p_device, }, signature='sv')
@@ -324,11 +324,22 @@ class RadioList(collections.Mapping): if cipher_disable: args['CipherTypeDisable'] = cipher_disable + if not wait: + self._radio_manager.CreateRadio(args, reply_handler=self._success, + error_handler=self._failure) + return None + path = self._radio_manager.CreateRadio(args) obj = Radio(path) self._dict[path] = obj return obj + def _success(self, bla): + pass + + def _failure(self, ex): + pass + class Hwsim(iwd.AsyncOpAbstract): _instances = WeakValueDictionary()
Signature · 1 line
2.34.1
Denis Kenzior
AppliedHi James,
Quoted 5 lines · James Prestwood
This happens quite often and spams the console with this error.
--- tools/hwsim.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Applied, thanks.
Regards,
-Denis