Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (station/AP/sniffer) |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, 2017, Qualcomm Atheros, Inc. |
Peng Xu | a7ac56e | 2018-06-26 16:07:19 -0700 | [diff] [blame] | 4 | * Copyright (c) 2018, The Linux Foundation |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5 | * All Rights Reserved. |
| 6 | * Licensed under the Clear BSD license. See README for more details. |
| 7 | */ |
| 8 | |
| 9 | #include "sigma_dut.h" |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 10 | #include "miracast.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 11 | |
| 12 | |
| 13 | static int cmd_dev_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 14 | struct sigma_cmd *cmd) |
| 15 | { |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 16 | #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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 24 | 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 | |
| 49 | static 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 Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 64 | static int cmd_dev_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 65 | struct sigma_cmd *cmd) |
| 66 | { |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 67 | const char *program = get_param(cmd, "Program"); |
| 68 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 69 | #ifdef MIRACAST |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 70 | if (program && (strcasecmp(program, "WFD") == 0 || |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 71 | strcasecmp(program, "DisplayR2") == 0)) { |
| 72 | if (get_param(cmd, "interface") == NULL) |
| 73 | return -1; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 74 | return miracast_dev_exec_action(dut, conn, cmd); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 75 | } |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 76 | #endif /* MIRACAST */ |
| 77 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 78 | if (program && strcasecmp(program, "DPP") == 0) |
| 79 | return dpp_dev_exec_action(dut, conn, cmd); |
| 80 | |
| 81 | return -2; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 85 | static 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 Xu | a7ac56e | 2018-06-26 16:07:19 -0700 | [diff] [blame] | 107 | static 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 | |
| 114 | static 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 | |
| 121 | static 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 Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 128 | static int req_intf(struct sigma_cmd *cmd) |
| 129 | { |
| 130 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 131 | } |
| 132 | |
| 133 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 134 | static 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 144 | static 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 152 | void 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 157 | sigma_dut_reg_cmd("dev_exec_action", req_prog, |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 158 | cmd_dev_exec_action); |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 159 | sigma_dut_reg_cmd("dev_configure_ie", req_intf, cmd_dev_configure_ie); |
Peng Xu | a7ac56e | 2018-06-26 16:07:19 -0700 | [diff] [blame] | 160 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 163 | } |