Add support for sending netlink messages

This allows sigma_dut to issue nl80211 commands directly without having
to use an external tool like iw (or go through wpa_supplicant) to do so.

An example of how to send a vendor command to the driver is provided in
atheros.c by function cmd_atheros_config_scan(), which is to enable or
disable scan functionality in the driver.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
diff --git a/atheros.c b/atheros.c
index 72be3b8..6367427 100644
--- a/atheros.c
+++ b/atheros.c
@@ -64,7 +64,56 @@
 }
 
 
+#ifdef NL80211_SUPPORT
+static int cmd_atheros_config_scan(struct sigma_dut *dut,
+				   struct sigma_conn *conn,
+				   struct sigma_cmd *cmd)
+{
+	struct nl_msg *msg;
+	int ret;
+	struct nlattr *params;
+	const char *val;
+	int ifindex;
+
+	val = get_param(cmd, "enable");
+	if (!val)
+		return -1;
+	ifindex = if_nametoindex("wlan0");
+	if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
+				    NL80211_CMD_VENDOR)) ||
+	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
+	    nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
+	    nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
+			QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
+	    !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
+	    nla_put_u8(msg,
+		       QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_ENABLE,
+		       atoi(val))) {
+		sigma_dut_print(dut, DUT_MSG_ERROR,
+				"%s: err in adding vendor_cmd and vendor_data",
+				__func__);
+		nlmsg_free(msg);
+		return -1;
+	}
+	nla_nest_end(msg, params);
+
+	ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
+	if (ret) {
+		sigma_dut_print(dut, DUT_MSG_ERROR,
+				"%s: err in send_and_recv_msgs, ret=%d",
+				__func__, ret);
+		return ret;
+	}
+
+	return 0;
+}
+#endif /* NL80211_SUPPORT */
+
+
 void atheros_register_cmds(void)
 {
 	sigma_dut_reg_cmd("sta_atheros", req_intf, cmd_sta_atheros);
+#ifdef NL80211_SUPPORT
+	sigma_dut_reg_cmd("atheros_config_scan", NULL, cmd_atheros_config_scan);
+#endif /* NL80211_SUPPORT */
 }