Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
Alan Tsai | dfafa3a | 2016-09-23 16:53:35 -0700 | [diff] [blame] | 2 | Copyright (c) 2016 Wi-Fi Alliance. All Rights Reserved |
Dake Zhao | 9770820 | 2014-11-26 13:59:04 -0800 | [diff] [blame] | 3 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 4 | Permission to use, copy, modify, and/or distribute this software for any purpose with or |
| 5 | without fee is hereby granted, provided that the above copyright notice and this permission |
Dake Zhao | 9770820 | 2014-11-26 13:59:04 -0800 | [diff] [blame] | 6 | notice appear in all copies. |
| 7 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING |
| 12 | FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
| 13 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
Dake Zhao | 9770820 | 2014-11-26 13:59:04 -0800 | [diff] [blame] | 14 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | |
| 16 | ******************************************************************************/ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 17 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 18 | /* |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 19 | * File: wfa_cs.c -- configuration and setup |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 20 | * This file contains all implementation for the dut setup and control |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 21 | * functions, such as network interfaces, ip address and wireless specific |
| 22 | * setup with its supplicant. |
| 23 | * |
| 24 | * The current implementation is to show how these functions |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 25 | * should be defined in order to support the Agent Control/Test Manager |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 26 | * control commands. To simplify the current work and avoid any GPL licenses, |
| 27 | * the functions mostly invoke shell commands by calling linux system call, |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 28 | * system("<commands>"). |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 29 | * |
| 30 | * It depends on the differnt device and platform, vendors can choice their |
| 31 | * own ways to interact its systems, supplicants and process these commands |
| 32 | * such as using the native APIs. |
| 33 | * |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 34 | * |
| 35 | */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
| 37 | #include <unistd.h> |
| 38 | #include <string.h> |
| 39 | #include <stdlib.h> |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 40 | #include <stdbool.h> |
| 41 | #include <stdarg.h> |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 42 | #include <sys/socket.h> |
| 43 | #include <arpa/inet.h> |
| 44 | #include <linux/types.h> |
| 45 | #include <linux/socket.h> |
| 46 | #include <poll.h> |
| 47 | |
| 48 | #include "wfa_portall.h" |
| 49 | #include "wfa_debug.h" |
| 50 | #include "wfa_ver.h" |
| 51 | #include "wfa_main.h" |
| 52 | #include "wfa_types.h" |
| 53 | #include "wfa_ca.h" |
| 54 | #include "wfa_tlv.h" |
| 55 | #include "wfa_sock.h" |
| 56 | #include "wfa_tg.h" |
| 57 | #include "wfa_cmds.h" |
| 58 | #include "wfa_rsp.h" |
| 59 | #include "wfa_utils.h" |
| 60 | #ifdef WFA_WMM_PS_EXT |
| 61 | #include "wfa_wmmps.h" |
| 62 | #endif |
| 63 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 64 | #define CERTIFICATES_PATH "/etc/wpa_supplicant" |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 65 | |
| 66 | /* Some device may only support UDP ECHO, activate this line */ |
| 67 | //#define WFA_PING_UDP_ECHO_ONLY 1 |
| 68 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 69 | #define WFA_ENABLED 1 |
| 70 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 71 | extern unsigned short wfa_defined_debug; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 72 | int wfaExecuteCLI(char* CLI); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 73 | |
| 74 | /* Since the two definitions are used all over the CA function */ |
| 75 | char gCmdStr[WFA_CMD_STR_SZ]; |
| 76 | dutCmdResponse_t gGenericResp; |
| 77 | int wfaTGSetPrio(int sockfd, int tgClass); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 78 | void create_apts_msg(int msg, unsigned int txbuf[], int id); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 79 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 80 | int sret = 0; |
| 81 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 82 | extern char e2eResults[]; |
Dake Zhao | 862c94b | 2014-12-08 14:35:35 -0800 | [diff] [blame] | 83 | |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 84 | #define RETURN_STA_CMD_ERROR(resp, statusCode, ...) \ |
| 85 | resp->status = statusCode; \ |
| 86 | wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, sizeof(resp->status), (BYTE*)resp, \ |
| 87 | respBuf); \ |
| 88 | *respLen = WFA_TLV_HDR_LEN + sizeof(resp->status); \ |
| 89 | DPRINT_ERR(WFA_ERR, __VA_ARGS__); \ |
| 90 | return WFA_FAILURE; |
| 91 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 92 | FILE* e2efp = NULL; |
| 93 | int chk_ret_status() { |
| 94 | char* ret = getenv(WFA_RET_ENV); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 95 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 96 | if (*ret == '1') |
| 97 | return WFA_SUCCESS; |
| 98 | else |
| 99 | return WFA_FAILURE; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Wojciech Jakobczyk | 249c1a0 | 2020-08-27 12:38:28 +0200 | [diff] [blame] | 102 | static int systemWithLog(char* command) { |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 103 | DPRINT_INFO(WFA_OUT, "exec: %s\n", command); |
| 104 | int ret = system(command); |
| 105 | if (ret != 0) { |
| 106 | DPRINT_INFO(WFA_OUT, "exit code %d\n", ret); |
| 107 | } |
| 108 | return ret; |
Wojciech Jakobczyk | 249c1a0 | 2020-08-27 12:38:28 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 111 | // Read a line from a file. |
| 112 | // It reads at most bufSize-1 bytes to buf. |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 113 | bool readLine(const char* filename, char* buf, const int bufSize) { |
| 114 | FILE* fp = NULL; |
| 115 | fp = fopen(filename, "r+"); |
| 116 | if (fp == NULL) { |
| 117 | return false; |
| 118 | } |
| 119 | char* ret = fgets(buf, bufSize, fp); |
| 120 | fclose(fp); |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 121 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 122 | if (ret == NULL) { |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | if (buf[strlen(buf) - 1] == '\n') { |
| 127 | buf[strlen(buf) - 1] = 0; |
| 128 | } |
| 129 | return true; |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 130 | } |
Wojciech Jakobczyk | 249c1a0 | 2020-08-27 12:38:28 +0200 | [diff] [blame] | 131 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 132 | /* |
| 133 | * agtCmdProcGetVersion(): response "ca_get_version" command to controller |
| 134 | * input: cmd --- not used |
| 135 | * valLen -- not used |
| 136 | * output: parms -- a buffer to store the version info response. |
| 137 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 138 | int agtCmdProcGetVersion(int len, BYTE* parms, int* respLen, BYTE* respBuf) { |
| 139 | dutCmdResponse_t* getverResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 140 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 141 | DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 142 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 143 | getverResp->status = STATUS_COMPLETE; |
| 144 | wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 145 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 146 | wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), |
| 147 | (BYTE*)getverResp, respBuf); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 148 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 149 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 150 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 151 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 155 | * getNetworkId(): |
| 156 | * This function gets the first network ID of interface ifname. If ssid is |
| 157 | * specified, restricts to search networks with the SSID. Empty ssid is |
| 158 | * treated as unspecified. If no network entry is found, returns -1. |
| 159 | */ |
| 160 | int getNetworkId(char* ifname, char* ssid) { |
| 161 | int cmdLen; |
| 162 | cmdLen = snprintf(gCmdStr, WFA_CMD_STR_SZ, |
| 163 | "wpa_cli.sh -i %s list_networks | tail -n +2", ifname); |
| 164 | if (ssid && *ssid != 0) { |
| 165 | // grep SSID with space boundary to avoid partial match. |
| 166 | cmdLen += snprintf(gCmdStr + cmdLen, WFA_CMD_STR_SZ - cmdLen, |
| 167 | " | grep \"\\s%s\\s\"", ssid); |
| 168 | } |
| 169 | |
| 170 | const char* tmpfile = "/tmp/.wfaListNetworkTmp"; |
| 171 | char cmdResult[32]; |
| 172 | snprintf(gCmdStr + cmdLen, WFA_CMD_STR_SZ - cmdLen, " | cut -f1 > %s", |
| 173 | tmpfile); |
| 174 | sret = systemWithLog(gCmdStr); |
| 175 | if (sret != 0 || !readLine(tmpfile, cmdResult, sizeof(cmdResult))) { |
| 176 | return -1; |
| 177 | } |
| 178 | return atoi(cmdResult); |
| 179 | } |
| 180 | |
| 181 | /* |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 182 | * wfaStaAssociate(): |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 183 | * The function is to force the station wireless I/F to re/associate |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 184 | * with the AP. |
| 185 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 186 | int wfaStaAssociate(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 187 | dutCommand_t* assoc = (dutCommand_t*)caCmdBuf; |
| 188 | char* ifname = assoc->intf; |
| 189 | dutCmdResponse_t* staAssocResp = &gGenericResp; |
| 190 | char cmdResult[32]; |
| 191 | const char* tmpfile = "/tmp/.wfaStaAssociateTmp"; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 192 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 193 | DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n"); |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 194 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 195 | // verify parameters |
| 196 | if (assoc->cmdsu.assoc.bssid[0] != '\0' || assoc->cmdsu.assoc.wps != 0) { |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 197 | RETURN_STA_CMD_ERROR(staAssocResp, STATUS_INVALID, |
| 198 | "unsupported command parameter\n"); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 199 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 200 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 201 | if (assoc->cmdsu.assoc.ssid[0] != '\0') { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 202 | int networkid = getNetworkId(ifname, assoc->cmdsu.assoc.ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 203 | if (networkid == -1) { |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 204 | RETURN_STA_CMD_ERROR(staAssocResp, STATUS_ERROR, |
| 205 | "network not configured\n"); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 206 | } else { |
| 207 | // enable the network and disable all others |
| 208 | sprintf(gCmdStr, "wpa_cli.sh -i %s select_network %d > %s", ifname, |
| 209 | networkid, tmpfile); |
| 210 | sret = systemWithLog(gCmdStr); |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 211 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 212 | } else { |
| 213 | // reassociate to current connected network |
| 214 | sprintf(gCmdStr, "wpa_cli.sh -i%s reassociate > %s", ifname, tmpfile); |
| 215 | sret = systemWithLog(gCmdStr); |
| 216 | } |
Wojciech Jakobczyk | 1084b01 | 2020-08-27 14:59:58 +0200 | [diff] [blame] | 217 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 218 | // check wpa_cli response |
| 219 | if (!readLine(tmpfile, cmdResult, sizeof(cmdResult))) { |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 220 | RETURN_STA_CMD_ERROR(staAssocResp, STATUS_ERROR, |
| 221 | "unable to read command output\n"); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 222 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 223 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 224 | if (strcmp(cmdResult, "OK") != 0) { |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 225 | RETURN_STA_CMD_ERROR(staAssocResp, STATUS_ERROR, |
| 226 | "associate network failed, error: %s\n", cmdResult); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | staAssocResp->status = STATUS_COMPLETE; |
| 230 | wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE*)staAssocResp, respBuf); |
| 231 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 232 | |
| 233 | return WFA_SUCCESS; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * wfaStaReAssociate(): |
| 238 | * The function is to force the station wireless I/F to re/associate |
| 239 | * with the AP. |
| 240 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 241 | int wfaStaReAssociate(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 242 | dutCommand_t* assoc = (dutCommand_t*)caCmdBuf; |
| 243 | char* ifname = assoc->intf; |
| 244 | dutCmdResponse_t* staAssocResp = &gGenericResp; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 245 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 246 | DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n"); |
| 247 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 248 | * if bssid appears, station should associate with the specific |
| 249 | * BSSID AP at its initial association. |
| 250 | * If it is different to the current associating AP, it will be forced to |
| 251 | * roam the new AP |
| 252 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 253 | if (assoc->cmdsu.assoc.bssid[0] != '\0') { |
| 254 | /* if (the first association) */ |
| 255 | /* just do initial association to the BSSID */ |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 256 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 257 | /* else (station already associate to an AP) */ |
| 258 | /* Do forced roaming */ |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 259 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 260 | } else { |
| 261 | /* use 'ifconfig' command to bring down the interface (linux specific) */ |
| 262 | sprintf(gCmdStr, "ifconfig %s down", ifname); |
| 263 | sret = systemWithLog(gCmdStr); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 264 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 265 | /* use 'ifconfig' command to bring up the interface (linux specific) */ |
| 266 | sprintf(gCmdStr, "ifconfig %s up", ifname); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 267 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 268 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 269 | * use 'wpa_cli' command to force a 802.11 re/associate |
| 270 | * (wpa_supplicant specific) |
| 271 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 272 | sprintf(gCmdStr, "wpa_cli.sh -i%s reassociate", ifname); |
| 273 | sret = systemWithLog(gCmdStr); |
| 274 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 275 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 276 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 277 | * Then report back to control PC for completion. |
| 278 | * This does not have failed/error status. The result only tells |
| 279 | * a completion. |
| 280 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 281 | staAssocResp->status = STATUS_COMPLETE; |
| 282 | wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE*)staAssocResp, respBuf); |
| 283 | *respLen = WFA_TLV_HDR_LEN + 4; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 284 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 285 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* |
| 289 | * wfaStaIsConnected(): |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 290 | * The function is to check whether the station's wireless I/F has |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 291 | * already connected to an AP. |
| 292 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 293 | int wfaStaIsConnected(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 294 | dutCommand_t* connStat = (dutCommand_t*)caCmdBuf; |
| 295 | dutCmdResponse_t* staConnectResp = &gGenericResp; |
| 296 | char* ifname = connStat->intf; |
| 297 | FILE* tmpfile = NULL; |
| 298 | char result[32]; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 299 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 300 | DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 301 | |
| 302 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 303 | sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname); |
| 304 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 305 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 306 | if (chk_ret_status() == WFA_SUCCESS) |
| 307 | staConnectResp->cmdru.connected = 1; |
| 308 | else |
| 309 | staConnectResp->cmdru.connected = 0; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 310 | #else |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 311 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 312 | * use 'wpa_cli' command to check the interface status |
| 313 | * none, scanning or complete (wpa_supplicant specific) |
| 314 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 315 | sprintf(gCmdStr, |
| 316 | "wpa_cli.sh -i%s status | grep ^wpa_state= | cut -f2- -d= > " |
| 317 | "/tmp/.isConnected", |
| 318 | ifname); |
| 319 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 320 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 321 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 322 | * the status is saved in a file. Open the file and check it. |
| 323 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 324 | tmpfile = fopen("/tmp/.isConnected", "r+"); |
| 325 | if (tmpfile == NULL) { |
| 326 | staConnectResp->status = STATUS_ERROR; |
| 327 | wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE*)staConnectResp, |
| 328 | respBuf); |
| 329 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 330 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 331 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 332 | return WFA_FAILURE; |
| 333 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 334 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 335 | sret = fscanf(tmpfile, "%s", (char*)result); |
| 336 | fclose(tmpfile); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 337 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 338 | if (strncmp(result, "COMPLETED", 9) == 0) |
| 339 | staConnectResp->cmdru.connected = 1; |
| 340 | else |
| 341 | staConnectResp->cmdru.connected = 0; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 342 | #endif |
| 343 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 344 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 345 | * Report back the status: Complete or Failed. |
| 346 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 347 | staConnectResp->status = STATUS_COMPLETE; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 348 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 349 | wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), |
| 350 | (BYTE*)staConnectResp, respBuf); |
| 351 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 352 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 353 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* |
| 357 | * wfaStaGetIpConfig(): |
| 358 | * This function is to retriev the ip info including |
| 359 | * 1. dhcp enable |
| 360 | * 2. ip address |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 361 | * 3. mask |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 362 | * 4. primary-dns |
| 363 | * 5. secondary-dns |
| 364 | * |
| 365 | * The current implementation is to use a script to find these information |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 366 | * and store them in a file. |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 367 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 368 | int wfaStaGetIpConfig(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 369 | int slen, i = 0; |
| 370 | dutCommand_t* getIpConf = (dutCommand_t*)caCmdBuf; |
| 371 | dutCmdResponse_t* ipconfigResp = &gGenericResp; |
| 372 | char* ifname = getIpConf->intf; |
| 373 | caStaGetIpConfigResp_t* ifinfo = &ipconfigResp->cmdru.getIfconfig; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 374 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 375 | FILE* tmpfd; |
| 376 | char string[256]; |
| 377 | char* str; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 378 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 379 | strcpy(ifinfo->dns[0], "0"); |
| 380 | strcpy(ifinfo->dns[1], "0"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 381 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 382 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 383 | * Run the script file "getipconfig.sh" to check the ip status |
| 384 | * (current implementation specific). |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 385 | * note: "getipconfig.sh" is only defined for the current implementation |
Wojciech Jakobczyk | 7154253 | 2020-08-28 10:52:00 +0200 | [diff] [blame] | 386 | * |
| 387 | * Example output: |
| 388 | * dhcpcli=/sbin/dhcpcd |
| 389 | * |
| 390 | * mac=50:e0:85:5f:e9:93 |
| 391 | * ipaddr=192.168.0.116 |
| 392 | * bcast=192.168.0.255 |
| 393 | * mask=255.255.255.0 |
| 394 | * nameserver 192.168.0.1 |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 395 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 396 | sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 397 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 398 | sret = systemWithLog(gCmdStr); |
| 399 | if (sret != 0) { |
| 400 | ipconfigResp->status = STATUS_ERROR; |
| 401 | wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE*)ipconfigResp, |
| 402 | respBuf); |
| 403 | *respLen = WFA_TLV_HDR_LEN + 4; |
Wojciech Jakobczyk | 7154253 | 2020-08-28 10:52:00 +0200 | [diff] [blame] | 404 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 405 | DPRINT_ERR(WFA_ERR, "error from getipconfig exec: %d\n", sret); |
| 406 | return WFA_FAILURE; |
| 407 | } |
| 408 | |
| 409 | /* open the output result and scan/retrieve the info */ |
| 410 | tmpfd = fopen("/tmp/ipconfig.txt", "r+"); |
| 411 | |
| 412 | if (tmpfd == NULL) { |
| 413 | ipconfigResp->status = STATUS_ERROR; |
| 414 | wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE*)ipconfigResp, |
| 415 | respBuf); |
| 416 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 417 | |
| 418 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 419 | return WFA_FAILURE; |
| 420 | } |
| 421 | |
| 422 | for (;;) { |
| 423 | if (fgets(string, 256, tmpfd) == NULL) |
| 424 | break; |
| 425 | |
| 426 | /* check dhcp enabled */ |
| 427 | if (strncmp(string, "dhcpcli", 7) == 0) { |
| 428 | str = strtok(string, "="); |
| 429 | str = strtok(NULL, "="); |
| 430 | if (str != NULL) |
| 431 | ifinfo->isDhcp = 1; |
| 432 | else |
| 433 | ifinfo->isDhcp = 0; |
Wojciech Jakobczyk | 7154253 | 2020-08-28 10:52:00 +0200 | [diff] [blame] | 434 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 435 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 436 | if (strncmp(string, "ipaddr", 6) == 0) { |
| 437 | str = strchr(string, '='); |
| 438 | if (str != NULL) { |
| 439 | strcpy(ifinfo->ipaddr, str + 1); |
| 440 | slen = strlen(ifinfo->ipaddr); |
| 441 | ifinfo->ipaddr[slen - 1] = '\0'; |
| 442 | } else |
| 443 | strcpy(ifinfo->ipaddr, "none"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 446 | /* check the mask */ |
| 447 | if (strncmp(string, "mask", 4) == 0) { |
| 448 | str = strchr(string, '='); |
| 449 | if (str != NULL) { |
| 450 | strcpy(ifinfo->mask, str + 1); |
| 451 | slen = strlen(ifinfo->mask); |
| 452 | ifinfo->mask[slen - 1] = '\0'; |
| 453 | } else |
| 454 | strcpy(ifinfo->mask, "none"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 455 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 456 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 457 | /* find out the dns server ip address */ |
| 458 | if (strncmp(string, "nameserv", 8) == 0) { |
| 459 | str = strchr(string, ' '); |
| 460 | if (str != NULL && i < 2) { |
| 461 | strcpy(ifinfo->dns[i], str + 1); |
| 462 | slen = strlen(ifinfo->dns[i]); |
| 463 | ifinfo->dns[i][slen - 1] = '\0'; |
| 464 | } else |
| 465 | strcpy(ifinfo->dns[i], "none"); |
| 466 | |
| 467 | i++; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 472 | * Report back the results |
| 473 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 474 | ipconfigResp->status = STATUS_COMPLETE; |
| 475 | wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), |
| 476 | (BYTE*)ipconfigResp, respBuf); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 477 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 478 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 479 | |
| 480 | #if 0 |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 481 | DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status, |
| 482 | ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask, |
| 483 | ifinfo->dns[0], ifinfo->dns[1], *respLen); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 484 | #endif |
| 485 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 486 | fclose(tmpfd); |
| 487 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /* |
| 491 | * wfaStaSetIpConfig(): |
| 492 | * The function is to set the ip configuration to a wireless I/F. |
| 493 | * 1. IP address |
| 494 | * 2. Mac address |
| 495 | * 3. default gateway |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 496 | * 4. dns nameserver (pri and sec). |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 497 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 498 | int wfaStaSetIpConfig(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 499 | dutCommand_t* setIpConf = (dutCommand_t*)caCmdBuf; |
| 500 | caStaSetIpConfig_t* ipconfig = &setIpConf->cmdsu.ipconfig; |
| 501 | dutCmdResponse_t* staSetIpResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 502 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 503 | DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n"); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 504 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 505 | if (ipconfig->isDhcp) { |
| 506 | DPRINT_INFO(WFA_OUT, "error: dhcp not supported\n"); |
| 507 | staSetIpResp->status = STATUS_INVALID; |
| 508 | wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE*)staSetIpResp, |
| 509 | respBuf); |
| 510 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 511 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 512 | return WFA_FAILURE; |
| 513 | } |
| 514 | |
| 515 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 516 | * Use command 'ifconfig' to configure the interface ip address, mask. |
| 517 | * (Linux specific). |
| 518 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 519 | sprintf(gCmdStr, "ifconfig %s %s netmask %s >/tmp/ifconfig.log 2>&1", |
| 520 | ipconfig->intf, ipconfig->ipaddr, ipconfig->mask); |
| 521 | DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr); |
| 522 | sret = systemWithLog(gCmdStr); |
| 523 | if (sret != 0) { |
| 524 | DPRINT_INFO(WFA_OUT, "exit code %d\n", sret); |
| 525 | } |
| 526 | |
| 527 | /* use command 'route add' to set set gatewway (linux specific) */ |
| 528 | if (ipconfig->defGateway[0] != '\0') { |
| 529 | sprintf(gCmdStr, "route add default gw %s >/tmp/route.log 2>&1", |
| 530 | ipconfig->defGateway); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 531 | DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 532 | sret = systemWithLog(gCmdStr); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 533 | if (sret != 0) { |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 534 | DPRINT_INFO(WFA_OUT, "exit code %d\n", sret); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 535 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 536 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 537 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 538 | /* set dns (linux specific) */ |
| 539 | sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk"); |
| 540 | DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr); |
| 541 | sret = systemWithLog(gCmdStr); |
| 542 | if (sret != 0) { |
| 543 | DPRINT_INFO(WFA_OUT, "exit code %d backing up resolv.conf\n", sret); |
| 544 | } |
Shuo-Peng Liao | 4a6d4ca | 2020-09-30 19:16:18 +0800 | [diff] [blame] | 545 | sprintf(gCmdStr, "echo nameserver %s > /etc/resolv.conf", ipconfig->pri_dns); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 546 | DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr); |
| 547 | sret = systemWithLog(gCmdStr); |
| 548 | if (sret != 0) { |
| 549 | DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret); |
| 550 | } |
| 551 | if (strlen(ipconfig->sec_dns) > 0) { |
Shuo-Peng Liao | 4a6d4ca | 2020-09-30 19:16:18 +0800 | [diff] [blame] | 552 | sprintf(gCmdStr, "echo nameserver %s >> /etc/resolv.conf", |
| 553 | ipconfig->sec_dns); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 554 | DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 555 | sret = systemWithLog(gCmdStr); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 556 | if (sret != 0) { |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 557 | DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret); |
Wojciech Jakobczyk | fc3b011 | 2020-08-26 11:30:55 +0200 | [diff] [blame] | 558 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 559 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 560 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 561 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 562 | * report status |
| 563 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 564 | staSetIpResp->status = STATUS_COMPLETE; |
| 565 | wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE*)staSetIpResp, respBuf); |
| 566 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 567 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 568 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* |
| 572 | * wfaStaVerifyIpConnection(): |
| 573 | * The function is to verify if the station has IP connection with an AP by |
| 574 | * send ICMP/pings to the AP. |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 575 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 576 | int wfaStaVerifyIpConnection(int len, |
| 577 | BYTE* caCmdBuf, |
| 578 | int* respLen, |
| 579 | BYTE* respBuf) { |
| 580 | dutCommand_t* verip = (dutCommand_t*)caCmdBuf; |
| 581 | dutCmdResponse_t* verifyIpResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 582 | |
| 583 | #ifndef WFA_PING_UDP_ECHO_ONLY |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 584 | char strout[64], *pcnt; |
| 585 | FILE* tmpfile; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 586 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 587 | DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 588 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 589 | /* set timeout value in case not set */ |
| 590 | if (verip->cmdsu.verifyIp.timeout <= 0) { |
| 591 | verip->cmdsu.verifyIp.timeout = 10; |
| 592 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 593 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 594 | /* execute the ping command and pipe the result to a tmp file */ |
| 595 | sprintf(gCmdStr, |
| 596 | "ping %s -c 3 -W %u | grep loss | cut -f3 -d, 1>& /tmp/pingout.txt", |
| 597 | verip->cmdsu.verifyIp.dipaddr, verip->cmdsu.verifyIp.timeout); |
| 598 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 599 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 600 | /* scan/check the output */ |
| 601 | tmpfile = fopen("/tmp/pingout.txt", "r+"); |
| 602 | if (tmpfile == NULL) { |
| 603 | verifyIpResp->status = STATUS_ERROR; |
| 604 | wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE*)verifyIpResp, |
| 605 | respBuf); |
| 606 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 607 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 608 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 609 | return WFA_FAILURE; |
| 610 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 611 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 612 | verifyIpResp->status = STATUS_COMPLETE; |
| 613 | if (fscanf(tmpfile, "%s", strout) == EOF) |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 614 | verifyIpResp->cmdru.connected = 0; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 615 | else { |
| 616 | pcnt = strtok(strout, "%"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 617 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 618 | /* if the loss rate is 100%, not able to connect */ |
| 619 | if (atoi(pcnt) == 100) |
| 620 | verifyIpResp->cmdru.connected = 0; |
| 621 | else |
| 622 | verifyIpResp->cmdru.connected = 1; |
| 623 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 624 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 625 | fclose(tmpfile); |
| 626 | #else |
| 627 | int btSockfd; |
| 628 | struct pollfd fds[2]; |
| 629 | int timeout = 2000; |
| 630 | char anyBuf[64]; |
| 631 | struct sockaddr_in toAddr; |
| 632 | int done = 1, cnt = 0, ret, nbytes; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 633 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 634 | verifyIpResp->status = STATUS_COMPLETE; |
| 635 | verifyIpResp->cmdru.connected = 0; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 636 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 637 | btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 638 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 639 | if (btSockfd == -1) { |
| 640 | verifyIpResp->status = STATUS_ERROR; |
| 641 | wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE*)verifyIpResp, |
| 642 | respBuf); |
| 643 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 644 | return WFA_FAILURE; |
| 645 | ; |
| 646 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 647 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 648 | toAddr.sin_family = AF_INET; |
| 649 | toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr); |
| 650 | toAddr.sin_port = htons(WFA_UDP_ECHO_PORT); |
| 651 | |
| 652 | while (done) { |
| 653 | wfaTrafficSendTo(btSockfd, (char*)anyBuf, 64, (struct sockaddr*)&toAddr); |
| 654 | cnt++; |
| 655 | |
| 656 | fds[0].fd = btSockfd; |
| 657 | fds[0].events = POLLIN | POLLOUT; |
| 658 | |
| 659 | ret = poll(fds, 1, timeout); |
| 660 | switch (ret) { |
| 661 | case 0: |
| 662 | /* it is time out, count a packet lost*/ |
| 663 | break; |
| 664 | case -1: |
| 665 | /* it is an error */ |
| 666 | default: { |
| 667 | switch (fds[0].revents) { |
| 668 | case POLLIN: |
| 669 | case POLLPRI: |
| 670 | case POLLOUT: |
| 671 | nbytes = wfaTrafficRecv(btSockfd, (char*)anyBuf, |
| 672 | (struct sockaddr*)&toAddr); |
| 673 | if (nbytes != 0) |
| 674 | verifyIpResp->cmdru.connected = 1; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 675 | done = 0; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 676 | break; |
| 677 | default: |
| 678 | /* errors but not care */ |
| 679 | ; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 680 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 681 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 682 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 683 | if (cnt == 3) { |
| 684 | done = 0; |
| 685 | } |
| 686 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 687 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 688 | #endif |
| 689 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 690 | wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), |
| 691 | (BYTE*)verifyIpResp, respBuf); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 692 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 693 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 694 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 695 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /* |
| 699 | * wfaStaGetMacAddress() |
| 700 | * This function is to retrieve the MAC address of a wireless I/F. |
| 701 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 702 | int wfaStaGetMacAddress(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 703 | dutCommand_t* getMac = (dutCommand_t*)caCmdBuf; |
| 704 | dutCmdResponse_t* getmacResp = &gGenericResp; |
| 705 | char* str; |
| 706 | char* ifname = getMac->intf; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 707 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 708 | FILE* tmpfd; |
| 709 | char string[257]; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 710 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 711 | DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n"); |
| 712 | /* |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 713 | * run the script "getipconfig.sh" to find out the mac |
| 714 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 715 | sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname); |
| 716 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 717 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 718 | tmpfd = fopen("/tmp/ipconfig.txt", "r+"); |
| 719 | if (tmpfd == NULL) { |
| 720 | getmacResp->status = STATUS_ERROR; |
| 721 | wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE*)getmacResp, |
| 722 | respBuf); |
| 723 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 724 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 725 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 726 | return WFA_FAILURE; |
| 727 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 728 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 729 | if (fgets((char*)&string[0], 256, tmpfd) == NULL) { |
| 730 | getmacResp->status = STATUS_ERROR; |
| 731 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 732 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 733 | str = strtok(string, " "); |
| 734 | while (str && ((strcmp(str, "HWaddr")) != 0)) { |
| 735 | str = strtok(NULL, " "); |
| 736 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 737 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 738 | /* get mac */ |
| 739 | if (str) { |
| 740 | str = strtok(NULL, " "); |
| 741 | strcpy(getmacResp->cmdru.mac, str); |
| 742 | getmacResp->status = STATUS_COMPLETE; |
| 743 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 744 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 745 | wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), |
| 746 | (BYTE*)getmacResp, respBuf); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 747 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 748 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 749 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 750 | fclose(tmpfd); |
| 751 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /* |
| 755 | * wfaStaGetStats(): |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 756 | * The function is to retrieve the statistics of the I/F's layer 2 txFrames, |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 757 | * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries. |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 758 | * Currently there is not definition how to use these info. |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 759 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 760 | int wfaStaGetStats(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 761 | dutCmdResponse_t* statsResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 762 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 763 | /* this is never used, you can skip this call */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 764 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 765 | statsResp->status = STATUS_ERROR; |
| 766 | wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), |
| 767 | (BYTE*)statsResp, respBuf); |
| 768 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 769 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 770 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /* |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 774 | * ensureNetworkId(): |
| 775 | * It tries to get network ID of the given SSID first. If so, returns it. |
| 776 | * Otherwise, adds one and returns the added network ID. Note that SSID can |
| 777 | * be NULL, meaning any existing network ID is okay. |
| 778 | * Returns -1 for any error. |
| 779 | */ |
| 780 | int ensureNetworkId(char* ifname, char* ssid) { |
| 781 | int networkId = getNetworkId(ifname, ssid); |
| 782 | if (networkId >= 0) { |
| 783 | return networkId; |
| 784 | } |
| 785 | |
| 786 | const char* tmpfile = "/tmp/.wfaAddNetworkTmp"; |
| 787 | char cmdResult[32]; |
| 788 | |
| 789 | // Network ID not found, try creating one and return the newly added network ID. |
| 790 | snprintf(gCmdStr, WFA_CMD_STR_SZ, "wpa_cli.sh -i%s add_network > %s", ifname, |
| 791 | tmpfile); |
| 792 | sret = systemWithLog(gCmdStr); |
| 793 | if (sret != 0 || !readLine(tmpfile, cmdResult, sizeof(cmdResult))) { |
| 794 | return -1; |
| 795 | } |
| 796 | |
| 797 | return atoi(cmdResult); |
| 798 | } |
| 799 | |
| 800 | // Helper function to return "wpa_cli.sh -i<ifname> <op>_network <networkId>". |
| 801 | // Note that the caller is responsible to provide char buffer. |
| 802 | char* networkCmd(char* buf, const char* ifname, int networkId, const char* op) { |
| 803 | sprintf(buf, "wpa_cli.sh -i%s %s_network %d", ifname, op, networkId); |
| 804 | return buf; |
| 805 | } |
| 806 | |
| 807 | /* |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 808 | * wfaSetEncryption(): |
| 809 | * The function is to set the wireless interface with WEP or none. |
| 810 | * |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 811 | * Since WEP is optional test, current function is only used for |
| 812 | * resetting the Security to NONE/Plaintext (OPEN). To test WEP, |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 813 | * this function should be replaced by the next one (wfaSetEncryption1()) |
| 814 | * |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 815 | * Input parameters: |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 816 | * 1. I/F |
| 817 | * 2. ssid |
| 818 | * 3. encpType - wep or none |
| 819 | * Optional: |
| 820 | * 4. key1 |
| 821 | * 5. key2 |
| 822 | * 6. key3 |
| 823 | * 7. key4 |
| 824 | * 8. activeKey Index |
| 825 | */ |
| 826 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 827 | int wfaSetEncryption1(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 828 | caStaSetEncryption_t* setEncryp = (caStaSetEncryption_t*)caCmdBuf; |
| 829 | dutCmdResponse_t* setEncrypResp = &gGenericResp; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 830 | char* ifname = setEncryp->intf; |
| 831 | char* ssid = setEncryp->ssid; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 832 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 833 | int networkId = ensureNetworkId(ifname, ssid); |
| 834 | if (networkId < 0) { |
| 835 | RETURN_STA_CMD_ERROR(setEncrypResp, STATUS_ERROR, |
| 836 | "unable to get network id"); |
| 837 | } |
| 838 | |
| 839 | // Disable the network first. |
| 840 | char cmd[64]; |
| 841 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 842 | |
| 843 | char setCmd[64]; |
| 844 | networkCmd(setCmd, ifname, networkId, "set"); |
| 845 | |
| 846 | // Set SSID. |
| 847 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 848 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 849 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 850 | // Tell the supplicant for infrastructure mode (1). |
| 851 | sprintf(gCmdStr, "%s mode 0", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 852 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 853 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 854 | // Set Key management to NONE (NO WPA) for plaintext or WEP. |
| 855 | sprintf(gCmdStr, "%s key_mgmt NONE", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 856 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 857 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 858 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 859 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 860 | setEncrypResp->status = STATUS_COMPLETE; |
| 861 | wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE*)setEncrypResp, |
| 862 | respBuf); |
| 863 | *respLen = WFA_TLV_HDR_LEN + 4; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 864 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 865 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* |
| 869 | * Since WEP is optional, this function could be used to replace |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 870 | * wfaSetEncryption() if necessary. |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 871 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 872 | int wfaSetEncryption(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 873 | caStaSetEncryption_t* setEncryp = (caStaSetEncryption_t*)caCmdBuf; |
| 874 | dutCmdResponse_t* setEncrypResp = &gGenericResp; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 875 | char* ifname = setEncryp->intf; |
| 876 | char* ssid = setEncryp->ssid; |
| 877 | |
| 878 | int networkId = ensureNetworkId(ifname, ssid); |
| 879 | if (networkId < 0) { |
| 880 | RETURN_STA_CMD_ERROR(setEncrypResp, STATUS_ERROR, |
| 881 | "unable to get network id"); |
| 882 | } |
| 883 | |
| 884 | // Disable the network first. |
| 885 | char cmd[64]; |
| 886 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 887 | |
| 888 | char setCmd[64]; |
| 889 | networkCmd(setCmd, ifname, networkId, "set"); |
| 890 | |
| 891 | // Set SSID. |
| 892 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, ssid); |
| 893 | sret = systemWithLog(gCmdStr); |
| 894 | |
| 895 | // Tell the supplicant for infrastructure mode (1). |
| 896 | sprintf(gCmdStr, "%s mode 0", setCmd); |
| 897 | sret = systemWithLog(gCmdStr); |
| 898 | |
| 899 | // Set Key management to NONE (NO WPA) for plaintext or WEP. |
| 900 | sprintf(gCmdStr, "%s key_mgmt NONE", setCmd); |
| 901 | sret = systemWithLog(gCmdStr); |
| 902 | |
| 903 | // Set keys. |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 904 | int i; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 905 | if (setEncryp->encpType == 1) { |
| 906 | for (i = 0; i < 4; i++) { |
| 907 | if (setEncryp->keys[i][0] != '\0') { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 908 | sprintf(gCmdStr, "%s wep_key %i %s", setCmd, i, setEncryp->keys[i]); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 909 | systemWithLog(gCmdStr); |
| 910 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 911 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 912 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 913 | // Set the active key. |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 914 | i = setEncryp->activeKeyIdx; |
| 915 | if (setEncryp->keys[i][0] != '\0') { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 916 | sprintf(gCmdStr, "%s wep_tx_keyidx %i", setCmd, i); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 917 | systemWithLog(gCmdStr); |
| 918 | } |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 919 | } else { |
| 920 | // Clearly remove the keys -- reported by p.schwann. |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 921 | for (i = 0; i < 4; i++) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 922 | sprintf(gCmdStr, "%s wep_key%i \"\"", setCmd, i); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 923 | systemWithLog(gCmdStr); |
| 924 | } |
| 925 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 926 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 927 | // Enable the network. |
| 928 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 929 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 930 | setEncrypResp->status = STATUS_COMPLETE; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 931 | wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE*)setEncrypResp, |
| 932 | respBuf); |
| 933 | *respLen = WFA_TLV_HDR_LEN + 4; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 934 | |
| 935 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 938 | int wfaStaSetSecurity(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 939 | int ret = WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 940 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 941 | return ret; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | /* |
| 945 | * wfaStaSetEapTLS(): |
| 946 | * This is to set |
| 947 | * 1. ssid |
| 948 | * 2. encrypType - tkip or aes-ccmp |
| 949 | * 3. keyManagementType - wpa or wpa2 |
| 950 | * 4. trustedRootCA |
| 951 | * 5. clientCertificate |
| 952 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 953 | int wfaStaSetEapTLS(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 954 | caStaSetEapTLS_t* setTLS = (caStaSetEapTLS_t*)caCmdBuf; |
| 955 | char* ifname = setTLS->intf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 956 | char* ssid = setTLS->ssid; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 957 | dutCmdResponse_t* setEapTlsResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 958 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 959 | DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 960 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 961 | // Need to store the trustedROOTCA and clientCertificate into a file first. |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 962 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 963 | sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, ssid, |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 964 | setTLS->trustedRootCA, setTLS->clientCertificate); |
| 965 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 966 | #else |
| 967 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 968 | int networkId = ensureNetworkId(ifname, ssid); |
| 969 | if (networkId < 0) { |
| 970 | RETURN_STA_CMD_ERROR(setEapTlsResp, STATUS_ERROR, |
| 971 | "unable to get network id"); |
| 972 | } |
| 973 | |
| 974 | // Disable the network first. |
| 975 | char cmd[64]; |
| 976 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 977 | |
| 978 | char setCmd[64]; |
| 979 | networkCmd(setCmd, ifname, networkId, "set"); |
| 980 | |
| 981 | // Set SSID. |
| 982 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, setTLS->ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 983 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 984 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 985 | // Set key management. |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 986 | if (strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0) { |
| 987 | } else if (strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0) { |
| 988 | } else if (strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0) { |
| 989 | } else if (strcasecmp(setTLS->keyMgmtType, "wpa") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 990 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 991 | } else if (strcasecmp(setTLS->keyMgmtType, "wpa2") == 0) { |
| 992 | // to take all and device to pick any one supported. |
| 993 | } else { |
| 994 | // ?? |
| 995 | } |
| 996 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 997 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 998 | // Protocol WPA. |
| 999 | sprintf(gCmdStr, "%s proto WPA", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1000 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1001 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1002 | sprintf(gCmdStr, "%s eap TLS", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1003 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1004 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1005 | sprintf(gCmdStr, "%s ca_cert '\"%s\"'", setCmd, setTLS->trustedRootCA); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1006 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1007 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1008 | sprintf(gCmdStr, "%s identity '\"wifi-user@wifilabs.local\"'", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1009 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1010 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1011 | sprintf(gCmdStr, "%s private_key '\"%s/%s\"'", setCmd, CERTIFICATES_PATH, |
| 1012 | setTLS->clientCertificate); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1013 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1014 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1015 | sprintf(gCmdStr, "%s private_key_passwd '\"wifi\"'", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1016 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1017 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1018 | // Enable network. |
| 1019 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1020 | #endif |
| 1021 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1022 | setEapTlsResp->status = STATUS_COMPLETE; |
| 1023 | wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE*)setEapTlsResp, respBuf); |
| 1024 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1025 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1026 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1030 | * The function is to set |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1031 | * 1. ssid |
| 1032 | * 2. passPhrase |
| 1033 | * 3. keyMangementType - wpa/wpa2 |
| 1034 | * 4. encrypType - tkip or aes-ccmp |
| 1035 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1036 | int wfaStaSetPSK(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1037 | /*Incompleted function*/ |
| 1038 | dutCmdResponse_t* setPskResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1039 | |
Dake Zhao | b7ed41a | 2014-12-04 11:24:58 -0800 | [diff] [blame] | 1040 | #ifndef WFA_PC_CONSOLE |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1041 | caStaSetPSK_t* setPSK = (caStaSetPSK_t*)caCmdBuf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1042 | char* ifname = setPSK->intf; |
| 1043 | char* ssid = setPSK->ssid; |
| 1044 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1045 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1046 | sprintf(gCmdStr, "wfa_set_psk %s %s %s", ifname, ssid, setPSK->passphrase); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1047 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1048 | #else |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1049 | int networkId = ensureNetworkId(ifname, ssid); |
| 1050 | if (networkId < 0) { |
| 1051 | RETURN_STA_CMD_ERROR(setPskResp, STATUS_ERROR, "unable to get network id"); |
| 1052 | } |
| 1053 | |
| 1054 | char cmd[64]; |
| 1055 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 1056 | |
| 1057 | char setCmd[64]; |
| 1058 | networkCmd(setCmd, ifname, networkId, "set"); |
| 1059 | |
| 1060 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, setPSK->ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1061 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1062 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1063 | if (strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0) |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1064 | sprintf(gCmdStr, "%s key_mgmt WPA2-SHA256", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1065 | else if (strcasecmp(setPSK->keyMgmtType, "wpa2") == 0) { |
| 1066 | // take all and device to pick it supported. |
| 1067 | } else if (strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0) { |
| 1068 | } else if (strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0) { |
| 1069 | } else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1070 | } else { |
| 1071 | sprintf(gCmdStr, "%s key_mgmt WPA-PSK", setCmd); |
| 1072 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1073 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1074 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1075 | sprintf(gCmdStr, "%s psk '\"%s\"'", setCmd, setPSK->passphrase); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1076 | sret = systemWithLog(gCmdStr); |
Ray Wang | 9c50869 | 2014-04-01 17:04:59 -0700 | [diff] [blame] | 1077 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1078 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 1079 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1080 | /* if PMF enable */ |
| 1081 | if (setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL) { |
| 1082 | } else if (setPSK->pmf == WFA_REQUIRED) { |
| 1083 | } else if (setPSK->pmf == WFA_F_REQUIRED) { |
| 1084 | } else if (setPSK->pmf == WFA_F_DISABLED) { |
| 1085 | } else { |
| 1086 | /* Disable PMF */ |
| 1087 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1088 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1089 | #endif |
| 1090 | |
Dake Zhao | b7ed41a | 2014-12-04 11:24:58 -0800 | [diff] [blame] | 1091 | #endif |
| 1092 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1093 | setPskResp->status = STATUS_COMPLETE; |
| 1094 | wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE*)setPskResp, respBuf); |
| 1095 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1096 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1097 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1101 | * wfaStaGetInfo(): |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1102 | * Get vendor specific information in name/value pair by a wireless I/F. |
| 1103 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1104 | int wfaStaGetInfo(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1105 | dutCmdResponse_t infoResp; |
| 1106 | dutCommand_t* getInfo = (dutCommand_t*)caCmdBuf; |
| 1107 | FILE* tmpfd; |
| 1108 | char vendor[256]; |
| 1109 | const char* vendorFileName = "/tmp/ifvendor.txt"; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1110 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1111 | sprintf(gCmdStr, "getifvendor.sh %s %s\n", getInfo->intf, vendorFileName); |
Wojciech Jakobczyk | b8af992 | 2020-08-25 14:49:44 +0200 | [diff] [blame] | 1112 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1113 | if (systemWithLog(gCmdStr) == -1) { |
| 1114 | infoResp.status = STATUS_ERROR; |
| 1115 | wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), |
| 1116 | (BYTE*)&infoResp, respBuf); |
Wojciech Jakobczyk | b8af992 | 2020-08-25 14:49:44 +0200 | [diff] [blame] | 1117 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1118 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1119 | DPRINT_ERR(WFA_ERR, "script %s failed\n", vendorFileName); |
| 1120 | return WFA_FAILURE; |
| 1121 | } |
| 1122 | |
| 1123 | /* open the output result and scan/retrieve the info */ |
| 1124 | tmpfd = fopen(vendorFileName, "r+"); |
| 1125 | |
| 1126 | if (tmpfd == NULL || fgets(vendor, 256, tmpfd) == NULL) { |
| 1127 | infoResp.status = STATUS_ERROR; |
| 1128 | wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), |
| 1129 | (BYTE*)&infoResp, respBuf); |
| 1130 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status); |
| 1131 | |
| 1132 | DPRINT_ERR(WFA_ERR, "file read failed\n"); |
| 1133 | |
| 1134 | if (tmpfd != NULL) { |
| 1135 | fclose(tmpfd); |
| 1136 | remove(vendorFileName); |
| 1137 | } |
| 1138 | |
| 1139 | return WFA_FAILURE; |
| 1140 | } |
| 1141 | |
| 1142 | snprintf(infoResp.cmdru.info, sizeof(infoResp.cmdru.info), |
| 1143 | "interface,%s,description,%s", getInfo->intf, vendor); |
| 1144 | |
| 1145 | infoResp.status = STATUS_COMPLETE; |
Shuo-Peng Liao | b35966c | 2020-09-28 12:30:10 +0800 | [diff] [blame] | 1146 | wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1147 | (BYTE*)&infoResp, respBuf); |
Shuo-Peng Liao | b35966c | 2020-09-28 12:30:10 +0800 | [diff] [blame] | 1148 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1149 | |
| 1150 | fclose(tmpfd); |
| 1151 | remove(vendorFileName); |
| 1152 | |
| 1153 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /* |
| 1157 | * wfaStaSetEapTTLS(): |
| 1158 | * This is to set |
| 1159 | * 1. ssid |
| 1160 | * 2. username |
| 1161 | * 3. passwd |
| 1162 | * 4. encrypType - tkip or aes-ccmp |
| 1163 | * 5. keyManagementType - wpa or wpa2 |
| 1164 | * 6. trustedRootCA |
| 1165 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1166 | int wfaStaSetEapTTLS(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1167 | caStaSetEapTTLS_t* setTTLS = (caStaSetEapTTLS_t*)caCmdBuf; |
| 1168 | char* ifname = setTTLS->intf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1169 | char* ssid = setTTLS->ssid; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1170 | dutCmdResponse_t* setEapTtlsResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1171 | |
| 1172 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1173 | sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, ssid, |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1174 | setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA); |
| 1175 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1176 | #else |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1177 | int networkId = ensureNetworkId(ifname, ssid); |
| 1178 | if (networkId < 0) { |
| 1179 | RETURN_STA_CMD_ERROR(setEapTtlsResp, STATUS_ERROR, |
| 1180 | "unable to get network id"); |
| 1181 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1182 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1183 | char cmd[64]; |
| 1184 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 1185 | |
| 1186 | char setCmd[64]; |
| 1187 | networkCmd(setCmd, ifname, networkId, "set"); |
| 1188 | |
| 1189 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, setTTLS->ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1190 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1191 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1192 | sprintf(gCmdStr, "%s identity '\"%s\"'", setCmd, setTTLS->username); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1193 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1194 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1195 | sprintf(gCmdStr, "%s password '\"%s\"'", setCmd, setTTLS->passwd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1196 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1197 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1198 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1199 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1200 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1201 | /* This may not need to set. if it is not set, default to take all */ |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1202 | // sprintf(cmdStr, "%s pairwise '\"%s\"", setCmd, setTTLS->encrptype); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1203 | if (strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0) { |
| 1204 | } else if (strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0) { |
| 1205 | } else if (strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0) { |
| 1206 | } else if (strcasecmp(setTTLS->keyMgmtType, "wpa") == 0) { |
| 1207 | } else if (strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0) { |
| 1208 | // to take all and device to pick one it supported |
| 1209 | } else { |
| 1210 | // ?? |
| 1211 | } |
| 1212 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1213 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1214 | sprintf(gCmdStr, "%s eap TTLS", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1215 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1216 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1217 | sprintf(gCmdStr, "%s ca_cert '\"%s/%s\"'", setCmd, CERTIFICATES_PATH, |
| 1218 | setTTLS->trustedRootCA); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1219 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1220 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1221 | sprintf(gCmdStr, "%s proto WPA", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1222 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1223 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1224 | sprintf(gCmdStr, "%s phase2 '\"auth=MSCHAPV2\"'", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1225 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1226 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1227 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1228 | #endif |
| 1229 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1230 | setEapTtlsResp->status = STATUS_COMPLETE; |
| 1231 | wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE*)setEapTtlsResp, respBuf); |
| 1232 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1233 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1234 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * wfaStaSetEapSIM(): |
| 1239 | * This is to set |
| 1240 | * 1. ssid |
| 1241 | * 2. user name |
| 1242 | * 3. passwd |
| 1243 | * 4. encrypType - tkip or aes-ccmp |
| 1244 | * 5. keyMangementType - wpa or wpa2 |
| 1245 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1246 | int wfaStaSetEapSIM(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1247 | caStaSetEapSIM_t* setSIM = (caStaSetEapSIM_t*)caCmdBuf; |
| 1248 | char* ifname = setSIM->intf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1249 | char* ssid = setSIM->ssid; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1250 | dutCmdResponse_t* setEapSimResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1251 | |
| 1252 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1253 | sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, ssid, setSIM->username, |
| 1254 | setSIM->encrptype); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1255 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1256 | #else |
| 1257 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1258 | int networkId = ensureNetworkId(ifname, ssid); |
| 1259 | if (networkId < 0) { |
| 1260 | RETURN_STA_CMD_ERROR(setEapSimResp, STATUS_ERROR, |
| 1261 | "unable to get network id"); |
| 1262 | } |
| 1263 | |
| 1264 | char cmd[64]; |
| 1265 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 1266 | |
| 1267 | char setCmd[64]; |
| 1268 | networkCmd(setCmd, ifname, networkId, "set"); |
| 1269 | |
| 1270 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1271 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1272 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1273 | sprintf(gCmdStr, "%s identity '\"%s\"'", setCmd, setSIM->username); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1274 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1275 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1276 | sprintf(gCmdStr, "%s pairwise '\"%s\"'", setCmd, setSIM->encrptype); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1277 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1278 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1279 | sprintf(gCmdStr, "%s eap SIM", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1280 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1281 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1282 | sprintf(gCmdStr, "%s proto WPA", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1283 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1284 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1285 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1286 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1287 | if (strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1288 | sprintf(gCmdStr, "%s key_mgmt WPA-SHA256", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1289 | } else if (strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1290 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1291 | } else if (strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1292 | sprintf(gCmdStr, "%s key_mgmt WPA-FT", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1293 | } else if (strcasecmp(setSIM->keyMgmtType, "wpa") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1294 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1295 | } else if (strcasecmp(setSIM->keyMgmtType, "wpa2") == 0) { |
| 1296 | // take all and device to pick one which is supported. |
| 1297 | } else { |
| 1298 | // ?? |
| 1299 | } |
| 1300 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1301 | |
| 1302 | #endif |
| 1303 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1304 | setEapSimResp->status = STATUS_COMPLETE; |
| 1305 | wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE*)setEapSimResp, respBuf); |
| 1306 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1307 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1308 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | /* |
| 1312 | * wfaStaSetPEAP() |
| 1313 | * This is to set |
| 1314 | * 1. ssid |
| 1315 | * 2. user name |
| 1316 | * 3. passwd |
| 1317 | * 4. encryType - tkip or aes-ccmp |
| 1318 | * 5. keyMgmtType - wpa or wpa2 |
| 1319 | * 6. trustedRootCA |
| 1320 | * 7. innerEAP |
| 1321 | * 8. peapVersion |
| 1322 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1323 | int wfaStaSetPEAP(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1324 | caStaSetEapPEAP_t* setPEAP = (caStaSetEapPEAP_t*)caCmdBuf; |
| 1325 | char* ifname = setPEAP->intf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1326 | char* ssid = setPEAP->ssid; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1327 | dutCmdResponse_t* setPeapResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1328 | |
| 1329 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1330 | sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, ssid, |
| 1331 | setPEAP->username, setPEAP->passwd, setPEAP->trustedRootCA, |
| 1332 | setPEAP->encrptype, setPEAP->peapVersion, setPEAP->innerEAP); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1333 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1334 | #else |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1335 | int networkId = ensureNetworkId(ifname, ssid); |
| 1336 | if (networkId < 0) { |
| 1337 | RETURN_STA_CMD_ERROR(setPeapResp, STATUS_ERROR, "unable to get network id"); |
| 1338 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1339 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1340 | char cmd[64]; |
| 1341 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 1342 | |
| 1343 | char setCmd[64]; |
| 1344 | networkCmd(setCmd, ifname, networkId, "set"); |
| 1345 | |
| 1346 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1347 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1348 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1349 | sprintf(gCmdStr, "%s eap PEAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1350 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1351 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1352 | sprintf(gCmdStr, "%s anonymous_identity '\"anonymous\"' ", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1353 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1354 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1355 | sprintf(gCmdStr, "%s identity '\"%s\"'", setCmd, setPEAP->username); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1356 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1357 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1358 | sprintf(gCmdStr, "%s password '\"%s\"'", setCmd, setPEAP->passwd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1359 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1360 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1361 | sprintf(gCmdStr, "%s ca_cert '\"%s/%s\"'", setCmd, CERTIFICATES_PATH, |
| 1362 | setPEAP->trustedRootCA); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1363 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1364 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1365 | if (strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1366 | sprintf(gCmdStr, "%s key_mgmt WPA-SHA256", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1367 | } else if (strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1368 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1369 | } else if (strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1370 | sprintf(gCmdStr, "%s key_mgmt WPA-FT", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1371 | } else if (strcasecmp(setPEAP->keyMgmtType, "wpa") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1372 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1373 | } else if (strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0) { |
| 1374 | // take all and device to pick one which is supported. |
| 1375 | } else { |
| 1376 | // ?? |
| 1377 | } |
| 1378 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1379 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1380 | sprintf(gCmdStr, "%s phase1 '\"peaplabel=%i\"'", setCmd, |
| 1381 | setPEAP->peapVersion); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1382 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1383 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1384 | sprintf(gCmdStr, "%s phase2 '\"auth=%s\"'", setCmd, setPEAP->innerEAP); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1385 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1386 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1387 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1388 | #endif |
| 1389 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1390 | setPeapResp->status = STATUS_COMPLETE; |
| 1391 | wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE*)setPeapResp, respBuf); |
| 1392 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1393 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1394 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | /* |
| 1398 | * wfaStaSetUAPSD() |
| 1399 | * This is to set |
| 1400 | * 1. acBE |
| 1401 | * 2. acBK |
| 1402 | * 3. acVI |
| 1403 | * 4. acVO |
| 1404 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1405 | int wfaStaSetUAPSD(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1406 | dutCmdResponse_t* setUAPSDResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1407 | #if 0 /* used for only one specific device, need to update to reflect yours */ |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1408 | caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf; |
| 1409 | char *ifname = setUAPSD->intf; |
| 1410 | char tmpStr[10]; |
| 1411 | char line[100]; |
| 1412 | char *pathl="/etc/Wireless/RT61STA"; |
| 1413 | BYTE acBE=1; |
| 1414 | BYTE acBK=1; |
| 1415 | BYTE acVO=1; |
| 1416 | BYTE acVI=1; |
| 1417 | BYTE APSDCapable; |
| 1418 | FILE *pipe; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1419 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1420 | /* |
| 1421 | * A series of setting need to be done before doing WMM-PS |
| 1422 | * Additional steps of configuration may be needed. |
| 1423 | */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1424 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1425 | /* |
| 1426 | * bring down the interface |
| 1427 | */ |
| 1428 | sprintf(gCmdStr, "ifconfig %s down",ifname); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 1429 | sret = systemWithLog(gCmdStr); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1430 | /* |
| 1431 | * Unload the Driver |
| 1432 | */ |
| 1433 | sprintf(gCmdStr, "rmmod rt61"); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 1434 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1435 | #ifndef WFA_WMM_AC |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1436 | if(setUAPSD->acBE != 1) |
| 1437 | acBE=setUAPSD->acBE = 0; |
| 1438 | if(setUAPSD->acBK != 1) |
| 1439 | acBK=setUAPSD->acBK = 0; |
| 1440 | if(setUAPSD->acVO != 1) |
| 1441 | acVO=setUAPSD->acVO = 0; |
| 1442 | if(setUAPSD->acVI != 1) |
| 1443 | acVI=setUAPSD->acVI = 0; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1444 | #else |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1445 | acBE=setUAPSD->acBE; |
| 1446 | acBK=setUAPSD->acBK; |
| 1447 | acVO=setUAPSD->acVO; |
| 1448 | acVI=setUAPSD->acVI; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1449 | #endif |
| 1450 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1451 | APSDCapable = acBE||acBK||acVO||acVI; |
| 1452 | /* |
| 1453 | * set other AC parameters |
| 1454 | */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1455 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1456 | sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO); |
| 1457 | sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 1458 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1459 | |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1460 | sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 1461 | sret = systemWithLog(gCmdStr); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1462 | pipe = popen("uname -r", "r"); |
| 1463 | /* Read into line the output of uname*/ |
| 1464 | fscanf(pipe,"%s",line); |
| 1465 | pclose(pipe); |
| 1466 | |
| 1467 | /* |
| 1468 | * load the Driver |
| 1469 | */ |
| 1470 | sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 1471 | sret = systemWithLog(gCmdStr); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1472 | |
| 1473 | sprintf(gCmdStr, "ifconfig %s up",ifname); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 1474 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1475 | #endif |
| 1476 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1477 | setUAPSDResp->status = STATUS_COMPLETE; |
| 1478 | wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE*)setUAPSDResp, respBuf); |
| 1479 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1480 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1483 | int wfaDeviceGetInfo(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1484 | dutCommand_t* dutCmd = (dutCommand_t*)caCmdBuf; |
| 1485 | caDevInfo_t* devInfo = &dutCmd->cmdsu.dev; |
| 1486 | dutCmdResponse_t* infoResp = &gGenericResp; |
| 1487 | /*a vendor can fill in the proper info or anything non-disclosure */ |
| 1488 | caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER}; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1489 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1490 | DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1491 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1492 | if (devInfo->fw == 0) |
| 1493 | memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t)); |
| 1494 | else { |
| 1495 | // Call internal API to pull the version ID */ |
| 1496 | strncpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15); |
| 1497 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1498 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1499 | infoResp->status = STATUS_COMPLETE; |
| 1500 | wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), |
| 1501 | (BYTE*)infoResp, respBuf); |
| 1502 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1503 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1504 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | /* |
| 1508 | * This funciton is to retrieve a list of interfaces and return |
| 1509 | * the list back to Agent control. |
| 1510 | * ******************************************************************** |
| 1511 | * Note: We intend to make this WLAN interface name as a hardcode name. |
| 1512 | * Therefore, for a particular device, you should know and change the name |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1513 | * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in |
| 1514 | * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1515 | * likely is hardcoded just for CAPI command responses. |
| 1516 | * ******************************************************************* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1517 | * |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1518 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1519 | int wfaDeviceListIF(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1520 | dutCmdResponse_t* infoResp = &gGenericResp; |
| 1521 | dutCommand_t* ifList = (dutCommand_t*)caCmdBuf; |
| 1522 | caDeviceListIFResp_t* ifListResp = &infoResp->cmdru.ifList; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1523 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1524 | DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1525 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1526 | switch (ifList->cmdsu.iftype) { |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1527 | case IF_80211: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1528 | infoResp->status = STATUS_COMPLETE; |
| 1529 | ifListResp->iftype = IF_80211; |
| 1530 | strcpy(ifListResp->ifs[0], WFA_STAUT_IF); |
| 1531 | strcpy(ifListResp->ifs[1], "NULL"); |
| 1532 | strcpy(ifListResp->ifs[2], "NULL"); |
| 1533 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1534 | case IF_ETH: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1535 | infoResp->status = STATUS_COMPLETE; |
| 1536 | ifListResp->iftype = IF_ETH; |
| 1537 | strcpy(ifListResp->ifs[0], "eth0"); |
| 1538 | strcpy(ifListResp->ifs[1], "NULL"); |
| 1539 | strcpy(ifListResp->ifs[2], "NULL"); |
| 1540 | break; |
| 1541 | default: { |
| 1542 | infoResp->status = STATUS_ERROR; |
| 1543 | wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE*)infoResp, respBuf); |
| 1544 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1545 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1546 | return WFA_SUCCESS; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1547 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1548 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1549 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1550 | wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), |
| 1551 | (BYTE*)infoResp, respBuf); |
| 1552 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1553 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1554 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1557 | int wfaStaDebugSet(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1558 | dutCmdResponse_t* debugResp = &gGenericResp; |
| 1559 | dutCommand_t* debugSet = (dutCommand_t*)caCmdBuf; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1560 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1561 | DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1562 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1563 | if (debugSet->cmdsu.dbg.state == 1) /* enable */ |
| 1564 | wfa_defined_debug |= debugSet->cmdsu.dbg.level; |
| 1565 | else |
| 1566 | wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1567 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1568 | debugResp->status = STATUS_COMPLETE; |
| 1569 | wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), |
| 1570 | (BYTE*)debugResp, respBuf); |
| 1571 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1572 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1573 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1576 | /* |
| 1577 | * wfaStaGetBSSID(): |
| 1578 | * This function is to retrieve BSSID of a specific wireless I/F. |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1579 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1580 | int wfaStaGetBSSID(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1581 | char string[64]; |
| 1582 | char* str; |
| 1583 | FILE* tmpfd; |
| 1584 | dutCmdResponse_t* bssidResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1585 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1586 | DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n"); |
| 1587 | /* retrieve the BSSID */ |
| 1588 | sprintf(gCmdStr, "wpa_cli.sh status > /tmp/bssid.txt"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1589 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1590 | systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1591 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1592 | tmpfd = fopen("/tmp/bssid.txt", "r+"); |
| 1593 | if (tmpfd == NULL) { |
| 1594 | bssidResp->status = STATUS_ERROR; |
| 1595 | wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE*)bssidResp, respBuf); |
| 1596 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1597 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1598 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 1599 | return WFA_FAILURE; |
| 1600 | } |
| 1601 | |
| 1602 | for (;;) { |
| 1603 | if (fscanf(tmpfd, "%s", string) == EOF) { |
| 1604 | bssidResp->status = STATUS_COMPLETE; |
| 1605 | strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00"); |
| 1606 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1607 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1608 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1609 | if (strncmp(string, "bssid", 5) == 0) { |
| 1610 | str = strtok(string, "="); |
| 1611 | str = strtok(NULL, "="); |
| 1612 | if (str != NULL) { |
| 1613 | strcpy(bssidResp->cmdru.bssid, str); |
| 1614 | bssidResp->status = STATUS_COMPLETE; |
| 1615 | break; |
| 1616 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1617 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1618 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1619 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1620 | wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), |
| 1621 | (BYTE*)bssidResp, respBuf); |
| 1622 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1623 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1624 | fclose(tmpfd); |
| 1625 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /* |
| 1629 | * wfaStaSetIBSS() |
| 1630 | * This is to set |
| 1631 | * 1. ssid |
| 1632 | * 2. channel |
| 1633 | * 3. encrypType - none or wep |
| 1634 | * optional |
| 1635 | * 4. key1 |
| 1636 | * 5. key2 |
| 1637 | * 6. key3 |
| 1638 | * 7. key4 |
| 1639 | * 8. activeIndex - 1, 2, 3, or 4 |
| 1640 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1641 | int wfaStaSetIBSS(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1642 | caStaSetIBSS_t* setIBSS = (caStaSetIBSS_t*)caCmdBuf; |
| 1643 | dutCmdResponse_t* setIbssResp = &gGenericResp; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1644 | |
| 1645 | char* ifname = setIBSS->intf; |
| 1646 | char* ssid = setIBSS->ssid; |
| 1647 | |
| 1648 | int networkId = ensureNetworkId(ifname, ssid); |
| 1649 | if (networkId < 0) { |
| 1650 | RETURN_STA_CMD_ERROR(setIbssResp, STATUS_ERROR, "unable to get network id"); |
| 1651 | } |
| 1652 | |
| 1653 | // Disable the network first. |
| 1654 | char cmd[64]; |
| 1655 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 1656 | |
| 1657 | char setCmd[64]; |
| 1658 | networkCmd(setCmd, ifname, networkId, "set"); |
| 1659 | |
| 1660 | // Set SSID. |
| 1661 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, ssid); |
| 1662 | sret = systemWithLog(gCmdStr); |
| 1663 | |
| 1664 | // Set channel for IBSS. |
| 1665 | sprintf(gCmdStr, "iwconfig %s channel %i", setCmd, setIBSS->channel); |
| 1666 | sret = systemWithLog(gCmdStr); |
| 1667 | |
| 1668 | // Tell the supplicant for IBSS mode (1). |
| 1669 | sprintf(gCmdStr, "%s mode 1", setCmd); |
| 1670 | sret = systemWithLog(gCmdStr); |
| 1671 | |
| 1672 | // Set Key management to NONE (NO WPA) for plaintext or WEP. |
| 1673 | sprintf(gCmdStr, "%s key_mgmt NONE", setCmd); |
| 1674 | sret = systemWithLog(gCmdStr); |
| 1675 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1676 | int i; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1677 | if (setIBSS->encpType == 1) { |
| 1678 | for (i = 0; i < 4; i++) { |
| 1679 | if (strlen(setIBSS->keys[i]) == 5 || strlen(setIBSS->keys[i]) == 13) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1680 | sprintf(gCmdStr, "%s wep_key%i \"%s\"", setCmd, i, setIBSS->keys[i]); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1681 | sret = systemWithLog(gCmdStr); |
| 1682 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1683 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1684 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1685 | i = setIBSS->activeKeyIdx; |
| 1686 | if (strlen(setIBSS->keys[i]) == 5 || strlen(setIBSS->keys[i]) == 13) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1687 | sprintf(gCmdStr, "%s wep_tx_keyidx %i", setCmd, setIBSS->activeKeyIdx); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1688 | sret = systemWithLog(gCmdStr); |
| 1689 | } |
| 1690 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1691 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 1692 | // Enable the network. |
| 1693 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1694 | setIbssResp->status = STATUS_COMPLETE; |
| 1695 | wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE*)setIbssResp, respBuf); |
| 1696 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1697 | |
| 1698 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | /* |
| 1702 | * wfaSetMode(): |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1703 | * The function is to set the wireless interface with a given mode (possible |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1704 | * adhoc) |
| 1705 | * Input parameters: |
| 1706 | * 1. I/F |
| 1707 | * 2. ssid |
| 1708 | * 3. mode adhoc or managed |
| 1709 | * 4. encType |
| 1710 | * 5. channel |
| 1711 | * 6. key(s) |
| 1712 | * 7. active key |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1713 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1714 | int wfaStaSetMode(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1715 | caStaSetMode_t* setmode = (caStaSetMode_t*)caCmdBuf; |
| 1716 | dutCmdResponse_t* SetModeResp = &gGenericResp; |
| 1717 | int i; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1718 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1719 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1720 | * bring down the interface |
| 1721 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1722 | sprintf(gCmdStr, "ifconfig %s down", setmode->intf); |
| 1723 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1724 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1725 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1726 | * distroy the interface |
| 1727 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1728 | sprintf(gCmdStr, "wlanconfig %s destroy", setmode->intf); |
| 1729 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1730 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1731 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1732 | * re-create the interface with the given mode |
| 1733 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1734 | if (setmode->mode == 1) |
| 1735 | sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc", |
| 1736 | setmode->intf); |
| 1737 | else |
| 1738 | sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed", |
| 1739 | setmode->intf); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1740 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1741 | sret = systemWithLog(gCmdStr); |
| 1742 | if (setmode->encpType == ENCRYPT_WEP) { |
| 1743 | int j = setmode->activeKeyIdx; |
| 1744 | for (i = 0; i < 4; i++) { |
| 1745 | if (setmode->keys[i][0] != '\0') { |
| 1746 | sprintf(gCmdStr, "iwconfig %s key s:%s", setmode->intf, |
| 1747 | setmode->keys[i]); |
| 1748 | sret = systemWithLog(gCmdStr); |
| 1749 | } |
| 1750 | /* set active key */ |
| 1751 | if (setmode->keys[j][0] != '\0') |
| 1752 | sprintf(gCmdStr, "iwconfig %s key s:%s", setmode->intf, |
| 1753 | setmode->keys[j]); |
| 1754 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1755 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1756 | } |
| 1757 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1758 | * Set channel for IBSS |
| 1759 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1760 | if (setmode->channel) { |
| 1761 | sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel); |
| 1762 | sret = systemWithLog(gCmdStr); |
| 1763 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1764 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1765 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1766 | * set SSID |
| 1767 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1768 | sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid); |
| 1769 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1770 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1771 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1772 | * bring up the interface |
| 1773 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1774 | sprintf(gCmdStr, "ifconfig %s up", setmode->intf); |
| 1775 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1776 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1777 | SetModeResp->status = STATUS_COMPLETE; |
| 1778 | wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE*)SetModeResp, respBuf); |
| 1779 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1780 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1781 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1784 | int wfaStaSetPwrSave(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1785 | caStaSetPwrSave_t* setps = (caStaSetPwrSave_t*)caCmdBuf; |
| 1786 | dutCmdResponse_t* SetPSResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1787 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1788 | sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode); |
| 1789 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1790 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1791 | SetPSResp->status = STATUS_COMPLETE; |
| 1792 | wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE*)SetPSResp, respBuf); |
| 1793 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1794 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1795 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1798 | int wfaStaUpload(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1799 | caStaUpload_t* upload = &((dutCommand_t*)caCmdBuf)->cmdsu.upload; |
| 1800 | dutCmdResponse_t* upLoadResp = &gGenericResp; |
| 1801 | caStaUploadResp_t* upld = &upLoadResp->cmdru.uld; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1802 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1803 | if (upload->type == WFA_UPLOAD_VHSO_RPT) { |
| 1804 | int rbytes; |
| 1805 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1806 | * if asked for the first packet, always to open the file |
| 1807 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1808 | if (upload->next == 1) { |
| 1809 | if (e2efp != NULL) { |
| 1810 | fclose(e2efp); |
| 1811 | e2efp = NULL; |
| 1812 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1813 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1814 | e2efp = fopen(e2eResults, "r"); |
| 1815 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1816 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1817 | if (e2efp == NULL) { |
| 1818 | upLoadResp->status = STATUS_ERROR; |
| 1819 | wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE*)upLoadResp, respBuf); |
| 1820 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1821 | return WFA_FAILURE; |
| 1822 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1823 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1824 | rbytes = fread(upld->bytes, 1, 256, e2efp); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1825 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1826 | if (rbytes < 256) { |
| 1827 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1828 | * this means no more bytes after this read |
| 1829 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1830 | upld->seqnum = 0; |
| 1831 | fclose(e2efp); |
| 1832 | e2efp = NULL; |
| 1833 | } else { |
| 1834 | upld->seqnum = upload->next; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1835 | } |
| 1836 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1837 | upld->nbytes = rbytes; |
| 1838 | |
| 1839 | upLoadResp->status = STATUS_COMPLETE; |
| 1840 | wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), |
| 1841 | (BYTE*)upLoadResp, respBuf); |
| 1842 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 1843 | } else { |
| 1844 | upLoadResp->status = STATUS_ERROR; |
| 1845 | wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE*)upLoadResp, respBuf); |
| 1846 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1847 | } |
| 1848 | |
| 1849 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1850 | } |
| 1851 | /* |
| 1852 | * wfaStaSetWMM() |
| 1853 | * TO be ported on a specific plaform for the DUT |
| 1854 | * This is to set the WMM related parameters at the DUT. |
| 1855 | * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF) |
| 1856 | * It is expected that this function will set all the WMM related parametrs for a particular GROUP . |
| 1857 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1858 | int wfaStaSetWMM(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1859 | #ifdef WFA_WMM_AC |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1860 | caStaSetWMM_t* setwmm = (caStaSetWMM_t*)caCmdBuf; |
| 1861 | char* ifname = setwmm->intf; |
| 1862 | dutCmdResponse_t* setwmmResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1863 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1864 | switch (setwmm->group) { |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1865 | case GROUP_WMMAC: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1866 | if (setwmm->send_trig) { |
| 1867 | int Sockfd; |
| 1868 | struct sockaddr_in psToAddr; |
| 1869 | unsigned int TxMsg[512]; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1870 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1871 | Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346); |
| 1872 | memset(&psToAddr, 0, sizeof(psToAddr)); |
| 1873 | psToAddr.sin_family = AF_INET; |
| 1874 | psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr); |
| 1875 | psToAddr.sin_port = htons(12346); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1876 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1877 | switch (setwmm->trig_ac) { |
| 1878 | case WMMAC_AC_VO: |
| 1879 | wfaTGSetPrio(Sockfd, 7); |
| 1880 | create_apts_msg(APTS_CK_VO, TxMsg, 0); |
| 1881 | printf("\r\nSending AC_VO trigger packet\n"); |
| 1882 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1883 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1884 | case WMMAC_AC_VI: |
| 1885 | wfaTGSetPrio(Sockfd, 5); |
| 1886 | create_apts_msg(APTS_CK_VI, TxMsg, 0); |
| 1887 | printf("\r\nSending AC_VI trigger packet\n"); |
| 1888 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1889 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1890 | case WMMAC_AC_BK: |
| 1891 | wfaTGSetPrio(Sockfd, 2); |
| 1892 | create_apts_msg(APTS_CK_BK, TxMsg, 0); |
| 1893 | printf("\r\nSending AC_BK trigger packet\n"); |
| 1894 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1895 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1896 | default: |
| 1897 | case WMMAC_AC_BE: |
| 1898 | wfaTGSetPrio(Sockfd, 0); |
| 1899 | create_apts_msg(APTS_CK_BE, TxMsg, 0); |
| 1900 | printf("\r\nSending AC_BE trigger packet\n"); |
| 1901 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1904 | sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr*)&psToAddr, |
| 1905 | sizeof(struct sockaddr)); |
| 1906 | close(Sockfd); |
| 1907 | usleep(1000000); |
| 1908 | } else if (setwmm->action == WMMAC_ADDTS) { |
| 1909 | printf( |
| 1910 | "ADDTS AC PARAMS: dialog id: %d, TID: %d, " |
| 1911 | "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d" |
| 1912 | "Fixed %d, MSDU Size: %d, Max MSDU Size %d, " |
| 1913 | "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, " |
| 1914 | "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, " |
| 1915 | "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, " |
| 1916 | "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, " |
| 1917 | "SPLUSBW: %f, " |
| 1918 | "MEDIUM TIME: %d, ACCESSCAT: %d\n", |
| 1919 | setwmm->actions.addts.dialog_token, |
| 1920 | setwmm->actions.addts.tspec.tsinfo.TID, |
| 1921 | setwmm->actions.addts.tspec.tsinfo.direction, |
| 1922 | setwmm->actions.addts.tspec.tsinfo.PSB, |
| 1923 | setwmm->actions.addts.tspec.tsinfo.UP, |
| 1924 | setwmm->actions.addts.tspec.tsinfo.infoAck, |
| 1925 | setwmm->actions.addts.tspec.tsinfo.bstSzDef, |
| 1926 | setwmm->actions.addts.tspec.Fixed, setwmm->actions.addts.tspec.size, |
| 1927 | setwmm->actions.addts.tspec.maxsize, |
| 1928 | setwmm->actions.addts.tspec.min_srvc, |
| 1929 | setwmm->actions.addts.tspec.max_srvc, |
| 1930 | setwmm->actions.addts.tspec.inactivity, |
| 1931 | setwmm->actions.addts.tspec.suspension, |
| 1932 | setwmm->actions.addts.tspec.srvc_strt_tim, |
| 1933 | setwmm->actions.addts.tspec.mindatarate, |
| 1934 | setwmm->actions.addts.tspec.meandatarate, |
| 1935 | setwmm->actions.addts.tspec.peakdatarate, |
| 1936 | setwmm->actions.addts.tspec.burstsize, |
| 1937 | setwmm->actions.addts.tspec.delaybound, |
| 1938 | setwmm->actions.addts.tspec.PHYrate, |
| 1939 | setwmm->actions.addts.tspec.sba, |
| 1940 | setwmm->actions.addts.tspec.medium_time, |
| 1941 | setwmm->actions.addts.accesscat); |
| 1942 | |
| 1943 | //tspec should be set here. |
| 1944 | |
| 1945 | sret = systemWithLog(gCmdStr); |
| 1946 | } else if (setwmm->action == WMMAC_DELTS) { |
| 1947 | // send del tspec |
| 1948 | } |
| 1949 | |
| 1950 | setwmmResp->status = STATUS_COMPLETE; |
| 1951 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1952 | |
| 1953 | case GROUP_WMMCONF: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1954 | sprintf(gCmdStr, "iwconfig %s rts %d", ifname, |
| 1955 | setwmm->actions.config.rts_thr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1956 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1957 | sret = systemWithLog(gCmdStr); |
| 1958 | sprintf(gCmdStr, "iwconfig %s frag %d", ifname, |
| 1959 | setwmm->actions.config.frag_thr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1960 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1961 | sret = systemWithLog(gCmdStr); |
| 1962 | sprintf(gCmdStr, "iwpriv %s wmmcfg %d", ifname, |
| 1963 | setwmm->actions.config.wmm); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1964 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1965 | sret = systemWithLog(gCmdStr); |
| 1966 | setwmmResp->status = STATUS_COMPLETE; |
| 1967 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1968 | |
| 1969 | default: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1970 | DPRINT_ERR(WFA_ERR, "The group %d is not supported\n", setwmm->group); |
| 1971 | setwmmResp->status = STATUS_ERROR; |
| 1972 | break; |
| 1973 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1974 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1975 | wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE*)setwmmResp, respBuf); |
| 1976 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1977 | #endif |
| 1978 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1979 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1982 | int wfaStaSendNeigReq(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1983 | dutCmdResponse_t* sendNeigReqResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1984 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1985 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 1986 | * run your device to send NEIGREQ |
| 1987 | */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1988 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1989 | sendNeigReqResp->status = STATUS_COMPLETE; |
| 1990 | wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE*)sendNeigReqResp, |
| 1991 | respBuf); |
| 1992 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1993 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1994 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 1997 | int wfaStaSetEapFAST(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 1998 | caStaSetEapFAST_t* setFAST = (caStaSetEapFAST_t*)caCmdBuf; |
| 1999 | char* ifname = setFAST->intf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2000 | char* ssid = setFAST->ssid; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2001 | dutCmdResponse_t* setEapFastResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2002 | |
| 2003 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2004 | sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, ssid, |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2005 | setFAST->username, setFAST->passwd, setFAST->pacFileName, |
| 2006 | setFAST->innerEAP); |
| 2007 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2008 | #else |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2009 | int networkId = ensureNetworkId(ifname, ssid); |
| 2010 | if (networkId < 0) { |
| 2011 | RETURN_STA_CMD_ERROR(setEapFastResp, STATUS_ERROR, |
| 2012 | "unable to get network id"); |
| 2013 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2014 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2015 | // Disable the network first. |
| 2016 | char cmd[64]; |
| 2017 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
| 2018 | |
| 2019 | char setCmd[64]; |
| 2020 | networkCmd(setCmd, ifname, networkId, "set"); |
| 2021 | |
| 2022 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, setFAST->ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2023 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2024 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2025 | sprintf(gCmdStr, "%s identity '\"%s\"'", setCmd, setFAST->username); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2026 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2027 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2028 | sprintf(gCmdStr, "%s password '\"%s\"'", setCmd, setFAST->passwd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2029 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2030 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2031 | if (strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0) { |
| 2032 | } else if (strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0) { |
| 2033 | } else if (strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0) { |
| 2034 | } else if (strcasecmp(setFAST->keyMgmtType, "wpa") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2035 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2036 | } else if (strcasecmp(setFAST->keyMgmtType, "wpa2") == 0) { |
| 2037 | // take all and device to pick one which is supported. |
| 2038 | } else { |
| 2039 | // ?? |
| 2040 | } |
| 2041 | sret = systemWithLog(gCmdStr); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2042 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2043 | sprintf(gCmdStr, "%s eap FAST", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2044 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2045 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2046 | sprintf(gCmdStr, "%s pac_file '\"%s/%s\"'", setCmd, CERTIFICATES_PATH, |
| 2047 | setFAST->pacFileName); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2048 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2049 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2050 | sprintf(gCmdStr, "%s anonymous_identity '\"anonymous\"'", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2051 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2052 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2053 | sprintf(gCmdStr, "%s phase1 '\"fast_provisioning=1\"'", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2054 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2055 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2056 | sprintf(gCmdStr, "%s phase2 '\"auth=%s\"'", setCmd, setFAST->innerEAP); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2057 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2058 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2059 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2060 | #endif |
| 2061 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2062 | setEapFastResp->status = STATUS_COMPLETE; |
| 2063 | wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE*)setEapFastResp, respBuf); |
| 2064 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2065 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2066 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2069 | int wfaStaSetEapAKA(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2070 | caStaSetEapAKA_t* setAKA = (caStaSetEapAKA_t*)caCmdBuf; |
| 2071 | char* ifname = setAKA->intf; |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2072 | char* ssid = setAKA->ssid; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2073 | dutCmdResponse_t* setEapAkaResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2074 | |
| 2075 | #ifdef WFA_NEW_CLI_FORMAT |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2076 | sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, ssid, setAKA->username, |
| 2077 | setAKA->passwd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2078 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2079 | #else |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2080 | int networkId = ensureNetworkId(ifname, ssid); |
| 2081 | if (networkId < 0) { |
| 2082 | RETURN_STA_CMD_ERROR(setEapAkaResp, STATUS_ERROR, |
| 2083 | "unable to get network id"); |
| 2084 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2085 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2086 | // Disable the network first. |
| 2087 | char cmd[64]; |
| 2088 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "disable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2089 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2090 | char setCmd[64]; |
| 2091 | networkCmd(setCmd, ifname, networkId, "set"); |
| 2092 | |
| 2093 | sprintf(gCmdStr, "%s ssid '\"%s\"'", setCmd, setAKA->ssid); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2094 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2095 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2096 | if (strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0) { |
| 2097 | } else if (strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0) { |
| 2098 | } else if (strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0) { |
| 2099 | } else if (strcasecmp(setAKA->keyMgmtType, "wpa") == 0) { |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2100 | sprintf(gCmdStr, "%s key_mgmt WPA-EAP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2101 | } else if (strcasecmp(setAKA->keyMgmtType, "wpa2") == 0) { |
| 2102 | // take all and device to pick one which is supported. |
| 2103 | } else { |
| 2104 | // ?? |
| 2105 | } |
| 2106 | sret = systemWithLog(gCmdStr); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2107 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2108 | sprintf(gCmdStr, "%s proto WPA2", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2109 | sret = systemWithLog(gCmdStr); |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2110 | sprintf(gCmdStr, "%s proto CCMP", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2111 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2112 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2113 | sprintf(gCmdStr, "%s eap AKA", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2114 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2115 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2116 | sprintf(gCmdStr, "%s phase1 \"result_ind=1\"", setCmd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2117 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2118 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2119 | sprintf(gCmdStr, "%s identity '\"%s\"'", setCmd, setAKA->username); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2120 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2121 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2122 | sprintf(gCmdStr, "%s password '\"%s\"'", setCmd, setAKA->passwd); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2123 | sret = systemWithLog(gCmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2124 | |
Shuo-Peng Liao | 9aba0bc | 2020-10-01 09:53:13 +0800 | [diff] [blame] | 2125 | sret = systemWithLog(networkCmd(cmd, ifname, networkId, "enable")); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2126 | #endif |
| 2127 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2128 | setEapAkaResp->status = STATUS_COMPLETE; |
| 2129 | wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE*)setEapAkaResp, respBuf); |
| 2130 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2131 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2132 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2135 | int wfaStaSetSystime(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2136 | caStaSetSystime_t* systime = (caStaSetSystime_t*)caCmdBuf; |
| 2137 | dutCmdResponse_t* setSystimeResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2138 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2139 | DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2140 | |
Wojciech Jakobczyk | 569662f | 2020-09-04 08:41:42 +0200 | [diff] [blame] | 2141 | sprintf(gCmdStr, "date %02d%02d%02d%02d%04d.%02d", systime->month, |
| 2142 | systime->date, systime->hours, systime->minutes, systime->year, |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2143 | systime->seconds); |
| 2144 | sret = systemWithLog(gCmdStr); |
Wojciech Jakobczyk | 569662f | 2020-09-04 08:41:42 +0200 | [diff] [blame] | 2145 | if (sret != 0) { |
| 2146 | RETURN_STA_CMD_ERROR(setSystimeResp, STATUS_ERROR, |
| 2147 | "error running date command, exit code: %d\n", sret); |
| 2148 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2149 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2150 | setSystimeResp->status = STATUS_COMPLETE; |
| 2151 | wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE*)setSystimeResp, respBuf); |
| 2152 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2153 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2154 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | #ifdef WFA_STA_TB |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2158 | int wfaStaPresetParams(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2159 | dutCmdResponse_t* PresetParamsResp = &gGenericResp; |
| 2160 | caStaPresetParameters_t* presetParams = (caStaPresetParameters_t*)caCmdBuf; |
| 2161 | BYTE presetDone = 1; |
| 2162 | int st = 0; |
| 2163 | char cmdStr[128]; |
| 2164 | char string[256]; |
| 2165 | FILE* tmpfd = NULL; |
| 2166 | long val; |
| 2167 | char* endptr; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2168 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2169 | DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2170 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2171 | if (presetParams->supplicant == eWpaSupplicant) { |
| 2172 | st = access("/tmp/processid.txt", F_OK); |
| 2173 | if (st != -1) { |
| 2174 | st = remove("/tmp/processid.txt"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2175 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2176 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2177 | sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", |
| 2178 | "wpa_supplicant"); |
| 2179 | st = systemWithLog(cmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2180 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2181 | tmpfd = fopen("/tmp/processid.txt", "r+"); |
| 2182 | if (tmpfd == NULL) { |
| 2183 | DPRINT_ERR(WFA_ERR, "process id file not exist\n"); |
| 2184 | return WFA_FAILURE; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2185 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2186 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2187 | for (;;) { |
| 2188 | if (fgets(string, 256, tmpfd) == NULL) |
| 2189 | break; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2190 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2191 | errno = 0; |
| 2192 | val = strtol(string, &endptr, 10); |
| 2193 | if (errno != 0 && val == 0) { |
| 2194 | DPRINT_ERR(WFA_ERR, "strtol error\n"); |
| 2195 | return WFA_FAILURE; |
| 2196 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2197 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2198 | if (endptr == string) { |
| 2199 | DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n"); |
| 2200 | } |
| 2201 | |
| 2202 | presetDone = 1; |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | if (presetParams->wmmFlag) { |
| 2207 | st = wfaExecuteCLI(gCmdStr); |
| 2208 | switch (st) { |
| 2209 | case 0: |
| 2210 | presetDone = 1; |
| 2211 | break; |
| 2212 | case 1: |
| 2213 | presetDone = 0; |
| 2214 | break; |
| 2215 | case 2: |
| 2216 | presetDone = 0; |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | if (presetParams->modeFlag != 0) { |
| 2222 | switch (presetParams->wirelessMode) { |
| 2223 | default: |
| 2224 | printf("other mode does not need to support\n"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2225 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2226 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2227 | st = wfaExecuteCLI(gCmdStr); |
| 2228 | switch (st) { |
| 2229 | case 0: |
| 2230 | presetDone = 1; |
| 2231 | break; |
| 2232 | case 1: |
| 2233 | presetDone = 0; |
| 2234 | case 2: |
| 2235 | presetDone = 0; |
| 2236 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2237 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2238 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 2239 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2240 | if (presetParams->psFlag) { |
| 2241 | printf("%s\n", gCmdStr); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 2242 | sret = systemWithLog(gCmdStr); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2243 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2244 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2245 | /************the followings are used for Voice Enterprise **************/ |
| 2246 | if (presetParams->program == PROG_TYPE_VENT) { |
| 2247 | if (presetParams->ftoa == eEnable) { |
| 2248 | // enable Fast BSS Transition Over the Air |
| 2249 | } else { |
| 2250 | // disable Fast BSS Transition Over the Air |
| 2251 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2252 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2253 | if (presetParams->ftds == eEnable) { |
| 2254 | // enable Fast BSS Transition Over the DS |
| 2255 | } else { |
| 2256 | // disable Fast BSS Transition Over the DS |
| 2257 | } |
| 2258 | |
| 2259 | if (presetParams->activescan == eEnable) { |
| 2260 | // Enable Active Scan on STA |
| 2261 | } else { |
| 2262 | // disable Active Scan on STA |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | /************the followings are used for Wi-Fi Display *************/ |
| 2267 | if (presetParams->program == PROG_TYPE_WFD) { |
| 2268 | if (presetParams->tdlsFlag) { |
| 2269 | // enable / disable tdls based on tdls |
| 2270 | } |
| 2271 | if (presetParams->wfdDevTypeFlag) { |
| 2272 | // set WFD device type to source/sink/dual based on wfdDevType |
| 2273 | } |
| 2274 | if (presetParams->wfdUibcGenFlag) { |
| 2275 | // enable / disable the feature |
| 2276 | } |
| 2277 | if (presetParams->wfdUibcHidFlag) { |
| 2278 | // enable / disable feature |
| 2279 | } |
| 2280 | if (presetParams->wfdUiInputFlag) { |
| 2281 | // set the UI input as mentioned |
| 2282 | } |
| 2283 | if (presetParams->wfdHdcpFlag) { |
| 2284 | // enable / disable feature |
| 2285 | } |
| 2286 | if (presetParams->wfdFrameSkipFlag) { |
| 2287 | // enable / disable feature |
| 2288 | } |
| 2289 | if (presetParams->wfdAvChangeFlag) { |
| 2290 | // enable / disable feature |
| 2291 | } |
| 2292 | if (presetParams->wfdStandByFlag) { |
| 2293 | // enable / disable feature |
| 2294 | } |
| 2295 | if (presetParams->wfdInVideoFlag) { |
| 2296 | // select the input vide as protecteed or non-protetcted or protected audio |
| 2297 | // or unprotected audio etc. |
| 2298 | } |
| 2299 | |
| 2300 | if (presetParams->wfdVideoFmatFlag) { |
| 2301 | // set the video format as requested |
| 2302 | |
| 2303 | //switch(presetParams->wfdVideoFmt ) |
| 2304 | //{ |
| 2305 | // case e640x480p60: |
| 2306 | // ; |
| 2307 | // default: |
| 2308 | // set the mandatory |
| 2309 | // } |
| 2310 | } |
| 2311 | if (presetParams->wfdAudioFmatFlag) { |
| 2312 | // set the Audio format as requested |
| 2313 | |
| 2314 | //switch(presetParams->wfdAudioFmt ) |
| 2315 | //{ |
| 2316 | // case eMandatoryAudioMode: |
| 2317 | // ; |
| 2318 | // case eDefaultAudioMode: |
| 2319 | // ; |
| 2320 | |
| 2321 | // default: |
| 2322 | // set the mandatory |
| 2323 | // } |
| 2324 | } |
| 2325 | |
| 2326 | if (presetParams->wfdI2cFlag) { |
| 2327 | // enable / disable feature |
| 2328 | } |
| 2329 | if (presetParams->wfdVideoRecoveryFlag) { |
| 2330 | // enable / disable feature |
| 2331 | } |
| 2332 | if (presetParams->wfdPrefDisplayFlag) { |
| 2333 | // enable / disable feature |
| 2334 | } |
| 2335 | if (presetParams->wfdServiceDiscoveryFlag) { |
| 2336 | // enable / disable feature |
| 2337 | } |
| 2338 | if (presetParams->wfd3dVideoFlag) { |
| 2339 | // enable / disable feature |
| 2340 | } |
| 2341 | if (presetParams->wfdMultiTxStreamFlag) { |
| 2342 | // enable / disable feature |
| 2343 | } |
| 2344 | if (presetParams->wfdTimeSyncFlag) { |
| 2345 | // enable / disable feature |
| 2346 | } |
| 2347 | if (presetParams->wfdEDIDFlag) { |
| 2348 | // enable / disable feature |
| 2349 | } |
| 2350 | if (presetParams->wfdUIBCPrepareFlag) { |
| 2351 | // Provdes information to start valid WFD session to check UIBC operation. |
| 2352 | } |
| 2353 | if (presetParams->wfdCoupledCapFlag) { |
| 2354 | // enable / disable feature |
| 2355 | } |
| 2356 | if (presetParams->wfdOptionalFeatureFlag) { |
| 2357 | // disable all program specific optional features |
| 2358 | } |
| 2359 | if (presetParams->wfdSessionAvailFlag) { |
| 2360 | // enable / disable session available bit |
| 2361 | } |
| 2362 | if (presetParams->wfdDeviceDiscoverabilityFlag) { |
| 2363 | // enable / disable feature |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | if (presetParams->program == PROG_TYPE_WFDS) { |
| 2368 | if (presetParams->wfdsType == eAcceptPD) { |
| 2369 | // preset to accept PD request |
| 2370 | if (presetParams->wfdsConnectionCapabilityFlag == 1) { |
| 2371 | // use presetParams->wfdsConnectionCapability and set role accordingly |
| 2372 | } |
| 2373 | } |
| 2374 | if (presetParams->wfdsType == eRejectPD) { |
| 2375 | // preset to Reject PD request |
| 2376 | } |
| 2377 | if (presetParams->wfdsType == eIgnorePD) { |
| 2378 | // preset to Ignore PD request |
| 2379 | } |
| 2380 | if (presetParams->wfdsType == eRejectSession) { |
| 2381 | // preset to reject Session request |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | if (presetDone) { |
| 2386 | PresetParamsResp->status = STATUS_COMPLETE; |
| 2387 | } else { |
| 2388 | PresetParamsResp->status = STATUS_INVALID; |
| 2389 | } |
| 2390 | |
| 2391 | wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE*)PresetParamsResp, |
| 2392 | respBuf); |
| 2393 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2394 | |
| 2395 | return WFA_SUCCESS; |
| 2396 | } |
| 2397 | |
| 2398 | int wfaStaSet11n(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2399 | dutCmdResponse_t* v11nParamsResp = &gGenericResp; |
| 2400 | |
| 2401 | v11nParamsResp->status = STATUS_COMPLETE; |
| 2402 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE*)v11nParamsResp, respBuf); |
| 2403 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2404 | return WFA_SUCCESS; |
| 2405 | } |
| 2406 | int wfaStaSetWireless(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2407 | dutCmdResponse_t* staWirelessResp = &gGenericResp; |
| 2408 | |
| 2409 | staWirelessResp->status = STATUS_COMPLETE; |
| 2410 | wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE*)staWirelessResp, |
| 2411 | respBuf); |
| 2412 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2413 | return WFA_SUCCESS; |
| 2414 | } |
| 2415 | |
| 2416 | int wfaStaSendADDBA(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2417 | dutCmdResponse_t* staSendADDBAResp = &gGenericResp; |
| 2418 | |
| 2419 | wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE*)staSendADDBAResp, |
| 2420 | respBuf); |
| 2421 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2422 | return WFA_SUCCESS; |
| 2423 | } |
| 2424 | |
| 2425 | int wfaStaSetRIFS(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2426 | dutCmdResponse_t* staSetRIFSResp = &gGenericResp; |
| 2427 | |
| 2428 | wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE*)staSetRIFSResp, |
| 2429 | respBuf); |
| 2430 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2431 | |
| 2432 | return WFA_SUCCESS; |
| 2433 | } |
| 2434 | |
| 2435 | int wfaStaSendCoExistMGMT(int len, |
| 2436 | BYTE* caCmdBuf, |
| 2437 | int* respLen, |
| 2438 | BYTE* respBuf) { |
| 2439 | dutCmdResponse_t* staSendMGMTResp = &gGenericResp; |
| 2440 | |
| 2441 | wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE*)staSendMGMTResp, |
| 2442 | respBuf); |
| 2443 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2444 | |
| 2445 | return WFA_SUCCESS; |
| 2446 | } |
| 2447 | |
| 2448 | int wfaStaResetDefault(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2449 | caStaResetDefault_t* reset = (caStaResetDefault_t*)caCmdBuf; |
| 2450 | dutCmdResponse_t* ResetResp = &gGenericResp; |
| 2451 | |
| 2452 | // need to make your own command available for this, here is only an example |
| 2453 | sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog); |
| 2454 | sret = systemWithLog(gCmdStr); |
| 2455 | |
| 2456 | ResetResp->status = STATUS_COMPLETE; |
| 2457 | wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE*)ResetResp, respBuf); |
| 2458 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2459 | |
| 2460 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | #else |
| 2464 | |
Wojciech Jakobczyk | 01c627a | 2020-09-02 09:51:21 +0200 | [diff] [blame] | 2465 | int wfaStaSetRIFS(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2466 | caStaSetRIFS_t* setRifs = (caStaSetRIFS_t*)caCmdBuf; |
| 2467 | dutCmdResponse_t* staSetRIFSResp = &gGenericResp; |
| 2468 | |
| 2469 | DPRINT_INFO(WFA_OUT, "entering wfaStaSetRIFS ...\n"); |
| 2470 | DPRINT_INFO(WFA_OUT, "%s %d\n", setRifs->intf, setRifs->action); |
| 2471 | |
| 2472 | if (setRifs->action) { |
| 2473 | DPRINT_INFO(WFA_WNG, |
| 2474 | "command sta_set_rifs_test is deprecated and not implemented " |
| 2475 | "for action=enable\n"); |
| 2476 | |
| 2477 | staSetRIFSResp->status = STATUS_INVALID; |
| 2478 | wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, sizeof(staSetRIFSResp->status), |
| 2479 | (BYTE*)staSetRIFSResp, respBuf); |
| 2480 | *respLen = WFA_TLV_HDR_LEN + sizeof(staSetRIFSResp->status); |
| 2481 | |
| 2482 | return WFA_FAILURE; |
| 2483 | } |
| 2484 | |
| 2485 | DPRINT_INFO(WFA_WNG, |
| 2486 | "command sta_set_rifs_test is deprecated and will be ignored for " |
| 2487 | "action=disable\n"); |
| 2488 | |
| 2489 | staSetRIFSResp->status = STATUS_COMPLETE; |
| 2490 | wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, sizeof(staSetRIFSResp->status), |
| 2491 | (BYTE*)staSetRIFSResp, respBuf); |
| 2492 | *respLen = WFA_TLV_HDR_LEN + sizeof(staSetRIFSResp->status); |
| 2493 | |
| 2494 | return WFA_SUCCESS; |
| 2495 | } |
| 2496 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2497 | int wfaStaTestBedCmd(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2498 | dutCmdResponse_t* staCmdResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2499 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2500 | wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE*)staCmdResp, respBuf); |
| 2501 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2502 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2503 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2504 | } |
| 2505 | #endif |
| 2506 | |
| 2507 | /* |
| 2508 | * This is used to send a frame or action frame |
| 2509 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2510 | int wfaStaDevSendFrame(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2511 | dutCommand_t* cmd = (dutCommand_t*)caCmdBuf; |
| 2512 | /* uncomment it if needed */ |
| 2513 | // char *ifname = cmd->intf; |
| 2514 | dutCmdResponse_t* devSendResp = &gGenericResp; |
| 2515 | caStaDevSendFrame_t* sf = &cmd->cmdsu.sf; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2516 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2517 | DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n"); |
| 2518 | /* processing the frame */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2519 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2520 | switch (sf->program) { |
| 2521 | case PROG_TYPE_PMF: { |
| 2522 | pmfFrame_t* pmf = &sf->frameType.pmf; |
| 2523 | switch (pmf->eFrameName) { |
| 2524 | case PMF_TYPE_DISASSOC: { |
| 2525 | /* use the protected to set what type of key to send */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2526 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2527 | } break; |
| 2528 | case PMF_TYPE_DEAUTH: { |
| 2529 | } break; |
| 2530 | case PMF_TYPE_SAQUERY: { |
| 2531 | } break; |
| 2532 | case PMF_TYPE_AUTH: { |
| 2533 | } break; |
| 2534 | case PMF_TYPE_ASSOCREQ: { |
| 2535 | } break; |
| 2536 | case PMF_TYPE_REASSOCREQ: { |
| 2537 | } break; |
| 2538 | } |
| 2539 | } break; |
| 2540 | case PROG_TYPE_TDLS: { |
| 2541 | tdlsFrame_t* tdls = &sf->frameType.tdls; |
| 2542 | switch (tdls->eFrameName) { |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2543 | case TDLS_TYPE_DISCOVERY: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2544 | /* use the peer mac address to send the frame */ |
| 2545 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2546 | case TDLS_TYPE_SETUP: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2547 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2548 | case TDLS_TYPE_TEARDOWN: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2549 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2550 | case TDLS_TYPE_CHANNELSWITCH: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2551 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2552 | case TDLS_TYPE_NULLFRAME: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2553 | break; |
| 2554 | } |
| 2555 | } break; |
| 2556 | case PROG_TYPE_VENT: { |
| 2557 | ventFrame_t* vent = &sf->frameType.vent; |
| 2558 | switch (vent->type) { |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2559 | case VENT_TYPE_NEIGREQ: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2560 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2561 | case VENT_TYPE_TRANSMGMT: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2562 | break; |
| 2563 | } |
| 2564 | } break; |
| 2565 | case PROG_TYPE_WFD: { |
| 2566 | wfdFrame_t* wfd = &sf->frameType.wfd; |
| 2567 | switch (wfd->eframe) { |
| 2568 | case WFD_FRAME_PRBREQ: { |
| 2569 | /* send probe req */ |
| 2570 | } break; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 2571 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2572 | case WFD_FRAME_PRBREQ_TDLS_REQ: { |
| 2573 | /* send tunneled tdls probe req */ |
| 2574 | } break; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 2575 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2576 | case WFD_FRAME_11V_TIMING_MSR_REQ: { |
| 2577 | /* send 11v timing mearurement request */ |
| 2578 | } break; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 2579 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2580 | case WFD_FRAME_RTSP: { |
| 2581 | /* send WFD RTSP messages*/ |
| 2582 | // fetch the type of RTSP message and send it. |
| 2583 | switch (wfd->eRtspMsgType) { |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2584 | case WFD_RTSP_PAUSE: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2585 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2586 | case WFD_RTSP_PLAY: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2587 | //send RTSP PLAY |
| 2588 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2589 | case WFD_RTSP_TEARDOWN: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2590 | //send RTSP TEARDOWN |
| 2591 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2592 | case WFD_RTSP_TRIG_PAUSE: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2593 | //send RTSP TRIGGER PAUSE |
| 2594 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2595 | case WFD_RTSP_TRIG_PLAY: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2596 | //send RTSP TRIGGER PLAY |
| 2597 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2598 | case WFD_RTSP_TRIG_TEARDOWN: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2599 | //send RTSP TRIGGER TEARDOWN |
| 2600 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2601 | case WFD_RTSP_SET_PARAMETER: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2602 | //send RTSP SET PARAMETER |
| 2603 | if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD) { |
| 2604 | //send RTSP SET PARAMETER message for UIBC keyboard |
| 2605 | } |
| 2606 | if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE) { |
| 2607 | //send RTSP SET PARAMETER message for UIBC Mouse |
| 2608 | } else if (wfd->eSetParams == WFD_CAP_RE_NEGO) { |
| 2609 | //send RTSP SET PARAMETER message Capability re-negotiation |
| 2610 | } else if (wfd->eSetParams == WFD_STANDBY) { |
| 2611 | //send RTSP SET PARAMETER message for standby |
| 2612 | } else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE) { |
| 2613 | //send RTSP SET PARAMETER message for UIBC settings enable |
| 2614 | } else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE) { |
| 2615 | //send RTSP SET PARAMETER message for UIBC settings disable |
| 2616 | } else if (wfd->eSetParams == WFD_ROUTE_AUDIO) { |
| 2617 | //send RTSP SET PARAMETER message for route audio |
| 2618 | } else if (wfd->eSetParams == WFD_3D_VIDEOPARAM) { |
| 2619 | //send RTSP SET PARAMETER message for 3D video parameters |
| 2620 | } else if (wfd->eSetParams == WFD_2D_VIDEOPARAM) { |
| 2621 | //send RTSP SET PARAMETER message for 2D video parameters |
| 2622 | } |
| 2623 | break; |
| 2624 | } |
| 2625 | } break; |
| 2626 | } |
| 2627 | } break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2628 | /* not need to support HS2 release 1, due to very short time period */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2629 | case PROG_TYPE_HS2_R2: { |
| 2630 | /* type of frames */ |
| 2631 | hs2Frame_t* hs2 = &sf->frameType.hs2_r2; |
| 2632 | switch (hs2->eframe) { |
| 2633 | case HS2_FRAME_ANQPQuery: { |
| 2634 | } break; |
| 2635 | case HS2_FRAME_DLSRequest: { |
| 2636 | } break; |
| 2637 | case HS2_FRAME_GARPReq: { |
| 2638 | } break; |
| 2639 | case HS2_FRAME_GARPRes: { |
| 2640 | } break; |
| 2641 | case HS2_FRAME_NeighAdv: { |
| 2642 | } |
| 2643 | case HS2_FRAME_ARPProbe: { |
| 2644 | } |
| 2645 | case HS2_FRAME_ARPAnnounce: { |
| 2646 | } break; |
| 2647 | case HS2_FRAME_NeighSolicitReq: { |
| 2648 | } break; |
| 2649 | case HS2_FRAME_ARPReply: { |
| 2650 | } break; |
| 2651 | } |
Dake Zhao | 9770820 | 2014-11-26 13:59:04 -0800 | [diff] [blame] | 2652 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2653 | } /* PROG_TYPE_HS2-R2 */ |
| 2654 | case PROG_TYPE_GEN: { |
| 2655 | /* General frames */ |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2656 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2657 | } |
| 2658 | devSendResp->status = STATUS_COMPLETE; |
| 2659 | wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE*)devSendResp, respBuf); |
| 2660 | *respLen = WFA_TLV_HDR_LEN + 4; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2661 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2662 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | /* |
| 2666 | * This is used to set a temporary MAC address of an interface |
| 2667 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2668 | int wfaStaSetMacAddr(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2669 | // Uncomment it if needed |
| 2670 | //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf; |
| 2671 | // char *ifname = cmd->intf; |
| 2672 | dutCmdResponse_t* staCmdResp = &gGenericResp; |
| 2673 | // Uncomment it if needed |
| 2674 | //char *macaddr = &cmd->cmdsu.macaddr[0]; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2675 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2676 | wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE*)staCmdResp, respBuf); |
| 2677 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2678 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2679 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2682 | int wfaStaDisconnect(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2683 | dutCommand_t* cmd = (dutCommand_t*)caCmdBuf; |
| 2684 | char* ifname = cmd->intf; |
| 2685 | char string[64]; |
| 2686 | char* token; |
| 2687 | FILE* tmpfd; |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2688 | dutCmdResponse_t* staDiscResp = &gGenericResp; |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2689 | uint32_t networkId; |
| 2690 | const char* tmpfile = "/tmp/.wfaStaDisconnectTmp"; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2691 | |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2692 | DPRINT_INFO(WFA_OUT, "Entering wfaStaDisconnect ...\n"); |
| 2693 | // Retrieve the network id. |
| 2694 | sprintf(gCmdStr, "wpa_cli.sh status > %s", tmpfile); |
| 2695 | sret = systemWithLog(gCmdStr); |
| 2696 | if (sret != 0) { |
| 2697 | RETURN_STA_CMD_ERROR(staDiscResp, STATUS_ERROR, |
| 2698 | "error getting wpa_supplicant status: %d\n", sret); |
| 2699 | } |
| 2700 | |
| 2701 | tmpfd = fopen(tmpfile, "r+"); |
| 2702 | if (tmpfd == NULL) { |
| 2703 | RETURN_STA_CMD_ERROR(staDiscResp, STATUS_ERROR, "temp file open failed\n"); |
| 2704 | } |
| 2705 | |
| 2706 | networkId = -1; |
| 2707 | for (;;) { |
| 2708 | if (fgets(string, sizeof(string), tmpfd) == NULL) { |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | if (strncmp(string, "id", 2) == 0) { |
| 2713 | token = strtok(string, "="); |
| 2714 | token = strtok(NULL, "="); |
| 2715 | if (token != NULL) { |
| 2716 | networkId = atoi(token); |
| 2717 | break; |
| 2718 | } |
| 2719 | } |
| 2720 | } |
| 2721 | fclose(tmpfd); |
| 2722 | |
Wojciech Jakobczyk | 5a22f90 | 2020-10-15 09:51:26 +0000 | [diff] [blame^] | 2723 | if (networkId != -1) { |
| 2724 | sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network %d > %s", ifname, |
| 2725 | networkId, tmpfile); |
| 2726 | sret = systemWithLog(gCmdStr); |
| 2727 | if (sret != 0) { |
| 2728 | RETURN_STA_CMD_ERROR(staDiscResp, STATUS_ERROR, |
| 2729 | "error disabling network: %d\n", sret); |
| 2730 | } |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2731 | |
Wojciech Jakobczyk | 5a22f90 | 2020-10-15 09:51:26 +0000 | [diff] [blame^] | 2732 | if (!readLine(tmpfile, string, sizeof(string))) { |
| 2733 | RETURN_STA_CMD_ERROR(staDiscResp, STATUS_ERROR, |
| 2734 | "unable to read command output\n"); |
| 2735 | } |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2736 | |
Wojciech Jakobczyk | 5a22f90 | 2020-10-15 09:51:26 +0000 | [diff] [blame^] | 2737 | if (strcmp(string, "OK") != 0) { |
| 2738 | RETURN_STA_CMD_ERROR(staDiscResp, STATUS_ERROR, |
| 2739 | "disable network failed, error: %s\n", string); |
| 2740 | } |
| 2741 | } else { |
| 2742 | DPRINT_INFO(WFA_OUT, "No network connected\n"); |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2743 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2744 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2745 | staDiscResp->status = STATUS_COMPLETE; |
Wojciech Jakobczyk | 90875a1 | 2020-09-03 12:41:03 +0200 | [diff] [blame] | 2746 | wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, sizeof(dutCmdResponse_t), |
| 2747 | (BYTE*)staDiscResp, respBuf); |
| 2748 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2749 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2750 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | /* Execute CLI, read the status from Environment variable */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2754 | int wfaExecuteCLI(char* CLI) { |
| 2755 | char* retstr; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2756 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2757 | sret = systemWithLog(CLI); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2758 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2759 | retstr = getenv("WFA_CLI_STATUS"); |
| 2760 | printf("cli status %s\n", retstr); |
| 2761 | return atoi(retstr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | /* Supporting Functions */ |
| 2765 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2766 | void wfaSendPing(tgPingStart_t* staPing, float* interval, int streamid) { |
| 2767 | int totalpkts, tos = -1; |
| 2768 | char cmdStr[256]; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2769 | // char *addr = staPing->dipaddr; |
| 2770 | #ifdef WFA_PC_CONSOLE |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2771 | char addr[40]; |
| 2772 | char bflag[] = "-b"; |
| 2773 | char* tmpstr; |
| 2774 | int inum = 0; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2775 | #else |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2776 | char bflag[] = " "; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2777 | #endif |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2778 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2779 | totalpkts = (int)(staPing->duration * staPing->frameRate); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2780 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2781 | #ifdef WFA_PC_CONSOLE |
| 2782 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2783 | printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d", streamid); |
| 2784 | |
| 2785 | strcpy(addr, staPing->dipaddr); |
| 2786 | printf("\nCS :the addr is %s ", addr); |
| 2787 | printf("\nCS :Inside the WFA_PC_CONSLE BLOCK"); |
| 2788 | printf("\nCS :the addr is %s ", addr); |
| 2789 | if (staPing->iptype == 2) { |
| 2790 | memset(bflag, 0, strlen(bflag)); |
| 2791 | } else { |
| 2792 | tmpstr = strtok(addr, "."); |
| 2793 | inum = atoi(tmpstr); |
| 2794 | |
| 2795 | printf("interval %f\n", *interval); |
| 2796 | |
| 2797 | if (inum >= 224 && inum <= 239) // multicast |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2798 | { |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2799 | } else // if not MC, check if it is BC address |
| 2800 | { |
| 2801 | printf("\nCS :Inside the BC address BLOCK"); |
| 2802 | printf("\nCS :the inum %d", inum); |
| 2803 | strtok(NULL, "."); |
| 2804 | //strtok(NULL, "."); |
| 2805 | tmpstr = strtok(NULL, "."); |
| 2806 | printf("tmpstr %s\n", tmpstr); |
| 2807 | inum = atoi(tmpstr); |
| 2808 | printf("\nCS : The string is %s", tmpstr); |
| 2809 | if (inum != 255) |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 2810 | memset(bflag, 0, strlen(bflag)); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2811 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2812 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2813 | #endif |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2814 | if (staPing->dscp >= 0) { |
| 2815 | tos = convertDscpToTos(staPing->dscp); |
| 2816 | if (tos < 0) |
| 2817 | printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp); |
| 2818 | } |
| 2819 | printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n", streamid, |
| 2820 | staPing->iptype); |
| 2821 | printf("IPtype : %i tos=%d", staPing->iptype, tos); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2822 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2823 | if (staPing->iptype == 2) { |
| 2824 | if (tos > 0) |
| 2825 | sprintf(cmdStr, |
| 2826 | "echo streamid=%i > /tmp/spout_%d.txt;wfaping6.sh %s %s -i %f -c " |
| 2827 | "%i -Q %d -s %i -q >> /tmp/spout_%d.txt 2>/dev/null", |
| 2828 | streamid, streamid, bflag, staPing->dipaddr, *interval, totalpkts, |
| 2829 | tos, staPing->frameSize, streamid); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 2830 | else |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2831 | sprintf(cmdStr, |
| 2832 | "echo streamid=%i > /tmp/spout_%d.txt;wfaping6.sh %s %s -i %f -c " |
| 2833 | "%i -s %i -q >> /tmp/spout_%d.txt 2>/dev/null", |
| 2834 | streamid, streamid, bflag, staPing->dipaddr, *interval, totalpkts, |
| 2835 | staPing->frameSize, streamid); |
Wojciech Jakobczyk | 317dc71 | 2020-08-27 12:46:16 +0200 | [diff] [blame] | 2836 | sret = systemWithLog(cmdStr); |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2837 | printf("\nCS : The command string is %s", cmdStr); |
| 2838 | } else { |
| 2839 | if (tos > 0) |
| 2840 | sprintf(cmdStr, |
| 2841 | "echo streamid=%i > /tmp/spout_%d.txt;wfaping.sh %s %s -i %f -c " |
| 2842 | "%i -Q %d -s %i -q >> /tmp/spout_%d.txt 2>/dev/null", |
| 2843 | streamid, streamid, bflag, staPing->dipaddr, *interval, totalpkts, |
| 2844 | tos, staPing->frameSize, streamid); |
| 2845 | else |
| 2846 | sprintf(cmdStr, |
| 2847 | "echo streamid=%i > /tmp/spout_%d.txt;wfaping.sh %s %s -i %f -c " |
| 2848 | "%i -s %i -q >> /tmp/spout_%d.txt 2>/dev/null", |
| 2849 | streamid, streamid, bflag, staPing->dipaddr, *interval, totalpkts, |
| 2850 | staPing->frameSize, streamid); |
| 2851 | sret = systemWithLog(cmdStr); |
| 2852 | printf("\nCS : The command string is %s", cmdStr); |
| 2853 | } |
| 2854 | sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt", streamid); |
| 2855 | sret = systemWithLog(cmdStr); |
| 2856 | printf("\nCS : The command string is %s", cmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2857 | } |
| 2858 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2859 | int wfaStopPing(dutCmdResponse_t* stpResp, int streamid) { |
| 2860 | char strout[256]; |
| 2861 | FILE* tmpfile = NULL; |
| 2862 | char cmdStr[128]; |
| 2863 | printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid); |
| 2864 | sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt", streamid); |
| 2865 | sret = systemWithLog(cmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2866 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2867 | printf("\nCS : The command string is %s", cmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2868 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2869 | sret = systemWithLog("stoping.sh /tmp/pid.txt ; sleep 2"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2870 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2871 | sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt", streamid); |
| 2872 | sret = systemWithLog(cmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2873 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2874 | printf("\nCS : The command string is %s", cmdStr); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2875 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2876 | tmpfile = fopen("/tmp/stpsta.txt", "r+"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2877 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2878 | if (tmpfile == NULL) { |
| 2879 | return WFA_FAILURE; |
| 2880 | } |
| 2881 | |
| 2882 | if (fscanf(tmpfile, "%s", strout) != EOF) { |
| 2883 | if (*strout == '\0') { |
| 2884 | stpResp->cmdru.pingStp.sendCnt = 0; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2887 | else |
| 2888 | stpResp->cmdru.pingStp.sendCnt = atoi(strout); |
| 2889 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2890 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2891 | printf("\nwfaStopPing after scan sent count %i\n", |
| 2892 | stpResp->cmdru.pingStp.sendCnt); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2893 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2894 | if (fscanf(tmpfile, "%s", strout) != EOF) { |
| 2895 | if (*strout == '\0') { |
| 2896 | stpResp->cmdru.pingStp.repliedCnt = 0; |
| 2897 | } else |
| 2898 | stpResp->cmdru.pingStp.repliedCnt = atoi(strout); |
| 2899 | } |
| 2900 | printf("wfaStopPing after scan replied count %i\n", |
| 2901 | stpResp->cmdru.pingStp.repliedCnt); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2902 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2903 | fclose(tmpfile); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2904 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2905 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2908 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2909 | * wfaStaGetP2pDevAddress(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2910 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2911 | int wfaStaGetP2pDevAddress(int len, |
| 2912 | BYTE* caCmdBuf, |
| 2913 | int* respLen, |
| 2914 | BYTE* respBuf) { |
| 2915 | dutCmdResponse_t infoResp; |
| 2916 | /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2917 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2918 | printf("\n Entry wfaStaGetP2pDevAddress... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2919 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2920 | // Fetch the device ID and store into infoResp->cmdru.devid |
| 2921 | //strcpy(infoResp->cmdru.devid, str); |
| 2922 | strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2923 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2924 | infoResp.status = STATUS_COMPLETE; |
| 2925 | wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), |
| 2926 | (BYTE*)&infoResp, respBuf); |
| 2927 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2928 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2929 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2932 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2933 | * wfaStaSetP2p(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2934 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2935 | int wfaStaSetP2p(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2936 | dutCmdResponse_t infoResp; |
| 2937 | /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2938 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2939 | printf("\n Entry wfaStaSetP2p... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2940 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2941 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2942 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2943 | infoResp.status = STATUS_COMPLETE; |
| 2944 | wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 2945 | respBuf); |
| 2946 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2947 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2948 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2949 | } |
| 2950 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2951 | * wfaStaP2pConnect(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2952 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2953 | int wfaStaP2pConnect(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2954 | dutCmdResponse_t infoResp; |
| 2955 | /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2956 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2957 | printf("\n Entry wfaStaP2pConnect... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2958 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2959 | // Implement the function and does not return anything. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2960 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2961 | infoResp.status = STATUS_COMPLETE; |
| 2962 | wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 2963 | respBuf); |
| 2964 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2965 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2966 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2970 | * wfaStaStartAutoGo(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2971 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2972 | int wfaStaStartAutoGo(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 2973 | dutCmdResponse_t infoResp; |
| 2974 | //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2975 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2976 | printf("\n Entry wfaStaStartAutoGo... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2977 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2978 | // Fetch the group ID and store into infoResp->cmdru.grpid |
| 2979 | strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2980 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2981 | infoResp.status = STATUS_COMPLETE; |
| 2982 | wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), |
| 2983 | (BYTE*)&infoResp, respBuf); |
| 2984 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2985 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2986 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2989 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 2990 | * wfaStaP2pStartGrpFormation(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2991 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2992 | int wfaStaP2pStartGrpFormation(int len, |
| 2993 | BYTE* caCmdBuf, |
| 2994 | int* respLen, |
| 2995 | BYTE* respBuf) { |
| 2996 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2997 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 2998 | printf("\n Entry wfaStaP2pStartGrpFormation... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 2999 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3000 | strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT"); |
| 3001 | strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3002 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3003 | infoResp.status = STATUS_COMPLETE; |
| 3004 | wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), |
| 3005 | (BYTE*)&infoResp, respBuf); |
| 3006 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3007 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3008 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3011 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3012 | * wfaStaP2pDissolve(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3013 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3014 | int wfaStaP2pDissolve(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3015 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3016 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3017 | printf("\n Entry wfaStaP2pDissolve... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3018 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3019 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3020 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3021 | infoResp.status = STATUS_COMPLETE; |
| 3022 | wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), |
| 3023 | (BYTE*)&infoResp, respBuf); |
| 3024 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3025 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3026 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3030 | * wfaStaSendP2pInvReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3031 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3032 | int wfaStaSendP2pInvReq(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3033 | dutCmdResponse_t infoResp; |
| 3034 | /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3035 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3036 | printf("\n Entry wfaStaSendP2pInvReq... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3037 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3038 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3039 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3040 | infoResp.status = STATUS_COMPLETE; |
| 3041 | wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), |
| 3042 | (BYTE*)&infoResp, respBuf); |
| 3043 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3044 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3045 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3048 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3049 | * wfaStaAcceptP2pInvReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3050 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3051 | int wfaStaAcceptP2pInvReq(int len, |
| 3052 | BYTE* caCmdBuf, |
| 3053 | int* respLen, |
| 3054 | BYTE* respBuf) { |
| 3055 | dutCmdResponse_t infoResp; |
| 3056 | /* uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3057 | * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf; |
| 3058 | */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3059 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3060 | printf("\n Entry wfaStaAcceptP2pInvReq... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3061 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3062 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3063 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3064 | infoResp.status = STATUS_COMPLETE; |
| 3065 | wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), |
| 3066 | (BYTE*)&infoResp, respBuf); |
| 3067 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3068 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3069 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3072 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3073 | * wfaStaSendP2pProvDisReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3074 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3075 | int wfaStaSendP2pProvDisReq(int len, |
| 3076 | BYTE* caCmdBuf, |
| 3077 | int* respLen, |
| 3078 | BYTE* respBuf) { |
| 3079 | dutCmdResponse_t infoResp; |
| 3080 | /* uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3081 | * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf; |
| 3082 | */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3083 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3084 | printf("\n Entry wfaStaSendP2pProvDisReq... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3085 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3086 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3087 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3088 | infoResp.status = STATUS_COMPLETE; |
| 3089 | wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), |
| 3090 | (BYTE*)&infoResp, respBuf); |
| 3091 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3092 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3093 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3097 | * wfaStaSetWpsPbc(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3098 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3099 | int wfaStaSetWpsPbc(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3100 | dutCmdResponse_t infoResp; |
| 3101 | /* uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3102 | * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf; |
| 3103 | */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3104 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3105 | printf("\n Entry wfaStaSetWpsPbc... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3106 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3107 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3108 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3109 | infoResp.status = STATUS_COMPLETE; |
| 3110 | wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), |
| 3111 | (BYTE*)&infoResp, respBuf); |
| 3112 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3113 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3114 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3118 | * wfaStaWpsReadPin(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3119 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3120 | int wfaStaWpsReadPin(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3121 | dutCmdResponse_t infoResp; |
| 3122 | /* uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3123 | * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf; |
| 3124 | */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3125 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3126 | printf("\n Entry wfaStaWpsReadPin... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3127 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3128 | // Fetch the device PIN and put in infoResp->cmdru.wpsPin |
| 3129 | //strcpy(infoResp->cmdru.wpsPin, "12345678"); |
| 3130 | strcpy(&infoResp.cmdru.wpsPin[0], "1234456"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3131 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3132 | infoResp.status = STATUS_COMPLETE; |
| 3133 | wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), |
| 3134 | (BYTE*)&infoResp, respBuf); |
| 3135 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3136 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3137 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3140 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3141 | * wfaStaWpsReadLabel(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3142 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3143 | int wfaStaWpsReadLabel(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3144 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3145 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3146 | printf("\n Entry wfaStaWpsReadLabel... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3147 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3148 | // Fetch the device Label and put in infoResp->cmdru.wpsPin |
| 3149 | //strcpy(infoResp->cmdru.wpsPin, "12345678"); |
| 3150 | strcpy(&infoResp.cmdru.wpsPin[0], "1234456"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3151 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3152 | infoResp.status = STATUS_COMPLETE; |
| 3153 | wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), |
| 3154 | (BYTE*)&infoResp, respBuf); |
| 3155 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3156 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3157 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3160 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3161 | * wfaStaWpsEnterPin(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3162 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3163 | int wfaStaWpsEnterPin(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3164 | dutCmdResponse_t infoResp; |
| 3165 | /* uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3166 | * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf; |
| 3167 | */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3168 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3169 | printf("\n Entry wfaStaWpsEnterPin... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3170 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3171 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3172 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3173 | infoResp.status = STATUS_COMPLETE; |
| 3174 | wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), |
| 3175 | (BYTE*)&infoResp, respBuf); |
| 3176 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3177 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3178 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3179 | } |
| 3180 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3181 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3182 | * wfaStaGetPsk(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3183 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3184 | int wfaStaGetPsk(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3185 | dutCmdResponse_t infoResp; |
| 3186 | /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3187 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3188 | printf("\n Entry wfaStaGetPsk... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3189 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3190 | // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo |
| 3191 | strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456"); |
| 3192 | strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3193 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3194 | infoResp.status = STATUS_COMPLETE; |
| 3195 | wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 3196 | respBuf); |
| 3197 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3198 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3199 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3203 | * wfaStaP2pReset(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3204 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3205 | int wfaStaP2pReset(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3206 | dutCmdResponse_t infoResp; |
| 3207 | /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3208 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3209 | printf("\n Entry wfaStaP2pReset... "); |
| 3210 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3211 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3212 | infoResp.status = STATUS_COMPLETE; |
| 3213 | wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 3214 | respBuf); |
| 3215 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3216 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3217 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3220 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3221 | * wfaStaGetP2pIpConfig(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3222 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3223 | int wfaStaGetP2pIpConfig(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3224 | dutCmdResponse_t infoResp; |
| 3225 | /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3226 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3227 | caStaGetIpConfigResp_t* ifinfo = &(infoResp.cmdru.getIfconfig); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3228 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3229 | printf("\n Entry wfaStaGetP2pIpConfig... "); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3230 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3231 | ifinfo->isDhcp = 0; |
| 3232 | strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111"); |
| 3233 | strcpy(&(ifinfo->mask[0]), "255.255.255.0"); |
| 3234 | strcpy(&(ifinfo->dns[0][0]), "192.165.100.1"); |
| 3235 | strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3236 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3237 | infoResp.status = STATUS_COMPLETE; |
| 3238 | wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), |
| 3239 | (BYTE*)&infoResp, respBuf); |
| 3240 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3241 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3242 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3245 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3246 | * wfaStaSendServiceDiscoveryReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3247 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3248 | int wfaStaSendServiceDiscoveryReq(int len, |
| 3249 | BYTE* caCmdBuf, |
| 3250 | int* respLen, |
| 3251 | BYTE* respBuf) { |
| 3252 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3253 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3254 | printf("\n Entry wfaStaSendServiceDiscoveryReq... "); |
| 3255 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3256 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3257 | infoResp.status = STATUS_COMPLETE; |
| 3258 | wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, |
| 3259 | sizeof(infoResp), (BYTE*)&infoResp, respBuf); |
| 3260 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3261 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3262 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3263 | } |
| 3264 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3265 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3266 | * wfaStaSendP2pPresenceReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3267 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3268 | int wfaStaSendP2pPresenceReq(int len, |
| 3269 | BYTE* caCmdBuf, |
| 3270 | int* respLen, |
| 3271 | BYTE* respBuf) { |
| 3272 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3273 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3274 | infoResp.status = STATUS_COMPLETE; |
| 3275 | wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), |
| 3276 | (BYTE*)&infoResp, respBuf); |
| 3277 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3278 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3279 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3283 | * wfaStaSetSleepReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3284 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3285 | int wfaStaSetSleepReq(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3286 | dutCmdResponse_t infoResp; |
| 3287 | /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3288 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3289 | printf("\n Entry wfaStaSetSleepReq... "); |
| 3290 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3291 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3292 | infoResp.status = STATUS_COMPLETE; |
| 3293 | wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), |
| 3294 | (BYTE*)&infoResp, respBuf); |
| 3295 | *respLen = WFA_TLV_HDR_LEN + 4; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3296 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3297 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3301 | * wfaStaSetOpportunisticPsReq(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3302 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3303 | int wfaStaSetOpportunisticPsReq(int len, |
| 3304 | BYTE* caCmdBuf, |
| 3305 | int* respLen, |
| 3306 | BYTE* respBuf) { |
| 3307 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3308 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3309 | printf("\n Entry wfaStaSetOpportunisticPsReq... "); |
| 3310 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3311 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3312 | infoResp.status = STATUS_COMPLETE; |
| 3313 | wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), |
| 3314 | (BYTE*)&infoResp, respBuf); |
| 3315 | *respLen = WFA_TLV_HDR_LEN + 4; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3316 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3317 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3318 | } |
| 3319 | #ifndef WFA_STA_TB |
| 3320 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3321 | * wfaStaPresetParams(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3322 | */ |
| 3323 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3324 | int wfaStaPresetParams(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3325 | dutCmdResponse_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3326 | |
Wojciech Jakobczyk | a1e5322 | 2020-09-07 10:16:10 +0200 | [diff] [blame] | 3327 | DPRINT_INFO(WFA_WNG, "command sta_preset_testparameters will be ignored\n"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3328 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3329 | infoResp.status = STATUS_COMPLETE; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3330 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3331 | wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE*)&infoResp, |
| 3332 | respBuf); |
| 3333 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3334 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3335 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3336 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3337 | int wfaStaSet11n(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3338 | dutCmdResponse_t infoResp; |
| 3339 | dutCmdResponse_t* v11nParamsResp = &infoResp; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3340 | |
Wojciech Jakobczyk | a1e5322 | 2020-09-07 10:16:10 +0200 | [diff] [blame] | 3341 | DPRINT_INFO(WFA_WNG, "command sta_set_11n will be ignored\n"); |
| 3342 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3343 | #ifdef WFA_11N_SUPPORT_ONLY |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3344 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3345 | caSta11n_t* v11nParams = (caSta11n_t*)caCmdBuf; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3346 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3347 | int st = 0; // SUCCESS |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3348 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3349 | DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n"); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3350 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3351 | if (v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2) { |
| 3352 | // implement the funciton |
| 3353 | if (st != 0) { |
| 3354 | v11nParamsResp->status = STATUS_ERROR; |
| 3355 | strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed"); |
| 3356 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3357 | (BYTE*)v11nParamsResp, respBuf); |
| 3358 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3359 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3360 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3361 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3362 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3363 | if (v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2) { |
| 3364 | // implement the funciton |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3365 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3366 | if (st != 0) { |
| 3367 | v11nParamsResp->status = STATUS_ERROR; |
| 3368 | strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed"); |
| 3369 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3370 | (BYTE*)v11nParamsResp, respBuf); |
| 3371 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3372 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3373 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3374 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3375 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3376 | if (v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2) { |
| 3377 | // implement the funciton |
| 3378 | if (st != 0) { |
| 3379 | v11nParamsResp->status = STATUS_ERROR; |
| 3380 | strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed"); |
| 3381 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3382 | (BYTE*)v11nParamsResp, respBuf); |
| 3383 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3384 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3385 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3386 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3387 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3388 | if (v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2) { |
| 3389 | // implement the funciton |
| 3390 | if (st != 0) { |
| 3391 | v11nParamsResp->status = STATUS_ERROR; |
| 3392 | strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed"); |
| 3393 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3394 | (BYTE*)v11nParamsResp, respBuf); |
| 3395 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3396 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3397 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3398 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3399 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3400 | if (v11nParams->mcs32 != 0xFF && v11nParams->mcs32 < 2 && |
| 3401 | v11nParams->mcs_fixedrate[0] != '\0') { |
| 3402 | // implement the funciton |
| 3403 | //st = wfaExecuteCLI(gCmdStr); |
| 3404 | if (st != 0) { |
| 3405 | v11nParamsResp->status = STATUS_ERROR; |
| 3406 | strcpy(v11nParamsResp->cmdru.info, "set_mcs failed"); |
| 3407 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3408 | (BYTE*)v11nParamsResp, respBuf); |
| 3409 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3410 | return FALSE; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3411 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3412 | } else if (v11nParams->mcs32 != 0xFF && v11nParams->mcs32 < 2 && |
| 3413 | v11nParams->mcs_fixedrate[0] == '\0') { |
| 3414 | // implement the funciton |
| 3415 | //st = wfaExecuteCLI(gCmdStr); |
| 3416 | if (st != 0) { |
| 3417 | v11nParamsResp->status = STATUS_ERROR; |
| 3418 | strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed"); |
| 3419 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3420 | (BYTE*)v11nParamsResp, respBuf); |
| 3421 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3422 | return FALSE; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3423 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3424 | } else if (v11nParams->mcs32 == 0xFF && |
| 3425 | v11nParams->mcs_fixedrate[0] != '\0') { |
| 3426 | // implement the funciton |
| 3427 | //st = wfaExecuteCLI(gCmdStr); |
| 3428 | if (st != 0) { |
| 3429 | v11nParamsResp->status = STATUS_ERROR; |
| 3430 | strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed"); |
| 3431 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3432 | (BYTE*)v11nParamsResp, respBuf); |
| 3433 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3434 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3435 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3436 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3437 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3438 | if (v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2) { |
| 3439 | // implement the funciton |
| 3440 | //st = wfaExecuteCLI(gCmdStr); |
| 3441 | if (st != 0) { |
| 3442 | v11nParamsResp->status = STATUS_ERROR; |
| 3443 | strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed"); |
| 3444 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3445 | (BYTE*)v11nParamsResp, respBuf); |
| 3446 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3447 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3448 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3449 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3450 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3451 | if (v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2) { |
| 3452 | // implement the funciton |
| 3453 | //st = wfaExecuteCLI(gCmdStr); |
| 3454 | if (st != 0) { |
| 3455 | v11nParamsResp->status = STATUS_ERROR; |
| 3456 | strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed"); |
| 3457 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3458 | (BYTE*)v11nParamsResp, respBuf); |
| 3459 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3460 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3461 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3462 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3463 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3464 | if (v11nParams->smps != 0xFFFF) { |
| 3465 | if (v11nParams->smps == 0) { |
| 3466 | // implement the funciton |
| 3467 | //st = wfaExecuteCLI(gCmdStr); |
| 3468 | } else if (v11nParams->smps == 1) { |
| 3469 | // implement the funciton |
| 3470 | //st = wfaExecuteCLI(gCmdStr); |
| 3471 | ; |
| 3472 | } else if (v11nParams->smps == 2) { |
| 3473 | // implement the funciton |
| 3474 | //st = wfaExecuteCLI(gCmdStr); |
| 3475 | ; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3476 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3477 | if (st != 0) { |
| 3478 | v11nParamsResp->status = STATUS_ERROR; |
| 3479 | strcpy(v11nParamsResp->cmdru.info, "set_smps failed"); |
| 3480 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3481 | (BYTE*)v11nParamsResp, respBuf); |
| 3482 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3483 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3484 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3485 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3486 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3487 | if (v11nParams->stbc_rx != 0xFFFF) { |
| 3488 | // implement the funciton |
| 3489 | //st = wfaExecuteCLI(gCmdStr); |
| 3490 | if (st != 0) { |
| 3491 | v11nParamsResp->status = STATUS_ERROR; |
| 3492 | strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed"); |
| 3493 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3494 | (BYTE*)v11nParamsResp, respBuf); |
| 3495 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3496 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3497 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3498 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3499 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3500 | if (v11nParams->width[0] != '\0') { |
| 3501 | // implement the funciton |
| 3502 | //st = wfaExecuteCLI(gCmdStr); |
| 3503 | if (st != 0) { |
| 3504 | v11nParamsResp->status = STATUS_ERROR; |
| 3505 | strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed"); |
| 3506 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3507 | (BYTE*)v11nParamsResp, respBuf); |
| 3508 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3509 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3510 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3511 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3512 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3513 | if (v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2) { |
| 3514 | // implement the funciton |
| 3515 | //st = wfaExecuteCLI(gCmdStr); |
| 3516 | if (st != 0) { |
| 3517 | v11nParamsResp->status = STATUS_ERROR; |
| 3518 | strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed"); |
| 3519 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3520 | (BYTE*)v11nParamsResp, respBuf); |
| 3521 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3522 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3523 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3524 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3525 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3526 | if (v11nParams->txsp_stream != 0 && v11nParams->txsp_stream < 4) { |
| 3527 | // implement the funciton |
| 3528 | //st = wfaExecuteCLI(gCmdStr); |
| 3529 | if (st != 0) { |
| 3530 | v11nParamsResp->status = STATUS_ERROR; |
| 3531 | strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed"); |
| 3532 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3533 | (BYTE*)v11nParamsResp, respBuf); |
| 3534 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3535 | return FALSE; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3536 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | if (v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4) { |
| 3540 | // implement the funciton |
| 3541 | //st = wfaExecuteCLI(gCmdStr); |
| 3542 | if (st != 0) { |
| 3543 | v11nParamsResp->status = STATUS_ERROR; |
| 3544 | strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed"); |
| 3545 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), |
| 3546 | (BYTE*)v11nParamsResp, respBuf); |
| 3547 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3548 | return FALSE; |
| 3549 | } |
| 3550 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3551 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3552 | #endif |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3553 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3554 | v11nParamsResp->status = STATUS_COMPLETE; |
| 3555 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE*)v11nParamsResp, respBuf); |
| 3556 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3557 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3558 | } |
Wojciech Jakobczyk | a1e5322 | 2020-09-07 10:16:10 +0200 | [diff] [blame] | 3559 | |
| 3560 | int wfaStaSetWireless(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3561 | dutCmdResponse_t* staWirelessResp = &gGenericResp; |
| 3562 | |
| 3563 | DPRINT_INFO(WFA_WNG, "command sta_set_wireless will be ignored\n"); |
| 3564 | |
| 3565 | staWirelessResp->status = STATUS_COMPLETE; |
| 3566 | wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE*)staWirelessResp, |
| 3567 | respBuf); |
| 3568 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3569 | return WFA_SUCCESS; |
| 3570 | } |
| 3571 | |
| 3572 | int wfaStaSendADDBA(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3573 | dutCmdResponse_t* staSendADDBAResp = &gGenericResp; |
| 3574 | |
| 3575 | DPRINT_INFO(WFA_WNG, "command sta_send_addba will be ignored\n"); |
| 3576 | |
| 3577 | staSendADDBAResp->status = STATUS_COMPLETE; |
| 3578 | wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE*)staSendADDBAResp, |
| 3579 | respBuf); |
| 3580 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3581 | return WFA_SUCCESS; |
| 3582 | } |
| 3583 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3584 | #endif |
| 3585 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3586 | * wfaStaAddArpTableEntry(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3587 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3588 | int wfaStaAddArpTableEntry(int len, |
| 3589 | BYTE* caCmdBuf, |
| 3590 | int* respLen, |
| 3591 | BYTE* respBuf) { |
| 3592 | dutCmdResponse_t infoResp; |
| 3593 | /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3594 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3595 | printf("\n Entry wfastaAddARPTableEntry... "); |
| 3596 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3597 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3598 | infoResp.status = STATUS_COMPLETE; |
| 3599 | wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), |
| 3600 | (BYTE*)&infoResp, respBuf); |
| 3601 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3602 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3603 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3607 | * wfaStaBlockICMPResponse(): |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3608 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3609 | int wfaStaBlockICMPResponse(int len, |
| 3610 | BYTE* caCmdBuf, |
| 3611 | int* respLen, |
| 3612 | BYTE* respBuf) { |
| 3613 | dutCmdResponse_t infoResp; |
| 3614 | /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3615 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3616 | printf("\n Entry wfaStaBlockICMPResponse... "); |
| 3617 | // Implement the function and this does not return any thing back. |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3618 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3619 | infoResp.status = STATUS_COMPLETE; |
| 3620 | wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), |
| 3621 | (BYTE*)&infoResp, respBuf); |
| 3622 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3623 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3624 | return WFA_SUCCESS; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3625 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3626 | |
| 3627 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3628 | * wfaStaSetRadio(): |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3629 | */ |
| 3630 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3631 | int wfaStaSetRadio(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3632 | dutCommand_t* setRadio = (dutCommand_t*)caCmdBuf; |
| 3633 | dutCmdResponse_t* staCmdResp = &gGenericResp; |
| 3634 | caStaSetRadio_t* sr = &setRadio->cmdsu.sr; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3635 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3636 | if (sr->mode == WFA_OFF) { |
| 3637 | // turn radio off |
| 3638 | } else { |
| 3639 | // always turn the radio on |
| 3640 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3641 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3642 | staCmdResp->status = STATUS_COMPLETE; |
| 3643 | wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE*)staCmdResp, respBuf); |
| 3644 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3645 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3646 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3649 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3650 | * wfaStaSetRFeature(): |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3651 | */ |
| 3652 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3653 | int wfaStaSetRFeature(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3654 | dutCommand_t* dutCmd = (dutCommand_t*)caCmdBuf; |
| 3655 | caStaRFeat_t* rfeat = &dutCmd->cmdsu.rfeat; |
| 3656 | dutCmdResponse_t* caResp = &gGenericResp; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3657 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3658 | if (strcasecmp(rfeat->prog, "tdls") == 0) { |
| 3659 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3660 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3661 | caResp->status = STATUS_COMPLETE; |
| 3662 | wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE*)caResp, respBuf); |
| 3663 | *respLen = WFA_TLV_HDR_LEN + 4; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3664 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3665 | return WFA_SUCCESS; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3668 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3669 | * wfaStaStartWfdConnection(): |
| 3670 | */ |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3671 | int wfaStaStartWfdConnection(int len, |
| 3672 | BYTE* caCmdBuf, |
| 3673 | int* respLen, |
| 3674 | BYTE* respBuf) { |
| 3675 | dutCmdResponse_t infoResp; |
| 3676 | //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3677 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3678 | printf("\n Entry wfaStaStartWfdConnection... "); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3679 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3680 | // Fetch the GrpId and WFD session and return |
| 3681 | strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890"); |
| 3682 | strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY"); |
| 3683 | strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3684 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3685 | infoResp.status = STATUS_COMPLETE; |
| 3686 | wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), |
| 3687 | (BYTE*)&infoResp, respBuf); |
| 3688 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3689 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3690 | return WFA_SUCCESS; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3691 | } |
| 3692 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3693 | * wfaStaCliCommand(): |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3694 | */ |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3695 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3696 | int wfaStaCliCommand(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3697 | char cmdName[32]; |
| 3698 | char *pcmdStr = NULL, *str; |
| 3699 | int st = 1; |
| 3700 | char CmdStr[WFA_CMD_STR_SZ]; |
| 3701 | FILE* wfaCliFd; |
| 3702 | char wfaCliBuff[64]; |
| 3703 | char retstr[256]; |
| 3704 | int CmdReturnFlag = 0; |
| 3705 | char tmp[256]; |
| 3706 | FILE* sh_pipe = NULL; |
| 3707 | caStaCliCmdResp_t infoResp; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3708 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3709 | printf("\nEntry wfaStaCliCommand; command Received: %s\n", caCmdBuf); |
| 3710 | memcpy(cmdName, strtok_r((char*)caCmdBuf, ",", (char**)&pcmdStr), 32); |
| 3711 | sprintf(CmdStr, "%s", cmdName); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3712 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3713 | for (;;) { |
| 3714 | // construct CLI standard cmd string |
| 3715 | str = strtok_r(NULL, ",", &pcmdStr); |
| 3716 | if (str == NULL || str[0] == '\0') |
| 3717 | break; |
| 3718 | else { |
| 3719 | strcat(strcat(CmdStr, " /"), str); |
| 3720 | str = strtok_r(NULL, ",", &pcmdStr); |
| 3721 | strcat(strcat(CmdStr, " "), str); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3722 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3723 | } |
| 3724 | // check the return process |
| 3725 | wfaCliFd = fopen("/etc/WfaEndpoint/wfa_cli.txt", "r"); |
| 3726 | if (wfaCliFd != NULL) { |
| 3727 | while (fgets(wfaCliBuff, 64, wfaCliFd) != NULL) { |
| 3728 | //printf("\nLine read from CLI file : %s",wfaCliBuff); |
| 3729 | if (ferror(wfaCliFd)) |
| 3730 | break; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3731 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3732 | str = strtok(wfaCliBuff, "-"); |
| 3733 | if (strcmp(str, cmdName) == 0) { |
| 3734 | str = strtok(NULL, ","); |
| 3735 | if (str != NULL) { |
| 3736 | if (strcmp(str, "TRUE") == 0) |
| 3737 | CmdReturnFlag = 1; |
| 3738 | } else |
| 3739 | printf( |
| 3740 | "ERR wfa_cli.txt, inside line format not end with , or missing " |
| 3741 | "TRUE/FALSE\n"); |
| 3742 | break; |
| 3743 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3744 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3745 | fclose(wfaCliFd); |
| 3746 | } else { |
| 3747 | printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n"); |
| 3748 | goto cleanup; |
| 3749 | } |
| 3750 | |
| 3751 | //printf("\n Command Return Flag : %d",CmdReturnFlag); |
| 3752 | memset(&retstr[0], '\0', 255); |
| 3753 | memset(&tmp[0], '\0', 255); |
| 3754 | sprintf(gCmdStr, "%s", CmdStr); |
| 3755 | printf("\nCLI Command -- %s\n", gCmdStr); |
| 3756 | |
| 3757 | sh_pipe = popen(gCmdStr, "r"); |
| 3758 | if (!sh_pipe) { |
| 3759 | printf("Error in opening pipe\n"); |
| 3760 | goto cleanup; |
| 3761 | } |
| 3762 | |
| 3763 | sleep(5); |
| 3764 | //tmp_val=getdelim(&retstr,255,"\n",sh_pipe); |
| 3765 | if (fgets(&retstr[0], 255, sh_pipe) == NULL) { |
| 3766 | printf("Getting NULL string in popen return\n"); |
| 3767 | goto cleanup; |
| 3768 | } else |
| 3769 | printf("popen return str=%s\n", retstr); |
| 3770 | |
| 3771 | sleep(2); |
| 3772 | if (pclose(sh_pipe) == -1) { |
| 3773 | printf("Error in closing shell cmd pipe\n"); |
| 3774 | goto cleanup; |
| 3775 | } |
| 3776 | sh_pipe = NULL; |
| 3777 | sleep(2); |
| 3778 | |
| 3779 | // find status first in output |
| 3780 | str = strtok_r((char*)retstr, "-", (char**)&pcmdStr); |
| 3781 | if (str != NULL) { |
| 3782 | memset(tmp, 0, 10); |
| 3783 | memcpy(tmp, str, 2); |
| 3784 | printf("cli status=%s\n", tmp); |
| 3785 | if (strlen(tmp) > 0) |
| 3786 | st = atoi(tmp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3787 | else |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3788 | printf("Missing status code\n"); |
| 3789 | } else { |
| 3790 | printf("wfaStaCliCommand no return code found\n"); |
| 3791 | } |
| 3792 | infoResp.resFlag = CmdReturnFlag; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3793 | |
Dake Zhao | 9770820 | 2014-11-26 13:59:04 -0800 | [diff] [blame] | 3794 | cleanup: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3795 | if (sh_pipe) |
| 3796 | pclose(sh_pipe); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3797 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3798 | switch (st) { |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3799 | case 0: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3800 | infoResp.status = STATUS_COMPLETE; |
| 3801 | if (CmdReturnFlag) { |
| 3802 | if ((pcmdStr != NULL) && (strlen(pcmdStr) > 0)) { |
| 3803 | memset(&(infoResp.result[0]), '\0', WFA_CLI_CMD_RESP_LEN - 1); |
| 3804 | strncpy(&infoResp.result[0], pcmdStr, |
| 3805 | (strlen(pcmdStr) < WFA_CLI_CMD_RESP_LEN) |
| 3806 | ? strlen(pcmdStr) |
| 3807 | : (WFA_CLI_CMD_RESP_LEN - 2)); |
| 3808 | printf("Return CLI result string to CA=%s\n", &(infoResp.result[0])); |
| 3809 | } else { |
| 3810 | strcpy(&infoResp.result[0], "No return string found\n"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3811 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3812 | } |
| 3813 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3814 | case 1: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3815 | infoResp.status = STATUS_ERROR; |
| 3816 | break; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3817 | case 2: |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3818 | infoResp.status = STATUS_INVALID; |
| 3819 | break; |
| 3820 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3821 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3822 | wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 3823 | respBuf); |
| 3824 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3825 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3826 | printf("Exit from wfaStaCliCommand\n"); |
| 3827 | return TRUE; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3828 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3829 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3830 | * wfaStaConnectGoStartWfd(): |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3831 | */ |
| 3832 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3833 | int wfaStaConnectGoStartWfd(int len, |
| 3834 | BYTE* caCmdBuf, |
| 3835 | int* respLen, |
| 3836 | BYTE* respBuf) { |
| 3837 | dutCmdResponse_t infoResp; |
| 3838 | // caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3839 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3840 | printf("\n Entry wfaStaConnectGoStartWfd... "); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3841 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3842 | // connect the specified GO and then establish the wfd session |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3843 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3844 | // Fetch WFD session and return |
| 3845 | strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890"); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3846 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3847 | infoResp.status = STATUS_COMPLETE; |
| 3848 | wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), |
| 3849 | (BYTE*)&infoResp, respBuf); |
| 3850 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3851 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3852 | return WFA_SUCCESS; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3856 | * wfaStaGenerateEvent(): |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3857 | */ |
| 3858 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3859 | int wfaStaGenerateEvent(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3860 | dutCmdResponse_t infoResp; |
| 3861 | caStaGenEvent_t* staGenerateEvent = |
| 3862 | (caStaGenEvent_t*)caCmdBuf; //uncomment and use it |
| 3863 | caWfdStaGenEvent_t* wfdGenEvent; |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3864 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3865 | printf("\n Entry wfaStaGenerateEvent... "); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3866 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3867 | // Geneate the specified action and return with complete/error. |
| 3868 | if (staGenerateEvent->program == PROG_TYPE_WFD) { |
| 3869 | wfdGenEvent = &staGenerateEvent->wfdEvent; |
| 3870 | if (wfdGenEvent->type == eUibcGen) { |
| 3871 | } else if (wfdGenEvent->type == eUibcHid) { |
| 3872 | } else if (wfdGenEvent->type == eFrameSkip) { |
| 3873 | } else if (wfdGenEvent->type == eI2cRead) { |
| 3874 | } else if (wfdGenEvent->type == eI2cWrite) { |
| 3875 | } else if (wfdGenEvent->type == eInputContent) { |
| 3876 | } else if (wfdGenEvent->type == eIdrReq) { |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3877 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3878 | } |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3879 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3880 | infoResp.status = STATUS_COMPLETE; |
| 3881 | wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), |
| 3882 | (BYTE*)&infoResp, respBuf); |
| 3883 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3884 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3885 | return WFA_SUCCESS; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3886 | } |
| 3887 | |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3888 | /* |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3889 | * wfaStaReinvokeWfdSession(): |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3890 | */ |
| 3891 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3892 | int wfaStaReinvokeWfdSession(int len, |
| 3893 | BYTE* caCmdBuf, |
| 3894 | int* respLen, |
| 3895 | BYTE* respBuf) { |
| 3896 | dutCmdResponse_t infoResp; |
| 3897 | // caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3898 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3899 | printf("\n Entry wfaStaReinvokeWfdSession... "); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3900 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3901 | // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3902 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3903 | infoResp.status = STATUS_COMPLETE; |
| 3904 | wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), |
| 3905 | (BYTE*)&infoResp, respBuf); |
| 3906 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3907 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3908 | return WFA_SUCCESS; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3909 | } |
| 3910 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3911 | int wfaStaGetParameter(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3912 | dutCmdResponse_t infoResp; |
| 3913 | caStaGetParameter_t* staGetParam = |
| 3914 | (caStaGetParameter_t*)caCmdBuf; //uncomment and use it |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3915 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3916 | caStaGetParameterResp_t* paramList = &infoResp.cmdru.getParamValue; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3917 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3918 | printf("\n Entry wfaStaGetParameter... "); |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3919 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3920 | // Check the program type |
| 3921 | if (staGetParam->program == PROG_TYPE_WFD) { |
| 3922 | if (staGetParam->getParamValue == eDiscoveredDevList) { |
| 3923 | // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes. |
| 3924 | paramList->getParamType = eDiscoveredDevList; |
| 3925 | strcpy((char*)¶mList->devList, |
| 3926 | "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88"); |
Dake Zhao | 0a83217 | 2015-01-06 11:08:47 -0800 | [diff] [blame] | 3927 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3928 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3929 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3930 | if (staGetParam->program == PROG_TYPE_WFDS) { |
| 3931 | if (staGetParam->getParamValue == eDiscoveredDevList) { |
| 3932 | // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes. |
| 3933 | paramList->getParamType = eDiscoveredDevList; |
| 3934 | strcpy((char*)¶mList->devList, |
| 3935 | "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88"); |
Dake Zhao | cda4a1d | 2015-06-11 10:14:15 -0700 | [diff] [blame] | 3936 | } |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3937 | if (staGetParam->getParamValue == eOpenPorts) { |
| 3938 | // Run the port checker tool |
| 3939 | // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes. |
| 3940 | paramList->getParamType = eOpenPorts; |
| 3941 | strcpy((char*)¶mList->devList, "22 139 445 68 9700"); |
| 3942 | } |
| 3943 | } |
| 3944 | if (staGetParam->program == PROG_TYPE_NAN) { |
| 3945 | if (staGetParam->getParamValue == eMasterPref) { |
| 3946 | // Get the master preference of the device and return the value |
| 3947 | paramList->getParamType = eMasterPref; |
| 3948 | strcpy((char*)¶mList->masterPref, "0xff"); |
| 3949 | } |
| 3950 | } |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3951 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3952 | infoResp.status = STATUS_COMPLETE; |
| 3953 | wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), |
| 3954 | (BYTE*)&infoResp, respBuf); |
| 3955 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 3956 | |
| 3957 | return WFA_SUCCESS; |
Harsh Madhiwalla | 8e496e0 | 2014-02-25 14:54:53 -0800 | [diff] [blame] | 3958 | } |
| 3959 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3960 | int wfaStaNfcAction(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 3961 | dutCmdResponse_t infoResp; |
| 3962 | caStaNfcAction_t* getStaNfcAction = |
| 3963 | (caStaNfcAction_t*)caCmdBuf; //uncomment and use it |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame] | 3964 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3965 | printf("\n Entry wfaStaNfcAction... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 3966 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3967 | if (getStaNfcAction->nfcOperation == eNfcHandOver) { |
| 3968 | printf("\n NfcAction - HandOver... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 3969 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3970 | } else if (getStaNfcAction->nfcOperation == eNfcReadTag) { |
| 3971 | printf("\n NfcAction - Read Tag... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 3972 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3973 | } else if (getStaNfcAction->nfcOperation == eNfcWriteSelect) { |
| 3974 | printf("\n NfcAction - Write Select... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 3975 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3976 | } else if (getStaNfcAction->nfcOperation == eNfcWriteConfig) { |
| 3977 | printf("\n NfcAction - Write Config... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 3978 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 3979 | } else if (getStaNfcAction->nfcOperation == eNfcWritePasswd) { |
| 3980 | printf("\n NfcAction - Write Password... "); |
| 3981 | |
| 3982 | } else if (getStaNfcAction->nfcOperation == eNfcWpsHandOver) { |
| 3983 | printf("\n NfcAction - WPS Handover... "); |
| 3984 | } |
| 3985 | |
| 3986 | // Fetch the device mode and put in infoResp->cmdru.p2presult |
| 3987 | //strcpy(infoResp->cmdru.p2presult, "GO"); |
| 3988 | |
| 3989 | // Fetch the device grp id and put in infoResp->cmdru.grpid |
| 3990 | //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID"); |
| 3991 | |
| 3992 | strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT"); |
| 3993 | strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID"); |
| 3994 | infoResp.cmdru.staNfcAction.peerRole = 1; |
| 3995 | |
| 3996 | infoResp.status = STATUS_COMPLETE; |
| 3997 | wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 3998 | respBuf); |
| 3999 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 4000 | |
| 4001 | return WFA_SUCCESS; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4004 | int wfaStaExecAction(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 4005 | dutCmdResponse_t infoResp; |
| 4006 | caStaExecAction_t* staExecAction = |
| 4007 | (caStaExecAction_t*)caCmdBuf; //comment if not used |
Dake Zhao | cda4a1d | 2015-06-11 10:14:15 -0700 | [diff] [blame] | 4008 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4009 | printf("\n Entry wfaStaExecAction... "); |
Dake Zhao | cda4a1d | 2015-06-11 10:14:15 -0700 | [diff] [blame] | 4010 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4011 | if (staExecAction->prog == PROG_TYPE_NAN) { |
| 4012 | // Perform necessary configurations and actions |
| 4013 | // return the MAC address conditionally as per CAPI specification |
| 4014 | } |
| 4015 | |
| 4016 | infoResp.status = STATUS_COMPLETE; |
| 4017 | wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 4018 | respBuf); |
| 4019 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 4020 | |
| 4021 | return WFA_SUCCESS; |
Dake Zhao | cda4a1d | 2015-06-11 10:14:15 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4024 | int wfaStaInvokeCommand(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 4025 | dutCmdResponse_t infoResp; |
| 4026 | caStaInvokeCmd_t* staInvokeCmd = |
| 4027 | (caStaInvokeCmd_t*)caCmdBuf; //uncomment and use it |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4028 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4029 | printf("\n Entry wfaStaInvokeCommand... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4030 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4031 | // based on the command type , invoke API or complete the required procedures |
| 4032 | // return the defined parameters based on the command that is received ( example response below) |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4033 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4034 | if (staInvokeCmd->cmdType == ePrimitiveCmdType && |
| 4035 | staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt) { |
| 4036 | infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt; |
| 4037 | infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1; |
| 4038 | strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0] |
| 4039 | .servName, |
| 4040 | "org.wi-fi.wfds.send.rx"); |
| 4041 | infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = |
| 4042 | 0x0000f; |
| 4043 | strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0] |
| 4044 | .serviceMac, |
| 4045 | "ab:cd:ef:gh:ij:kl"); |
| 4046 | } else if (staInvokeCmd->cmdType == ePrimitiveCmdType && |
| 4047 | staInvokeCmd->InvokeCmds.primtiveType.PrimType == |
| 4048 | eCmdPrimTypeSeek) { |
| 4049 | infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek; |
| 4050 | infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff; |
| 4051 | } else if (staInvokeCmd->cmdType == ePrimitiveCmdType && |
| 4052 | staInvokeCmd->InvokeCmds.primtiveType.PrimType == |
| 4053 | eCmdPrimTypeConnSession) { |
| 4054 | infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession; |
| 4055 | infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff; |
| 4056 | strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result, "GO"); |
| 4057 | strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId, |
| 4058 | "DIRECT-AB WFADUT"); |
| 4059 | } |
| 4060 | infoResp.status = STATUS_COMPLETE; |
| 4061 | wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 4062 | respBuf); |
| 4063 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4064 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4065 | return WFA_SUCCESS; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4068 | int wfaStaManageService(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 4069 | dutCmdResponse_t infoResp; |
| 4070 | //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4071 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4072 | printf("\n Entry wfaStaManageService... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4073 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4074 | // based on the manage service type , invoke API's or complete the required procedures |
| 4075 | // return the defined parameters based on the command that is received ( example response below) |
| 4076 | strcpy(infoResp.cmdru.staManageServ.result, "CLIENT"); |
| 4077 | strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID"); |
| 4078 | infoResp.cmdru.staManageServ.sessionID = 0x000ff; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4079 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4080 | infoResp.status = STATUS_COMPLETE; |
| 4081 | wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), |
| 4082 | (BYTE*)&infoResp, respBuf); |
| 4083 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4084 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4085 | return WFA_SUCCESS; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4088 | int wfaStaGetEvents(int len, BYTE* caCmdBuf, int* respLen, BYTE* respBuf) { |
| 4089 | dutCmdResponse_t infoResp; |
| 4090 | caStaGetEvents_t* staGetEvents = |
| 4091 | (caStaGetEvents_t*)caCmdBuf; //uncomment and use it |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4092 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4093 | printf("\n Entry wfaStaGetEvents... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4094 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4095 | if (staGetEvents->program == PROG_TYPE_NAN) { |
| 4096 | // Get all the events from the Log file or stored events |
| 4097 | // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac |
| 4098 | } |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4099 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4100 | // Get all the event from the Log file or stored events |
| 4101 | // return the received/recorded events as space seperated list ( example response below) |
| 4102 | strcpy(infoResp.cmdru.staGetEvents.result, |
| 4103 | "SearchResult SearchTerminated AdvertiseStatus SessionRequest " |
| 4104 | "ConnectStatus SessionStatus PortStatus"); |
| 4105 | |
| 4106 | infoResp.status = STATUS_COMPLETE; |
| 4107 | wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE*)&infoResp, |
| 4108 | respBuf); |
| 4109 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 4110 | |
| 4111 | return WFA_SUCCESS; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4114 | int wfaStaGetEventDetails(int len, |
| 4115 | BYTE* caCmdBuf, |
| 4116 | int* respLen, |
| 4117 | BYTE* respBuf) { |
| 4118 | dutCmdResponse_t infoResp; |
| 4119 | caStaGetEventDetails_t* getStaGetEventDetails = |
| 4120 | (caStaGetEventDetails_t*)caCmdBuf; //uncomment and use it |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4121 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4122 | printf("\n Entry wfaStaGetEventDetails... "); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4123 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4124 | // based on the Requested Event type |
| 4125 | // return the latest corresponding evnet detailed parameters ( example response below) |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4126 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4127 | if (getStaGetEventDetails->eventId == eSearchResult) { |
| 4128 | // fetch from log file or event history for the search result event and return the parameters |
| 4129 | infoResp.cmdru.staGetEventDetails.eventID = eSearchResult; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4130 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4131 | infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = |
| 4132 | 0x00abcd; |
| 4133 | strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult |
| 4134 | .serviceMac, |
| 4135 | "ab:cd:ef:gh:ij:kl"); |
| 4136 | infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = |
| 4137 | 0x00dcba; |
| 4138 | strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult |
| 4139 | .serviceName, |
| 4140 | "org.wi-fi.wfds.send.rx"); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4141 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4142 | infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult |
| 4143 | .serviceStatus = eServiceAvilable; |
| 4144 | } else if ( |
| 4145 | getStaGetEventDetails->eventId == |
| 4146 | eSearchTerminated) { // fetch from log file or event history for the search terminated event and return the parameters |
| 4147 | infoResp.cmdru.staGetEventDetails.eventID = eSearchTerminated; |
| 4148 | infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated |
| 4149 | .searchID = 0x00abcd; |
| 4150 | } else if ( |
| 4151 | getStaGetEventDetails->eventId == |
| 4152 | eAdvertiseStatus) { // fetch from log file or event history for the Advertise Status event and return the parameters |
| 4153 | infoResp.cmdru.staGetEventDetails.eventID = eAdvertiseStatus; |
| 4154 | infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = |
| 4155 | 0x00dcba; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4156 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4157 | infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = |
| 4158 | eAdvertised; |
| 4159 | } else if ( |
| 4160 | getStaGetEventDetails->eventId == |
| 4161 | eSessionRequest) { // fetch from log file or event history for the session request event and return the parameters |
| 4162 | infoResp.cmdru.staGetEventDetails.eventID = eSessionRequest; |
| 4163 | infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = |
| 4164 | 0x00dcba; |
| 4165 | strcpy( |
| 4166 | infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac, |
| 4167 | "ab:cd:ef:gh:ij:kl"); |
| 4168 | infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = |
| 4169 | 0x00baba; |
| 4170 | } else if ( |
| 4171 | getStaGetEventDetails->eventId == |
| 4172 | eSessionStatus) { // fetch from log file or event history for the session status event and return the parameters |
| 4173 | infoResp.cmdru.staGetEventDetails.eventID = eSessionStatus; |
| 4174 | infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = |
| 4175 | 0x00baba; |
| 4176 | strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus |
| 4177 | .sessionMac, |
| 4178 | "ab:cd:ef:gh:ij:kl"); |
| 4179 | infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = |
| 4180 | eSessionStateOpen; |
| 4181 | } else if (getStaGetEventDetails->eventId == eConnectStatus) { |
| 4182 | infoResp.cmdru.staGetEventDetails.eventID = eConnectStatus; |
| 4183 | infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = |
| 4184 | 0x00baba; |
| 4185 | strcpy( |
| 4186 | infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac, |
| 4187 | "ab:cd:ef:gh:ij:kl"); |
| 4188 | infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = |
| 4189 | eGroupFormationComplete; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4190 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4191 | } else if (getStaGetEventDetails->eventId == ePortStatus) { |
| 4192 | infoResp.cmdru.staGetEventDetails.eventID = ePortStatus; |
| 4193 | infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = |
| 4194 | 0x00baba; |
| 4195 | strcpy( |
| 4196 | infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac, |
| 4197 | "ab:cd:ef:gh:ij:kl"); |
| 4198 | infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009; |
| 4199 | infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = |
| 4200 | eLocalPortAllowed; |
| 4201 | } |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4202 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4203 | infoResp.status = STATUS_COMPLETE; |
| 4204 | wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), |
| 4205 | (BYTE*)&infoResp, respBuf); |
| 4206 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4207 | |
Shuo-Peng Liao | 0ca23a3 | 2020-09-03 13:12:58 +0800 | [diff] [blame] | 4208 | return WFA_SUCCESS; |
Dake Zhao | 655efed | 2015-03-11 17:39:13 -0700 | [diff] [blame] | 4209 | } |