hwsim: add --no-register option
PATCH 1/11 hwsim: add --no-register option
Starts hwsim but does not register to mac80211_hwsim. This is to allow autotests to disable hwsim, while still having the ability to create/destroy radios over DBus.
--- tools/hwsim.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
tools/hwsim.c +9 -1
@@ -151,6 +151,7 @@ static enum action {static bool no_vif_attr;static bool p2p_attr; +static bool no_register = false;static const char *radio_name_attr;static struct l_dbus *dbus;static struct l_queue *rules;
@@ -2347,6 +2348,9 @@ static void get_interface_done_initial(void *user_data) {struct l_genl_msg *msg; +if (no_register) +return ; + msg =l_genl_msg_new_sized (HWSIM_CMD_REGISTER ,4 );l_genl_family_send (hwsim, msg, register_callback,NULL ,NULL ); }
@@ -2625,6 +2629,7 @@ static const struct option main_options[] = { { "version", no_argument, NULL, 'v' }, { "iftype-disable", required_argument, NULL, 't' }, { "cipher-disable", required_argument, NULL, 'c' }, + { "no-register", no_argument, NULL, 'r' }, { "help", no_argument, NULL, 'h' }, { } };
@@ -2636,7 +2641,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,":L:CD:kndetc:ipvh" , main_options, + opt =getopt_long (argc, argv,":L:CD:kndetrc:ipvh" , main_options,NULL );if (opt <0 )break ;
@@ -2682,6 +2687,9 @@ int main(int argc, char *argv[])case 'c' :hwsim_disable_ciphers (optarg);break ; +case 'r' : + no_register = true; +break ;case 'v' :printf ("%s\n" ,VERSION );return EXIT_SUCCESS ;
Signature · 1 line
2.26.2
PATCH 2/11 hwsim: check pending_create_msg before replying
In the NEW_RADIO callback hwsim was assuming that DBus had no yet replied to the Create() method. In some cases the NEW_RADIO event fires before the actual callback which will respond to DBus. This causes a crash in the create callback.
--- tools/hwsim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/hwsim.c +1 -1
@@ -1579,7 +1579,7 @@ static void radio_manager_create_callback(struct l_genl_msg *msg,*/ radio =l_queue_find (radio_info, radio_info_match_id,L_UINT_TO_PTR (pending_create_radio_id)); -if (radio) { +if (radio && pending_create_msg) {const char *path =radio_get_path (radio); reply =l_dbus_message_new_method_return (pending_create_msg);
Signature · 1 line
2.26.2
PATCH 3/11 auto-t: fix hwsim.py to use Destroy rather than Remove
In reply to James PrestwoodThere is no Remove() method, but since this code never was used it remained incorrect for quite some time.
--- autotests/util/hwsim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
autotests/util/hwsim.py +1 -1
@@ -203,7 +203,7 @@ class Radio(HwsimDBusAbstract): return [str(addr) for addr in self._properties['Addresses']] def remove(self): - self._iface.Remove(reply_handler=self._success, + self._iface.Destroy(reply_handler=self._success, error_handler=self._failure) self._wait_for_async_op()
Signature · 1 line
2.26.2
PATCH 4/11 hwsim: change radio Create() to take a dictionary
In reply to James PrestwoodThe Create() API was limited to only taking a Name and boolean (for p2p enabling). The actual hwsim nl80211 API can take more attributes than this (which are actually utilized when creating from the command line). To get the DBus API up to the same functionality the two arguments in Create were replaced with a single dictionary. This allows for extending later if more arguments are needed.
--- tools/hwsim.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
tools/hwsim.c +28 -7
@@ -1599,20 +1599,38 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus, void *user_data) {struct l_genl_msg *new_msg; -const char *name; -bool p2p; +struct l_dbus_message_iter dict; +struct l_dbus_message_iter variant; +const char *key; +const char *name =NULL ; +bool p2p = false;if (pending_create_msg)return dbus_error_busy (message); -if (!l_dbus_message_get_arguments (message,"sb" , &name, &p2p)) -return dbus_error_invalid_args (message); +if (!l_dbus_message_get_arguments (message,"a{sv}" , &dict)) + goto invalid; + +while (l_dbus_message_iter_next_entry (&dict, &key, &variant)) { +bool ret = false; - new_msg =l_genl_msg_new_sized (HWSIM_CMD_NEW_RADIO ,16 +strlen (name)); +if (!strcmp (key,"Name" )) + ret =l_dbus_message_iter_get_variant (&variant, +"s" , &name); +else if (!strcmp (key,"P2P" )) + ret =l_dbus_message_iter_get_variant (&variant, +"b" , &p2p); + +if (!ret) + goto invalid; + } + + new_msg =l_genl_msg_new_sized (HWSIM_CMD_NEW_RADIO , +16 + name ?strlen (name) :0 );l_genl_msg_append_attr (new_msg,HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE ,0 ,NULL ); -if (name[0 ]) +if (name)l_genl_msg_append_attr (new_msg,HWSIM_ATTR_RADIO_NAME ,strlen (name) +1 , name);
@@ -1627,12 +1645,15 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus, pending_create_radio_id =0 ;return NULL ; + +invalid: +return dbus_error_invalid_args (message); }static void setup_radio_manager_interface (struct l_dbus_interface *interface) {l_dbus_interface_method (interface,"CreateRadio" ,0 , - radio_manager_create,"o" ,"sb" , + radio_manager_create,"o" ,"a{sv}" ,"path" ,"name" ,"p2p_device" ); }
Signature · 1 line
2.26.2
PATCH 5/11 auto-t: update hwsim radio create to use dictionary
In reply to James Prestwood--- autotests/util/hwsim.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
autotests/util/hwsim.py +9 -2
@@ -249,8 +249,15 @@ class RadioList(collections.Mapping): def _interfaces_removed_handler(self, path, interfaces): del _dict[path] - def create(self, name='', p2p_device=False): - path = self._radio_manager.CreateRadio(name, p2p_device) + def create(self, name=None, p2p_device=False): + args = dbus.Dictionary({ + 'P2P': p2p_device, + }, signature='sv') + + if name: + args['Name'] = name + + path = self._radio_manager.CreateRadio(args) obj = Radio(path) self._dict[path] = obj return obj
Signature · 1 line
2.26.2
PATCH 6/11 test-runner: add wait_for_dbus_service
In reply to James PrestwoodCommon API to wait for a DBus service to appear on the bus
--- tools/test-runner | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/test-runner +9 -0
@@ -616,6 +616,15 @@ class Namespace: return False + def wait_for_dbus_service(self, service): + tries = 0 + + while not self._bus.name_has_owner(service): + if tries > 200: + raise TimeoutError('DBus service %s did not appear', service) + tries += 1 + sleep(0.1) + def __str__(self): ret = 'Namespace: %s\n' % self.name ret += 'Processes:\n'
Signature · 1 line
2.26.2
PATCH 7/11 test-runner: start hwsim always (optionally --no-register)
In reply to James PrestwoodAlways start hwsim but if tests do not need radio rules start with the --no-register option.
--- tools/test-runner | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/test-runner +8 -4
@@ -675,6 +675,14 @@ class TestContext(Namespace): def create_radios(self): setup = self.hw_config['SETUP'] nradios = int(setup['num_radios']) + args = ['hwsim'] + + if not self.hw_config['SETUP'].get('hwsim_medium', 'yes') in ['yes', '1', 'true']: + # register hwsim as medium + args.extend(['--no-register']) + + self.start_process(args) + self.wait_for_dbus_service('net.connman.hwsim') for i in range(nradios): name = 'rad%u' % i
@@ -690,10 +698,6 @@ class TestContext(Namespace): self.radios.append(VirtualRadio(name, rad_config)) self.cur_radio_id += 1 - if self.hw_config['SETUP'].get('hwsim_medium', 'yes') in ['yes', '1', 'true']: - # register hwsim as medium - self.start_process(['hwsim']) - def discover_radios(self): phys = [] iw = pyroute2.iwutil.IW()
Signature · 1 line
2.26.2
PATCH 8/11 hwsim: add iftype/cipher disabling through DBus
In reply to James PrestwoodUpdate the Dbus API to allow disabling iftypes and ciphers just as you can with the command line.
--- tools/hwsim.c | 141 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 84 insertions(+), 57 deletions(-)
tools/hwsim.c +84 -57
@@ -195,6 +195,62 @@ static void do_debug(const char *str, void *user_data)l_info ("%s%s" , prefix, str); } +static void hwsim_disable_support (const char *disable, +const struct hwsim_support *map,uint32_t *mask) +{ +char **list =l_strsplit (disable,',' ); +char **iter = list; +int i; + +while (*iter) { +for (i =0 ; map[i].name; i++) { +if (!strcmp (map[i].name, *iter)) + *mask &= ~(map[i].value); + } + + iter++; + } + +l_strfreev (list); +} + +static bool is_cipher_disabled (const char *args,enum crypto_cipher cipher) +{ +char **list =l_strsplit (args,',' ); +char **iter = list; +int i; + +while (*iter) { +for (i =0 ; cipher_map[i].name; i++) { +if (!strcmp (*iter, cipher_map[i].name) && + cipher == cipher_map[i].value) { +printf ("disable cipher: %s\n" , cipher_map[i].name); +l_strfreev (list); +return true; + } + } + + iter++; + } + +l_strfreev (list); + +return false; +} + +static void hwsim_disable_ciphers (const char *disable) +{ +uint8_t i; + +for (i =0 ; i <L_ARRAY_SIZE (hwsim_supported_ciphers); i++) { +if (is_cipher_disabled (disable, hwsim_supported_ciphers[i])) +continue ; + + hwsim_ciphers[hwsim_num_ciphers] = hwsim_supported_ciphers[i]; + hwsim_num_ciphers++; + } +} +static void create_callback (struct l_genl_msg *msg,void *user_data) {struct l_genl_attr attr;
@@ -1604,6 +1660,8 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,const char *key;const char *name =NULL ;bool p2p = false; +const char *disabled_iftypes =NULL ; +const char *disabled_ciphers =NULL ;if (pending_create_msg)return dbus_error_busy (message);
@@ -1620,7 +1678,12 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,else if (!strcmp (key,"P2P" )) ret =l_dbus_message_iter_get_variant (&variant,"b" , &p2p); - +else if (!strcmp (key,"InterfaceTypeDisable" )) + ret =l_dbus_message_iter_get_variant (&variant,"s" , + &disabled_iftypes); +else if (!strcmp (key,"CipherTypeDisable" )) + ret =l_dbus_message_iter_get_variant (&variant,"s" , + &disabled_ciphers);if (!ret) goto invalid; }
@@ -1638,6 +1701,26 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,l_genl_msg_append_attr (new_msg,HWSIM_ATTR_SUPPORT_P2P_DEVICE ,0 ,NULL ); +if (disabled_iftypes) { +hwsim_disable_support (disabled_iftypes, iftype_map, + &hwsim_iftypes); + +if (hwsim_iftypes !=HWSIM_DEFAULT_IFTYPES ) +l_genl_msg_append_attr (new_msg, +HWSIM_ATTR_IFTYPE_SUPPORT , +4 , &hwsim_iftypes); + } + +if (disabled_ciphers) { +hwsim_disable_ciphers (disabled_ciphers); + +if (hwsim_num_ciphers) +l_genl_msg_append_attr (new_msg,HWSIM_ATTR_CIPHER_SUPPORT , +sizeof (uint32_t ) * hwsim_num_ciphers, + hwsim_ciphers); + + } +l_genl_family_send (hwsim, new_msg, radio_manager_create_callback, pending_create_msg,NULL );
@@ -2525,62 +2608,6 @@ error:l_main_quit (); } -static void hwsim_disable_support (char *disable, -const struct hwsim_support *map,uint32_t *mask) -{ -char **list =l_strsplit (disable,',' ); -char **iter = list; -int i; - -while (*iter) { -for (i =0 ; map[i].name; i++) { -if (!strcmp (map[i].name, *iter)) - *mask &= ~(map[i].value); - } - - iter++; - } - -l_strfreev (list); -} - -static bool is_cipher_disabled (char *args,enum crypto_cipher cipher) -{ -char **list =l_strsplit (args,',' ); -char **iter = list; -int i; - -while (*iter) { -for (i =0 ; cipher_map[i].name; i++) { -if (!strcmp (*iter, cipher_map[i].name) && - cipher == cipher_map[i].value) { -printf ("disable cipher: %s\n" , cipher_map[i].name); -l_strfreev (list); -return true; - } - } - - iter++; - } - -l_strfreev (list); - -return false; -} - -static void hwsim_disable_ciphers (char *disable) -{ -uint8_t i; - -for (i =0 ; i <L_ARRAY_SIZE (hwsim_supported_ciphers); i++) { -if (is_cipher_disabled (disable, hwsim_supported_ciphers[i])) -continue ; - - hwsim_ciphers[hwsim_num_ciphers] = hwsim_supported_ciphers[i]; - hwsim_num_ciphers++; - } -} -static void family_discovered (const struct l_genl_family_info *info,void *user_data) {
Signature · 1 line
2.26.2
PATCH 9/11 auto-t: add iftype/cipher disable to hwsim.py
In reply to James Prestwood--- autotests/util/hwsim.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
autotests/util/hwsim.py +8 -1
@@ -249,7 +249,8 @@ class RadioList(collections.Mapping): def _interfaces_removed_handler(self, path, interfaces): del _dict[path] - def create(self, name=None, p2p_device=False): + def create(self, name=None, p2p_device=False, iftype_disable=None, + cipher_disable=None): args = dbus.Dictionary({ 'P2P': p2p_device, }, signature='sv')
@@ -257,6 +258,12 @@ class RadioList(collections.Mapping): if name: args['Name'] = name + if iftype_disable: + args['InterfaceTypeDisable'] = iftype_disable + + if cipher_disable: + args['CipherTypeDisable'] = cipher_disable + path = self._radio_manager.CreateRadio(args) obj = Radio(path) self._dict[path] = obj
Signature · 1 line
2.26.2
PATCH 10/11 test-runner: Use DBus for hwsim radios
In reply to James PrestwoodUse the hwsim DBus API rather than command line. This both is faster and more dynamic than doing so with the command line. This also avoids tracking the radio ID since we can just hang on to the radio Dbus object directly.
--- tools/test-runner | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
tools/test-runner +9 -19
@@ -41,7 +41,6 @@ TIOCSTTY = 0x540E config = None intf_id = 0 -rad_id = 0 TEST_MAX_TIMEOUT = 120
@@ -314,35 +313,26 @@ class VirtualRadio(Radio): than the command line. ''' def __init__(self, name, config=None): - global rad_id - - super().__init__(name) - self.disable_cipher = None self.disable_iftype = None - args = ['hwsim', '--create', '--name', self.name, '--nointerface', '--p2p'] + hwsim = importlib.import_module('hwsim').Hwsim() if config: - self.disable_iftype = config.get('iftype_disable', False) - if self.disable_iftype: - args.append('--iftype-disable') - args.append(self.disable_iftype) - - self.disable_cipher = config.get('cipher_disable', False) - if self.disable_cipher: - args.append('--cipher-disable') - args.append(self.disable_cipher) + self.disable_iftype = config.get('iftype_disable', None) + self.disable_cipher = config.get('cipher_disable', None) - Process(args, wait=True) + self._radio = hwsim.radios.create(name, p2p_device=True, + iftype_disable=self.disable_iftype, + cipher_disable=self.disable_cipher) - self.id = rad_id - rad_id += 1 + super().__init__(self._radio.name) def __del__(self): super().__del__() - Process(['hwsim', '--destroy=%s' % self.id]) + self._radio.remove() + self._radio = None def __str__(self): ret = super().__str__()
Signature · 1 line
2.26.2
PATCH 11/11 auto-t: fix hwsim.py spoof frame
In reply to James PrestwoodAfter the change creating radios from DBus the radio address pair seems to come in mismatch order, meaning the radio address at index zero may not always be what is expected. Instead of hardcoding addresses[0] the address is checked in the entire addresses array.
--- autotests/util/hwsim.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
autotests/util/hwsim.py +3 -3
@@ -330,15 +330,15 @@ class Hwsim(iwd.AsyncOpAbstract): obj = objects[path] for interface in obj: if interface == HWSIM_INTERFACE_INTERFACE: - if obj[interface]['Address'] == radio.addresses[0]: + if obj[interface]['Address'] in radio.addresses: radio_path = path break iface = dbus.Interface(self._bus.get_object(HWSIM_SERVICE, radio_path), HWSIM_INTERFACE_INTERFACE) - iface.SendFrame(bytearray.fromhex(station.replace(':', '')), - freq, -30, bytearray.fromhex(frame)) + iface.SendFrame(dbus.ByteArray(bytearray.fromhex(station.replace(':', ''))), + freq, -30, dbus.ByteArray(bytearray.fromhex(frame))) def get_radio(self, name): for path in self.radios:
Signature · 1 line
2.26.2
Hi James,
Quoted 7 lines · James Prestwood
Starts hwsim but does not register to
mac80211_hwsim. This is to allow autotests to disable hwsim, while still having the ability to create/destroy radios over DBus.--- tools/hwsim.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Patch 11 held back per your request...
Patches 1-10 applied thanks.
Regards,
-Denis