blob: 6e418ff9eac8098cb4964eff2f7bfad8bb488cf1 [file] [log] [blame]
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001/****************************************************************************
Alan Tsaidfafa3a2016-09-23 16:53:35 -07002Copyright (c) 2016 Wi-Fi Alliance. All Rights Reserved
Dake Zhao97708202014-11-26 13:59:04 -08003
Dake Zhao0a832172015-01-06 11:08:47 -08004Permission to use, copy, modify, and/or distribute this software for any purpose with or
5without fee is hereby granted, provided that the above copyright notice and this permission
Dake Zhao97708202014-11-26 13:59:04 -08006notice appear in all copies.
7
Dake Zhao0a832172015-01-06 11:08:47 -08008THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
12FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
Dake Zhao97708202014-11-26 13:59:04 -080014THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16******************************************************************************/
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000017
Dake Zhao0a832172015-01-06 11:08:47 -080018/*
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000019 * File: wfa_cs.c -- configuration and setup
Dake Zhao0a832172015-01-06 11:08:47 -080020 * This file contains all implementation for the dut setup and control
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000021 * 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 Zhao0a832172015-01-06 11:08:47 -080025 * should be defined in order to support the Agent Control/Test Manager
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000026 * 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 Zhao0a832172015-01-06 11:08:47 -080028 * system("<commands>").
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000029 *
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 Zhao0a832172015-01-06 11:08:47 -080034 *
35 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000036#include <stdio.h>
37#include <unistd.h>
38#include <string.h>
39#include <stdlib.h>
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +020040#include <stdbool.h>
41#include <stdarg.h>
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000042#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
64#define CERTIFICATES_PATH "/etc/wpa_supplicant"
65
66/* Some device may only support UDP ECHO, activate this line */
67//#define WFA_PING_UDP_ECHO_ONLY 1
68
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080069#define WFA_ENABLED 1
70
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000071extern unsigned short wfa_defined_debug;
72int wfaExecuteCLI(char *CLI);
73
74/* Since the two definitions are used all over the CA function */
75char gCmdStr[WFA_CMD_STR_SZ];
76dutCmdResponse_t gGenericResp;
77int wfaTGSetPrio(int sockfd, int tgClass);
78void create_apts_msg(int msg, unsigned int txbuf[],int id);
79
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080080int sret = 0;
81
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000082extern char e2eResults[];
Dake Zhao862c94b2014-12-08 14:35:35 -080083
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000084FILE *e2efp = NULL;
85int chk_ret_status()
86{
87 char *ret = getenv(WFA_RET_ENV);
88
89 if(*ret == '1')
Dake Zhao0a832172015-01-06 11:08:47 -080090 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000091 else
Dake Zhao0a832172015-01-06 11:08:47 -080092 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000093}
94
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +020095static int systemWithLog(char* command) {
96 DPRINT_INFO(WFA_OUT, "exec: %s\n", command);
97 int ret = system(command);
98 if (ret != 0) {
99 DPRINT_INFO(WFA_OUT, "exit code %d\n", ret);
100 }
101 return ret;
102}
103
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200104// Read a line from a file.
105// It reads at most bufSize-1 bytes to buf.
106bool readLine(const char *filename, char *buf, const int bufSize) {
107
108 FILE *fp = NULL;
109 fp = fopen(filename, "r+");
110 if (fp == NULL)
111 {
112 return false;
113 }
114 char* ret = fgets(buf, bufSize, fp);
115 fclose(fp);
116
117 if (ret == NULL)
118 {
119 return false;
120 }
121
122 if (buf[strlen(buf) - 1] == '\n')
123 {
124 buf[strlen(buf) - 1] = 0;
125 }
126 return true;
127}
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200128
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000129/*
130 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
131 * input: cmd --- not used
132 * valLen -- not used
133 * output: parms -- a buffer to store the version info response.
134 */
135int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
136{
137 dutCmdResponse_t *getverResp = &gGenericResp;
138
139 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
140
141 getverResp->status = STATUS_COMPLETE;
142 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
143
144 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
145
146 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
147
148 return WFA_SUCCESS;
149}
150
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200151#define RETURN_STA_ASSOCIATE_ERROR(statusCode, ...)\
152 staAssocResp->status = statusCode;\
153 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, sizeof(staAssocResp->status), (BYTE *)staAssocResp, respBuf);\
154 *respLen = WFA_TLV_HDR_LEN + sizeof(staAssocResp->status);\
155 DPRINT_ERR(WFA_ERR, __VA_ARGS__);\
156 return WFA_FAILURE;
157
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000158/*
159 * wfaStaAssociate():
Dake Zhao0a832172015-01-06 11:08:47 -0800160 * The function is to force the station wireless I/F to re/associate
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000161 * with the AP.
162 */
163int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
164{
Dake Zhao0a832172015-01-06 11:08:47 -0800165 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
166 char *ifname = assoc->intf;
167 dutCmdResponse_t *staAssocResp = &gGenericResp;
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200168 char cmdResult[32];
169 const char *tmpfile = "/tmp/.wfaStaAssociateTmp";
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000170
Dake Zhao0a832172015-01-06 11:08:47 -0800171 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200172
173 // verify parameters
174 if(assoc->cmdsu.assoc.bssid[0] != '\0' || assoc->cmdsu.assoc.wps != 0)
Dake Zhao0a832172015-01-06 11:08:47 -0800175 {
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200176 RETURN_STA_ASSOCIATE_ERROR(STATUS_INVALID, "unsupported command parameter\n");
177 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000178
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200179 if(assoc->cmdsu.assoc.ssid[0] != '\0')
180 {
181 int networkid = -1;
182
183 // get network id
184 sprintf(gCmdStr, "wpa_cli.sh -i %s list_networks | grep %s | cut -f1 -d= > %s",
185 ifname, assoc->cmdsu.assoc.ssid, tmpfile);
186 sret = systemWithLog(gCmdStr);
187 if (sret != 0) {
188 RETURN_STA_ASSOCIATE_ERROR(STATUS_ERROR, "error running wpa_cli, exit code: %d\n", sret);
189 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000190
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200191 if (!readLine(tmpfile, cmdResult, sizeof(cmdResult)))
192 {
193 RETURN_STA_ASSOCIATE_ERROR(STATUS_ERROR, "unable to read network id (network not configured?)\n");
194 }
195 networkid = atoi(cmdResult);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000196
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200197 if (networkid == -1)
198 {
199 RETURN_STA_ASSOCIATE_ERROR(STATUS_ERROR, "network not configured\n");
200 } else
201 {
202 // enable the network and disable all others
203 sprintf(gCmdStr, "wpa_cli.sh -i %s select_network %d > %s",
204 ifname, networkid, tmpfile);
205 sret = systemWithLog(gCmdStr);
206 }
Dake Zhao0a832172015-01-06 11:08:47 -0800207 }
208 else
209 {
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200210 // reassociate to current connected network
211 sprintf(gCmdStr, "wpa_cli.sh -i%s reassociate > %s", ifname, tmpfile);
212 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000213 }
214
Wojciech Jakobczyk1084b012020-08-27 14:59:58 +0200215 // check wpa_cli response
216 if (!readLine(tmpfile, cmdResult, sizeof(cmdResult)))
217 {
218 RETURN_STA_ASSOCIATE_ERROR(STATUS_ERROR, "unable to read command output\n");
219 }
220
221 if (strcmp(cmdResult, "OK") != 0)
222 {
223 RETURN_STA_ASSOCIATE_ERROR(STATUS_ERROR, "associate network failed, error: %s\n", cmdResult);
224 }
225
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000226 staAssocResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -0800227 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000228 *respLen = WFA_TLV_HDR_LEN + 4;
229
Dake Zhao0a832172015-01-06 11:08:47 -0800230 return WFA_SUCCESS;
231}
232
233/*
234 * wfaStaReAssociate():
235 * The function is to force the station wireless I/F to re/associate
236 * with the AP.
237 */
238int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
239{
240 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
241 char *ifname = assoc->intf;
242 dutCmdResponse_t *staAssocResp = &gGenericResp;
243
244 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
245 /*
246 * if bssid appears, station should associate with the specific
247 * BSSID AP at its initial association.
248 * If it is different to the current associating AP, it will be forced to
249 * roam the new AP
250 */
251 if(assoc->cmdsu.assoc.bssid[0] != '\0')
252 {
253 /* if (the first association) */
254 /* just do initial association to the BSSID */
255
256
257 /* else (station already associate to an AP) */
258 /* Do forced roaming */
259
260 }
261 else
262 {
263 /* use 'ifconfig' command to bring down the interface (linux specific) */
264 sprintf(gCmdStr, "ifconfig %s down", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200265 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800266
267 /* use 'ifconfig' command to bring up the interface (linux specific) */
268 sprintf(gCmdStr, "ifconfig %s up", ifname);
269
270 /*
271 * use 'wpa_cli' command to force a 802.11 re/associate
272 * (wpa_supplicant specific)
273 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200274 sprintf(gCmdStr, "wpa_cli.sh -i%s reassociate", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200275 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800276 }
277
278 /*
279 * Then report back to control PC for completion.
280 * This does not have failed/error status. The result only tells
281 * a completion.
282 */
283 staAssocResp->status = STATUS_COMPLETE;
284 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
285 *respLen = WFA_TLV_HDR_LEN + 4;
286
287 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000288}
289
290/*
291 * wfaStaIsConnected():
Dake Zhao0a832172015-01-06 11:08:47 -0800292 * The function is to check whether the station's wireless I/F has
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000293 * already connected to an AP.
294 */
295int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
296{
Dake Zhao0a832172015-01-06 11:08:47 -0800297 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
298 dutCmdResponse_t *staConnectResp = &gGenericResp;
299 char *ifname = connStat->intf;
300 FILE *tmpfile = NULL;
301 char result[32];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000302
303
Dake Zhao0a832172015-01-06 11:08:47 -0800304 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000305
306#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800307 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200308 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000309
Dake Zhao0a832172015-01-06 11:08:47 -0800310 if(chk_ret_status() == WFA_SUCCESS)
311 staConnectResp->cmdru.connected = 1;
312 else
313 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000314#else
Dake Zhao0a832172015-01-06 11:08:47 -0800315 /*
316 * use 'wpa_cli' command to check the interface status
317 * none, scanning or complete (wpa_supplicant specific)
318 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200319 sprintf(gCmdStr, "wpa_cli.sh -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200320 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000321
Dake Zhao0a832172015-01-06 11:08:47 -0800322 /*
323 * the status is saved in a file. Open the file and check it.
324 */
325 tmpfile = fopen("/tmp/.isConnected", "r+");
326 if(tmpfile == NULL)
327 {
328 staConnectResp->status = STATUS_ERROR;
329 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
330 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000331
Dake Zhao0a832172015-01-06 11:08:47 -0800332 DPRINT_ERR(WFA_ERR, "file open failed\n");
333 return WFA_FAILURE;
334 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000335
Dake Zhao0a832172015-01-06 11:08:47 -0800336 sret = fscanf(tmpfile, "%s", (char *)result);
Li Yincba7d352015-09-23 20:30:49 +0800337 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000338
Dake Zhao0a832172015-01-06 11:08:47 -0800339 if(strncmp(result, "COMPLETED", 9) == 0)
340 staConnectResp->cmdru.connected = 1;
341 else
342 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000343#endif
344
Dake Zhao0a832172015-01-06 11:08:47 -0800345 /*
346 * Report back the status: Complete or Failed.
347 */
348 staConnectResp->status = STATUS_COMPLETE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000349
Dake Zhao0a832172015-01-06 11:08:47 -0800350 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
351 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
352
353 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000354}
355
356/*
357 * wfaStaGetIpConfig():
358 * This function is to retriev the ip info including
359 * 1. dhcp enable
360 * 2. ip address
Dake Zhao0a832172015-01-06 11:08:47 -0800361 * 3. mask
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000362 * 4. primary-dns
363 * 5. secondary-dns
364 *
365 * The current implementation is to use a script to find these information
Dake Zhao0a832172015-01-06 11:08:47 -0800366 * and store them in a file.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000367 */
368int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
369{
370 int slen, ret, i = 0;
371 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
Dake Zhao0a832172015-01-06 11:08:47 -0800372 dutCmdResponse_t *ipconfigResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000373 char *ifname = getIpConf->intf;
374 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
375
376 FILE *tmpfd;
377 char string[256];
378 char *str;
379
380 /*
381 * check a script file (the current implementation specific)
382 */
383 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
384 if(ret == -1)
385 {
Dake Zhao0a832172015-01-06 11:08:47 -0800386 ipconfigResp->status = STATUS_ERROR;
387 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
388 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000389
Dake Zhao0a832172015-01-06 11:08:47 -0800390 DPRINT_ERR(WFA_ERR, "file not exist\n");
391 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000392
393 }
394
395 strcpy(ifinfo->dns[0], "0");
396 strcpy(ifinfo->dns[1], "0");
Dake Zhao0a832172015-01-06 11:08:47 -0800397
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000398 /*
Dake Zhao0a832172015-01-06 11:08:47 -0800399 * Run the script file "getipconfig.sh" to check the ip status
400 * (current implementation specific).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000401 * note: "getipconfig.sh" is only defined for the current implementation
402 */
Dake Zhao0a832172015-01-06 11:08:47 -0800403 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000404
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200405 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000406
407 /* open the output result and scan/retrieve the info */
408 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
409
410 if(tmpfd == NULL)
411 {
Dake Zhao0a832172015-01-06 11:08:47 -0800412 ipconfigResp->status = STATUS_ERROR;
413 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
414 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000415
Dake Zhao0a832172015-01-06 11:08:47 -0800416 DPRINT_ERR(WFA_ERR, "file open failed\n");
417 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000418 }
419
420 for(;;)
421 {
422 if(fgets(string, 256, tmpfd) == NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800423 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000424
425 /* check dhcp enabled */
426 if(strncmp(string, "dhcpcli", 7) ==0)
427 {
428 str = strtok(string, "=");
429 str = strtok(NULL, "=");
430 if(str != NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800431 ifinfo->isDhcp = 1;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000432 else
Dake Zhao0a832172015-01-06 11:08:47 -0800433 ifinfo->isDhcp = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000434 }
435
436 /* find out the ip address */
437 if(strncmp(string, "ipaddr", 6) == 0)
438 {
439 str = strtok(string, "=");
440 str = strtok(NULL, " ");
441 if(str != NULL)
442 {
Dake Zhao0a832172015-01-06 11:08:47 -0800443 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800444
Dake Zhao0a832172015-01-06 11:08:47 -0800445 ifinfo->ipaddr[15]='\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000446 }
447 else
Dake Zhao0a832172015-01-06 11:08:47 -0800448 wSTRNCPY(ifinfo->ipaddr, "none", 15);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000449 }
450
451 /* check the mask */
452 if(strncmp(string, "mask", 4) == 0)
453 {
454 char ttstr[16];
455 char *ttp = ttstr;
456
457 str = strtok_r(string, "=", &ttp);
458 if(*ttp != '\0')
459 {
Dake Zhao0a832172015-01-06 11:08:47 -0800460 strcpy(ifinfo->mask, ttp);
461 slen = strlen(ifinfo->mask);
462 ifinfo->mask[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000463 }
464 else
Dake Zhao0a832172015-01-06 11:08:47 -0800465 strcpy(ifinfo->mask, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000466 }
467
468 /* find out the dns server ip address */
469 if(strncmp(string, "nameserv", 8) == 0)
470 {
471 char ttstr[16];
472 char *ttp = ttstr;
Dake Zhao0a832172015-01-06 11:08:47 -0800473
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000474 str = strtok_r(string, " ", &ttp);
475 if(str != NULL && i < 2)
476 {
Dake Zhao0a832172015-01-06 11:08:47 -0800477 strcpy(ifinfo->dns[i], ttp);
478 slen = strlen(ifinfo->dns[i]);
479 ifinfo->dns[i][slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000480 }
481 else
Dake Zhao0a832172015-01-06 11:08:47 -0800482 strcpy(ifinfo->dns[i], "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000483
484 i++;
485 }
Dake Zhao0a832172015-01-06 11:08:47 -0800486 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000487
Dake Zhao0a832172015-01-06 11:08:47 -0800488 /*
489 * Report back the results
490 */
491 ipconfigResp->status = STATUS_COMPLETE;
492 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000493
Dake Zhao0a832172015-01-06 11:08:47 -0800494 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000495
496#if 0
Dake Zhao0a832172015-01-06 11:08:47 -0800497 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
498 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
499 ifinfo->dns[0], ifinfo->dns[1], *respLen);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000500#endif
501
Dake Zhao0a832172015-01-06 11:08:47 -0800502 fclose(tmpfd);
503 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000504}
505
506/*
507 * wfaStaSetIpConfig():
508 * The function is to set the ip configuration to a wireless I/F.
509 * 1. IP address
510 * 2. Mac address
511 * 3. default gateway
Dake Zhao0a832172015-01-06 11:08:47 -0800512 * 4. dns nameserver (pri and sec).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000513 */
514int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
515{
Dake Zhao0a832172015-01-06 11:08:47 -0800516 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
517 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
518 dutCmdResponse_t *staSetIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000519
Dake Zhao0a832172015-01-06 11:08:47 -0800520 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200521
522 if (ipconfig->isDhcp) {
523 DPRINT_INFO(WFA_OUT, "error: dhcp not supported\n");
524 staSetIpResp->status = STATUS_INVALID;
525 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
526 *respLen = WFA_TLV_HDR_LEN + 4;
527
528 return WFA_FAILURE;
529 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000530
Dake Zhao0a832172015-01-06 11:08:47 -0800531 /*
532 * Use command 'ifconfig' to configure the interface ip address, mask.
533 * (Linux specific).
534 */
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200535 sprintf(gCmdStr, "ifconfig %s %s netmask %s >/tmp/ifconfig.log 2>&1", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
536 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200537 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200538 if (sret != 0) {
539 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
540 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000541
Dake Zhao0a832172015-01-06 11:08:47 -0800542 /* use command 'route add' to set set gatewway (linux specific) */
543 if(ipconfig->defGateway[0] != '\0')
544 {
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200545 sprintf(gCmdStr, "route add default gw %s >/tmp/route.log 2>&1", ipconfig->defGateway);
546 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200547 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200548 if (sret != 0) {
549 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
550 }
Dake Zhao0a832172015-01-06 11:08:47 -0800551 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000552
Dake Zhao0a832172015-01-06 11:08:47 -0800553 /* set dns (linux specific) */
554 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200555 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200556 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200557 if (sret != 0) {
558 DPRINT_INFO(WFA_OUT, "exit code %d backing up resolv.conf\n", sret);
559 }
Dake Zhao0a832172015-01-06 11:08:47 -0800560 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200561 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200562 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200563 if (sret != 0) {
564 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
565 }
566 if (strlen(ipconfig->sec_dns) > 0) {
567 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
568 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200569 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200570 if (sret != 0) {
571 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
572 }
573 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000574
Dake Zhao0a832172015-01-06 11:08:47 -0800575 /*
576 * report status
577 */
578 staSetIpResp->status = STATUS_COMPLETE;
579 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
580 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000581
Dake Zhao0a832172015-01-06 11:08:47 -0800582 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000583}
584
585/*
586 * wfaStaVerifyIpConnection():
587 * The function is to verify if the station has IP connection with an AP by
588 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800589 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000590int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
591{
Dake Zhao0a832172015-01-06 11:08:47 -0800592 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
593 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000594
595#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800596 char strout[64], *pcnt;
597 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000598
Dake Zhao0a832172015-01-06 11:08:47 -0800599 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
600
601 /* set timeout value in case not set */
602 if(verip->cmdsu.verifyIp.timeout <= 0)
603 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000604 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800605 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000606
Dake Zhao0a832172015-01-06 11:08:47 -0800607 /* execute the ping command and pipe the result to a tmp file */
608 sprintf(gCmdStr, "ping %s -c 3 -W %u | grep loss | cut -f3 -d, 1>& /tmp/pingout.txt", verip->cmdsu.verifyIp.dipaddr, verip->cmdsu.verifyIp.timeout);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200609 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000610
Dake Zhao0a832172015-01-06 11:08:47 -0800611 /* scan/check the output */
612 tmpfile = fopen("/tmp/pingout.txt", "r+");
613 if(tmpfile == NULL)
614 {
615 verifyIpResp->status = STATUS_ERROR;
616 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
617 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000618
Dake Zhao0a832172015-01-06 11:08:47 -0800619 DPRINT_ERR(WFA_ERR, "file open failed\n");
620 return WFA_FAILURE;
621 }
622
623 verifyIpResp->status = STATUS_COMPLETE;
624 if(fscanf(tmpfile, "%s", strout) == EOF)
625 verifyIpResp->cmdru.connected = 0;
626 else
627 {
628 pcnt = strtok(strout, "%");
629
630 /* if the loss rate is 100%, not able to connect */
631 if(atoi(pcnt) == 100)
632 verifyIpResp->cmdru.connected = 0;
633 else
634 verifyIpResp->cmdru.connected = 1;
635 }
636
637 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000638#else
Dake Zhao0a832172015-01-06 11:08:47 -0800639 int btSockfd;
640 struct pollfd fds[2];
641 int timeout = 2000;
642 char anyBuf[64];
643 struct sockaddr_in toAddr;
644 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000645
Dake Zhao0a832172015-01-06 11:08:47 -0800646 verifyIpResp->status = STATUS_COMPLETE;
647 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000648
Dake Zhao0a832172015-01-06 11:08:47 -0800649 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000650
Dake Zhao0a832172015-01-06 11:08:47 -0800651 if(btSockfd == -1)
652 {
653 verifyIpResp->status = STATUS_ERROR;
654 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
655 *respLen = WFA_TLV_HDR_LEN + 4;
656 return WFA_FAILURE;;
657 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000658
Dake Zhao0a832172015-01-06 11:08:47 -0800659 toAddr.sin_family = AF_INET;
660 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
661 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000662
Dake Zhao0a832172015-01-06 11:08:47 -0800663 while(done)
664 {
665 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
666 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000667
Dake Zhao0a832172015-01-06 11:08:47 -0800668 fds[0].fd = btSockfd;
669 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000670
Dake Zhao0a832172015-01-06 11:08:47 -0800671 ret = poll(fds, 1, timeout);
672 switch(ret)
673 {
674 case 0:
675 /* it is time out, count a packet lost*/
676 break;
677 case -1:
678 /* it is an error */
679 default:
680 {
681 switch(fds[0].revents)
682 {
683 case POLLIN:
684 case POLLPRI:
685 case POLLOUT:
686 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
687 if(nbytes != 0)
688 verifyIpResp->cmdru.connected = 1;
689 done = 0;
690 break;
691 default:
692 /* errors but not care */
693 ;
694 }
695 }
696 }
697 if(cnt == 3)
698 {
699 done = 0;
700 }
701 }
702
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000703#endif
704
Dake Zhao0a832172015-01-06 11:08:47 -0800705 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000706
Dake Zhao0a832172015-01-06 11:08:47 -0800707 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
708
709 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000710}
711
712/*
713 * wfaStaGetMacAddress()
714 * This function is to retrieve the MAC address of a wireless I/F.
715 */
716int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
717{
718 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
719 dutCmdResponse_t *getmacResp = &gGenericResp;
720 char *str;
721 char *ifname = getMac->intf;
722
723 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800724 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000725
726 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
727 /*
728 * run the script "getipconfig.sh" to find out the mac
729 */
Dake Zhao0a832172015-01-06 11:08:47 -0800730 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200731 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000732
733 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
734 if(tmpfd == NULL)
735 {
Dake Zhao0a832172015-01-06 11:08:47 -0800736 getmacResp->status = STATUS_ERROR;
737 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
738 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000739
Dake Zhao0a832172015-01-06 11:08:47 -0800740 DPRINT_ERR(WFA_ERR, "file open failed\n");
741 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000742 }
743
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800744 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
745 {
Dake Zhao0a832172015-01-06 11:08:47 -0800746 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000747 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800748
749 str = strtok(string, " ");
750 while(str && ((strcmp(str,"HWaddr")) != 0))
751 {
Dake Zhao0a832172015-01-06 11:08:47 -0800752 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800753 }
Dake Zhao0a832172015-01-06 11:08:47 -0800754
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800755 /* get mac */
756 if(str)
757 {
758 str = strtok(NULL, " ");
759 strcpy(getmacResp->cmdru.mac, str);
760 getmacResp->status = STATUS_COMPLETE;
761 }
Dake Zhao0a832172015-01-06 11:08:47 -0800762
763 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000764
765 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
766
767 fclose(tmpfd);
768 return WFA_SUCCESS;
769}
770
771/*
772 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800773 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000774 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800775 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000776 */
777int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
778{
Dake Zhao0a832172015-01-06 11:08:47 -0800779 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000780
Dake Zhao0a832172015-01-06 11:08:47 -0800781 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000782
Dake Zhao0a832172015-01-06 11:08:47 -0800783 statsResp->status = STATUS_ERROR;
784 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
785 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000786
787
Dake Zhao0a832172015-01-06 11:08:47 -0800788 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000789}
790
791/*
792 * wfaSetEncryption():
793 * The function is to set the wireless interface with WEP or none.
794 *
Dake Zhao0a832172015-01-06 11:08:47 -0800795 * Since WEP is optional test, current function is only used for
796 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000797 * this function should be replaced by the next one (wfaSetEncryption1())
798 *
Dake Zhao0a832172015-01-06 11:08:47 -0800799 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000800 * 1. I/F
801 * 2. ssid
802 * 3. encpType - wep or none
803 * Optional:
804 * 4. key1
805 * 5. key2
806 * 6. key3
807 * 7. key4
808 * 8. activeKey Index
809 */
810
811int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
812{
Dake Zhao0a832172015-01-06 11:08:47 -0800813 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
814 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000815
Dake Zhao0a832172015-01-06 11:08:47 -0800816 /*
817 * disable the network first
818 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200819 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200820 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000821
Dake Zhao0a832172015-01-06 11:08:47 -0800822 /*
823 * set SSID
824 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200825 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200826 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000827
Dake Zhao0a832172015-01-06 11:08:47 -0800828 /*
829 * Tell the supplicant for infrastructure mode (1)
830 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200831 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200832 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000833
Dake Zhao0a832172015-01-06 11:08:47 -0800834 /*
835 * set Key management to NONE (NO WPA) for plaintext or WEP
836 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200837 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200838 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000839
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200840 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200841 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000842
Dake Zhao0a832172015-01-06 11:08:47 -0800843 setEncrypResp->status = STATUS_COMPLETE;
844 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
845 *respLen = WFA_TLV_HDR_LEN + 4;
846
847 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000848}
849
850/*
851 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800852 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000853 */
854int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
855{
Dake Zhao0a832172015-01-06 11:08:47 -0800856 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
857 dutCmdResponse_t *setEncrypResp = &gGenericResp;
858 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000859
Dake Zhao0a832172015-01-06 11:08:47 -0800860 /*
861 * disable the network first
862 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200863 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setEncryp->intf);
864 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000865
Dake Zhao0a832172015-01-06 11:08:47 -0800866 /*
867 * set SSID
868 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200869 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
870 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000871
Dake Zhao0a832172015-01-06 11:08:47 -0800872 /*
873 * Tell the supplicant for infrastructure mode (1)
874 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200875 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 0", setEncryp->intf);
876 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000877
Dake Zhao0a832172015-01-06 11:08:47 -0800878 /*
879 * set Key management to NONE (NO WPA) for plaintext or WEP
880 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200881 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
882 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000883
Dake Zhao0a832172015-01-06 11:08:47 -0800884 /* set keys */
885 if(setEncryp->encpType == 1)
886 {
887 for(i=0; i<4; i++)
888 {
889 if(setEncryp->keys[i][0] != '\0')
890 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200891 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i %s",
Dake Zhao0a832172015-01-06 11:08:47 -0800892 setEncryp->intf, i, setEncryp->keys[i]);
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200893 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800894 }
895 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000896
Dake Zhao0a832172015-01-06 11:08:47 -0800897 /* set active key */
898 i = setEncryp->activeKeyIdx;
899 if(setEncryp->keys[i][0] != '\0')
900 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200901 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_tx_keyidx %i",
Dake Zhao0a832172015-01-06 11:08:47 -0800902 setEncryp->intf, setEncryp->activeKeyIdx);
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200903 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800904 }
905 }
906 else /* clearly remove the keys -- reported by p.schwann */
907 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000908
Dake Zhao0a832172015-01-06 11:08:47 -0800909 for(i = 0; i < 4; i++)
910 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200911 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
912 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800913 }
914 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000915
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200916 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setEncryp->intf);
917 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000918
Dake Zhao0a832172015-01-06 11:08:47 -0800919 setEncrypResp->status = STATUS_COMPLETE;
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200920 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, sizeof(setEncrypResp->status), (BYTE *)setEncrypResp, respBuf);
921 *respLen = WFA_TLV_HDR_LEN + sizeof(setEncrypResp->status);
Dake Zhao0a832172015-01-06 11:08:47 -0800922
923 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000924}
925
926int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
927{
928 int ret = WFA_SUCCESS;
929
930 return ret;
931}
932
933/*
934 * wfaStaSetEapTLS():
935 * This is to set
936 * 1. ssid
937 * 2. encrypType - tkip or aes-ccmp
938 * 3. keyManagementType - wpa or wpa2
939 * 4. trustedRootCA
940 * 5. clientCertificate
941 */
942int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
943{
Dake Zhao0a832172015-01-06 11:08:47 -0800944 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
945 char *ifname = setTLS->intf;
946 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000947
Dake Zhao0a832172015-01-06 11:08:47 -0800948 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000949
Dake Zhao0a832172015-01-06 11:08:47 -0800950 /*
951 * need to store the trustedROOTCA and clientCertificate into a file first.
952 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000953#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800954 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200955 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000956#else
957
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200958 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200959 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000960
Dake Zhao0a832172015-01-06 11:08:47 -0800961 /* ssid */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200962 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200963 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000964
Dake Zhao0a832172015-01-06 11:08:47 -0800965 /* key management */
966 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
967 {
968 }
969 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
970 {
971 }
972 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
973 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000974
Dake Zhao0a832172015-01-06 11:08:47 -0800975 }
976 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
977 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200978 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -0800979 }
980 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
981 {
982 // to take all and device to pick any one supported.
983 }
984 else
985 {
986 // ??
987 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200988 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000989
Dake Zhao0a832172015-01-06 11:08:47 -0800990 /* protocol WPA */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200991 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200992 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000993
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200994 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap TLS", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200995 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000996
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200997 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200998 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000999
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001000 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001001 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001002
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001003 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001004 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001005
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001006 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001007 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001008
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001009 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001010 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001011#endif
1012
Dake Zhao0a832172015-01-06 11:08:47 -08001013 setEapTlsResp->status = STATUS_COMPLETE;
1014 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
1015 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001016
Dake Zhao0a832172015-01-06 11:08:47 -08001017 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001018}
1019
1020/*
Dake Zhao0a832172015-01-06 11:08:47 -08001021 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001022 * 1. ssid
1023 * 2. passPhrase
1024 * 3. keyMangementType - wpa/wpa2
1025 * 4. encrypType - tkip or aes-ccmp
1026 */
1027int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -08001028{
1029 /*Incompleted function*/
1030 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001031
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001032#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -08001033 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001034#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001035 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001036 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001037#else
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001038 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001039 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001040
Dake Zhao0a832172015-01-06 11:08:47 -08001041 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001042 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001043 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
1044 {
1045 // take all and device to pick it supported.
1046 }
1047 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
1048 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001049
Dake Zhao0a832172015-01-06 11:08:47 -08001050 }
1051 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
1052 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001053
Dake Zhao0a832172015-01-06 11:08:47 -08001054 }
1055 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
1056 {
Ray Wang9c508692014-04-01 17:04:59 -07001057
Dake Zhao0a832172015-01-06 11:08:47 -08001058 }
1059 else
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001060 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001061
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001062 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001063
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001064 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001065 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001066
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001067 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setPSK->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001068 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001069
Dake Zhao0a832172015-01-06 11:08:47 -08001070 /* if PMF enable */
1071 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
1072 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001073
Dake Zhao0a832172015-01-06 11:08:47 -08001074 }
1075 else if(setPSK->pmf == WFA_REQUIRED)
1076 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001077
Dake Zhao0a832172015-01-06 11:08:47 -08001078 }
1079 else if(setPSK->pmf == WFA_F_REQUIRED)
1080 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001081
Dake Zhao0a832172015-01-06 11:08:47 -08001082 }
1083 else if(setPSK->pmf == WFA_F_DISABLED)
1084 {
1085
1086 }
1087 else
1088 {
1089 /* Disable PMF */
1090
1091 }
1092
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001093#endif
1094
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001095#endif
1096
Dake Zhao0a832172015-01-06 11:08:47 -08001097 setPskResp->status = STATUS_COMPLETE;
1098 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1099 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001100
Dake Zhao0a832172015-01-06 11:08:47 -08001101 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001102}
1103
1104/*
Dake Zhao0a832172015-01-06 11:08:47 -08001105 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001106 * Get vendor specific information in name/value pair by a wireless I/F.
1107 */
1108int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1109{
Dake Zhao0a832172015-01-06 11:08:47 -08001110 dutCmdResponse_t infoResp;
1111 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001112 FILE *tmpfd;
1113 char vendor[256];
1114 const char* vendorFileName = "/tmp/ifvendor.txt";
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001115
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001116 sprintf(gCmdStr, "getifvendor.sh %s %s\n", getInfo->intf, vendorFileName);
1117
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001118 if (systemWithLog(gCmdStr) == -1)
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001119 {
1120 infoResp.status = STATUS_ERROR;
1121 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1122 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1123
1124 DPRINT_ERR(WFA_ERR, "script %s failed\n", vendorFileName);
1125 return WFA_FAILURE;
1126 }
1127
1128 /* open the output result and scan/retrieve the info */
1129 tmpfd = fopen(vendorFileName, "r+");
1130
1131 if(tmpfd == NULL || fgets(vendor, 256, tmpfd) == NULL)
1132 {
1133 infoResp.status = STATUS_ERROR;
1134 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1135 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1136
1137 DPRINT_ERR(WFA_ERR, "file read failed\n");
1138
1139 if (tmpfd != NULL)
1140 {
1141 fclose(tmpfd);
1142 remove(vendorFileName);
1143 }
1144
1145 return WFA_FAILURE;
1146 }
1147
1148 snprintf(infoResp.cmdru.info, sizeof(infoResp.cmdru.info), "interface,%s,description,%s",
1149 getInfo->intf, vendor);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001150
Dake Zhao0a832172015-01-06 11:08:47 -08001151 infoResp.status = STATUS_COMPLETE;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001152 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1153 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1154
1155 fclose(tmpfd);
1156 remove(vendorFileName);
Dake Zhao0a832172015-01-06 11:08:47 -08001157
1158 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001159}
1160
1161/*
1162 * wfaStaSetEapTTLS():
1163 * This is to set
1164 * 1. ssid
1165 * 2. username
1166 * 3. passwd
1167 * 4. encrypType - tkip or aes-ccmp
1168 * 5. keyManagementType - wpa or wpa2
1169 * 6. trustedRootCA
1170 */
1171int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1172{
Dake Zhao0a832172015-01-06 11:08:47 -08001173 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1174 char *ifname = setTTLS->intf;
1175 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001176
1177#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001178 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001179 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001180#else
1181
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001182 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001183 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001184
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001185 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001186 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001187
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001188 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001189 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001190
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001191 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001192 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001193
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001194 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001195 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001196
Dake Zhao0a832172015-01-06 11:08:47 -08001197 /* This may not need to set. if it is not set, default to take all */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001198// sprintf(cmdStr, "wpa_cli.sh -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001199 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1200 {
1201 }
1202 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1203 {
1204 }
1205 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1206 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001207
Dake Zhao0a832172015-01-06 11:08:47 -08001208 }
1209 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1210 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001211
Dake Zhao0a832172015-01-06 11:08:47 -08001212 }
1213 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1214 {
1215 // to take all and device to pick one it supported
1216 }
1217 else
1218 {
1219 // ??
1220 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001221 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001222
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001223 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap TTLS", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001224 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001225
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001226 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001227 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001228
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001229 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001230 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001231
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001232 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001233 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001234
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001235 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001236 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001237#endif
1238
Dake Zhao0a832172015-01-06 11:08:47 -08001239 setEapTtlsResp->status = STATUS_COMPLETE;
1240 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1241 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001242
Dake Zhao0a832172015-01-06 11:08:47 -08001243 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001244}
1245
1246/*
1247 * wfaStaSetEapSIM():
1248 * This is to set
1249 * 1. ssid
1250 * 2. user name
1251 * 3. passwd
1252 * 4. encrypType - tkip or aes-ccmp
1253 * 5. keyMangementType - wpa or wpa2
1254 */
1255int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1256{
Dake Zhao0a832172015-01-06 11:08:47 -08001257 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1258 char *ifname = setSIM->intf;
1259 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001260
1261#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001262 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001263 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001264#else
1265
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001266 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001267 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001268
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001269 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001270 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001271
1272
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001273 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001274 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001275
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001276 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001277 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001278
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001279 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap SIM", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001280 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001281
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001282 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001283 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001284
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001285 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001286 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001287
Dake Zhao0a832172015-01-06 11:08:47 -08001288 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1289 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001290 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001291 }
1292 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1293 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001294 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001295 }
1296 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1297 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001298 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-FT", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001299 }
1300 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1301 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001302 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001303 }
1304 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1305 {
1306 // take all and device to pick one which is supported.
1307 }
1308 else
1309 {
1310 // ??
1311 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001312 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001313
1314#endif
1315
Dake Zhao0a832172015-01-06 11:08:47 -08001316 setEapSimResp->status = STATUS_COMPLETE;
1317 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1318 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001319
Dake Zhao0a832172015-01-06 11:08:47 -08001320 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001321}
1322
1323/*
1324 * wfaStaSetPEAP()
1325 * This is to set
1326 * 1. ssid
1327 * 2. user name
1328 * 3. passwd
1329 * 4. encryType - tkip or aes-ccmp
1330 * 5. keyMgmtType - wpa or wpa2
1331 * 6. trustedRootCA
1332 * 7. innerEAP
1333 * 8. peapVersion
1334 */
1335int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1336{
Dake Zhao0a832172015-01-06 11:08:47 -08001337 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1338 char *ifname = setPEAP->intf;
1339 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001340
1341#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001342 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1343 setPEAP->passwd, setPEAP->trustedRootCA,
1344 setPEAP->encrptype, setPEAP->peapVersion,
1345 setPEAP->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001346 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001347#else
1348
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001349 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001350 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001351
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001352 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001353 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001354
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001355 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap PEAP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001356 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001357
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001358 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001359 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001360
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001361 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001362 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001363
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001364 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001365 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001366
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001367 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001368 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001369
Dake Zhao0a832172015-01-06 11:08:47 -08001370 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1371 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001372 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001373 }
1374 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1375 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001376 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001377 }
1378 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1379 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001380 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-FT", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001381 }
1382 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1383 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001384 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001385 }
1386 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1387 {
1388 // take all and device to pick one which is supported.
1389 }
1390 else
1391 {
1392 // ??
1393 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001394 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001395
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001396 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001397 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001398
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001399 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001400 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001401
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001402 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001403 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001404#endif
1405
Dake Zhao0a832172015-01-06 11:08:47 -08001406 setPeapResp->status = STATUS_COMPLETE;
1407 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1408 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001409
Dake Zhao0a832172015-01-06 11:08:47 -08001410 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001411}
1412
1413/*
1414 * wfaStaSetUAPSD()
1415 * This is to set
1416 * 1. acBE
1417 * 2. acBK
1418 * 3. acVI
1419 * 4. acVO
1420 */
1421int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1422{
Dake Zhao0a832172015-01-06 11:08:47 -08001423 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001424#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001425 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1426 char *ifname = setUAPSD->intf;
1427 char tmpStr[10];
1428 char line[100];
1429 char *pathl="/etc/Wireless/RT61STA";
1430 BYTE acBE=1;
1431 BYTE acBK=1;
1432 BYTE acVO=1;
1433 BYTE acVI=1;
1434 BYTE APSDCapable;
1435 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001436
Dake Zhao0a832172015-01-06 11:08:47 -08001437 /*
1438 * A series of setting need to be done before doing WMM-PS
1439 * Additional steps of configuration may be needed.
1440 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001441
Dake Zhao0a832172015-01-06 11:08:47 -08001442 /*
1443 * bring down the interface
1444 */
1445 sprintf(gCmdStr, "ifconfig %s down",ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001446 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001447 /*
1448 * Unload the Driver
1449 */
1450 sprintf(gCmdStr, "rmmod rt61");
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001451 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001452#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001453 if(setUAPSD->acBE != 1)
1454 acBE=setUAPSD->acBE = 0;
1455 if(setUAPSD->acBK != 1)
1456 acBK=setUAPSD->acBK = 0;
1457 if(setUAPSD->acVO != 1)
1458 acVO=setUAPSD->acVO = 0;
1459 if(setUAPSD->acVI != 1)
1460 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001461#else
Dake Zhao0a832172015-01-06 11:08:47 -08001462 acBE=setUAPSD->acBE;
1463 acBK=setUAPSD->acBK;
1464 acVO=setUAPSD->acVO;
1465 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001466#endif
1467
Dake Zhao0a832172015-01-06 11:08:47 -08001468 APSDCapable = acBE||acBK||acVO||acVI;
1469 /*
1470 * set other AC parameters
1471 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001472
Dake Zhao0a832172015-01-06 11:08:47 -08001473 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1474 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 Jakobczyk317dc712020-08-27 12:46:16 +02001475 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001476
Dake Zhao0a832172015-01-06 11:08:47 -08001477 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001478 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001479 pipe = popen("uname -r", "r");
1480 /* Read into line the output of uname*/
1481 fscanf(pipe,"%s",line);
1482 pclose(pipe);
1483
1484 /*
1485 * load the Driver
1486 */
1487 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001488 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001489
1490 sprintf(gCmdStr, "ifconfig %s up",ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001491 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001492#endif
1493
Dake Zhao0a832172015-01-06 11:08:47 -08001494 setUAPSDResp->status = STATUS_COMPLETE;
1495 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1496 *respLen = WFA_TLV_HDR_LEN + 4;
1497 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001498}
1499
1500int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1501{
Dake Zhao0a832172015-01-06 11:08:47 -08001502 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1503 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1504 dutCmdResponse_t *infoResp = &gGenericResp;
1505 /*a vendor can fill in the proper info or anything non-disclosure */
1506 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001507
Dake Zhao0a832172015-01-06 11:08:47 -08001508 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001509
Dake Zhao0a832172015-01-06 11:08:47 -08001510 if(devInfo->fw == 0)
1511 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1512 else
1513 {
1514 // Call internal API to pull the version ID */
Li Yin1ac40782015-09-23 20:38:07 +08001515 strncpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
Dake Zhao0a832172015-01-06 11:08:47 -08001516 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001517
Dake Zhao0a832172015-01-06 11:08:47 -08001518 infoResp->status = STATUS_COMPLETE;
1519 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1520 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001521
Dake Zhao0a832172015-01-06 11:08:47 -08001522 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001523
1524}
1525
1526/*
1527 * This funciton is to retrieve a list of interfaces and return
1528 * the list back to Agent control.
1529 * ********************************************************************
1530 * Note: We intend to make this WLAN interface name as a hardcode name.
1531 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001532 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1533 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001534 * likely is hardcoded just for CAPI command responses.
1535 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001536 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001537 */
1538int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1539{
Dake Zhao0a832172015-01-06 11:08:47 -08001540 dutCmdResponse_t *infoResp = &gGenericResp;
1541 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1542 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001543
Dake Zhao0a832172015-01-06 11:08:47 -08001544 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001545
Dake Zhao0a832172015-01-06 11:08:47 -08001546 switch(ifList->cmdsu.iftype)
1547 {
1548 case IF_80211:
1549 infoResp->status = STATUS_COMPLETE;
1550 ifListResp->iftype = IF_80211;
1551 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1552 strcpy(ifListResp->ifs[1], "NULL");
1553 strcpy(ifListResp->ifs[2], "NULL");
1554 break;
1555 case IF_ETH:
1556 infoResp->status = STATUS_COMPLETE;
1557 ifListResp->iftype = IF_ETH;
1558 strcpy(ifListResp->ifs[0], "eth0");
1559 strcpy(ifListResp->ifs[1], "NULL");
1560 strcpy(ifListResp->ifs[2], "NULL");
1561 break;
1562 default:
1563 {
1564 infoResp->status = STATUS_ERROR;
1565 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1566 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001567
Dake Zhao0a832172015-01-06 11:08:47 -08001568 return WFA_SUCCESS;
1569 }
1570 }
1571
1572 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1573 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1574
1575 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001576}
1577
1578int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1579{
Dake Zhao0a832172015-01-06 11:08:47 -08001580 dutCmdResponse_t *debugResp = &gGenericResp;
1581 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001582
Dake Zhao0a832172015-01-06 11:08:47 -08001583 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001584
Dake Zhao0a832172015-01-06 11:08:47 -08001585 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1586 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1587 else
1588 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001589
Dake Zhao0a832172015-01-06 11:08:47 -08001590 debugResp->status = STATUS_COMPLETE;
1591 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1592 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001593
1594
Dake Zhao0a832172015-01-06 11:08:47 -08001595 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001596}
1597
1598
1599/*
1600 * wfaStaGetBSSID():
1601 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001602 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001603int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1604{
Dake Zhao0a832172015-01-06 11:08:47 -08001605 char string[64];
1606 char *str;
1607 FILE *tmpfd;
1608 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001609
Dake Zhao0a832172015-01-06 11:08:47 -08001610 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1611 /* retrieve the BSSID */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001612 sprintf(gCmdStr, "wpa_cli.sh status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001613
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001614 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001615
Dake Zhao0a832172015-01-06 11:08:47 -08001616 tmpfd = fopen("/tmp/bssid.txt", "r+");
1617 if(tmpfd == NULL)
1618 {
1619 bssidResp->status = STATUS_ERROR;
1620 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1621 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001622
Dake Zhao0a832172015-01-06 11:08:47 -08001623 DPRINT_ERR(WFA_ERR, "file open failed\n");
1624 return WFA_FAILURE;
1625 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001626
Dake Zhao0a832172015-01-06 11:08:47 -08001627 for(;;)
1628 {
1629 if(fscanf(tmpfd, "%s", string) == EOF)
1630 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001631 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001632 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001633 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001634 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001635
Dake Zhao0a832172015-01-06 11:08:47 -08001636 if(strncmp(string, "bssid", 5) == 0)
1637 {
1638 str = strtok(string, "=");
1639 str = strtok(NULL, "=");
1640 if(str != NULL)
1641 {
1642 strcpy(bssidResp->cmdru.bssid, str);
1643 bssidResp->status = STATUS_COMPLETE;
1644 break;
1645 }
1646 }
1647 }
1648
1649 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1650 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1651
1652 fclose(tmpfd);
1653 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001654}
1655
1656/*
1657 * wfaStaSetIBSS()
1658 * This is to set
1659 * 1. ssid
1660 * 2. channel
1661 * 3. encrypType - none or wep
1662 * optional
1663 * 4. key1
1664 * 5. key2
1665 * 6. key3
1666 * 7. key4
1667 * 8. activeIndex - 1, 2, 3, or 4
1668 */
1669int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1670{
Dake Zhao0a832172015-01-06 11:08:47 -08001671 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1672 dutCmdResponse_t *setIbssResp = &gGenericResp;
1673 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001674
Dake Zhao0a832172015-01-06 11:08:47 -08001675 /*
1676 * disable the network first
1677 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001678 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001679 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001680
Dake Zhao0a832172015-01-06 11:08:47 -08001681 /*
1682 * set SSID
1683 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001684 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001685 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001686
Dake Zhao0a832172015-01-06 11:08:47 -08001687 /*
1688 * Set channel for IBSS
1689 */
1690 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001691 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001692
Dake Zhao0a832172015-01-06 11:08:47 -08001693 /*
1694 * Tell the supplicant for IBSS mode (1)
1695 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001696 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 1", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001697 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001698
Dake Zhao0a832172015-01-06 11:08:47 -08001699 /*
1700 * set Key management to NONE (NO WPA) for plaintext or WEP
1701 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001702 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001703 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001704
Dake Zhao0a832172015-01-06 11:08:47 -08001705 if(setIBSS->encpType == 1)
1706 {
1707 for(i=0; i<4; i++)
1708 {
1709 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1710 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001711 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i \"%s\"",
Dake Zhao0a832172015-01-06 11:08:47 -08001712 setIBSS->intf, i, setIBSS->keys[i]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001713 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001714 }
1715 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001716
Dake Zhao0a832172015-01-06 11:08:47 -08001717 i = setIBSS->activeKeyIdx;
1718 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1719 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001720 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_tx_keyidx %i",
Dake Zhao0a832172015-01-06 11:08:47 -08001721 setIBSS->intf, setIBSS->activeKeyIdx);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001722 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001723 }
1724 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001725
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001726 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001727 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001728
Dake Zhao0a832172015-01-06 11:08:47 -08001729 setIbssResp->status = STATUS_COMPLETE;
1730 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1731 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001732
Dake Zhao0a832172015-01-06 11:08:47 -08001733 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001734}
1735
1736/*
1737 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001738 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001739 * adhoc)
1740 * Input parameters:
1741 * 1. I/F
1742 * 2. ssid
1743 * 3. mode adhoc or managed
1744 * 4. encType
1745 * 5. channel
1746 * 6. key(s)
1747 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001748 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001749int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1750{
Dake Zhao0a832172015-01-06 11:08:47 -08001751 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1752 dutCmdResponse_t *SetModeResp = &gGenericResp;
1753 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001754
Dake Zhao0a832172015-01-06 11:08:47 -08001755 /*
1756 * bring down the interface
1757 */
1758 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001759 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001760
Dake Zhao0a832172015-01-06 11:08:47 -08001761 /*
1762 * distroy the interface
1763 */
1764 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001765 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001766
1767
Dake Zhao0a832172015-01-06 11:08:47 -08001768 /*
1769 * re-create the interface with the given mode
1770 */
1771 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001772 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001773 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001774 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1775
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001776 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001777 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001778 {
Dake Zhao0a832172015-01-06 11:08:47 -08001779 int j = setmode->activeKeyIdx;
1780 for(i=0; i<4; i++)
1781 {
1782 if(setmode->keys[i][0] != '\0')
1783 {
1784 sprintf(gCmdStr, "iwconfig %s key s:%s",
1785 setmode->intf, setmode->keys[i]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001786 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001787 }
1788 /* set active key */
1789 if(setmode->keys[j][0] != '\0')
1790 sprintf(gCmdStr, "iwconfig %s key s:%s",
1791 setmode->intf, setmode->keys[j]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001792 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001793 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001794
1795 }
Dake Zhao0a832172015-01-06 11:08:47 -08001796 /*
1797 * Set channel for IBSS
1798 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001799 if(setmode->channel)
1800 {
Dake Zhao0a832172015-01-06 11:08:47 -08001801 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001802 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001803 }
1804
1805
Dake Zhao0a832172015-01-06 11:08:47 -08001806 /*
1807 * set SSID
1808 */
1809 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001810 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001811
Dake Zhao0a832172015-01-06 11:08:47 -08001812 /*
1813 * bring up the interface
1814 */
1815 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001816 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001817
Dake Zhao0a832172015-01-06 11:08:47 -08001818 SetModeResp->status = STATUS_COMPLETE;
1819 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1820 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001821
Dake Zhao0a832172015-01-06 11:08:47 -08001822 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001823}
1824
1825int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1826{
Dake Zhao0a832172015-01-06 11:08:47 -08001827 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1828 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001829
Dake Zhao0a832172015-01-06 11:08:47 -08001830 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001831 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001832
1833
Dake Zhao0a832172015-01-06 11:08:47 -08001834 SetPSResp->status = STATUS_COMPLETE;
1835 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1836 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001837
Dake Zhao0a832172015-01-06 11:08:47 -08001838 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001839}
1840
1841int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1842{
Dake Zhao0a832172015-01-06 11:08:47 -08001843 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1844 dutCmdResponse_t *upLoadResp = &gGenericResp;
1845 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001846
Dake Zhao0a832172015-01-06 11:08:47 -08001847 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1848 {
1849 int rbytes;
1850 /*
1851 * if asked for the first packet, always to open the file
1852 */
1853 if(upload->next == 1)
1854 {
1855 if(e2efp != NULL)
1856 {
1857 fclose(e2efp);
1858 e2efp = NULL;
1859 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001860
Dake Zhao0a832172015-01-06 11:08:47 -08001861 e2efp = fopen(e2eResults, "r");
1862 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001863
Dake Zhao0a832172015-01-06 11:08:47 -08001864 if(e2efp == NULL)
1865 {
1866 upLoadResp->status = STATUS_ERROR;
1867 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1868 *respLen = WFA_TLV_HDR_LEN + 4;
1869 return WFA_FAILURE;
1870 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001871
Dake Zhao0a832172015-01-06 11:08:47 -08001872 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001873
Dake Zhao0a832172015-01-06 11:08:47 -08001874 if(rbytes < 256)
1875 {
1876 /*
1877 * this means no more bytes after this read
1878 */
1879 upld->seqnum = 0;
1880 fclose(e2efp);
1881 e2efp=NULL;
1882 }
1883 else
1884 {
1885 upld->seqnum = upload->next;
1886 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001887
Dake Zhao0a832172015-01-06 11:08:47 -08001888 upld->nbytes = rbytes;
1889
1890 upLoadResp->status = STATUS_COMPLETE;
1891 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1892 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1893 }
1894 else
1895 {
1896 upLoadResp->status = STATUS_ERROR;
1897 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1898 *respLen = WFA_TLV_HDR_LEN + 4;
1899 }
1900
1901 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001902}
1903/*
1904 * wfaStaSetWMM()
1905 * TO be ported on a specific plaform for the DUT
1906 * This is to set the WMM related parameters at the DUT.
1907 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1908 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1909 */
1910int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1911{
1912#ifdef WFA_WMM_AC
1913 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1914 char *ifname = setwmm->intf;
1915 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001916
1917 switch(setwmm->group)
1918 {
1919 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001920 if (setwmm->send_trig)
1921 {
1922 int Sockfd;
1923 struct sockaddr_in psToAddr;
1924 unsigned int TxMsg[512];
1925
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001926 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001927 memset(&psToAddr, 0, sizeof(psToAddr));
1928 psToAddr.sin_family = AF_INET;
1929 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1930 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001931
1932
Dake Zhao0a832172015-01-06 11:08:47 -08001933 switch (setwmm->trig_ac)
1934 {
1935 case WMMAC_AC_VO:
1936 wfaTGSetPrio(Sockfd, 7);
1937 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1938 printf("\r\nSending AC_VO trigger packet\n");
1939 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001940
Dake Zhao0a832172015-01-06 11:08:47 -08001941 case WMMAC_AC_VI:
1942 wfaTGSetPrio(Sockfd, 5);
1943 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1944 printf("\r\nSending AC_VI trigger packet\n");
1945 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001946
Dake Zhao0a832172015-01-06 11:08:47 -08001947 case WMMAC_AC_BK:
1948 wfaTGSetPrio(Sockfd, 2);
1949 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1950 printf("\r\nSending AC_BK trigger packet\n");
1951 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001952
Dake Zhao0a832172015-01-06 11:08:47 -08001953 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001954 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001955 wfaTGSetPrio(Sockfd, 0);
1956 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1957 printf("\r\nSending AC_BE trigger packet\n");
1958 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001959 }
1960
Dake Zhao0a832172015-01-06 11:08:47 -08001961 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1962 sizeof(struct sockaddr));
1963 close(Sockfd);
1964 usleep(1000000);
1965 }
1966 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001967 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001968 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001969 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1970 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1971 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1972 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1973 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1974 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1975 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1976 setwmm->actions.addts.dialog_token,
1977 setwmm->actions.addts.tspec.tsinfo.TID,
1978 setwmm->actions.addts.tspec.tsinfo.direction,
1979 setwmm->actions.addts.tspec.tsinfo.PSB,
1980 setwmm->actions.addts.tspec.tsinfo.UP,
1981 setwmm->actions.addts.tspec.tsinfo.infoAck,
1982 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1983 setwmm->actions.addts.tspec.Fixed,
1984 setwmm->actions.addts.tspec.size,
1985 setwmm->actions.addts.tspec.maxsize,
1986 setwmm->actions.addts.tspec.min_srvc,
1987 setwmm->actions.addts.tspec.max_srvc,
1988 setwmm->actions.addts.tspec.inactivity,
1989 setwmm->actions.addts.tspec.suspension,
1990 setwmm->actions.addts.tspec.srvc_strt_tim,
1991 setwmm->actions.addts.tspec.mindatarate,
1992 setwmm->actions.addts.tspec.meandatarate,
1993 setwmm->actions.addts.tspec.peakdatarate,
1994 setwmm->actions.addts.tspec.burstsize,
1995 setwmm->actions.addts.tspec.delaybound,
1996 setwmm->actions.addts.tspec.PHYrate,
1997 setwmm->actions.addts.tspec.sba,
1998 setwmm->actions.addts.tspec.medium_time,
1999 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002000
Dake Zhao862c94b2014-12-08 14:35:35 -08002001 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002002
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002003 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002004 }
2005 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08002006 {
2007 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002008 }
2009
2010 setwmmResp->status = STATUS_COMPLETE;
2011 break;
2012
2013 case GROUP_WMMCONF:
2014 sprintf(gCmdStr, "iwconfig %s rts %d",
2015 ifname,setwmm->actions.config.rts_thr);
2016
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002017 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002018 sprintf(gCmdStr, "iwconfig %s frag %d",
2019 ifname,setwmm->actions.config.frag_thr);
2020
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002021 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002022 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
2023 ifname, setwmm->actions.config.wmm);
2024
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002025 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002026 setwmmResp->status = STATUS_COMPLETE;
2027 break;
2028
2029 default:
2030 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
2031 setwmmResp->status = STATUS_ERROR;
2032 break;
2033
2034 }
2035
2036 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
2037 *respLen = WFA_TLV_HDR_LEN + 4;
2038#endif
2039
2040 return WFA_SUCCESS;
2041}
2042
2043int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2044{
Dake Zhao0a832172015-01-06 11:08:47 -08002045 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002046
Dake Zhao0a832172015-01-06 11:08:47 -08002047 /*
2048 * run your device to send NEIGREQ
2049 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002050
Dake Zhao0a832172015-01-06 11:08:47 -08002051 sendNeigReqResp->status = STATUS_COMPLETE;
2052 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
2053 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002054
Dake Zhao0a832172015-01-06 11:08:47 -08002055 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002056}
2057
2058int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2059{
2060 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
2061 char *ifname = setFAST->intf;
2062 dutCmdResponse_t *setEapFastResp = &gGenericResp;
2063
2064#ifdef WFA_NEW_CLI_FORMAT
2065 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08002066 setFAST->passwd, setFAST->pacFileName,
2067 setFAST->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002068 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002069#else
2070
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002071 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002072 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002073
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002074 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002075 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002076
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002077 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002078 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002079
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002080 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002081 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002082
2083 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
2084 {
2085 }
2086 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
2087 {
2088 }
2089 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
2090 {
Dake Zhao0a832172015-01-06 11:08:47 -08002091
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002092 }
2093 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2094 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002095 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002096 }
2097 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2098 {
Dake Zhao0a832172015-01-06 11:08:47 -08002099 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002100 }
2101 else
2102 {
Dake Zhao0a832172015-01-06 11:08:47 -08002103 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002104 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002105 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002106
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002107 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap FAST", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002108 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002109
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002110 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002111 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002112
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002113 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002114 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002115
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002116 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002117 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002118
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002119 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002120 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002121
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002122 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002123 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002124#endif
2125
2126 setEapFastResp->status = STATUS_COMPLETE;
2127 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2128 *respLen = WFA_TLV_HDR_LEN + 4;
2129
2130 return WFA_SUCCESS;
2131}
2132
2133int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2134{
2135 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2136 char *ifname = setAKA->intf;
2137 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2138
2139#ifdef WFA_NEW_CLI_FORMAT
2140 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002141 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002142#else
2143
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002144 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002145 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002146
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002147 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002148 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002149
2150 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2151 {
2152 }
2153 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2154 {
2155 }
2156 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2157 {
Dake Zhao0a832172015-01-06 11:08:47 -08002158
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002159 }
2160 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2161 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002162 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002163 }
2164 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2165 {
Dake Zhao0a832172015-01-06 11:08:47 -08002166 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002167 }
2168 else
2169 {
Dake Zhao0a832172015-01-06 11:08:47 -08002170 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002171 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002172 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002173
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002174 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA2", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002175 sret = systemWithLog(gCmdStr);
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002176 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto CCMP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002177 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002178
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002179 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap AKA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002180 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002181
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002182 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002183 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002184
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002185 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002186 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002187
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002188 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002189 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002190
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002191 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002192 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002193#endif
2194
2195 setEapAkaResp->status = STATUS_COMPLETE;
2196 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2197 *respLen = WFA_TLV_HDR_LEN + 4;
2198
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002199 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002200}
2201
2202int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2203{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002204 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2205 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002206
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002207 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002208
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002209 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002210 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002211
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002212 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002213 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002214
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002215 setSystimeResp->status = STATUS_COMPLETE;
2216 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2217 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002218
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002219 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002220}
2221
2222#ifdef WFA_STA_TB
2223int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2224{
Dake Zhao0a832172015-01-06 11:08:47 -08002225 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2226 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2227 BYTE presetDone = 1;
2228 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002229 char cmdStr[128];
2230 char string[256];
2231 FILE *tmpfd = NULL;
2232 long val;
2233 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002234
Dake Zhao0a832172015-01-06 11:08:47 -08002235 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002236
Ray Wangd11ca032015-05-29 18:25:46 -07002237 if (presetParams->supplicant == eWpaSupplicant)
2238 {
2239 st = access("/tmp/processid.txt", F_OK);
2240 if (st != -1)
2241 {
2242 st = remove("/tmp/processid.txt");
2243 }
2244
2245 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002246 st = systemWithLog(cmdStr);
Ray Wangd11ca032015-05-29 18:25:46 -07002247
2248 tmpfd = fopen("/tmp/processid.txt", "r+");
2249 if (tmpfd == NULL)
2250 {
2251 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2252 return WFA_FAILURE;
2253 }
2254
2255 for (;;)
2256 {
2257 if (fgets(string, 256, tmpfd) == NULL)
2258 break;
2259
2260 errno = 0;
2261 val = strtol(string, &endptr, 10);
2262 if (errno != 0 && val == 0)
2263 {
2264 DPRINT_ERR(WFA_ERR, "strtol error\n");
2265 return WFA_FAILURE;
2266 }
2267
2268 if (endptr == string)
2269 {
2270 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2271 }
2272
2273 presetDone = 1;
2274 }
2275 }
2276
Dake Zhao0a832172015-01-06 11:08:47 -08002277 if(presetParams->wmmFlag)
2278 {
2279 st = wfaExecuteCLI(gCmdStr);
2280 switch(st)
2281 {
2282 case 0:
2283 presetDone = 1;
2284 break;
2285 case 1:
2286 presetDone = 0;
2287 break;
2288 case 2:
2289 presetDone = 0;
2290 break;
2291 }
2292 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002293
Dake Zhao0a832172015-01-06 11:08:47 -08002294 if(presetParams->modeFlag != 0)
2295 {
2296 switch(presetParams->wirelessMode)
2297 {
2298 default:
2299 printf("other mode does not need to support\n");
2300 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002301
Dake Zhao0a832172015-01-06 11:08:47 -08002302 st = wfaExecuteCLI(gCmdStr);
2303 switch(st)
2304 {
2305 case 0:
2306 presetDone = 1;
2307 break;
2308 case 1:
2309 presetDone = 0;
2310 case 2:
2311 presetDone = 0;
2312 break;
2313 }
2314 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002315
2316
Dake Zhao0a832172015-01-06 11:08:47 -08002317 if(presetParams->psFlag)
2318 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002319
Dake Zhao0a832172015-01-06 11:08:47 -08002320 printf("%s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002321 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002322 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002323
Dake Zhao0a832172015-01-06 11:08:47 -08002324 /************the followings are used for Voice Enterprise **************/
2325 if(presetParams->program == PROG_TYPE_VENT)
2326 {
2327 if(presetParams->ftoa == eEnable)
2328 {
2329 // enable Fast BSS Transition Over the Air
2330 }
2331 else
2332 {
2333 // disable Fast BSS Transition Over the Air
2334 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002335
Dake Zhao0a832172015-01-06 11:08:47 -08002336 if(presetParams->ftds == eEnable)
2337 {
2338 // enable Fast BSS Transition Over the DS
2339 }
2340 else
2341 {
2342 // disable Fast BSS Transition Over the DS
2343 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002344
Dake Zhao0a832172015-01-06 11:08:47 -08002345 if(presetParams->activescan == eEnable)
2346 {
2347 // Enable Active Scan on STA
2348 }
2349 else
2350 {
2351 // disable Active Scan on STA
2352 }
2353 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002354
Dake Zhao0a832172015-01-06 11:08:47 -08002355 /************the followings are used for Wi-Fi Display *************/
2356 if(presetParams->program == PROG_TYPE_WFD)
2357 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002358
Dake Zhao0a832172015-01-06 11:08:47 -08002359 if(presetParams->tdlsFlag)
2360 {
2361 // enable / disable tdls based on tdls
2362 }
2363 if(presetParams->wfdDevTypeFlag)
2364 {
2365 // set WFD device type to source/sink/dual based on wfdDevType
2366 }
2367 if(presetParams->wfdUibcGenFlag)
2368 {
2369 // enable / disable the feature
2370 }
2371 if(presetParams->wfdUibcHidFlag)
2372 {
2373 // enable / disable feature
2374 }
2375 if(presetParams->wfdUiInputFlag)
2376 {
2377 // set the UI input as mentioned
2378 }
2379 if(presetParams->wfdHdcpFlag)
2380 {
2381 // enable / disable feature
2382 }
2383 if(presetParams->wfdFrameSkipFlag)
2384 {
2385 // enable / disable feature
2386 }
2387 if(presetParams->wfdAvChangeFlag)
2388 {
2389 // enable / disable feature
2390 }
2391 if(presetParams->wfdStandByFlag)
2392 {
2393 // enable / disable feature
2394 }
2395 if(presetParams->wfdInVideoFlag)
2396 {
2397 // select the input vide as protecteed or non-protetcted or protected audio
2398 // or unprotected audio etc.
2399 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002400
Dake Zhao0a832172015-01-06 11:08:47 -08002401 if(presetParams->wfdVideoFmatFlag)
2402 {
2403 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002404
Dake Zhao0a832172015-01-06 11:08:47 -08002405 //switch(presetParams->wfdVideoFmt )
2406 //{
2407 // case e640x480p60:
2408 // ;
2409 // default:
2410 // set the mandatory
2411 // }
2412 }
2413 if(presetParams->wfdAudioFmatFlag)
2414 {
2415 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002416
Dake Zhao0a832172015-01-06 11:08:47 -08002417 //switch(presetParams->wfdAudioFmt )
2418 //{
2419 // case eMandatoryAudioMode:
2420 // ;
2421 // case eDefaultAudioMode:
2422 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002423
Dake Zhao0a832172015-01-06 11:08:47 -08002424 // default:
2425 // set the mandatory
2426 // }
2427 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002428
Dake Zhao0a832172015-01-06 11:08:47 -08002429 if(presetParams->wfdI2cFlag)
2430 {
2431 // enable / disable feature
2432 }
2433 if(presetParams->wfdVideoRecoveryFlag)
2434 {
2435 // enable / disable feature
2436 }
2437 if(presetParams->wfdPrefDisplayFlag)
2438 {
2439 // enable / disable feature
2440 }
2441 if(presetParams->wfdServiceDiscoveryFlag)
2442 {
2443 // enable / disable feature
2444 }
2445 if(presetParams->wfd3dVideoFlag)
2446 {
2447 // enable / disable feature
2448 }
2449 if(presetParams->wfdMultiTxStreamFlag)
2450 {
2451 // enable / disable feature
2452 }
2453 if(presetParams->wfdTimeSyncFlag)
2454 {
2455 // enable / disable feature
2456 }
2457 if(presetParams->wfdEDIDFlag)
2458 {
2459 // enable / disable feature
2460 }
2461 if(presetParams->wfdUIBCPrepareFlag)
2462 {
2463 // Provdes information to start valid WFD session to check UIBC operation.
2464 }
2465 if(presetParams->wfdCoupledCapFlag)
2466 {
2467 // enable / disable feature
2468 }
2469 if(presetParams->wfdOptionalFeatureFlag)
2470 {
2471 // disable all program specific optional features
2472 }
2473 if(presetParams->wfdSessionAvailFlag)
2474 {
2475 // enable / disable session available bit
2476 }
2477 if(presetParams->wfdDeviceDiscoverabilityFlag)
2478 {
2479 // enable / disable feature
2480 }
2481 }
2482
Dake Zhao655efed2015-03-11 17:39:13 -07002483 if(presetParams->program == PROG_TYPE_WFDS)
2484 {
2485
2486 if(presetParams->wfdsType == eAcceptPD)
2487 {
2488 // preset to accept PD request
2489 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2490 {
2491 // use presetParams->wfdsConnectionCapability and set role accordingly
2492 }
2493
2494 }
2495 if(presetParams->wfdsType == eRejectPD)
2496 {
2497 // preset to Reject PD request
2498 }
2499 if(presetParams->wfdsType == eIgnorePD)
2500 {
2501 // preset to Ignore PD request
2502 }
2503 if(presetParams->wfdsType == eRejectSession)
2504 {
2505 // preset to reject Session request
2506 }
2507
2508 }
2509
2510 if (presetDone)
2511 {
2512 PresetParamsResp->status = STATUS_COMPLETE;
2513 }
2514 else
2515 {
2516 PresetParamsResp->status = STATUS_INVALID;
2517 }
Dake Zhao0a832172015-01-06 11:08:47 -08002518
2519 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2520 *respLen = WFA_TLV_HDR_LEN + 4;
2521
2522 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002523}
2524
2525int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2526{
2527 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2528
2529 v11nParamsResp->status = STATUS_COMPLETE;
2530 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2531 *respLen = WFA_TLV_HDR_LEN + 4;
2532 return WFA_SUCCESS;
2533}
2534int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2535{
2536 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2537
2538 staWirelessResp->status = STATUS_COMPLETE;
2539 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2540 *respLen = WFA_TLV_HDR_LEN + 4;
2541 return WFA_SUCCESS;
2542}
2543
2544int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2545{
2546 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2547
2548 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2549 *respLen = WFA_TLV_HDR_LEN + 4;
2550 return WFA_SUCCESS;
2551}
2552
2553int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2554{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002555 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002556
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002557 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2558 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002559
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002560 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002561}
2562
2563int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2564{
2565 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2566
2567 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2568 *respLen = WFA_TLV_HDR_LEN + 4;
2569
2570 return WFA_SUCCESS;
2571
2572}
2573
2574int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2575{
Dake Zhao0a832172015-01-06 11:08:47 -08002576 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2577 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002578
2579
Dake Zhao0a832172015-01-06 11:08:47 -08002580 // need to make your own command available for this, here is only an example
2581 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002582 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002583
Dake Zhao0a832172015-01-06 11:08:47 -08002584 ResetResp->status = STATUS_COMPLETE;
2585 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2586 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002587
Dake Zhao0a832172015-01-06 11:08:47 -08002588 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002589}
2590
2591#else
2592
2593int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2594{
2595 dutCmdResponse_t *staCmdResp = &gGenericResp;
2596
2597 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2598 *respLen = WFA_TLV_HDR_LEN + 4;
2599
2600 return WFA_SUCCESS;
2601}
2602#endif
2603
2604/*
2605 * This is used to send a frame or action frame
2606 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002607int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002608{
Dake Zhao0a832172015-01-06 11:08:47 -08002609 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2610 /* uncomment it if needed */
2611 // char *ifname = cmd->intf;
2612 dutCmdResponse_t *devSendResp = &gGenericResp;
2613 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002614
Dake Zhao0a832172015-01-06 11:08:47 -08002615 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2616 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002617
Dake Zhao0a832172015-01-06 11:08:47 -08002618 switch(sf->program)
2619 {
2620 case PROG_TYPE_PMF:
2621 {
2622 pmfFrame_t *pmf = &sf->frameType.pmf;
2623 switch(pmf->eFrameName)
2624 {
2625 case PMF_TYPE_DISASSOC:
2626 {
2627 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002628
Dake Zhao0a832172015-01-06 11:08:47 -08002629 }
2630 break;
2631 case PMF_TYPE_DEAUTH:
2632 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002633
Dake Zhao0a832172015-01-06 11:08:47 -08002634 }
2635 break;
2636 case PMF_TYPE_SAQUERY:
2637 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002638
Dake Zhao0a832172015-01-06 11:08:47 -08002639 }
2640 break;
2641 case PMF_TYPE_AUTH:
2642 {
2643 }
2644 break;
2645 case PMF_TYPE_ASSOCREQ:
2646 {
2647 }
2648 break;
2649 case PMF_TYPE_REASSOCREQ:
2650 {
2651 }
2652 break;
2653 }
2654 }
2655 break;
2656 case PROG_TYPE_TDLS:
2657 {
2658 tdlsFrame_t *tdls = &sf->frameType.tdls;
2659 switch(tdls->eFrameName)
2660 {
2661 case TDLS_TYPE_DISCOVERY:
2662 /* use the peer mac address to send the frame */
2663 break;
2664 case TDLS_TYPE_SETUP:
2665 break;
2666 case TDLS_TYPE_TEARDOWN:
2667 break;
2668 case TDLS_TYPE_CHANNELSWITCH:
2669 break;
2670 case TDLS_TYPE_NULLFRAME:
2671 break;
2672 }
2673 }
2674 break;
2675 case PROG_TYPE_VENT:
2676 {
2677 ventFrame_t *vent = &sf->frameType.vent;
2678 switch(vent->type)
2679 {
2680 case VENT_TYPE_NEIGREQ:
2681 break;
2682 case VENT_TYPE_TRANSMGMT:
2683 break;
2684 }
2685 }
2686 break;
2687 case PROG_TYPE_WFD:
2688 {
2689 wfdFrame_t *wfd = &sf->frameType.wfd;
2690 switch(wfd->eframe)
2691 {
2692 case WFD_FRAME_PRBREQ:
2693 {
2694 /* send probe req */
2695 }
2696 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002697
Dake Zhao0a832172015-01-06 11:08:47 -08002698 case WFD_FRAME_PRBREQ_TDLS_REQ:
2699 {
2700 /* send tunneled tdls probe req */
2701 }
2702 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002703
Dake Zhao0a832172015-01-06 11:08:47 -08002704 case WFD_FRAME_11V_TIMING_MSR_REQ:
2705 {
2706 /* send 11v timing mearurement request */
2707 }
2708 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002709
Dake Zhao0a832172015-01-06 11:08:47 -08002710 case WFD_FRAME_RTSP:
2711 {
2712 /* send WFD RTSP messages*/
2713 // fetch the type of RTSP message and send it.
2714 switch(wfd->eRtspMsgType)
2715 {
2716 case WFD_RTSP_PAUSE:
2717 break;
2718 case WFD_RTSP_PLAY:
2719 //send RTSP PLAY
2720 break;
2721 case WFD_RTSP_TEARDOWN:
2722 //send RTSP TEARDOWN
2723 break;
2724 case WFD_RTSP_TRIG_PAUSE:
2725 //send RTSP TRIGGER PAUSE
2726 break;
2727 case WFD_RTSP_TRIG_PLAY:
2728 //send RTSP TRIGGER PLAY
2729 break;
2730 case WFD_RTSP_TRIG_TEARDOWN:
2731 //send RTSP TRIGGER TEARDOWN
2732 break;
2733 case WFD_RTSP_SET_PARAMETER:
2734 //send RTSP SET PARAMETER
2735 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2736 {
2737 //send RTSP SET PARAMETER message for UIBC keyboard
2738 }
2739 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2740 {
2741 //send RTSP SET PARAMETER message for UIBC Mouse
2742 }
2743 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2744 {
2745 //send RTSP SET PARAMETER message Capability re-negotiation
2746 }
2747 else if (wfd->eSetParams == WFD_STANDBY)
2748 {
2749 //send RTSP SET PARAMETER message for standby
2750 }
2751 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2752 {
2753 //send RTSP SET PARAMETER message for UIBC settings enable
2754 }
2755 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2756 {
2757 //send RTSP SET PARAMETER message for UIBC settings disable
2758 }
2759 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2760 {
2761 //send RTSP SET PARAMETER message for route audio
2762 }
2763 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2764 {
2765 //send RTSP SET PARAMETER message for 3D video parameters
2766 }
2767 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2768 {
2769 //send RTSP SET PARAMETER message for 2D video parameters
2770 }
2771 break;
Dake Zhao97708202014-11-26 13:59:04 -08002772 }
Dake Zhao0a832172015-01-06 11:08:47 -08002773 }
2774 break;
2775 }
2776 }
2777 break;
2778 /* not need to support HS2 release 1, due to very short time period */
2779 case PROG_TYPE_HS2_R2:
2780 {
2781 /* type of frames */
2782 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2783 switch(hs2->eframe)
2784 {
2785 case HS2_FRAME_ANQPQuery:
2786 {
Dake Zhao97708202014-11-26 13:59:04 -08002787
Dake Zhao0a832172015-01-06 11:08:47 -08002788 }
2789 break;
2790 case HS2_FRAME_DLSRequest:
2791 {
Dake Zhao97708202014-11-26 13:59:04 -08002792
Dake Zhao0a832172015-01-06 11:08:47 -08002793 }
2794 break;
2795 case HS2_FRAME_GARPReq:
2796 {
Dake Zhao97708202014-11-26 13:59:04 -08002797
Dake Zhao0a832172015-01-06 11:08:47 -08002798 }
2799 break;
2800 case HS2_FRAME_GARPRes:
2801 {
2802 }
2803 break;
2804 case HS2_FRAME_NeighAdv:
2805 {
2806 }
2807 case HS2_FRAME_ARPProbe:
2808 {
2809 }
2810 case HS2_FRAME_ARPAnnounce:
2811 {
Dake Zhao97708202014-11-26 13:59:04 -08002812
Dake Zhao0a832172015-01-06 11:08:47 -08002813 }
2814 break;
2815 case HS2_FRAME_NeighSolicitReq:
2816 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002817
Dake Zhao0a832172015-01-06 11:08:47 -08002818 }
2819 break;
2820 case HS2_FRAME_ARPReply:
2821 {
2822
2823 }
2824 break;
2825 }
2826
2827 }/* PROG_TYPE_HS2-R2 */
2828 case PROG_TYPE_GEN:
2829 {
2830 /* General frames */
2831 }
2832
2833
2834 }
2835 devSendResp->status = STATUS_COMPLETE;
2836 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2837 *respLen = WFA_TLV_HDR_LEN + 4;
2838
2839 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002840}
2841
2842/*
2843 * This is used to set a temporary MAC address of an interface
2844 */
2845int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2846{
Dake Zhao0a832172015-01-06 11:08:47 -08002847 // Uncomment it if needed
2848 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2849 // char *ifname = cmd->intf;
2850 dutCmdResponse_t *staCmdResp = &gGenericResp;
2851 // Uncomment it if needed
2852 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002853
Dake Zhao0a832172015-01-06 11:08:47 -08002854 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2855 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002856
Dake Zhao0a832172015-01-06 11:08:47 -08002857 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002858}
2859
2860
2861int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2862{
2863 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2864 //char *intf = disc->intf;
2865 dutCmdResponse_t *staDiscResp = &gGenericResp;
2866
2867 // stop the supplicant
2868
2869 staDiscResp->status = STATUS_COMPLETE;
2870
2871 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2872 *respLen = WFA_TLV_HDR_LEN + 4;
2873
2874 return WFA_SUCCESS;
2875}
2876
2877/* Execute CLI, read the status from Environment variable */
2878int wfaExecuteCLI(char *CLI)
2879{
Dake Zhao0a832172015-01-06 11:08:47 -08002880 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002881
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002882 sret = systemWithLog(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002883
Dake Zhao0a832172015-01-06 11:08:47 -08002884 retstr = getenv("WFA_CLI_STATUS");
2885 printf("cli status %s\n", retstr);
2886 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002887}
2888
2889/* Supporting Functions */
2890
2891void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2892{
Dake Zhao97708202014-11-26 13:59:04 -08002893 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002894 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002895// char *addr = staPing->dipaddr;
2896#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002897 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002898 char bflag[] = "-b";
2899 char *tmpstr;
2900 int inum=0;
2901#else
2902 char bflag[] = " ";
2903#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002904
Ray Wang9b47f362014-03-19 16:51:10 -07002905 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002906
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002907#ifdef WFA_PC_CONSOLE
2908
Dake Zhao353c55e2015-07-20 18:54:45 -07002909 printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d",streamid);
2910
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002911 strcpy(addr,staPing->dipaddr);
Dake Zhao353c55e2015-07-20 18:54:45 -07002912 printf("\nCS :the addr is %s ",addr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002913 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2914 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002915 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002916 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002917 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002918 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002919 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002920 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002921 tmpstr = strtok(addr, ".");
2922 inum = atoi(tmpstr);
2923
2924 printf("interval %f\n", *interval);
2925
2926 if(inum >= 224 && inum <= 239) // multicast
2927 {
2928 }
2929 else // if not MC, check if it is BC address
2930 {
2931 printf("\nCS :Inside the BC address BLOCK");
2932 printf("\nCS :the inum %d",inum);
2933 strtok(NULL, ".");
2934 //strtok(NULL, ".");
2935 tmpstr = strtok(NULL, ".");
2936 printf("tmpstr %s\n", tmpstr);
2937 inum = atoi(tmpstr);
2938 printf("\nCS : The string is %s",tmpstr);
2939 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002940 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002941 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002942 }
2943#endif
Dake Zhao97708202014-11-26 13:59:04 -08002944 if ( staPing->dscp >= 0)
2945 {
Dake Zhao0a832172015-01-06 11:08:47 -08002946 tos= convertDscpToTos(staPing->dscp);
2947 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002948 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2949 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002950 printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n",streamid, staPing->iptype);
Dake Zhao97708202014-11-26 13:59:04 -08002951 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002952
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002953 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002954 {
Dake Zhao97708202014-11-26 13:59:04 -08002955 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002956 sprintf(cmdStr, "echo streamid=%i > /tmp/spout_%d.txt;wfaping6.sh %s %s -i %f -c %i -Q %d -s %i -q >> /tmp/spout_%d.txt 2>/dev/null",
2957 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002958 else
Dake Zhao0a832172015-01-06 11:08:47 -08002959 sprintf(cmdStr, "echo streamid=%i > /tmp/spout_%d.txt;wfaping6.sh %s %s -i %f -c %i -s %i -q >> /tmp/spout_%d.txt 2>/dev/null",
2960 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002961 sret = systemWithLog(cmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002962 printf("\nCS : The command string is %s",cmdStr);
2963 }
2964 else
2965 {
Dake Zhao97708202014-11-26 13:59:04 -08002966 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002967 sprintf(cmdStr, "echo streamid=%i > /tmp/spout_%d.txt;wfaping.sh %s %s -i %f -c %i -Q %d -s %i -q >> /tmp/spout_%d.txt 2>/dev/null",
2968 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002969 else
Dake Zhao0a832172015-01-06 11:08:47 -08002970 sprintf(cmdStr, "echo streamid=%i > /tmp/spout_%d.txt;wfaping.sh %s %s -i %f -c %i -s %i -q >> /tmp/spout_%d.txt 2>/dev/null",
2971 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002972 sret = systemWithLog(cmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002973 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002974 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002975 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002976 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002977 printf("\nCS : The command string is %s",cmdStr);
2978
2979}
2980
2981int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2982{
2983 char strout[256];
2984 FILE *tmpfile = NULL;
2985 char cmdStr[128];
Dake Zhao353c55e2015-07-20 18:54:45 -07002986 printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002987 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002988 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002989
2990 printf("\nCS : The command string is %s",cmdStr);
2991
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002992 sret = systemWithLog("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002993
2994 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002995 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002996
2997 printf("\nCS : The command string is %s",cmdStr);
2998
2999 tmpfile = fopen("/tmp/stpsta.txt", "r+");
3000
3001 if(tmpfile == NULL)
3002 {
3003 return WFA_FAILURE;
3004 }
3005
3006 if(fscanf(tmpfile, "%s", strout) != EOF)
3007 {
3008 if(*strout == '\0')
3009 {
3010 stpResp->cmdru.pingStp.sendCnt = 0;
3011 }
3012
3013 else
3014 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
3015 }
3016
Dake Zhao353c55e2015-07-20 18:54:45 -07003017 printf("\nwfaStopPing after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003018
3019
3020 if(fscanf(tmpfile, "%s", strout) != EOF)
3021 {
3022 if(*strout == '\0')
3023 {
3024 stpResp->cmdru.pingStp.repliedCnt = 0;
3025 }
3026 else
3027 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
3028 }
Dake Zhao353c55e2015-07-20 18:54:45 -07003029 printf("wfaStopPing after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003030
3031 fclose(tmpfile);
3032
3033 return WFA_SUCCESS;
3034}
3035
Ankur Vachhanic485b712012-02-15 23:29:49 +00003036/*
Dake Zhao0a832172015-01-06 11:08:47 -08003037 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003038 */
3039int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3040{
Dake Zhao0a832172015-01-06 11:08:47 -08003041 dutCmdResponse_t infoResp;
3042 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003043
Dake Zhao0a832172015-01-06 11:08:47 -08003044 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003045
Dake Zhao0a832172015-01-06 11:08:47 -08003046 // Fetch the device ID and store into infoResp->cmdru.devid
3047 //strcpy(infoResp->cmdru.devid, str);
3048 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003049
Dake Zhao0a832172015-01-06 11:08:47 -08003050 infoResp.status = STATUS_COMPLETE;
3051 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3052 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3053
3054 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003055}
3056
3057
3058
3059/*
Dake Zhao0a832172015-01-06 11:08:47 -08003060 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003061 */
3062int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3063{
Dake Zhao0a832172015-01-06 11:08:47 -08003064 dutCmdResponse_t infoResp;
3065 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00003066
Dake Zhao0a832172015-01-06 11:08:47 -08003067 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003068
Dake Zhao0a832172015-01-06 11:08:47 -08003069 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003070
Dake Zhao0a832172015-01-06 11:08:47 -08003071 infoResp.status = STATUS_COMPLETE;
3072 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3073 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3074
3075 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003076}
3077/*
Dake Zhao0a832172015-01-06 11:08:47 -08003078 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003079 */
3080int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3081{
Dake Zhao0a832172015-01-06 11:08:47 -08003082 dutCmdResponse_t infoResp;
3083 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003084
Dake Zhao0a832172015-01-06 11:08:47 -08003085 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003086
Dake Zhao0a832172015-01-06 11:08:47 -08003087 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003088
Ankur Vachhanic485b712012-02-15 23:29:49 +00003089
Dake Zhao0a832172015-01-06 11:08:47 -08003090 infoResp.status = STATUS_COMPLETE;
3091 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3092 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3093
3094 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003095}
3096
3097/*
Dake Zhao0a832172015-01-06 11:08:47 -08003098 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003099 */
3100int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3101{
Dake Zhao0a832172015-01-06 11:08:47 -08003102 dutCmdResponse_t infoResp;
3103 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003104
Dake Zhao0a832172015-01-06 11:08:47 -08003105 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003106
Dake Zhao0a832172015-01-06 11:08:47 -08003107 // Fetch the group ID and store into infoResp->cmdru.grpid
3108 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003109
Dake Zhao0a832172015-01-06 11:08:47 -08003110 infoResp.status = STATUS_COMPLETE;
3111 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3112 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3113
3114 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003115}
3116
3117
3118
3119
3120/*
Dake Zhao0a832172015-01-06 11:08:47 -08003121 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003122 */
3123int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3124{
Dake Zhao0a832172015-01-06 11:08:47 -08003125 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003126
Dake Zhao0a832172015-01-06 11:08:47 -08003127 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003128
Dake Zhao0a832172015-01-06 11:08:47 -08003129 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3130 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003131
Ankur Vachhanic485b712012-02-15 23:29:49 +00003132
Dake Zhao0a832172015-01-06 11:08:47 -08003133 infoResp.status = STATUS_COMPLETE;
3134 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3135 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3136
3137 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003138}
3139
3140
3141/*
Dake Zhao0a832172015-01-06 11:08:47 -08003142 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003143 */
3144int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3145{
Dake Zhao0a832172015-01-06 11:08:47 -08003146 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003147
Dake Zhao0a832172015-01-06 11:08:47 -08003148 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003149
Dake Zhao0a832172015-01-06 11:08:47 -08003150 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003151
Dake Zhao0a832172015-01-06 11:08:47 -08003152 infoResp.status = STATUS_COMPLETE;
3153 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3154 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3155
3156 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003157}
3158
3159/*
Dake Zhao0a832172015-01-06 11:08:47 -08003160 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003161 */
3162int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3163{
Dake Zhao0a832172015-01-06 11:08:47 -08003164 dutCmdResponse_t infoResp;
3165 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003166
Dake Zhao0a832172015-01-06 11:08:47 -08003167 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003168
Dake Zhao0a832172015-01-06 11:08:47 -08003169 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003170
Dake Zhao0a832172015-01-06 11:08:47 -08003171 infoResp.status = STATUS_COMPLETE;
3172 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3173 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3174
3175 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003176}
3177
3178
3179/*
Dake Zhao0a832172015-01-06 11:08:47 -08003180 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003181 */
3182int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3183{
Dake Zhao0a832172015-01-06 11:08:47 -08003184 dutCmdResponse_t infoResp;
3185 /* uncomment and use it
3186 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3187 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003188
Dake Zhao0a832172015-01-06 11:08:47 -08003189 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003190
Dake Zhao0a832172015-01-06 11:08:47 -08003191 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003192
Dake Zhao0a832172015-01-06 11:08:47 -08003193 infoResp.status = STATUS_COMPLETE;
3194 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3195 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3196
3197 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003198}
3199
3200
3201/*
Dake Zhao0a832172015-01-06 11:08:47 -08003202 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003203 */
3204int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3205{
Dake Zhao0a832172015-01-06 11:08:47 -08003206 dutCmdResponse_t infoResp;
3207 /* uncomment and use it
3208 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3209 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003210
Dake Zhao0a832172015-01-06 11:08:47 -08003211 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003212
Dake Zhao0a832172015-01-06 11:08:47 -08003213 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003214
Dake Zhao0a832172015-01-06 11:08:47 -08003215 infoResp.status = STATUS_COMPLETE;
3216 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3217 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3218
3219 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003220}
3221
3222/*
Dake Zhao0a832172015-01-06 11:08:47 -08003223 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003224 */
3225int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3226{
Dake Zhao0a832172015-01-06 11:08:47 -08003227 dutCmdResponse_t infoResp;
3228 /* uncomment and use it
3229 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3230 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003231
Dake Zhao0a832172015-01-06 11:08:47 -08003232 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003233
Dake Zhao0a832172015-01-06 11:08:47 -08003234 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003235
Dake Zhao0a832172015-01-06 11:08:47 -08003236 infoResp.status = STATUS_COMPLETE;
3237 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3238 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3239
3240 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003241}
3242
3243/*
Dake Zhao0a832172015-01-06 11:08:47 -08003244 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003245 */
3246int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3247{
Dake Zhao0a832172015-01-06 11:08:47 -08003248 dutCmdResponse_t infoResp;
3249 /* uncomment and use it
3250 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3251 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003252
Dake Zhao0a832172015-01-06 11:08:47 -08003253 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003254
Dake Zhao0a832172015-01-06 11:08:47 -08003255 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3256 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3257 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003258
Ankur Vachhanic485b712012-02-15 23:29:49 +00003259
Dake Zhao0a832172015-01-06 11:08:47 -08003260 infoResp.status = STATUS_COMPLETE;
3261 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3262 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3263
3264 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003265}
3266
3267
3268
3269/*
Dake Zhao0a832172015-01-06 11:08:47 -08003270 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003271 */
3272int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3273{
Dake Zhao0a832172015-01-06 11:08:47 -08003274 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003275
Dake Zhao0a832172015-01-06 11:08:47 -08003276 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003277
Dake Zhao0a832172015-01-06 11:08:47 -08003278 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3279 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3280 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003281
Ankur Vachhanic485b712012-02-15 23:29:49 +00003282
Dake Zhao0a832172015-01-06 11:08:47 -08003283 infoResp.status = STATUS_COMPLETE;
3284 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3285 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3286
3287 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003288}
3289
3290
3291/*
Dake Zhao0a832172015-01-06 11:08:47 -08003292 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003293 */
3294int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3295{
Dake Zhao0a832172015-01-06 11:08:47 -08003296 dutCmdResponse_t infoResp;
3297 /* uncomment and use it
3298 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3299 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003300
Dake Zhao0a832172015-01-06 11:08:47 -08003301 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003302
Dake Zhao0a832172015-01-06 11:08:47 -08003303 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003304
Ankur Vachhanic485b712012-02-15 23:29:49 +00003305
Dake Zhao0a832172015-01-06 11:08:47 -08003306 infoResp.status = STATUS_COMPLETE;
3307 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3308 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3309
3310 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003311}
3312
3313
3314/*
Dake Zhao0a832172015-01-06 11:08:47 -08003315 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003316 */
3317int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3318{
Dake Zhao0a832172015-01-06 11:08:47 -08003319 dutCmdResponse_t infoResp;
3320 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003321
Dake Zhao0a832172015-01-06 11:08:47 -08003322 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003323
3324
Dake Zhao0a832172015-01-06 11:08:47 -08003325 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3326 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3327 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003328
Ankur Vachhanic485b712012-02-15 23:29:49 +00003329
Dake Zhao0a832172015-01-06 11:08:47 -08003330 infoResp.status = STATUS_COMPLETE;
3331 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3332 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3333
3334 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003335}
3336
3337/*
Dake Zhao0a832172015-01-06 11:08:47 -08003338 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003339 */
3340int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3341{
Dake Zhao0a832172015-01-06 11:08:47 -08003342 dutCmdResponse_t infoResp;
3343 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003344
Dake Zhao0a832172015-01-06 11:08:47 -08003345 printf("\n Entry wfaStaP2pReset... ");
3346 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003347
Dake Zhao0a832172015-01-06 11:08:47 -08003348 infoResp.status = STATUS_COMPLETE;
3349 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3350 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3351
3352 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003353}
3354
3355
3356
3357/*
Dake Zhao0a832172015-01-06 11:08:47 -08003358 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003359 */
3360int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3361{
Dake Zhao0a832172015-01-06 11:08:47 -08003362 dutCmdResponse_t infoResp;
3363 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003364
Dake Zhao0a832172015-01-06 11:08:47 -08003365 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003366
Dake Zhao0a832172015-01-06 11:08:47 -08003367 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003368
Dake Zhao0a832172015-01-06 11:08:47 -08003369 ifinfo->isDhcp =0;
3370 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3371 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3372 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3373 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3374
3375 infoResp.status = STATUS_COMPLETE;
3376 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3377 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3378
3379 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003380}
3381
3382
3383
3384
3385/*
Dake Zhao0a832172015-01-06 11:08:47 -08003386 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003387 */
3388int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3389{
Dake Zhao0a832172015-01-06 11:08:47 -08003390 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003391
Dake Zhao0a832172015-01-06 11:08:47 -08003392 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3393 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003394
Dake Zhao0a832172015-01-06 11:08:47 -08003395
3396 infoResp.status = STATUS_COMPLETE;
3397 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3398 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3399
3400 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003401}
3402
3403
3404
3405/*
Dake Zhao0a832172015-01-06 11:08:47 -08003406 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003407 */
3408int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3409{
Dake Zhao0a832172015-01-06 11:08:47 -08003410 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003411
Dake Zhao0a832172015-01-06 11:08:47 -08003412 infoResp.status = STATUS_COMPLETE;
3413 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3414 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003415
Dake Zhao0a832172015-01-06 11:08:47 -08003416 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003417}
3418
3419/*
Dake Zhao0a832172015-01-06 11:08:47 -08003420 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003421 */
3422int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3423{
Dake Zhao0a832172015-01-06 11:08:47 -08003424 dutCmdResponse_t infoResp;
3425 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003426
Dake Zhao0a832172015-01-06 11:08:47 -08003427 printf("\n Entry wfaStaSetSleepReq... ");
3428 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003429
Dake Zhao0a832172015-01-06 11:08:47 -08003430
3431 infoResp.status = STATUS_COMPLETE;
3432 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3433 *respLen = WFA_TLV_HDR_LEN +4;
3434
3435 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003436}
3437
3438/*
Dake Zhao0a832172015-01-06 11:08:47 -08003439 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003440 */
3441int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3442{
Dake Zhao0a832172015-01-06 11:08:47 -08003443 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003444
Dake Zhao0a832172015-01-06 11:08:47 -08003445 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3446 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003447
Dake Zhao0a832172015-01-06 11:08:47 -08003448
3449 infoResp.status = STATUS_COMPLETE;
3450 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3451 *respLen = WFA_TLV_HDR_LEN + 4;
3452
3453 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003454}
3455#ifndef WFA_STA_TB
3456/*
Dake Zhao0a832172015-01-06 11:08:47 -08003457 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003458 */
3459
3460int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3461{
Dake Zhao0a832172015-01-06 11:08:47 -08003462 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003463
Dake Zhao0a832172015-01-06 11:08:47 -08003464 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003465
Dake Zhao0a832172015-01-06 11:08:47 -08003466 // Implement the function and its sub commands
3467 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003468
Dake Zhao0a832172015-01-06 11:08:47 -08003469 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3470 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003471
Dake Zhao0a832172015-01-06 11:08:47 -08003472 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003473}
Dake Zhao0a832172015-01-06 11:08:47 -08003474int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003475{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003476
3477 dutCmdResponse_t infoResp;
3478 dutCmdResponse_t *v11nParamsResp = &infoResp;
3479
3480#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003481
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003482 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3483
3484 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003485
3486 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003487
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003488 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3489 {
Dake Zhao0a832172015-01-06 11:08:47 -08003490 // implement the funciton
3491 if(st != 0)
3492 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003493 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003494 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3495 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3496 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3497 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003498 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003499 }
Dake Zhao0a832172015-01-06 11:08:47 -08003500
Ankur Vachhanic485b712012-02-15 23:29:49 +00003501 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003502 {
Dake Zhao0a832172015-01-06 11:08:47 -08003503 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003504
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003505 if(st != 0)
3506 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003507 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003508 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3509 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3510 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3511 return FALSE;
3512 }
3513 }
3514
Ankur Vachhanic485b712012-02-15 23:29:49 +00003515 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003516 {
Dake Zhao0a832172015-01-06 11:08:47 -08003517 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003518 if(st != 0)
3519 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003520 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003521 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3522 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3523 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003524 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003525 }
3526 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003527
3528 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003529 {
3530 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003531 if(st != 0)
3532 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003533 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003534 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3535 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3536 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3537 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003538 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003539 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003540
3541 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003542 {
Dake Zhao0a832172015-01-06 11:08:47 -08003543 // implement the funciton
3544 //st = wfaExecuteCLI(gCmdStr);
3545 if(st != 0)
3546 {
3547 v11nParamsResp->status = STATUS_ERROR;
3548 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3549 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3550 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3551 return FALSE;
3552 }
3553 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003554 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3555 {
3556 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003557 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003558 if(st != 0)
3559 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003560 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003561 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003562 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3563 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003564 return FALSE;
3565 }
Dake Zhao0a832172015-01-06 11:08:47 -08003566 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003567 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3568 {
3569 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003570 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003571 if(st != 0)
3572 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003573 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003574 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003575 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3576 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003577 return FALSE;
3578 }
3579 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003580
3581 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003582 {
3583 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003584 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003585 if(st != 0)
3586 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003587 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003588 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003589 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3590 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003591 return FALSE;
3592 }
3593 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003594
3595 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003596 {
3597 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003598 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003599 if(st != 0)
3600 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003601 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003602 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3603 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3604 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3605 return FALSE;
3606 }
3607 }
3608
3609 if(v11nParams->smps != 0xFFFF)
3610 {
3611 if(v11nParams->smps == 0)
3612 {
Dake Zhao0a832172015-01-06 11:08:47 -08003613 // implement the funciton
3614 //st = wfaExecuteCLI(gCmdStr);
3615 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003616 else if(v11nParams->smps == 1)
3617 {
Dake Zhao0a832172015-01-06 11:08:47 -08003618 // implement the funciton
3619 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003620 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003621 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003622 else if(v11nParams->smps == 2)
3623 {
Dake Zhao0a832172015-01-06 11:08:47 -08003624 // implement the funciton
3625 //st = wfaExecuteCLI(gCmdStr);
3626 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003627 }
3628 if(st != 0)
3629 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003630 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003631 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3632 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3633 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3634 return FALSE;
3635 }
3636 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003637
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003638 if(v11nParams->stbc_rx != 0xFFFF)
3639 {
3640 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003641 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003642 if(st != 0)
3643 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003644 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003645 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003646 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3647 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003648 return FALSE;
3649 }
3650 }
Dake Zhao0a832172015-01-06 11:08:47 -08003651
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003652 if(v11nParams->width[0] != '\0')
3653 {
3654 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003655 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003656 if(st != 0)
3657 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003658 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003659 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3660 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3661 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3662 return FALSE;
3663 }
3664 }
Dake Zhao0a832172015-01-06 11:08:47 -08003665
Ankur Vachhanic485b712012-02-15 23:29:49 +00003666 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003667 {
3668 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003669 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003670 if(st != 0)
3671 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003672 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003673 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3674 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3675 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3676 return FALSE;
3677 }
3678 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003679
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003680 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3681 {
3682 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003683 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003684 if(st != 0)
3685 {
3686 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003687 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003688 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3689 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3690 return FALSE;
3691 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003692
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003693 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003694
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003695 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3696 {
3697 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003698 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003699 if(st != 0)
3700 {
3701 v11nParamsResp->status = STATUS_ERROR;
3702 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3703 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3704 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3705 return FALSE;
3706 }
3707 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003708
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003709#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003710
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003711 v11nParamsResp->status = STATUS_COMPLETE;
3712 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3713 *respLen = WFA_TLV_HDR_LEN + 4;
3714 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003715}
3716#endif
3717/*
Dake Zhao0a832172015-01-06 11:08:47 -08003718 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003719 */
3720int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3721{
Dake Zhao0a832172015-01-06 11:08:47 -08003722 dutCmdResponse_t infoResp;
3723 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003724
Dake Zhao0a832172015-01-06 11:08:47 -08003725 printf("\n Entry wfastaAddARPTableEntry... ");
3726 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003727
Dake Zhao0a832172015-01-06 11:08:47 -08003728 infoResp.status = STATUS_COMPLETE;
3729 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3730 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3731
3732 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003733}
3734
3735/*
Dake Zhao0a832172015-01-06 11:08:47 -08003736 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003737 */
3738int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3739{
Dake Zhao0a832172015-01-06 11:08:47 -08003740 dutCmdResponse_t infoResp;
3741 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003742
Dake Zhao0a832172015-01-06 11:08:47 -08003743 printf("\n Entry wfaStaBlockICMPResponse... ");
3744 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003745
Dake Zhao0a832172015-01-06 11:08:47 -08003746 infoResp.status = STATUS_COMPLETE;
3747 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3748 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3749
3750 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003751}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003752
3753/*
Dake Zhao0a832172015-01-06 11:08:47 -08003754 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003755 */
3756
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003757int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3758{
3759 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3760 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003761 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3762
3763 if(sr->mode == WFA_OFF)
3764 {
Dake Zhao0a832172015-01-06 11:08:47 -08003765 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003766 }
3767 else
3768 {
Dake Zhao0a832172015-01-06 11:08:47 -08003769 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003770 }
3771
3772 staCmdResp->status = STATUS_COMPLETE;
3773 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3774 *respLen = WFA_TLV_HDR_LEN + 4;
3775
3776 return WFA_SUCCESS;
3777}
3778
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003779/*
Dake Zhao0a832172015-01-06 11:08:47 -08003780 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003781 */
3782
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003783int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3784{
Dake Zhao0a832172015-01-06 11:08:47 -08003785 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3786 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3787 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003788
Dake Zhao0a832172015-01-06 11:08:47 -08003789 if(strcasecmp(rfeat->prog, "tdls") == 0)
3790 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003791
3792
Dake Zhao0a832172015-01-06 11:08:47 -08003793 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003794
Dake Zhao0a832172015-01-06 11:08:47 -08003795 caResp->status = STATUS_COMPLETE;
3796 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3797 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003798
Dake Zhao0a832172015-01-06 11:08:47 -08003799 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003800}
3801
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003802/*
Dake Zhao0a832172015-01-06 11:08:47 -08003803 * wfaStaStartWfdConnection():
3804 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003805int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3806{
Dake Zhao0a832172015-01-06 11:08:47 -08003807 dutCmdResponse_t infoResp;
3808 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003809
Dake Zhao0a832172015-01-06 11:08:47 -08003810 printf("\n Entry wfaStaStartWfdConnection... ");
3811
3812
3813 // Fetch the GrpId and WFD session and return
3814 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3815 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3816 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3817
3818 infoResp.status = STATUS_COMPLETE;
3819 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3820 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3821
3822 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003823}
3824/*
Dake Zhao0a832172015-01-06 11:08:47 -08003825 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003826 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003827
Ankur Vachhanic485b712012-02-15 23:29:49 +00003828int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3829{
Dake Zhao0a832172015-01-06 11:08:47 -08003830 char cmdName[32];
3831 char *pcmdStr=NULL, *str;
3832 int st = 1;
3833 char CmdStr[WFA_CMD_STR_SZ];
3834 FILE *wfaCliFd;
3835 char wfaCliBuff[64];
3836 char retstr[256];
3837 int CmdReturnFlag =0;
3838 char tmp[256];
Li Yincba7d352015-09-23 20:30:49 +08003839 FILE * sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003840 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003841
Dake Zhao0a832172015-01-06 11:08:47 -08003842 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3843 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3844 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003845
Dake Zhao0a832172015-01-06 11:08:47 -08003846 for(;;)
3847 {
3848 // construct CLI standard cmd string
3849 str = strtok_r(NULL, ",", &pcmdStr);
3850 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003851 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003852 else
3853 {
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003854 strcat(strcat(CmdStr, " /"), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003855 str = strtok_r(NULL, ",", &pcmdStr);
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003856 strcat(strcat(CmdStr, " "), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003857 }
3858 }
3859 // check the return process
3860 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3861 if(wfaCliFd!= NULL)
3862 {
3863 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3864 {
3865 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3866 if(ferror(wfaCliFd))
3867 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003868
Dake Zhao0a832172015-01-06 11:08:47 -08003869 str=strtok(wfaCliBuff,"-");
3870 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003871 {
Dake Zhao0a832172015-01-06 11:08:47 -08003872 str=strtok(NULL,",");
3873 if (str != NULL)
3874 {
3875 if(strcmp(str,"TRUE") == 0)
3876 CmdReturnFlag =1;
3877 }
3878 else
3879 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3880 break;
Dake Zhao97708202014-11-26 13:59:04 -08003881 }
Dake Zhao0a832172015-01-06 11:08:47 -08003882 }
3883 fclose(wfaCliFd);
3884 }
3885 else
3886 {
3887 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3888 goto cleanup;
3889 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003890
Dake Zhao0a832172015-01-06 11:08:47 -08003891 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3892 memset(&retstr[0],'\0',255);
3893 memset(&tmp[0],'\0',255);
3894 sprintf(gCmdStr, "%s", CmdStr);
3895 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003896
Dake Zhao0a832172015-01-06 11:08:47 -08003897 sh_pipe = popen(gCmdStr,"r");
3898 if(!sh_pipe)
3899 {
3900 printf ("Error in opening pipe\n");
3901 goto cleanup;
3902 }
Dake Zhao97708202014-11-26 13:59:04 -08003903
Dake Zhao0a832172015-01-06 11:08:47 -08003904 sleep(5);
3905 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3906 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3907 {
3908 printf("Getting NULL string in popen return\n");
3909 goto cleanup;
3910 }
3911 else
3912 printf("popen return str=%s\n",retstr);
3913
3914 sleep(2);
3915 if(pclose(sh_pipe) == -1)
3916 {
3917 printf("Error in closing shell cmd pipe\n");
3918 goto cleanup;
3919 }
Li Yincba7d352015-09-23 20:30:49 +08003920 sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003921 sleep(2);
3922
3923 // find status first in output
3924 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3925 if (str != NULL)
3926 {
3927 memset(tmp, 0, 10);
3928 memcpy(tmp, str, 2);
3929 printf("cli status=%s\n",tmp);
3930 if(strlen(tmp) > 0)
3931 st = atoi(tmp);
3932 else printf("Missing status code\n");
3933 }
3934 else
3935 {
3936 printf("wfaStaCliCommand no return code found\n");
3937 }
3938 infoResp.resFlag=CmdReturnFlag;
3939
Dake Zhao97708202014-11-26 13:59:04 -08003940cleanup:
Li Yincba7d352015-09-23 20:30:49 +08003941 if (sh_pipe)
3942 pclose(sh_pipe);
Dake Zhao0a832172015-01-06 11:08:47 -08003943
3944 switch(st)
3945 {
3946 case 0:
3947 infoResp.status = STATUS_COMPLETE;
3948 if (CmdReturnFlag)
3949 {
3950 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3951 {
3952 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003953 strncpy(&infoResp.result[0], pcmdStr ,(strlen(pcmdStr) < WFA_CLI_CMD_RESP_LEN ) ? strlen(pcmdStr) : (WFA_CLI_CMD_RESP_LEN-2) );
Dake Zhao0a832172015-01-06 11:08:47 -08003954 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3955 }
3956 else
3957 {
Dake Zhao97708202014-11-26 13:59:04 -08003958 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003959 }
3960 }
3961 break;
3962 case 1:
3963 infoResp.status = STATUS_ERROR;
3964 break;
3965 case 2:
3966 infoResp.status = STATUS_INVALID;
3967 break;
3968 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003969
Dake Zhao0a832172015-01-06 11:08:47 -08003970 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3971 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003972
Dake Zhao0a832172015-01-06 11:08:47 -08003973 printf("Exit from wfaStaCliCommand\n");
3974 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003975
Ankur Vachhanic485b712012-02-15 23:29:49 +00003976}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003977/*
Dake Zhao0a832172015-01-06 11:08:47 -08003978 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003979 */
3980
3981int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3982{
3983 dutCmdResponse_t infoResp;
3984// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003985
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003986 printf("\n Entry wfaStaConnectGoStartWfd... ");
3987
Dake Zhao0a832172015-01-06 11:08:47 -08003988 // connect the specified GO and then establish the wfd session
3989
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003990 // Fetch WFD session and return
3991 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3992
3993 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003994 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003995 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003996
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003997 return WFA_SUCCESS;
3998}
3999
4000/*
Dake Zhao0a832172015-01-06 11:08:47 -08004001 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004002 */
4003
4004int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4005{
4006 dutCmdResponse_t infoResp;
4007 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
4008 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08004009
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004010 printf("\n Entry wfaStaGenerateEvent... ");
4011
4012
4013 // Geneate the specified action and return with complete/error.
4014 if(staGenerateEvent->program == PROG_TYPE_WFD)
4015 {
4016 wfdGenEvent = &staGenerateEvent->wfdEvent;
4017 if(wfdGenEvent ->type == eUibcGen)
4018 {
Dake Zhao0a832172015-01-06 11:08:47 -08004019 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004020 else if(wfdGenEvent ->type == eUibcHid)
4021 {
Dake Zhao0a832172015-01-06 11:08:47 -08004022 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004023 else if(wfdGenEvent ->type == eFrameSkip)
4024 {
4025
4026 }
4027 else if(wfdGenEvent ->type == eI2cRead)
4028 {
4029 }
4030 else if(wfdGenEvent ->type == eI2cWrite)
4031 {
Dake Zhao0a832172015-01-06 11:08:47 -08004032 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004033 else if(wfdGenEvent ->type == eInputContent)
4034 {
Dake Zhao0a832172015-01-06 11:08:47 -08004035 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004036 else if(wfdGenEvent ->type == eIdrReq)
4037 {
Dake Zhao0a832172015-01-06 11:08:47 -08004038 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004039 }
Dake Zhao0a832172015-01-06 11:08:47 -08004040
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004041 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004042 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004043 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004044
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004045 return WFA_SUCCESS;
4046}
4047
Dake Zhao0a832172015-01-06 11:08:47 -08004048
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004049
4050
4051/*
Dake Zhao0a832172015-01-06 11:08:47 -08004052 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004053 */
4054
4055int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4056{
4057 dutCmdResponse_t infoResp;
4058// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08004059
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004060 printf("\n Entry wfaStaReinvokeWfdSession... ");
4061
4062 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08004063
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004064
4065 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004066 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004067 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004068
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004069 return WFA_SUCCESS;
4070}
4071
4072
4073int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4074{
Dake Zhao0a832172015-01-06 11:08:47 -08004075 dutCmdResponse_t infoResp;
4076 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004077
4078
Dake Zhao0a832172015-01-06 11:08:47 -08004079 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004080
Dake Zhao0a832172015-01-06 11:08:47 -08004081 printf("\n Entry wfaStaGetParameter... ");
4082
4083 // Check the program type
4084 if(staGetParam->program == PROG_TYPE_WFD)
4085 {
4086 if(staGetParam->getParamValue == eDiscoveredDevList )
4087 {
4088 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4089 paramList->getParamType = eDiscoveredDevList;
4090 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4091 }
4092 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004093
Dake Zhao655efed2015-03-11 17:39:13 -07004094 if(staGetParam->program == PROG_TYPE_WFDS)
4095 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004096
Dake Zhao655efed2015-03-11 17:39:13 -07004097 if(staGetParam->getParamValue == eDiscoveredDevList )
4098 {
4099 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4100 paramList->getParamType = eDiscoveredDevList;
4101 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4102
4103 }
4104 if(staGetParam->getParamValue == eOpenPorts)
4105 {
4106 // Run the port checker tool
4107 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
4108 paramList->getParamType = eOpenPorts;
4109 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
4110
4111 }
4112
4113 }
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004114 if(staGetParam->program == PROG_TYPE_NAN)
4115 {
4116 if(staGetParam->getParamValue == eMasterPref )
4117 {
4118 // Get the master preference of the device and return the value
4119 paramList->getParamType = eMasterPref;
4120 strcpy((char *)&paramList->masterPref, "0xff");
4121 }
4122 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004123
Dake Zhao655efed2015-03-11 17:39:13 -07004124 infoResp.status = STATUS_COMPLETE;
4125 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4126 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4127
4128 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004129}
4130
Ankur Vachhanic485b712012-02-15 23:29:49 +00004131
Dake Zhao655efed2015-03-11 17:39:13 -07004132int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4133{
4134
4135 dutCmdResponse_t infoResp;
4136 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4137
4138 printf("\n Entry wfaStaNfcAction... ");
4139
4140 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4141 {
4142 printf("\n NfcAction - HandOver... ");
4143
4144 }
4145 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4146 {
4147 printf("\n NfcAction - Read Tag... ");
4148
4149 }
4150 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4151 {
4152 printf("\n NfcAction - Write Select... ");
4153
4154 }
4155 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4156 {
4157 printf("\n NfcAction - Write Config... ");
4158
4159 }
4160 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4161 {
4162 printf("\n NfcAction - Write Password... ");
4163
4164 }
4165 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4166 {
4167 printf("\n NfcAction - WPS Handover... ");
4168
4169 }
4170
4171 // Fetch the device mode and put in infoResp->cmdru.p2presult
4172 //strcpy(infoResp->cmdru.p2presult, "GO");
4173
4174 // Fetch the device grp id and put in infoResp->cmdru.grpid
4175 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4176
4177 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4178 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4179 infoResp.cmdru.staNfcAction.peerRole = 1;
4180
4181
4182
4183
4184 infoResp.status = STATUS_COMPLETE;
4185 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4186 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4187
4188 return WFA_SUCCESS;
4189}
4190
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004191int wfaStaExecAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4192{
4193
4194 dutCmdResponse_t infoResp;
4195 caStaExecAction_t *staExecAction = (caStaExecAction_t *)caCmdBuf; //comment if not used
4196
4197 printf("\n Entry wfaStaExecAction... ");
4198
4199 if(staExecAction->prog == PROG_TYPE_NAN)
4200 {
4201 // Perform necessary configurations and actions
4202 // return the MAC address conditionally as per CAPI specification
4203 }
4204
4205 infoResp.status = STATUS_COMPLETE;
4206 wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4207 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4208
4209 return WFA_SUCCESS;
4210}
4211
Dake Zhao655efed2015-03-11 17:39:13 -07004212int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4213{
4214
4215 dutCmdResponse_t infoResp;
4216 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4217
4218 printf("\n Entry wfaStaInvokeCommand... ");
4219
4220
4221 // based on the command type , invoke API or complete the required procedures
4222 // return the defined parameters based on the command that is received ( example response below)
4223
4224 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4225 {
4226 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4227 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4228 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4229 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4230 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4231 }
4232 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4233 {
4234 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4235 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4236 }
4237 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4238 {
4239 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4240 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4241 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4242 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4243
4244 }
4245 infoResp.status = STATUS_COMPLETE;
4246 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4247 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4248
4249 return WFA_SUCCESS;
4250}
4251
4252
4253int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4254{
4255
4256 dutCmdResponse_t infoResp;
4257 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4258
4259 printf("\n Entry wfaStaManageService... ");
4260
4261 // based on the manage service type , invoke API's or complete the required procedures
4262 // return the defined parameters based on the command that is received ( example response below)
4263 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4264 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4265 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4266
4267 infoResp.status = STATUS_COMPLETE;
4268 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4269 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4270
4271 return WFA_SUCCESS;
4272}
4273
4274
4275
4276int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4277{
4278
4279 dutCmdResponse_t infoResp;
Dake Zhao353c55e2015-07-20 18:54:45 -07004280 caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004281
4282 printf("\n Entry wfaStaGetEvents... ");
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004283
4284 if(staGetEvents->program == PROG_TYPE_NAN)
4285 {
4286 // Get all the events from the Log file or stored events
4287 // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac
4288 }
Dake Zhao655efed2015-03-11 17:39:13 -07004289
4290 // Get all the event from the Log file or stored events
4291 // return the received/recorded events as space seperated list ( example response below)
4292 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4293
4294 infoResp.status = STATUS_COMPLETE;
4295 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4296 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4297
4298 return WFA_SUCCESS;
4299}
4300
4301int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4302{
4303
4304 dutCmdResponse_t infoResp;
Li Yinf467b182015-09-23 21:21:30 +08004305 caStaGetEventDetails_t *getStaGetEventDetails = (caStaGetEventDetails_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004306
4307 printf("\n Entry wfaStaGetEventDetails... ");
4308
4309
4310 // based on the Requested Event type
4311 // return the latest corresponding evnet detailed parameters ( example response below)
4312
4313 if(getStaGetEventDetails->eventId== eSearchResult )
4314 {
4315 // fetch from log file or event history for the search result event and return the parameters
4316 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4317
4318 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4319 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4320 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4321 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4322
4323 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4324 }
4325 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4326 { // fetch from log file or event history for the search terminated event and return the parameters
4327 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4328 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4329 }
4330 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4331 {// fetch from log file or event history for the Advertise Status event and return the parameters
4332 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4333 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4334
4335 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4336 }
4337 else if (getStaGetEventDetails->eventId == eSessionRequest)
4338 {// fetch from log file or event history for the session request event and return the parameters
4339 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4340 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4341 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4342 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4343 }
4344 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4345 {// fetch from log file or event history for the session status event and return the parameters
4346 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4347 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4348 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4349 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4350 }
4351 else if (getStaGetEventDetails->eventId == eConnectStatus)
4352 {
4353 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4354 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4355 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4356 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4357
4358 }
4359 else if (getStaGetEventDetails->eventId == ePortStatus)
4360 {
4361 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4362 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4363 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4364 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4365 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4366 }
4367
4368
4369
4370 infoResp.status = STATUS_COMPLETE;
4371 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4372 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4373
4374 return WFA_SUCCESS;
4375}
4376
4377
4378
4379