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. |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 4 | * All Rights Reserved. |
| 5 | * Licensed under the Clear BSD license. See README for more details. |
| 6 | */ |
| 7 | |
| 8 | #include "sigma_dut.h" |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 9 | #include "miracast.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 10 | |
| 11 | |
| 12 | static int cmd_dev_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 13 | struct sigma_cmd *cmd) |
| 14 | { |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 15 | #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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 23 | 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 | |
| 48 | static 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 Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 63 | static int cmd_dev_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 64 | struct sigma_cmd *cmd) |
| 65 | { |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 66 | const char *program = get_param(cmd, "Program"); |
| 67 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 68 | #ifdef MIRACAST |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 69 | if (program && (strcasecmp(program, "WFD") == 0 || |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 70 | strcasecmp(program, "DisplayR2") == 0)) { |
| 71 | if (get_param(cmd, "interface") == NULL) |
| 72 | return -1; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 73 | return miracast_dev_exec_action(dut, conn, cmd); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 74 | } |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 75 | #endif /* MIRACAST */ |
| 76 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 77 | if (program && strcasecmp(program, "DPP") == 0) |
| 78 | return dpp_dev_exec_action(dut, conn, cmd); |
| 79 | |
| 80 | return -2; |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 84 | static 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 | |
| 106 | static int req_intf(struct sigma_cmd *cmd) |
| 107 | { |
| 108 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 109 | } |
| 110 | |
| 111 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 112 | static 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 122 | static 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 130 | void 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 135 | sigma_dut_reg_cmd("dev_exec_action", req_prog, |
Amarnath Hullur Subramanyam | 9c381f5 | 2017-03-17 00:04:41 -0700 | [diff] [blame] | 136 | cmd_dev_exec_action); |
Jouni Malinen | 3c367e8 | 2017-06-23 17:01:47 +0300 | [diff] [blame] | 137 | sigma_dut_reg_cmd("dev_configure_ie", req_intf, cmd_dev_configure_ie); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 138 | } |