blob: 5fe57db144c166023ccfb9cb2b218a8fc9f6bc52 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP/sniffer)
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003 * Copyright (c) 2011-2013, 2017, Qualcomm Atheros, Inc.
Peng Xua7ac56e2018-06-26 16:07:19 -07004 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070010#include "miracast.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011
12
13static int cmd_dev_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
14 struct sigma_cmd *cmd)
15{
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070016#ifdef MIRACAST
17 const char *program = get_param(cmd, "Program");
18
19 if (program && (strcasecmp(program, "WFD") == 0 ||
20 strcasecmp(program, "DisplayR2") == 0))
21 return miracast_dev_send_frame(dut, conn, cmd);
22#endif /* MIRACAST */
23
Jouni Malinencd4e3c32015-10-29 12:39:56 +020024 if (dut->mode == SIGMA_MODE_STATION ||
25 dut->mode == SIGMA_MODE_UNKNOWN) {
26 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert "
27 "dev_send_frame to sta_send_frame");
28 return cmd_sta_send_frame(dut, conn, cmd);
29 }
30
31 if (dut->mode == SIGMA_MODE_AP) {
32 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert "
33 "dev_send_frame to ap_send_frame");
34 return cmd_ap_send_frame(dut, conn, cmd);
35 }
36
37#ifdef CONFIG_WLANTEST
38 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert dev_send_frame to "
39 "wlantest_send_frame");
40 return cmd_wlantest_send_frame(dut, conn, cmd);
41#else /* CONFIG_WLANTEST */
42 send_resp(dut, conn, SIGMA_ERROR,
43 "errorCode,Unsupported dev_send_frame");
44 return 0;
45#endif /* CONFIG_WLANTEST */
46}
47
48
49static int cmd_dev_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
50 struct sigma_cmd *cmd)
51{
52 const char *device = get_param(cmd, "Device");
53
54 if (device && strcasecmp(device, "STA") == 0) {
55 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert "
56 "dev_set_parameter to sta_set_parameter");
57 return cmd_sta_set_parameter(dut, conn, cmd);
58 }
59
60 return -1;
61}
62
63
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070064static int cmd_dev_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
65 struct sigma_cmd *cmd)
66{
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070067 const char *program = get_param(cmd, "Program");
68
Jouni Malinend86e5822017-08-29 03:55:32 +030069#ifdef MIRACAST
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070070 if (program && (strcasecmp(program, "WFD") == 0 ||
Jouni Malinend86e5822017-08-29 03:55:32 +030071 strcasecmp(program, "DisplayR2") == 0)) {
72 if (get_param(cmd, "interface") == NULL)
73 return -1;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070074 return miracast_dev_exec_action(dut, conn, cmd);
Jouni Malinend86e5822017-08-29 03:55:32 +030075 }
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070076#endif /* MIRACAST */
77
Jouni Malinend86e5822017-08-29 03:55:32 +030078 if (program && strcasecmp(program, "DPP") == 0)
79 return dpp_dev_exec_action(dut, conn, cmd);
80
81 return -2;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070082}
83
84
Jouni Malinen3c367e82017-06-23 17:01:47 +030085static int cmd_dev_configure_ie(struct sigma_dut *dut, struct sigma_conn *conn,
86 struct sigma_cmd *cmd)
87{
88 const char *ie_name = get_param(cmd, "IE_Name");
89 const char *contents = get_param(cmd, "Contents");
90
91 if (!ie_name || !contents)
92 return -1;
93
94 if (strcasecmp(ie_name, "RSNE") != 0) {
95 send_resp(dut, conn, SIGMA_ERROR,
96 "errorCode,Unsupported IE_Name value");
97 return 0;
98 }
99
100 free(dut->rsne_override);
101 dut->rsne_override = strdup(contents);
102
103 return dut->rsne_override ? 1 : -1;
104}
105
106
Peng Xua7ac56e2018-06-26 16:07:19 -0700107static int cmd_dev_start_test(struct sigma_dut *dut, struct sigma_conn *conn,
108 struct sigma_cmd *cmd)
109{
110 return 1;
111}
112
113
114static int cmd_dev_stop_test(struct sigma_dut *dut, struct sigma_conn *conn,
115 struct sigma_cmd *cmd)
116{
117 return 1;
118}
119
120
121static int cmd_dev_get_log(struct sigma_dut *dut, struct sigma_conn *conn,
122 struct sigma_cmd *cmd)
123{
124 return 1;
125}
126
127
Jouni Malinen3c367e82017-06-23 17:01:47 +0300128static int req_intf(struct sigma_cmd *cmd)
129{
130 return get_param(cmd, "interface") == NULL ? -1 : 0;
131}
132
133
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200134static int req_intf_prog(struct sigma_cmd *cmd)
135{
136 if (get_param(cmd, "interface") == NULL)
137 return -1;
138 if (get_param(cmd, "program") == NULL)
139 return -1;
140 return 0;
141}
142
143
Jouni Malinend86e5822017-08-29 03:55:32 +0300144static int req_prog(struct sigma_cmd *cmd)
145{
146 if (get_param(cmd, "program") == NULL)
147 return -1;
148 return 0;
149}
150
151
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200152void dev_register_cmds(void)
153{
154 sigma_dut_reg_cmd("dev_send_frame", req_intf_prog, cmd_dev_send_frame);
155 sigma_dut_reg_cmd("dev_set_parameter", req_intf_prog,
156 cmd_dev_set_parameter);
Jouni Malinend86e5822017-08-29 03:55:32 +0300157 sigma_dut_reg_cmd("dev_exec_action", req_prog,
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -0700158 cmd_dev_exec_action);
Jouni Malinen3c367e82017-06-23 17:01:47 +0300159 sigma_dut_reg_cmd("dev_configure_ie", req_intf, cmd_dev_configure_ie);
Peng Xua7ac56e2018-06-26 16:07:19 -0700160 sigma_dut_reg_cmd("dev_start_test", NULL, cmd_dev_start_test);
161 sigma_dut_reg_cmd("dev_stop_test", NULL, cmd_dev_stop_test);
162 sigma_dut_reg_cmd("dev_get_log", NULL, cmd_dev_get_log);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200163}