eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

test-nl80211util.c (1753B)


      1 
      2 #include <assert.h>
      3 #include <ell/ell.h>
      4 #include "src/nl80211util.h"
      5 #include "linux/nl80211.h"
      6 
      7 static void test_parse_attrs(const void *data)
      8 {
      9 	struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
     10 	uint32_t ifindex = 1;
     11 	uint32_t freq = 2;
     12 	int ret;
     13 
     14 	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
     15 	l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
     16 
     17 	ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
     18 					NL80211_ATTR_WIPHY_FREQ, &freq,
     19 					NL80211_ATTR_UNSPEC);
     20 	l_genl_msg_unref(msg);
     21 	assert(ret == 0);
     22 }
     23 
     24 static void test_parse_nested(const void *data)
     25 {
     26 	struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
     27 	uint32_t ifindex = 1;
     28 	uint32_t freq = 2;
     29 	uint8_t noise = 3;
     30 	uint8_t noise_out;
     31 	struct l_genl_attr nested;
     32 	int ret;
     33 	int ret_nested;
     34 
     35 	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
     36 	l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
     37 
     38 	l_genl_msg_enter_nested(msg, NL80211_ATTR_SURVEY_INFO);
     39 	l_genl_msg_append_attr(msg, NL80211_SURVEY_INFO_NOISE, 1, &noise);
     40 	l_genl_msg_leave_nested(msg);
     41 
     42 	ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
     43 					NL80211_ATTR_WIPHY_FREQ, &freq,
     44 					NL80211_ATTR_SURVEY_INFO, &nested,
     45 					NL80211_ATTR_UNSPEC);
     46 	ret_nested = nl80211_parse_nested(&nested, NL80211_ATTR_SURVEY_INFO,
     47 					NL80211_SURVEY_INFO_NOISE, &noise_out,
     48 					NL80211_ATTR_UNSPEC);
     49 	l_genl_msg_unref(msg);
     50 	assert(ret == 0);
     51 	assert(ret_nested == 0);
     52 	assert(noise_out == noise);
     53 }
     54 
     55 int main(int argc, char *argv[])
     56 {
     57 	l_test_init(&argc, &argv);
     58 
     59 	l_test_add("/nl80211util parse attrs", test_parse_attrs, NULL);
     60 	l_test_add("/nl80211util parse nested", test_parse_nested, NULL);
     61 
     62 	return l_test_run();
     63 }