diff mbox series

Changes in Hostapd_cli

Message ID MN2PR15MB2720955A2E0E851E841B056FB28B0@MN2PR15MB2720.namprd15.prod.outlook.com
State Deferred
Headers show
Series Changes in Hostapd_cli | expand

Commit Message

Henrique Moura Sept. 21, 2019, 8:57 p.m. UTC
Hi,


The attached patch allows the hostapd_cli to change the default WMM parameters. Four new commands were added that allow the user to get and set the parameters used by the AP and the values sent to the stations.



 

Henrique Moura




henriquemoura@hotmail.com



PhD Candidate - PPGCC/DCC/UFMG
Curriculum Lattes - http://lattes.cnpq.br/5445352795551453
diff mbox series

Patch

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 8d9d1a3be..360d47a12 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -1171,6 +1171,138 @@  static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data *hapd,
 	return pos - buf;
 }
 
+// This procedure returns the queue params from hostapd_cli
+// ref.
+//   http://docs.ros.org/diamondback/api/wpa_supplicant/html/structhostapd__data.html
+//   http://docs.ros.org/diamondback/api/wpa_supplicant/html/structhostapd__config.html
+//   http://docs.ros.org/diamondback/api/wpa_supplicant/html/structhostapd__tx__queue__params.html
+static int hostapd_ctrl_iface_get_queue_params(struct hostapd_data *hapd,
+					 char *buf, size_t buflen)
+{
+    int ret;
+    char *pos, *end;
+
+    pos = buf;
+    end = buf + buflen;
+
+    // see hostapd_config_tx_queue()
+    struct hostapd_config *conf = hapd->iconf;
+    for(int num = 0; num < NUM_TX_QUEUES; num++) { // NUM_TX_QUEUES defined in src/ap/ap_config.h
+        struct hostapd_tx_queue_params  *queue = &conf->tx_queue[num];
+        int aifs = queue->aifs;
+        int tx_cwmin = queue->cwmin;
+        int tx_cwmax = queue->cwmax;
+        int burst = queue->burst;
+
+        // return result
+        ret = os_snprintf(pos, end - pos,
+                          "Queue=%d : aifs=%d tx_cwmin=%d tx_cwmax=%d burst=%d\n",
+                          num, aifs, tx_cwmin, tx_cwmax, burst
+                          );
+        if (os_snprintf_error(end - pos, ret))
+            return pos - buf;
+        pos += ret;
+    }
+
+	return pos - buf;
+}
+
+// set the queue parameters
+static int hostapd_ctrl_iface_set_queue_params(struct hostapd_data *hapd,
+                     char *params, char *buf, size_t buflen)
+{
+    // read data
+    int num_queue, aifs, cw_min, cw_max, burst_time;
+    char *p = params;
+    num_queue = strtol (p, &p, 10);
+    aifs = strtol (p, &p, 10);
+    cw_min = strtol (p, &p, 10);
+    cw_max = strtol (p, &p, 10);
+    burst_time = strtol (p, &p, 10);
+
+    wpa_printf(MSG_INFO, "Set queue %d: aifs %d cw_min %d cw_max %d burst_time %d",
+    			num_queue, aifs, cw_min, cw_max, burst_time);
+
+    if (hostapd_set_tx_queue_params(hapd, num_queue, aifs, cw_min, cw_max, burst_time)){
+    	wpa_printf(MSG_INFO, "Failed to set TX queue parameters for queue %d", num_queue);
+    	return -1;
+    } else {
+    	// don't need to check if num_queue is valid, because if is invalid, never enters here
+
+    	// set this new data into the hapd struct
+    	struct hostapd_config *conf = hapd->iconf;
+    	struct hostapd_tx_queue_params * queue = &conf->tx_queue[num_queue];
+    	queue->aifs  = aifs;
+        queue->cwmin = cw_min;
+        queue->cwmax = cw_max;
+        queue->burst = burst_time;
+    }
+
+    return 0;
+}
+
+// get WMM parameters
+static int hostapd_ctrl_iface_get_wmm_params(struct hostapd_data *hapd,
+					 char *buf, size_t buflen)
+{
+    int ret;
+    char *pos, *end;
+
+    pos = buf;
+    end = buf + buflen;
+
+    struct hostapd_config *conf = hapd->iconf;
+    for(int num = 0; num < 4; num++) { 			// Value is fixed in 4
+        struct hostapd_wmm_ac_params *queue = &conf->wmm_ac_params[num];
+        int aifs = queue->aifs;
+        int tx_cwmin = queue->cwmin;
+        int tx_cwmax = queue->cwmax;
+        int txop = queue->txop_limit;
+
+        // return result
+        ret = os_snprintf(pos, end - pos,
+                          "Queue=%d : aifs=%d tx_cwmin=%d tx_cwmax=%d txop=%d\n",
+                          num, aifs, tx_cwmin, tx_cwmax, txop
+                          );
+        if (os_snprintf_error(end - pos, ret))
+            return pos - buf;
+        pos += ret;
+    }
+	return pos - buf;
+}
+
+static int hostapd_ctrl_iface_set_wmm_params(struct hostapd_data *hapd,
+                     char *params, char *buf, size_t buflen)
+{
+    // read data
+    int num_queue, aifs, cw_min, cw_max, txop;
+    char *p = params;
+    num_queue = strtol (p, &p, 10);
+    aifs = strtol (p, &p, 10);
+    cw_min = strtol (p, &p, 10);
+    cw_max = strtol (p, &p, 10);
+    txop = strtol (p, &p, 10);
+
+    if (num_queue < 0 || num_queue > 3){
+    	wpa_printf(MSG_ERROR, "Set wmm queue error: queue %d invalid", num_queue);
+    	return -1;
+    }
+
+    wpa_printf(MSG_INFO, "Set wmm queue %d: aifs %d cw_min %d cw_max %d txop %d",
+    			num_queue, aifs, cw_min, cw_max, txop);
+
+    struct hostapd_config *conf = hapd->iconf;
+    struct hostapd_wmm_ac_params *queue = &conf->wmm_ac_params[num_queue];
+
+    queue->aifs = aifs;
+    queue->cwmin = cw_min;
+    queue->cwmax = cw_max;
+    queue->txop_limit = txop;
+
+    ieee802_11_update_beacons(hapd->iface);
+
+    return 0;
+}
 
 static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
 					 char *buf, size_t buflen)
