[PATCH] tests: nl80211.py: fix attribute padding

Johannes Berg johannes at sipsolutions.net
Fri Dec 1 12:37:11 PST 2017


From: Johannes Berg <johannes.berg at intel.com>

The kernel started enforcing attribute lengths, and
nl80211.py had been doing it all wrong - the padding
must be present, but not part of the length.

Fix it to do it the right way.

Signed-off-by: Johannes Berg <johannes.berg at intel.com>
---
 tests/hwsim/nl80211.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tests/hwsim/nl80211.py b/tests/hwsim/nl80211.py
index 80870d9a2fce..966ea3f0e8da 100644
--- a/tests/hwsim/nl80211.py
+++ b/tests/hwsim/nl80211.py
@@ -320,24 +320,26 @@ nl80211_attr = {
 }
 
 def build_nl80211_attr(id, val):
-    return struct.pack("@HH", 4 + len(val), nl80211_attr[id]) + val
+    attr = struct.pack("@HH", 4 + len(val), nl80211_attr[id]) + val
+    if len(attr) % 4 != 0:
+        attr += '\0' * (4 - len(attr))
+    return attr
 
 def build_nl80211_attr_u32(id, val):
     return build_nl80211_attr(id, struct.pack("@I", val))
 
 def build_nl80211_attr_u16(id, val):
-    return build_nl80211_attr(id, struct.pack("@HH", val, 0))
+    return build_nl80211_attr(id, struct.pack("@H", val))
 
 def build_nl80211_attr_u8(id, val):
-    return build_nl80211_attr(id, struct.pack("@4B", val, 0, 0, 0))
+    return build_nl80211_attr(id, struct.pack("@B", val))
 
 def build_nl80211_attr_flag(id):
     return build_nl80211_attr(id, '')
 
 def build_nl80211_attr_mac(id, val):
     addr = struct.unpack('6B', binascii.unhexlify(val.replace(':','')))
-    t = addr + (0, 0)
-    aval = struct.pack('<6BBB', *t)
+    aval = struct.pack('<6B', *addr)
     return build_nl80211_attr(id, aval)
 
 def parse_nl80211_attrs(msg):
-- 
2.14.2




More information about the Hostap mailing list