blob: 4b6f8333e5fabd3d3f9c0f6e23d31f09bf6f25ef [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.
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004 * All Rights Reserved.
5 * Licensed under the Clear BSD license. See README for more details.
6 */
7
8#include "sigma_dut.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07009#include "miracast.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010
11
12static int cmd_dev_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
13 struct sigma_cmd *cmd)
14{
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070015#ifdef MIRACAST
16 const char *program = get_param(cmd, "Program");
17
18 if (program && (strcasecmp(program, "WFD") == 0 ||
19 strcasecmp(program, "DisplayR2") == 0))
20 return miracast_dev_send_frame(dut, conn, cmd);
21#endif /* MIRACAST */
22
Jouni Malinencd4e3c32015-10-29 12:39:56 +020023 if (dut->mode == SIGMA_MODE_STATION ||
24 dut->mode == SIGMA_MODE_UNKNOWN) {
25 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert "
26 "dev_send_frame to sta_send_frame");
27 return cmd_sta_send_frame(dut, conn, cmd);
28 }
29
30 if (dut->mode == SIGMA_MODE_AP) {
31 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert "
32 "dev_send_frame to ap_send_frame");
33 return cmd_ap_send_frame(dut, conn, cmd);
34 }
35
36#ifdef CONFIG_WLANTEST
37 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert dev_send_frame to "
38 "wlantest_send_frame");
39 return cmd_wlantest_send_frame(dut, conn, cmd);
40#else /* CONFIG_WLANTEST */
41 send_resp(dut, conn, SIGMA_ERROR,
42 "errorCode,Unsupported dev_send_frame");
43 return 0;
44#endif /* CONFIG_WLANTEST */
45}
46
47
48static int cmd_dev_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
49 struct sigma_cmd *cmd)
50{
51 const char *device = get_param(cmd, "Device");
52
53 if (device && strcasecmp(device, "STA") == 0) {
54 sigma_dut_print(dut, DUT_MSG_DEBUG, "Convert "
55 "dev_set_parameter to sta_set_parameter");
56 return cmd_sta_set_parameter(dut, conn, cmd);
57 }
58
59 return -1;
60}
61
62
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070063static int cmd_dev_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
64 struct sigma_cmd *cmd)
65{
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070066 const char *program = get_param(cmd, "Program");
67
Jouni Malinend86e5822017-08-29 03:55:32 +030068#ifdef MIRACAST
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070069 if (program && (strcasecmp(program, "WFD") == 0 ||
Jouni Malinend86e5822017-08-29 03:55:32 +030070 strcasecmp(program, "DisplayR2") == 0)) {
71 if (get_param(cmd, "interface") == NULL)
72 return -1;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070073 return miracast_dev_exec_action(dut, conn, cmd);
Jouni Malinend86e5822017-08-29 03:55:32 +030074 }
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070075#endif /* MIRACAST */
76
Jouni Malinend86e5822017-08-29 03:55:32 +030077 if (program && strcasecmp(program, "DPP") == 0)
78 return dpp_dev_exec_action(dut, conn, cmd);
79
80 return -2;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070081}
82
83
Jouni Malinen3c367e82017-06-23 17:01:47 +030084static int cmd_dev_configure_ie(struct sigma_dut *dut, struct sigma_conn *conn,
85 struct sigma_cmd *cmd)
86{
87 const char *ie_name = get_param(cmd, "IE_Name");
88 const char *contents = get_param(cmd, "Contents");
89
90 if (!ie_name || !contents)
91 return -1;
92
93 if (strcasecmp(ie_name, "RSNE") != 0) {
94 send_resp(dut, conn, SIGMA_ERROR,
95 "errorCode,Unsupported IE_Name value");
96 return 0;
97 }
98
99 free(dut->rsne_override);
100 dut->rsne_override = strdup(contents);
101
102 return dut->rsne_override ? 1 : -1;
103}
104
105
106static int req_intf(struct sigma_cmd *cmd)
107{
108 return get_param(cmd, "interface") == NULL ? -1 : 0;
109}
110
111
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200112static int req_intf_prog(struct sigma_cmd *cmd)
113{
114 if (get_param(cmd, "interface") == NULL)
115 return -1;
116 if (get_param(cmd, "program") == NULL)
117 return -1;
118 return 0;
119}
120
121
Jouni Malinend86e5822017-08-29 03:55:32 +0300122static int req_prog(struct sigma_cmd *cmd)
123{
124 if (get_param(cmd, "program") == NULL)
125 return -1;
126 return 0;
127}
128
129
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200130void dev_register_cmds(void)
131{
132 sigma_dut_reg_cmd("dev_send_frame", req_intf_prog, cmd_dev_send_frame);
133 sigma_dut_reg_cmd("dev_set_parameter", req_intf_prog,
134 cmd_dev_set_parameter);
Jouni Malinend86e5822017-08-29 03:55:32 +0300135 sigma_dut_reg_cmd("dev_exec_action", req_prog,
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -0700136 cmd_dev_exec_action);
Jouni Malinen3c367e82017-06-23 17:01:47 +0300137 sigma_dut_reg_cmd("dev_configure_ie", req_intf, cmd_dev_configure_ie);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200138}