@@ -3365,6 +3497,14 @@  static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
 	} else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
 		reply_len = hostapd_ctrl_iface_get_capability(
 			hapd, buf + 15, reply, reply_size);
+	} else if (os_strcmp(buf, "GET_QUEUE_PARAMS") == 0) { // HERE --- Added by gmj93 and h3dema
+		reply_len = hostapd_ctrl_iface_get_queue_params(hapd, reply, reply_size);
+    } else if (os_strncmp(buf, "SET_QUEUE_PARAMS", 16) == 0) { // HERE --- Added by gmj93 and h3dema
+        reply_len = hostapd_ctrl_iface_set_queue_params(hapd, buf + 16, reply, reply_size);
+    } else if (os_strcmp(buf, "GET_WMM_PARAMS") == 0) { // HERE --- Added by gmj93 and h3dema
+    	reply_len = hostapd_ctrl_iface_get_wmm_params(hapd, reply, reply_size);
+    } else if (os_strncmp(buf, "SET_WMM_PARAMS", 14) == 0) { // HERE --- Added by gmj93 and h3dema
+    	reply_len = hostapd_ctrl_iface_set_wmm_params(hapd, buf + 14, reply, reply_size);
 	} else {
 		os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
 		reply_len = 16;
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index 42edb7b25..0a5b44a51 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -817,6 +817,79 @@  static int hostapd_cli_cmd_license(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+/* get the WMM Queue parameters
+ */
+static int hostapd_cli_cmd_get_queue_params(struct wpa_ctrl *ctrl,
+                       int argc, char *argv[]) {
+    return wpa_ctrl_command(ctrl, "GET_QUEUE_PARAMS");  // processed by hostapd_ctrl_iface_get_queue_params()
+}
+
+
+/* set the WMM Queue parameters
+    - argv[0] = queue num
+    - argv[1] = aifs
+    - argv[2] = tx_cwmin
+    - argv[3] = tx_cwmax
+    - argv[4] = burst
+ */
+static int hostapd_cli_cmd_set_queue_params(struct wpa_ctrl *ctrl,
+                       int argc, char *argv[]) {
+	char buf[200];
+	int res;
+
+	if (argc != 5) {
+		printf("Invalid 'set_queue_params' command - "
+		       "five arguments (comma delimited queue params) "
+		       "is needed\n");
+		return -1;
+	}
+
+	res = os_snprintf(buf, sizeof(buf), "SET_QUEUE_PARAMS %s %s %s %s %s",
+						argv[0], argv[1], argv[2], argv[3], argv[4]);
+	if (os_snprintf_error(sizeof(buf), res))
+		return -1;
+
+    return wpa_ctrl_command(ctrl, buf);  // processed by hostapd_ctrl_iface_set_queue_params()
+}
+
+/* Get the WMM parameters, these values are send to the stations
+ */
+static int hostapd_cli_cmd_get_wmm_params(struct wpa_ctrl *ctrl,
+										  int argc, char *argv[]){
+	return wpa_ctrl_command(ctrl, "GET_WMM_PARAMS");
+}
+
+/* Set the WMM parameters in the beacon.
+   There are 4 queues in WMM, thus to change all parameters you have to call
+   this function four times.
+
+    - argv[0] = queue num
+    - argv[1] = aifs
+    - argv[2] = tx_cwmin
+    - argv[3] = tx_cwmax
+    - argv[4] = txop
+*/
+static int hostapd_cli_cmd_set_wmm_params(struct wpa_ctrl *ctrl,
+                       int argc, char *argv[]) {
+	char buf[200];
+	int res;
+
+	if (argc != 5) {
+		printf("Invalid 'set_wmm_params' command - "
+		       "five arguments (comma delimited queue params) "
+		       "is needed\n");
+		return -1;
+	}
+
+	res = os_snprintf(buf, sizeof(buf), "SET_WMM_PARAMS %s %s %s %s %s",
+						argv[0], argv[1], argv[2], argv[3], argv[4]);
+
+	if (os_snprintf_error(sizeof(buf), res))
+		return -1;
+
+    return wpa_ctrl_command(ctrl, buf);  // processed by hostapd_ctrl_iface_set_wmm_params()
+}
+
 static int hostapd_cli_cmd_set_qos_map_set(struct wpa_ctrl *ctrl,
 					   int argc, char *argv[])
 {
@@ -1683,6 +1756,21 @@  static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
 	  "<addr> [req_mode=] <measurement request hexdump>  = send a Beacon report request to a station" },
 	{ "reload_wpa_psk", hostapd_cli_cmd_reload_wpa_psk, NULL,
 	  "= reload wpa_psk_file only" },
+	//
+	// new things added by gmj93 and h3dema
+	//
+    { "get_queue_params", hostapd_cli_cmd_get_queue_params, NULL,
+      "= get the tx queue params (all queues)" },
+    { "set_queue_params", hostapd_cli_cmd_set_queue_params, NULL,
+      "= set the tx queue params (one queue)" },
+    { "get_wmm_params", hostapd_cli_cmd_get_wmm_params, NULL,
+	  "= get wmm queue params (all queues)"},
+	{ "set_wmm_params", hostapd_cli_cmd_set_wmm_params, NULL,
+      "= set wmm queue params (one queue)" },
+    // interesting things to add (become more indenpendent of IW)
+    // set RTS --> using ap_drv_ops.hostapd_set_rts()
+    // set Frag --> using ap_drv_ops.hostapd_set_frag()
+    // set tx power
 	{ NULL, NULL, NULL, NULL }
 };