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