Skip to content

Commit

Permalink
[noup] add hostapd_cli shell support
Browse files Browse the repository at this point in the history
Add hostapd_cli shell command.
Porting from zephyr wpa_cli impl.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
  • Loading branch information
fengming-ye authored and jukkar committed Sep 12, 2024
1 parent 0cf6d4f commit 18572ff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
37 changes: 31 additions & 6 deletions hostapd/hostapd_cli_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,44 @@

static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */

#define CMD_BUF_LEN 1024

static int hostapd_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd,
int min_args, int argc, char *argv[])
{
char buf[1024];
char buf[CMD_BUF_LEN] = {0};
int ret = 0;
bool interactive = 0;

for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "interactive") == 0) {
interactive = 1;
argv[i] = NULL;
argc--;
break;
}
}

if (argc < min_args) {
printf("Invalid %s command - at least %d argument%s required.\n",
cmd, min_args, min_args > 1 ? "s are" : " is");
wpa_printf(MSG_INFO, "Invalid %s command - at least %d argument%s "
"required.\n", cmd, min_args,
min_args > 1 ? "s are" : " is");
return -1;
}
if (write_cmd(buf, sizeof(buf), cmd, argc, argv) < 0)
return -1;
return hostapd_ctrl_command(ctrl, buf);

if (write_cmd(buf, CMD_BUF_LEN, cmd, argc, argv) < 0){
ret = -1;
goto out;
}

if (interactive)
ret = hostapd_ctrl_command_interactive(ctrl, buf);
else
ret = hostapd_ctrl_command(ctrl, buf);

out:
return ret;

}


Expand Down
6 changes: 5 additions & 1 deletion hostapd/hostapd_cli_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "includes.h"

#include "common/cli.h"
#include "common/wpa_ctrl.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "utils/edit.h"
Expand Down Expand Up @@ -213,6 +212,11 @@ int hostapd_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd)
return _wpa_ctrl_command(ctrl, cmd, 0, NULL);
}

int hostapd_ctrl_command_interactive(struct wpa_ctrl *ctrl, const char *cmd)
{
return _wpa_ctrl_command(ctrl, cmd, 1, NULL);
}

int zephyr_hostapd_cli_cmd_resp(const char *cmd, char *resp)
{
return _wpa_ctrl_command(hapd_ctrl_conn, cmd, 1, resp);
Expand Down
4 changes: 4 additions & 0 deletions hostapd/hostapd_cli_zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

#include <zephyr/kernel.h>

#include "common/wpa_ctrl.h"

void hostapd_cli_msg_cb(char *msg, size_t len);
int hostapd_request(struct wpa_ctrl *ctrl, int argc, char *argv[]);
int hostapd_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd);
int hostapd_ctrl_command_interactive(struct wpa_ctrl *ctrl, const char *cmd);
int zephyr_hostapd_cli_cmd_resp(const char *cmd, char *resp);
int zephyr_hostapd_cli_cmd_v(const char *fmt, ...);
int zephyr_hostapd_ctrl_init(void *ctx);
int zephyr_hostapd_ctrl_zephyr_cmd(int argc, const char *argv[]);
#endif /* __HOSTAPD_CLI_ZEPHYR_H_ */

0 comments on commit 18572ff

Please sign in to comment.