blob: 9f62050a18ce08aed4da278389abf79261029dd8 [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{
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200370 int slen, i = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000371 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
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000380 strcpy(ifinfo->dns[0], "0");
381 strcpy(ifinfo->dns[1], "0");
Dake Zhao0a832172015-01-06 11:08:47 -0800382
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000383 /*
Dake Zhao0a832172015-01-06 11:08:47 -0800384 * Run the script file "getipconfig.sh" to check the ip status
385 * (current implementation specific).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000386 * note: "getipconfig.sh" is only defined for the current implementation
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200387 *
388 * Example output:
389 * dhcpcli=/sbin/dhcpcd
390 *
391 * mac=50:e0:85:5f:e9:93
392 * ipaddr=192.168.0.116
393 * bcast=192.168.0.255
394 * mask=255.255.255.0
395 * nameserver 192.168.0.1
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000396 */
Dake Zhao0a832172015-01-06 11:08:47 -0800397 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000398
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200399 sret = systemWithLog(gCmdStr);
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200400 if (sret != 0)
401 {
402 ipconfigResp->status = STATUS_ERROR;
403 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
404 *respLen = WFA_TLV_HDR_LEN + 4;
405
406 DPRINT_ERR(WFA_ERR, "error from getipconfig exec: %d\n", sret);
407 return WFA_FAILURE;
408 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000409
410 /* open the output result and scan/retrieve the info */
411 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
412
413 if(tmpfd == NULL)
414 {
Dake Zhao0a832172015-01-06 11:08:47 -0800415 ipconfigResp->status = STATUS_ERROR;
416 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
417 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000418
Dake Zhao0a832172015-01-06 11:08:47 -0800419 DPRINT_ERR(WFA_ERR, "file open failed\n");
420 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000421 }
422
423 for(;;)
424 {
425 if(fgets(string, 256, tmpfd) == NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800426 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000427
428 /* check dhcp enabled */
429 if(strncmp(string, "dhcpcli", 7) ==0)
430 {
431 str = strtok(string, "=");
432 str = strtok(NULL, "=");
433 if(str != NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800434 ifinfo->isDhcp = 1;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000435 else
Dake Zhao0a832172015-01-06 11:08:47 -0800436 ifinfo->isDhcp = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000437 }
438
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000439 if(strncmp(string, "ipaddr", 6) == 0)
440 {
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200441 str = strchr(string, '=');
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000442 if(str != NULL)
443 {
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200444 strcpy(ifinfo->ipaddr, str + 1);
445 slen = strlen(ifinfo->ipaddr);
446 ifinfo->ipaddr[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000447 }
448 else
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200449 strcpy(ifinfo->ipaddr, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000450 }
451
452 /* check the mask */
453 if(strncmp(string, "mask", 4) == 0)
454 {
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200455 str = strchr(string, '=');
456 if(str != NULL)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000457 {
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200458 strcpy(ifinfo->mask, str + 1);
Dake Zhao0a832172015-01-06 11:08:47 -0800459 slen = strlen(ifinfo->mask);
460 ifinfo->mask[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000461 }
462 else
Dake Zhao0a832172015-01-06 11:08:47 -0800463 strcpy(ifinfo->mask, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000464 }
465
466 /* find out the dns server ip address */
467 if(strncmp(string, "nameserv", 8) == 0)
468 {
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200469 str = strchr(string, ' ');
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000470 if(str != NULL && i < 2)
471 {
Wojciech Jakobczyk71542532020-08-28 10:52:00 +0200472 strcpy(ifinfo->dns[i], str + 1);
Dake Zhao0a832172015-01-06 11:08:47 -0800473 slen = strlen(ifinfo->dns[i]);
474 ifinfo->dns[i][slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000475 }
476 else
Dake Zhao0a832172015-01-06 11:08:47 -0800477 strcpy(ifinfo->dns[i], "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000478
479 i++;
480 }
Dake Zhao0a832172015-01-06 11:08:47 -0800481 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000482
Dake Zhao0a832172015-01-06 11:08:47 -0800483 /*
484 * Report back the results
485 */
486 ipconfigResp->status = STATUS_COMPLETE;
487 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000488
Dake Zhao0a832172015-01-06 11:08:47 -0800489 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000490
491#if 0
Dake Zhao0a832172015-01-06 11:08:47 -0800492 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
493 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
494 ifinfo->dns[0], ifinfo->dns[1], *respLen);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000495#endif
496
Dake Zhao0a832172015-01-06 11:08:47 -0800497 fclose(tmpfd);
498 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000499}
500
501/*
502 * wfaStaSetIpConfig():
503 * The function is to set the ip configuration to a wireless I/F.
504 * 1. IP address
505 * 2. Mac address
506 * 3. default gateway
Dake Zhao0a832172015-01-06 11:08:47 -0800507 * 4. dns nameserver (pri and sec).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000508 */
509int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
510{
Dake Zhao0a832172015-01-06 11:08:47 -0800511 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
512 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
513 dutCmdResponse_t *staSetIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000514
Dake Zhao0a832172015-01-06 11:08:47 -0800515 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200516
517 if (ipconfig->isDhcp) {
518 DPRINT_INFO(WFA_OUT, "error: dhcp not supported\n");
519 staSetIpResp->status = STATUS_INVALID;
520 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
521 *respLen = WFA_TLV_HDR_LEN + 4;
522
523 return WFA_FAILURE;
524 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000525
Dake Zhao0a832172015-01-06 11:08:47 -0800526 /*
527 * Use command 'ifconfig' to configure the interface ip address, mask.
528 * (Linux specific).
529 */
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200530 sprintf(gCmdStr, "ifconfig %s %s netmask %s >/tmp/ifconfig.log 2>&1", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
531 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200532 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200533 if (sret != 0) {
534 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
535 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000536
Dake Zhao0a832172015-01-06 11:08:47 -0800537 /* use command 'route add' to set set gatewway (linux specific) */
538 if(ipconfig->defGateway[0] != '\0')
539 {
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200540 sprintf(gCmdStr, "route add default gw %s >/tmp/route.log 2>&1", ipconfig->defGateway);
541 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200542 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200543 if (sret != 0) {
544 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
545 }
Dake Zhao0a832172015-01-06 11:08:47 -0800546 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000547
Dake Zhao0a832172015-01-06 11:08:47 -0800548 /* set dns (linux specific) */
549 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200550 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200551 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200552 if (sret != 0) {
553 DPRINT_INFO(WFA_OUT, "exit code %d backing up resolv.conf\n", sret);
554 }
Dake Zhao0a832172015-01-06 11:08:47 -0800555 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200556 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200557 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200558 if (sret != 0) {
559 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
560 }
561 if (strlen(ipconfig->sec_dns) > 0) {
562 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
563 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200564 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200565 if (sret != 0) {
566 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
567 }
568 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000569
Dake Zhao0a832172015-01-06 11:08:47 -0800570 /*
571 * report status
572 */
573 staSetIpResp->status = STATUS_COMPLETE;
574 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
575 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000576
Dake Zhao0a832172015-01-06 11:08:47 -0800577 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000578}
579
580/*
581 * wfaStaVerifyIpConnection():
582 * The function is to verify if the station has IP connection with an AP by
583 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800584 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000585int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
586{
Dake Zhao0a832172015-01-06 11:08:47 -0800587 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
588 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000589
590#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800591 char strout[64], *pcnt;
592 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000593
Dake Zhao0a832172015-01-06 11:08:47 -0800594 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
595
596 /* set timeout value in case not set */
597 if(verip->cmdsu.verifyIp.timeout <= 0)
598 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000599 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800600 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000601
Dake Zhao0a832172015-01-06 11:08:47 -0800602 /* execute the ping command and pipe the result to a tmp file */
603 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 +0200604 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000605
Dake Zhao0a832172015-01-06 11:08:47 -0800606 /* scan/check the output */
607 tmpfile = fopen("/tmp/pingout.txt", "r+");
608 if(tmpfile == NULL)
609 {
610 verifyIpResp->status = STATUS_ERROR;
611 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
612 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000613
Dake Zhao0a832172015-01-06 11:08:47 -0800614 DPRINT_ERR(WFA_ERR, "file open failed\n");
615 return WFA_FAILURE;
616 }
617
618 verifyIpResp->status = STATUS_COMPLETE;
619 if(fscanf(tmpfile, "%s", strout) == EOF)
620 verifyIpResp->cmdru.connected = 0;
621 else
622 {
623 pcnt = strtok(strout, "%");
624
625 /* if the loss rate is 100%, not able to connect */
626 if(atoi(pcnt) == 100)
627 verifyIpResp->cmdru.connected = 0;
628 else
629 verifyIpResp->cmdru.connected = 1;
630 }
631
632 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000633#else
Dake Zhao0a832172015-01-06 11:08:47 -0800634 int btSockfd;
635 struct pollfd fds[2];
636 int timeout = 2000;
637 char anyBuf[64];
638 struct sockaddr_in toAddr;
639 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000640
Dake Zhao0a832172015-01-06 11:08:47 -0800641 verifyIpResp->status = STATUS_COMPLETE;
642 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000643
Dake Zhao0a832172015-01-06 11:08:47 -0800644 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000645
Dake Zhao0a832172015-01-06 11:08:47 -0800646 if(btSockfd == -1)
647 {
648 verifyIpResp->status = STATUS_ERROR;
649 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
650 *respLen = WFA_TLV_HDR_LEN + 4;
651 return WFA_FAILURE;;
652 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000653
Dake Zhao0a832172015-01-06 11:08:47 -0800654 toAddr.sin_family = AF_INET;
655 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
656 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000657
Dake Zhao0a832172015-01-06 11:08:47 -0800658 while(done)
659 {
660 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
661 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000662
Dake Zhao0a832172015-01-06 11:08:47 -0800663 fds[0].fd = btSockfd;
664 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000665
Dake Zhao0a832172015-01-06 11:08:47 -0800666 ret = poll(fds, 1, timeout);
667 switch(ret)
668 {
669 case 0:
670 /* it is time out, count a packet lost*/
671 break;
672 case -1:
673 /* it is an error */
674 default:
675 {
676 switch(fds[0].revents)
677 {
678 case POLLIN:
679 case POLLPRI:
680 case POLLOUT:
681 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
682 if(nbytes != 0)
683 verifyIpResp->cmdru.connected = 1;
684 done = 0;
685 break;
686 default:
687 /* errors but not care */
688 ;
689 }
690 }
691 }
692 if(cnt == 3)
693 {
694 done = 0;
695 }
696 }
697
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000698#endif
699
Dake Zhao0a832172015-01-06 11:08:47 -0800700 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000701
Dake Zhao0a832172015-01-06 11:08:47 -0800702 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
703
704 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000705}
706
707/*
708 * wfaStaGetMacAddress()
709 * This function is to retrieve the MAC address of a wireless I/F.
710 */
711int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
712{
713 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
714 dutCmdResponse_t *getmacResp = &gGenericResp;
715 char *str;
716 char *ifname = getMac->intf;
717
718 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800719 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000720
721 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
722 /*
723 * run the script "getipconfig.sh" to find out the mac
724 */
Dake Zhao0a832172015-01-06 11:08:47 -0800725 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200726 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000727
728 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
729 if(tmpfd == NULL)
730 {
Dake Zhao0a832172015-01-06 11:08:47 -0800731 getmacResp->status = STATUS_ERROR;
732 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
733 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000734
Dake Zhao0a832172015-01-06 11:08:47 -0800735 DPRINT_ERR(WFA_ERR, "file open failed\n");
736 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000737 }
738
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800739 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
740 {
Dake Zhao0a832172015-01-06 11:08:47 -0800741 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000742 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800743
744 str = strtok(string, " ");
745 while(str && ((strcmp(str,"HWaddr")) != 0))
746 {
Dake Zhao0a832172015-01-06 11:08:47 -0800747 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800748 }
Dake Zhao0a832172015-01-06 11:08:47 -0800749
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800750 /* get mac */
751 if(str)
752 {
753 str = strtok(NULL, " ");
754 strcpy(getmacResp->cmdru.mac, str);
755 getmacResp->status = STATUS_COMPLETE;
756 }
Dake Zhao0a832172015-01-06 11:08:47 -0800757
758 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000759
760 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
761
762 fclose(tmpfd);
763 return WFA_SUCCESS;
764}
765
766/*
767 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800768 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000769 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800770 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000771 */
772int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
773{
Dake Zhao0a832172015-01-06 11:08:47 -0800774 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000775
Dake Zhao0a832172015-01-06 11:08:47 -0800776 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000777
Dake Zhao0a832172015-01-06 11:08:47 -0800778 statsResp->status = STATUS_ERROR;
779 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
780 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000781
782
Dake Zhao0a832172015-01-06 11:08:47 -0800783 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000784}
785
786/*
787 * wfaSetEncryption():
788 * The function is to set the wireless interface with WEP or none.
789 *
Dake Zhao0a832172015-01-06 11:08:47 -0800790 * Since WEP is optional test, current function is only used for
791 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000792 * this function should be replaced by the next one (wfaSetEncryption1())
793 *
Dake Zhao0a832172015-01-06 11:08:47 -0800794 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000795 * 1. I/F
796 * 2. ssid
797 * 3. encpType - wep or none
798 * Optional:
799 * 4. key1
800 * 5. key2
801 * 6. key3
802 * 7. key4
803 * 8. activeKey Index
804 */
805
806int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
807{
Dake Zhao0a832172015-01-06 11:08:47 -0800808 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
809 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000810
Dake Zhao0a832172015-01-06 11:08:47 -0800811 /*
812 * disable the network first
813 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200814 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200815 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000816
Dake Zhao0a832172015-01-06 11:08:47 -0800817 /*
818 * set SSID
819 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200820 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200821 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000822
Dake Zhao0a832172015-01-06 11:08:47 -0800823 /*
824 * Tell the supplicant for infrastructure mode (1)
825 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200826 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200827 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000828
Dake Zhao0a832172015-01-06 11:08:47 -0800829 /*
830 * set Key management to NONE (NO WPA) for plaintext or WEP
831 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200832 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200833 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000834
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200835 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200836 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000837
Dake Zhao0a832172015-01-06 11:08:47 -0800838 setEncrypResp->status = STATUS_COMPLETE;
839 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
840 *respLen = WFA_TLV_HDR_LEN + 4;
841
842 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000843}
844
845/*
846 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800847 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000848 */
849int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
850{
Dake Zhao0a832172015-01-06 11:08:47 -0800851 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
852 dutCmdResponse_t *setEncrypResp = &gGenericResp;
853 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000854
Dake Zhao0a832172015-01-06 11:08:47 -0800855 /*
856 * disable the network first
857 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200858 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setEncryp->intf);
859 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000860
Dake Zhao0a832172015-01-06 11:08:47 -0800861 /*
862 * set SSID
863 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200864 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
865 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000866
Dake Zhao0a832172015-01-06 11:08:47 -0800867 /*
868 * Tell the supplicant for infrastructure mode (1)
869 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200870 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 0", setEncryp->intf);
871 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000872
Dake Zhao0a832172015-01-06 11:08:47 -0800873 /*
874 * set Key management to NONE (NO WPA) for plaintext or WEP
875 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200876 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
877 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000878
Dake Zhao0a832172015-01-06 11:08:47 -0800879 /* set keys */
880 if(setEncryp->encpType == 1)
881 {
882 for(i=0; i<4; i++)
883 {
884 if(setEncryp->keys[i][0] != '\0')
885 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200886 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i %s",
Dake Zhao0a832172015-01-06 11:08:47 -0800887 setEncryp->intf, i, setEncryp->keys[i]);
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200888 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800889 }
890 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000891
Dake Zhao0a832172015-01-06 11:08:47 -0800892 /* set active key */
893 i = setEncryp->activeKeyIdx;
894 if(setEncryp->keys[i][0] != '\0')
895 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200896 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_tx_keyidx %i",
Dake Zhao0a832172015-01-06 11:08:47 -0800897 setEncryp->intf, setEncryp->activeKeyIdx);
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200898 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800899 }
900 }
901 else /* clearly remove the keys -- reported by p.schwann */
902 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000903
Dake Zhao0a832172015-01-06 11:08:47 -0800904 for(i = 0; i < 4; i++)
905 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200906 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
907 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800908 }
909 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000910
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200911 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setEncryp->intf);
912 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000913
Dake Zhao0a832172015-01-06 11:08:47 -0800914 setEncrypResp->status = STATUS_COMPLETE;
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200915 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, sizeof(setEncrypResp->status), (BYTE *)setEncrypResp, respBuf);
916 *respLen = WFA_TLV_HDR_LEN + sizeof(setEncrypResp->status);
Dake Zhao0a832172015-01-06 11:08:47 -0800917
918 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000919}
920
921int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
922{
923 int ret = WFA_SUCCESS;
924
925 return ret;
926}
927
928/*
929 * wfaStaSetEapTLS():
930 * This is to set
931 * 1. ssid
932 * 2. encrypType - tkip or aes-ccmp
933 * 3. keyManagementType - wpa or wpa2
934 * 4. trustedRootCA
935 * 5. clientCertificate
936 */
937int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
938{
Dake Zhao0a832172015-01-06 11:08:47 -0800939 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
940 char *ifname = setTLS->intf;
941 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000942
Dake Zhao0a832172015-01-06 11:08:47 -0800943 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000944
Dake Zhao0a832172015-01-06 11:08:47 -0800945 /*
946 * need to store the trustedROOTCA and clientCertificate into a file first.
947 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000948#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800949 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200950 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000951#else
952
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200953 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200954 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000955
Dake Zhao0a832172015-01-06 11:08:47 -0800956 /* ssid */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200957 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200958 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000959
Dake Zhao0a832172015-01-06 11:08:47 -0800960 /* key management */
961 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
962 {
963 }
964 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
965 {
966 }
967 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
968 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000969
Dake Zhao0a832172015-01-06 11:08:47 -0800970 }
971 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
972 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200973 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -0800974 }
975 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
976 {
977 // to take all and device to pick any one supported.
978 }
979 else
980 {
981 // ??
982 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200983 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000984
Dake Zhao0a832172015-01-06 11:08:47 -0800985 /* protocol WPA */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200986 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200987 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000988
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200989 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap TLS", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200990 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000991
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200992 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200993 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000994
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200995 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200996 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000997
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200998 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 +0200999 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001000
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001001 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001002 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001003
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001004 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001005 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001006#endif
1007
Dake Zhao0a832172015-01-06 11:08:47 -08001008 setEapTlsResp->status = STATUS_COMPLETE;
1009 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
1010 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001011
Dake Zhao0a832172015-01-06 11:08:47 -08001012 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001013}
1014
1015/*
Dake Zhao0a832172015-01-06 11:08:47 -08001016 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001017 * 1. ssid
1018 * 2. passPhrase
1019 * 3. keyMangementType - wpa/wpa2
1020 * 4. encrypType - tkip or aes-ccmp
1021 */
1022int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -08001023{
1024 /*Incompleted function*/
1025 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001026
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001027#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -08001028 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001029#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001030 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001031 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001032#else
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001033 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001034 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001035
Dake Zhao0a832172015-01-06 11:08:47 -08001036 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001037 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001038 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
1039 {
1040 // take all and device to pick it supported.
1041 }
1042 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
1043 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001044
Dake Zhao0a832172015-01-06 11:08:47 -08001045 }
1046 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
1047 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001048
Dake Zhao0a832172015-01-06 11:08:47 -08001049 }
1050 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
1051 {
Ray Wang9c508692014-04-01 17:04:59 -07001052
Dake Zhao0a832172015-01-06 11:08:47 -08001053 }
1054 else
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001055 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001056
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001057 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001058
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001059 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001060 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001061
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001062 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setPSK->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001063 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001064
Dake Zhao0a832172015-01-06 11:08:47 -08001065 /* if PMF enable */
1066 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
1067 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001068
Dake Zhao0a832172015-01-06 11:08:47 -08001069 }
1070 else if(setPSK->pmf == WFA_REQUIRED)
1071 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001072
Dake Zhao0a832172015-01-06 11:08:47 -08001073 }
1074 else if(setPSK->pmf == WFA_F_REQUIRED)
1075 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001076
Dake Zhao0a832172015-01-06 11:08:47 -08001077 }
1078 else if(setPSK->pmf == WFA_F_DISABLED)
1079 {
1080
1081 }
1082 else
1083 {
1084 /* Disable PMF */
1085
1086 }
1087
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001088#endif
1089
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001090#endif
1091
Dake Zhao0a832172015-01-06 11:08:47 -08001092 setPskResp->status = STATUS_COMPLETE;
1093 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1094 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001095
Dake Zhao0a832172015-01-06 11:08:47 -08001096 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001097}
1098
1099/*
Dake Zhao0a832172015-01-06 11:08:47 -08001100 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001101 * Get vendor specific information in name/value pair by a wireless I/F.
1102 */
1103int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1104{
Dake Zhao0a832172015-01-06 11:08:47 -08001105 dutCmdResponse_t infoResp;
1106 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001107 FILE *tmpfd;
1108 char vendor[256];
1109 const char* vendorFileName = "/tmp/ifvendor.txt";
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001110
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001111 sprintf(gCmdStr, "getifvendor.sh %s %s\n", getInfo->intf, vendorFileName);
1112
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001113 if (systemWithLog(gCmdStr) == -1)
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001114 {
1115 infoResp.status = STATUS_ERROR;
1116 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1117 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1118
1119 DPRINT_ERR(WFA_ERR, "script %s failed\n", vendorFileName);
1120 return WFA_FAILURE;
1121 }
1122
1123 /* open the output result and scan/retrieve the info */
1124 tmpfd = fopen(vendorFileName, "r+");
1125
1126 if(tmpfd == NULL || fgets(vendor, 256, tmpfd) == NULL)
1127 {
1128 infoResp.status = STATUS_ERROR;
1129 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1130 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1131
1132 DPRINT_ERR(WFA_ERR, "file read failed\n");
1133
1134 if (tmpfd != NULL)
1135 {
1136 fclose(tmpfd);
1137 remove(vendorFileName);
1138 }
1139
1140 return WFA_FAILURE;
1141 }
1142
1143 snprintf(infoResp.cmdru.info, sizeof(infoResp.cmdru.info), "interface,%s,description,%s",
1144 getInfo->intf, vendor);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001145
Dake Zhao0a832172015-01-06 11:08:47 -08001146 infoResp.status = STATUS_COMPLETE;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001147 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1148 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1149
1150 fclose(tmpfd);
1151 remove(vendorFileName);
Dake Zhao0a832172015-01-06 11:08:47 -08001152
1153 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001154}
1155
1156/*
1157 * wfaStaSetEapTTLS():
1158 * This is to set
1159 * 1. ssid
1160 * 2. username
1161 * 3. passwd
1162 * 4. encrypType - tkip or aes-ccmp
1163 * 5. keyManagementType - wpa or wpa2
1164 * 6. trustedRootCA
1165 */
1166int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1167{
Dake Zhao0a832172015-01-06 11:08:47 -08001168 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1169 char *ifname = setTTLS->intf;
1170 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001171
1172#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001173 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 +02001174 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001175#else
1176
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001177 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001178 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001179
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001180 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001181 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001182
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001183 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001184 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001185
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001186 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001187 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001188
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001189 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001190 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001191
Dake Zhao0a832172015-01-06 11:08:47 -08001192 /* This may not need to set. if it is not set, default to take all */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001193// sprintf(cmdStr, "wpa_cli.sh -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001194 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1195 {
1196 }
1197 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1198 {
1199 }
1200 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1201 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001202
Dake Zhao0a832172015-01-06 11:08:47 -08001203 }
1204 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1205 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001206
Dake Zhao0a832172015-01-06 11:08:47 -08001207 }
1208 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1209 {
1210 // to take all and device to pick one it supported
1211 }
1212 else
1213 {
1214 // ??
1215 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001216 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001217
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001218 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap TTLS", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001219 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001220
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001221 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 +02001222 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001223
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001224 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001225 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001226
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001227 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001228 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001229
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001230 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001231 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001232#endif
1233
Dake Zhao0a832172015-01-06 11:08:47 -08001234 setEapTtlsResp->status = STATUS_COMPLETE;
1235 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1236 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001237
Dake Zhao0a832172015-01-06 11:08:47 -08001238 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001239}
1240
1241/*
1242 * wfaStaSetEapSIM():
1243 * This is to set
1244 * 1. ssid
1245 * 2. user name
1246 * 3. passwd
1247 * 4. encrypType - tkip or aes-ccmp
1248 * 5. keyMangementType - wpa or wpa2
1249 */
1250int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1251{
Dake Zhao0a832172015-01-06 11:08:47 -08001252 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1253 char *ifname = setSIM->intf;
1254 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001255
1256#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001257 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001258 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001259#else
1260
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001261 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001262 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001263
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001264 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001265 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001266
1267
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001268 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001269 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001270
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001271 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001272 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001273
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001274 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap SIM", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001275 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001276
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001277 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001278 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001279
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001280 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001281 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001282
Dake Zhao0a832172015-01-06 11:08:47 -08001283 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1284 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001285 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001286 }
1287 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1288 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001289 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001290 }
1291 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1292 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001293 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-FT", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001294 }
1295 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1296 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001297 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001298 }
1299 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1300 {
1301 // take all and device to pick one which is supported.
1302 }
1303 else
1304 {
1305 // ??
1306 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001307 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001308
1309#endif
1310
Dake Zhao0a832172015-01-06 11:08:47 -08001311 setEapSimResp->status = STATUS_COMPLETE;
1312 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1313 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001314
Dake Zhao0a832172015-01-06 11:08:47 -08001315 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001316}
1317
1318/*
1319 * wfaStaSetPEAP()
1320 * This is to set
1321 * 1. ssid
1322 * 2. user name
1323 * 3. passwd
1324 * 4. encryType - tkip or aes-ccmp
1325 * 5. keyMgmtType - wpa or wpa2
1326 * 6. trustedRootCA
1327 * 7. innerEAP
1328 * 8. peapVersion
1329 */
1330int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1331{
Dake Zhao0a832172015-01-06 11:08:47 -08001332 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1333 char *ifname = setPEAP->intf;
1334 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001335
1336#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001337 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1338 setPEAP->passwd, setPEAP->trustedRootCA,
1339 setPEAP->encrptype, setPEAP->peapVersion,
1340 setPEAP->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001341 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001342#else
1343
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001344 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001345 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001346
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001347 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001348 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001349
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001350 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap PEAP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001351 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001352
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001353 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001354 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001355
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001356 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001357 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001358
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001359 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001360 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001361
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001362 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 +02001363 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001364
Dake Zhao0a832172015-01-06 11:08:47 -08001365 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1366 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001367 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001368 }
1369 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1370 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001371 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001372 }
1373 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1374 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001375 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-FT", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001376 }
1377 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1378 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001379 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001380 }
1381 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1382 {
1383 // take all and device to pick one which is supported.
1384 }
1385 else
1386 {
1387 // ??
1388 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001389 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001390
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001391 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001392 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001393
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001394 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001395 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001396
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001397 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001398 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001399#endif
1400
Dake Zhao0a832172015-01-06 11:08:47 -08001401 setPeapResp->status = STATUS_COMPLETE;
1402 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1403 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001404
Dake Zhao0a832172015-01-06 11:08:47 -08001405 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001406}
1407
1408/*
1409 * wfaStaSetUAPSD()
1410 * This is to set
1411 * 1. acBE
1412 * 2. acBK
1413 * 3. acVI
1414 * 4. acVO
1415 */
1416int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1417{
Dake Zhao0a832172015-01-06 11:08:47 -08001418 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001419#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001420 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1421 char *ifname = setUAPSD->intf;
1422 char tmpStr[10];
1423 char line[100];
1424 char *pathl="/etc/Wireless/RT61STA";
1425 BYTE acBE=1;
1426 BYTE acBK=1;
1427 BYTE acVO=1;
1428 BYTE acVI=1;
1429 BYTE APSDCapable;
1430 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001431
Dake Zhao0a832172015-01-06 11:08:47 -08001432 /*
1433 * A series of setting need to be done before doing WMM-PS
1434 * Additional steps of configuration may be needed.
1435 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001436
Dake Zhao0a832172015-01-06 11:08:47 -08001437 /*
1438 * bring down the interface
1439 */
1440 sprintf(gCmdStr, "ifconfig %s down",ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001441 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001442 /*
1443 * Unload the Driver
1444 */
1445 sprintf(gCmdStr, "rmmod rt61");
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001446 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001447#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001448 if(setUAPSD->acBE != 1)
1449 acBE=setUAPSD->acBE = 0;
1450 if(setUAPSD->acBK != 1)
1451 acBK=setUAPSD->acBK = 0;
1452 if(setUAPSD->acVO != 1)
1453 acVO=setUAPSD->acVO = 0;
1454 if(setUAPSD->acVI != 1)
1455 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001456#else
Dake Zhao0a832172015-01-06 11:08:47 -08001457 acBE=setUAPSD->acBE;
1458 acBK=setUAPSD->acBK;
1459 acVO=setUAPSD->acVO;
1460 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001461#endif
1462
Dake Zhao0a832172015-01-06 11:08:47 -08001463 APSDCapable = acBE||acBK||acVO||acVI;
1464 /*
1465 * set other AC parameters
1466 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001467
Dake Zhao0a832172015-01-06 11:08:47 -08001468 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1469 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 +02001470 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001471
Dake Zhao0a832172015-01-06 11:08:47 -08001472 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001473 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001474 pipe = popen("uname -r", "r");
1475 /* Read into line the output of uname*/
1476 fscanf(pipe,"%s",line);
1477 pclose(pipe);
1478
1479 /*
1480 * load the Driver
1481 */
1482 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001483 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001484
1485 sprintf(gCmdStr, "ifconfig %s up",ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001486 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001487#endif
1488
Dake Zhao0a832172015-01-06 11:08:47 -08001489 setUAPSDResp->status = STATUS_COMPLETE;
1490 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1491 *respLen = WFA_TLV_HDR_LEN + 4;
1492 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001493}
1494
1495int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1496{
Dake Zhao0a832172015-01-06 11:08:47 -08001497 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1498 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1499 dutCmdResponse_t *infoResp = &gGenericResp;
1500 /*a vendor can fill in the proper info or anything non-disclosure */
1501 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001502
Dake Zhao0a832172015-01-06 11:08:47 -08001503 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001504
Dake Zhao0a832172015-01-06 11:08:47 -08001505 if(devInfo->fw == 0)
1506 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1507 else
1508 {
1509 // Call internal API to pull the version ID */
Li Yin1ac40782015-09-23 20:38:07 +08001510 strncpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
Dake Zhao0a832172015-01-06 11:08:47 -08001511 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001512
Dake Zhao0a832172015-01-06 11:08:47 -08001513 infoResp->status = STATUS_COMPLETE;
1514 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1515 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001516
Dake Zhao0a832172015-01-06 11:08:47 -08001517 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001518
1519}
1520
1521/*
1522 * This funciton is to retrieve a list of interfaces and return
1523 * the list back to Agent control.
1524 * ********************************************************************
1525 * Note: We intend to make this WLAN interface name as a hardcode name.
1526 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001527 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1528 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001529 * likely is hardcoded just for CAPI command responses.
1530 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001531 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001532 */
1533int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1534{
Dake Zhao0a832172015-01-06 11:08:47 -08001535 dutCmdResponse_t *infoResp = &gGenericResp;
1536 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1537 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001538
Dake Zhao0a832172015-01-06 11:08:47 -08001539 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001540
Dake Zhao0a832172015-01-06 11:08:47 -08001541 switch(ifList->cmdsu.iftype)
1542 {
1543 case IF_80211:
1544 infoResp->status = STATUS_COMPLETE;
1545 ifListResp->iftype = IF_80211;
1546 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1547 strcpy(ifListResp->ifs[1], "NULL");
1548 strcpy(ifListResp->ifs[2], "NULL");
1549 break;
1550 case IF_ETH:
1551 infoResp->status = STATUS_COMPLETE;
1552 ifListResp->iftype = IF_ETH;
1553 strcpy(ifListResp->ifs[0], "eth0");
1554 strcpy(ifListResp->ifs[1], "NULL");
1555 strcpy(ifListResp->ifs[2], "NULL");
1556 break;
1557 default:
1558 {
1559 infoResp->status = STATUS_ERROR;
1560 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1561 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001562
Dake Zhao0a832172015-01-06 11:08:47 -08001563 return WFA_SUCCESS;
1564 }
1565 }
1566
1567 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1568 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1569
1570 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001571}
1572
1573int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1574{
Dake Zhao0a832172015-01-06 11:08:47 -08001575 dutCmdResponse_t *debugResp = &gGenericResp;
1576 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001577
Dake Zhao0a832172015-01-06 11:08:47 -08001578 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001579
Dake Zhao0a832172015-01-06 11:08:47 -08001580 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1581 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1582 else
1583 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001584
Dake Zhao0a832172015-01-06 11:08:47 -08001585 debugResp->status = STATUS_COMPLETE;
1586 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1587 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001588
1589
Dake Zhao0a832172015-01-06 11:08:47 -08001590 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001591}
1592
1593
1594/*
1595 * wfaStaGetBSSID():
1596 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001597 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001598int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1599{
Dake Zhao0a832172015-01-06 11:08:47 -08001600 char string[64];
1601 char *str;
1602 FILE *tmpfd;
1603 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001604
Dake Zhao0a832172015-01-06 11:08:47 -08001605 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1606 /* retrieve the BSSID */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001607 sprintf(gCmdStr, "wpa_cli.sh status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001608
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001609 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001610
Dake Zhao0a832172015-01-06 11:08:47 -08001611 tmpfd = fopen("/tmp/bssid.txt", "r+");
1612 if(tmpfd == NULL)
1613 {
1614 bssidResp->status = STATUS_ERROR;
1615 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1616 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001617
Dake Zhao0a832172015-01-06 11:08:47 -08001618 DPRINT_ERR(WFA_ERR, "file open failed\n");
1619 return WFA_FAILURE;
1620 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001621
Dake Zhao0a832172015-01-06 11:08:47 -08001622 for(;;)
1623 {
1624 if(fscanf(tmpfd, "%s", string) == EOF)
1625 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001626 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001627 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001628 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001629 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001630
Dake Zhao0a832172015-01-06 11:08:47 -08001631 if(strncmp(string, "bssid", 5) == 0)
1632 {
1633 str = strtok(string, "=");
1634 str = strtok(NULL, "=");
1635 if(str != NULL)
1636 {
1637 strcpy(bssidResp->cmdru.bssid, str);
1638 bssidResp->status = STATUS_COMPLETE;
1639 break;
1640 }
1641 }
1642 }
1643
1644 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1645 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1646
1647 fclose(tmpfd);
1648 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001649}
1650
1651/*
1652 * wfaStaSetIBSS()
1653 * This is to set
1654 * 1. ssid
1655 * 2. channel
1656 * 3. encrypType - none or wep
1657 * optional
1658 * 4. key1
1659 * 5. key2
1660 * 6. key3
1661 * 7. key4
1662 * 8. activeIndex - 1, 2, 3, or 4
1663 */
1664int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1665{
Dake Zhao0a832172015-01-06 11:08:47 -08001666 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1667 dutCmdResponse_t *setIbssResp = &gGenericResp;
1668 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001669
Dake Zhao0a832172015-01-06 11:08:47 -08001670 /*
1671 * disable the network first
1672 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001673 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001674 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001675
Dake Zhao0a832172015-01-06 11:08:47 -08001676 /*
1677 * set SSID
1678 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001679 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001680 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001681
Dake Zhao0a832172015-01-06 11:08:47 -08001682 /*
1683 * Set channel for IBSS
1684 */
1685 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001686 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001687
Dake Zhao0a832172015-01-06 11:08:47 -08001688 /*
1689 * Tell the supplicant for IBSS mode (1)
1690 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001691 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 1", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001692 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001693
Dake Zhao0a832172015-01-06 11:08:47 -08001694 /*
1695 * set Key management to NONE (NO WPA) for plaintext or WEP
1696 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001697 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001698 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001699
Dake Zhao0a832172015-01-06 11:08:47 -08001700 if(setIBSS->encpType == 1)
1701 {
1702 for(i=0; i<4; i++)
1703 {
1704 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1705 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001706 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i \"%s\"",
Dake Zhao0a832172015-01-06 11:08:47 -08001707 setIBSS->intf, i, setIBSS->keys[i]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001708 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001709 }
1710 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001711
Dake Zhao0a832172015-01-06 11:08:47 -08001712 i = setIBSS->activeKeyIdx;
1713 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1714 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001715 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_tx_keyidx %i",
Dake Zhao0a832172015-01-06 11:08:47 -08001716 setIBSS->intf, setIBSS->activeKeyIdx);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001717 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001718 }
1719 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001720
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001721 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001722 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001723
Dake Zhao0a832172015-01-06 11:08:47 -08001724 setIbssResp->status = STATUS_COMPLETE;
1725 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1726 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001727
Dake Zhao0a832172015-01-06 11:08:47 -08001728 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001729}
1730
1731/*
1732 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001733 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001734 * adhoc)
1735 * Input parameters:
1736 * 1. I/F
1737 * 2. ssid
1738 * 3. mode adhoc or managed
1739 * 4. encType
1740 * 5. channel
1741 * 6. key(s)
1742 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001743 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001744int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1745{
Dake Zhao0a832172015-01-06 11:08:47 -08001746 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1747 dutCmdResponse_t *SetModeResp = &gGenericResp;
1748 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001749
Dake Zhao0a832172015-01-06 11:08:47 -08001750 /*
1751 * bring down the interface
1752 */
1753 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001754 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001755
Dake Zhao0a832172015-01-06 11:08:47 -08001756 /*
1757 * distroy the interface
1758 */
1759 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001760 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001761
1762
Dake Zhao0a832172015-01-06 11:08:47 -08001763 /*
1764 * re-create the interface with the given mode
1765 */
1766 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001767 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001768 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001769 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1770
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001771 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001772 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001773 {
Dake Zhao0a832172015-01-06 11:08:47 -08001774 int j = setmode->activeKeyIdx;
1775 for(i=0; i<4; i++)
1776 {
1777 if(setmode->keys[i][0] != '\0')
1778 {
1779 sprintf(gCmdStr, "iwconfig %s key s:%s",
1780 setmode->intf, setmode->keys[i]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001781 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001782 }
1783 /* set active key */
1784 if(setmode->keys[j][0] != '\0')
1785 sprintf(gCmdStr, "iwconfig %s key s:%s",
1786 setmode->intf, setmode->keys[j]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001787 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001788 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001789
1790 }
Dake Zhao0a832172015-01-06 11:08:47 -08001791 /*
1792 * Set channel for IBSS
1793 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001794 if(setmode->channel)
1795 {
Dake Zhao0a832172015-01-06 11:08:47 -08001796 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001797 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001798 }
1799
1800
Dake Zhao0a832172015-01-06 11:08:47 -08001801 /*
1802 * set SSID
1803 */
1804 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001805 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001806
Dake Zhao0a832172015-01-06 11:08:47 -08001807 /*
1808 * bring up the interface
1809 */
1810 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001811 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001812
Dake Zhao0a832172015-01-06 11:08:47 -08001813 SetModeResp->status = STATUS_COMPLETE;
1814 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1815 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001816
Dake Zhao0a832172015-01-06 11:08:47 -08001817 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001818}
1819
1820int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1821{
Dake Zhao0a832172015-01-06 11:08:47 -08001822 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1823 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001824
Dake Zhao0a832172015-01-06 11:08:47 -08001825 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001826 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001827
1828
Dake Zhao0a832172015-01-06 11:08:47 -08001829 SetPSResp->status = STATUS_COMPLETE;
1830 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1831 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001832
Dake Zhao0a832172015-01-06 11:08:47 -08001833 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001834}
1835
1836int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1837{
Dake Zhao0a832172015-01-06 11:08:47 -08001838 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1839 dutCmdResponse_t *upLoadResp = &gGenericResp;
1840 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001841
Dake Zhao0a832172015-01-06 11:08:47 -08001842 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1843 {
1844 int rbytes;
1845 /*
1846 * if asked for the first packet, always to open the file
1847 */
1848 if(upload->next == 1)
1849 {
1850 if(e2efp != NULL)
1851 {
1852 fclose(e2efp);
1853 e2efp = NULL;
1854 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001855
Dake Zhao0a832172015-01-06 11:08:47 -08001856 e2efp = fopen(e2eResults, "r");
1857 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001858
Dake Zhao0a832172015-01-06 11:08:47 -08001859 if(e2efp == NULL)
1860 {
1861 upLoadResp->status = STATUS_ERROR;
1862 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1863 *respLen = WFA_TLV_HDR_LEN + 4;
1864 return WFA_FAILURE;
1865 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001866
Dake Zhao0a832172015-01-06 11:08:47 -08001867 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001868
Dake Zhao0a832172015-01-06 11:08:47 -08001869 if(rbytes < 256)
1870 {
1871 /*
1872 * this means no more bytes after this read
1873 */
1874 upld->seqnum = 0;
1875 fclose(e2efp);
1876 e2efp=NULL;
1877 }
1878 else
1879 {
1880 upld->seqnum = upload->next;
1881 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001882
Dake Zhao0a832172015-01-06 11:08:47 -08001883 upld->nbytes = rbytes;
1884
1885 upLoadResp->status = STATUS_COMPLETE;
1886 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1887 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1888 }
1889 else
1890 {
1891 upLoadResp->status = STATUS_ERROR;
1892 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1893 *respLen = WFA_TLV_HDR_LEN + 4;
1894 }
1895
1896 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001897}
1898/*
1899 * wfaStaSetWMM()
1900 * TO be ported on a specific plaform for the DUT
1901 * This is to set the WMM related parameters at the DUT.
1902 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1903 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1904 */
1905int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1906{
1907#ifdef WFA_WMM_AC
1908 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1909 char *ifname = setwmm->intf;
1910 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001911
1912 switch(setwmm->group)
1913 {
1914 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001915 if (setwmm->send_trig)
1916 {
1917 int Sockfd;
1918 struct sockaddr_in psToAddr;
1919 unsigned int TxMsg[512];
1920
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001921 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001922 memset(&psToAddr, 0, sizeof(psToAddr));
1923 psToAddr.sin_family = AF_INET;
1924 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1925 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001926
1927
Dake Zhao0a832172015-01-06 11:08:47 -08001928 switch (setwmm->trig_ac)
1929 {
1930 case WMMAC_AC_VO:
1931 wfaTGSetPrio(Sockfd, 7);
1932 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1933 printf("\r\nSending AC_VO trigger packet\n");
1934 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001935
Dake Zhao0a832172015-01-06 11:08:47 -08001936 case WMMAC_AC_VI:
1937 wfaTGSetPrio(Sockfd, 5);
1938 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1939 printf("\r\nSending AC_VI trigger packet\n");
1940 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001941
Dake Zhao0a832172015-01-06 11:08:47 -08001942 case WMMAC_AC_BK:
1943 wfaTGSetPrio(Sockfd, 2);
1944 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1945 printf("\r\nSending AC_BK trigger packet\n");
1946 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001947
Dake Zhao0a832172015-01-06 11:08:47 -08001948 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001949 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001950 wfaTGSetPrio(Sockfd, 0);
1951 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1952 printf("\r\nSending AC_BE trigger packet\n");
1953 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001954 }
1955
Dake Zhao0a832172015-01-06 11:08:47 -08001956 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1957 sizeof(struct sockaddr));
1958 close(Sockfd);
1959 usleep(1000000);
1960 }
1961 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001962 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001963 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001964 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1965 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1966 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1967 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1968 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1969 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1970 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1971 setwmm->actions.addts.dialog_token,
1972 setwmm->actions.addts.tspec.tsinfo.TID,
1973 setwmm->actions.addts.tspec.tsinfo.direction,
1974 setwmm->actions.addts.tspec.tsinfo.PSB,
1975 setwmm->actions.addts.tspec.tsinfo.UP,
1976 setwmm->actions.addts.tspec.tsinfo.infoAck,
1977 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1978 setwmm->actions.addts.tspec.Fixed,
1979 setwmm->actions.addts.tspec.size,
1980 setwmm->actions.addts.tspec.maxsize,
1981 setwmm->actions.addts.tspec.min_srvc,
1982 setwmm->actions.addts.tspec.max_srvc,
1983 setwmm->actions.addts.tspec.inactivity,
1984 setwmm->actions.addts.tspec.suspension,
1985 setwmm->actions.addts.tspec.srvc_strt_tim,
1986 setwmm->actions.addts.tspec.mindatarate,
1987 setwmm->actions.addts.tspec.meandatarate,
1988 setwmm->actions.addts.tspec.peakdatarate,
1989 setwmm->actions.addts.tspec.burstsize,
1990 setwmm->actions.addts.tspec.delaybound,
1991 setwmm->actions.addts.tspec.PHYrate,
1992 setwmm->actions.addts.tspec.sba,
1993 setwmm->actions.addts.tspec.medium_time,
1994 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001995
Dake Zhao862c94b2014-12-08 14:35:35 -08001996 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001997
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001998 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001999 }
2000 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08002001 {
2002 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002003 }
2004
2005 setwmmResp->status = STATUS_COMPLETE;
2006 break;
2007
2008 case GROUP_WMMCONF:
2009 sprintf(gCmdStr, "iwconfig %s rts %d",
2010 ifname,setwmm->actions.config.rts_thr);
2011
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002012 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002013 sprintf(gCmdStr, "iwconfig %s frag %d",
2014 ifname,setwmm->actions.config.frag_thr);
2015
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002016 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002017 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
2018 ifname, setwmm->actions.config.wmm);
2019
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002020 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002021 setwmmResp->status = STATUS_COMPLETE;
2022 break;
2023
2024 default:
2025 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
2026 setwmmResp->status = STATUS_ERROR;
2027 break;
2028
2029 }
2030
2031 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
2032 *respLen = WFA_TLV_HDR_LEN + 4;
2033#endif
2034
2035 return WFA_SUCCESS;
2036}
2037
2038int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2039{
Dake Zhao0a832172015-01-06 11:08:47 -08002040 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002041
Dake Zhao0a832172015-01-06 11:08:47 -08002042 /*
2043 * run your device to send NEIGREQ
2044 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002045
Dake Zhao0a832172015-01-06 11:08:47 -08002046 sendNeigReqResp->status = STATUS_COMPLETE;
2047 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
2048 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002049
Dake Zhao0a832172015-01-06 11:08:47 -08002050 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002051}
2052
2053int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2054{
2055 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
2056 char *ifname = setFAST->intf;
2057 dutCmdResponse_t *setEapFastResp = &gGenericResp;
2058
2059#ifdef WFA_NEW_CLI_FORMAT
2060 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08002061 setFAST->passwd, setFAST->pacFileName,
2062 setFAST->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002063 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002064#else
2065
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002066 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002067 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002068
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002069 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002070 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002071
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002072 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002073 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002074
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002075 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002076 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002077
2078 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
2079 {
2080 }
2081 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
2082 {
2083 }
2084 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
2085 {
Dake Zhao0a832172015-01-06 11:08:47 -08002086
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002087 }
2088 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2089 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002090 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002091 }
2092 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2093 {
Dake Zhao0a832172015-01-06 11:08:47 -08002094 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002095 }
2096 else
2097 {
Dake Zhao0a832172015-01-06 11:08:47 -08002098 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002099 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002100 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002101
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002102 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap FAST", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002103 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002104
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002105 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 +02002106 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002107
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002108 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002109 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002110
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002111 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002112 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002113
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002114 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002115 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002116
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002117 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002118 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002119#endif
2120
2121 setEapFastResp->status = STATUS_COMPLETE;
2122 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2123 *respLen = WFA_TLV_HDR_LEN + 4;
2124
2125 return WFA_SUCCESS;
2126}
2127
2128int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2129{
2130 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2131 char *ifname = setAKA->intf;
2132 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2133
2134#ifdef WFA_NEW_CLI_FORMAT
2135 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002136 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002137#else
2138
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002139 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002140 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002141
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002142 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002143 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002144
2145 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2146 {
2147 }
2148 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2149 {
2150 }
2151 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2152 {
Dake Zhao0a832172015-01-06 11:08:47 -08002153
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002154 }
2155 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2156 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002157 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002158 }
2159 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2160 {
Dake Zhao0a832172015-01-06 11:08:47 -08002161 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002162 }
2163 else
2164 {
Dake Zhao0a832172015-01-06 11:08:47 -08002165 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002166 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002167 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002168
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002169 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA2", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002170 sret = systemWithLog(gCmdStr);
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002171 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto CCMP", ifname);
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 eap AKA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002175 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002176
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002177 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002178 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002179
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002180 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002181 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002182
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002183 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002184 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002185
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002186 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002187 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002188#endif
2189
2190 setEapAkaResp->status = STATUS_COMPLETE;
2191 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2192 *respLen = WFA_TLV_HDR_LEN + 4;
2193
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002194 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002195}
2196
2197int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2198{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002199 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2200 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002201
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002202 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002203
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002204 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002205 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002206
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002207 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002208 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002209
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002210 setSystimeResp->status = STATUS_COMPLETE;
2211 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2212 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002213
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002214 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002215}
2216
2217#ifdef WFA_STA_TB
2218int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2219{
Dake Zhao0a832172015-01-06 11:08:47 -08002220 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2221 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2222 BYTE presetDone = 1;
2223 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002224 char cmdStr[128];
2225 char string[256];
2226 FILE *tmpfd = NULL;
2227 long val;
2228 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002229
Dake Zhao0a832172015-01-06 11:08:47 -08002230 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002231
Ray Wangd11ca032015-05-29 18:25:46 -07002232 if (presetParams->supplicant == eWpaSupplicant)
2233 {
2234 st = access("/tmp/processid.txt", F_OK);
2235 if (st != -1)
2236 {
2237 st = remove("/tmp/processid.txt");
2238 }
2239
2240 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002241 st = systemWithLog(cmdStr);
Ray Wangd11ca032015-05-29 18:25:46 -07002242
2243 tmpfd = fopen("/tmp/processid.txt", "r+");
2244 if (tmpfd == NULL)
2245 {
2246 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2247 return WFA_FAILURE;
2248 }
2249
2250 for (;;)
2251 {
2252 if (fgets(string, 256, tmpfd) == NULL)
2253 break;
2254
2255 errno = 0;
2256 val = strtol(string, &endptr, 10);
2257 if (errno != 0 && val == 0)
2258 {
2259 DPRINT_ERR(WFA_ERR, "strtol error\n");
2260 return WFA_FAILURE;
2261 }
2262
2263 if (endptr == string)
2264 {
2265 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2266 }
2267
2268 presetDone = 1;
2269 }
2270 }
2271
Dake Zhao0a832172015-01-06 11:08:47 -08002272 if(presetParams->wmmFlag)
2273 {
2274 st = wfaExecuteCLI(gCmdStr);
2275 switch(st)
2276 {
2277 case 0:
2278 presetDone = 1;
2279 break;
2280 case 1:
2281 presetDone = 0;
2282 break;
2283 case 2:
2284 presetDone = 0;
2285 break;
2286 }
2287 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002288
Dake Zhao0a832172015-01-06 11:08:47 -08002289 if(presetParams->modeFlag != 0)
2290 {
2291 switch(presetParams->wirelessMode)
2292 {
2293 default:
2294 printf("other mode does not need to support\n");
2295 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002296
Dake Zhao0a832172015-01-06 11:08:47 -08002297 st = wfaExecuteCLI(gCmdStr);
2298 switch(st)
2299 {
2300 case 0:
2301 presetDone = 1;
2302 break;
2303 case 1:
2304 presetDone = 0;
2305 case 2:
2306 presetDone = 0;
2307 break;
2308 }
2309 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002310
2311
Dake Zhao0a832172015-01-06 11:08:47 -08002312 if(presetParams->psFlag)
2313 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002314
Dake Zhao0a832172015-01-06 11:08:47 -08002315 printf("%s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002316 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002317 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002318
Dake Zhao0a832172015-01-06 11:08:47 -08002319 /************the followings are used for Voice Enterprise **************/
2320 if(presetParams->program == PROG_TYPE_VENT)
2321 {
2322 if(presetParams->ftoa == eEnable)
2323 {
2324 // enable Fast BSS Transition Over the Air
2325 }
2326 else
2327 {
2328 // disable Fast BSS Transition Over the Air
2329 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002330
Dake Zhao0a832172015-01-06 11:08:47 -08002331 if(presetParams->ftds == eEnable)
2332 {
2333 // enable Fast BSS Transition Over the DS
2334 }
2335 else
2336 {
2337 // disable Fast BSS Transition Over the DS
2338 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002339
Dake Zhao0a832172015-01-06 11:08:47 -08002340 if(presetParams->activescan == eEnable)
2341 {
2342 // Enable Active Scan on STA
2343 }
2344 else
2345 {
2346 // disable Active Scan on STA
2347 }
2348 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002349
Dake Zhao0a832172015-01-06 11:08:47 -08002350 /************the followings are used for Wi-Fi Display *************/
2351 if(presetParams->program == PROG_TYPE_WFD)
2352 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002353
Dake Zhao0a832172015-01-06 11:08:47 -08002354 if(presetParams->tdlsFlag)
2355 {
2356 // enable / disable tdls based on tdls
2357 }
2358 if(presetParams->wfdDevTypeFlag)
2359 {
2360 // set WFD device type to source/sink/dual based on wfdDevType
2361 }
2362 if(presetParams->wfdUibcGenFlag)
2363 {
2364 // enable / disable the feature
2365 }
2366 if(presetParams->wfdUibcHidFlag)
2367 {
2368 // enable / disable feature
2369 }
2370 if(presetParams->wfdUiInputFlag)
2371 {
2372 // set the UI input as mentioned
2373 }
2374 if(presetParams->wfdHdcpFlag)
2375 {
2376 // enable / disable feature
2377 }
2378 if(presetParams->wfdFrameSkipFlag)
2379 {
2380 // enable / disable feature
2381 }
2382 if(presetParams->wfdAvChangeFlag)
2383 {
2384 // enable / disable feature
2385 }
2386 if(presetParams->wfdStandByFlag)
2387 {
2388 // enable / disable feature
2389 }
2390 if(presetParams->wfdInVideoFlag)
2391 {
2392 // select the input vide as protecteed or non-protetcted or protected audio
2393 // or unprotected audio etc.
2394 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002395
Dake Zhao0a832172015-01-06 11:08:47 -08002396 if(presetParams->wfdVideoFmatFlag)
2397 {
2398 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002399
Dake Zhao0a832172015-01-06 11:08:47 -08002400 //switch(presetParams->wfdVideoFmt )
2401 //{
2402 // case e640x480p60:
2403 // ;
2404 // default:
2405 // set the mandatory
2406 // }
2407 }
2408 if(presetParams->wfdAudioFmatFlag)
2409 {
2410 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002411
Dake Zhao0a832172015-01-06 11:08:47 -08002412 //switch(presetParams->wfdAudioFmt )
2413 //{
2414 // case eMandatoryAudioMode:
2415 // ;
2416 // case eDefaultAudioMode:
2417 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002418
Dake Zhao0a832172015-01-06 11:08:47 -08002419 // default:
2420 // set the mandatory
2421 // }
2422 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002423
Dake Zhao0a832172015-01-06 11:08:47 -08002424 if(presetParams->wfdI2cFlag)
2425 {
2426 // enable / disable feature
2427 }
2428 if(presetParams->wfdVideoRecoveryFlag)
2429 {
2430 // enable / disable feature
2431 }
2432 if(presetParams->wfdPrefDisplayFlag)
2433 {
2434 // enable / disable feature
2435 }
2436 if(presetParams->wfdServiceDiscoveryFlag)
2437 {
2438 // enable / disable feature
2439 }
2440 if(presetParams->wfd3dVideoFlag)
2441 {
2442 // enable / disable feature
2443 }
2444 if(presetParams->wfdMultiTxStreamFlag)
2445 {
2446 // enable / disable feature
2447 }
2448 if(presetParams->wfdTimeSyncFlag)
2449 {
2450 // enable / disable feature
2451 }
2452 if(presetParams->wfdEDIDFlag)
2453 {
2454 // enable / disable feature
2455 }
2456 if(presetParams->wfdUIBCPrepareFlag)
2457 {
2458 // Provdes information to start valid WFD session to check UIBC operation.
2459 }
2460 if(presetParams->wfdCoupledCapFlag)
2461 {
2462 // enable / disable feature
2463 }
2464 if(presetParams->wfdOptionalFeatureFlag)
2465 {
2466 // disable all program specific optional features
2467 }
2468 if(presetParams->wfdSessionAvailFlag)
2469 {
2470 // enable / disable session available bit
2471 }
2472 if(presetParams->wfdDeviceDiscoverabilityFlag)
2473 {
2474 // enable / disable feature
2475 }
2476 }
2477
Dake Zhao655efed2015-03-11 17:39:13 -07002478 if(presetParams->program == PROG_TYPE_WFDS)
2479 {
2480
2481 if(presetParams->wfdsType == eAcceptPD)
2482 {
2483 // preset to accept PD request
2484 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2485 {
2486 // use presetParams->wfdsConnectionCapability and set role accordingly
2487 }
2488
2489 }
2490 if(presetParams->wfdsType == eRejectPD)
2491 {
2492 // preset to Reject PD request
2493 }
2494 if(presetParams->wfdsType == eIgnorePD)
2495 {
2496 // preset to Ignore PD request
2497 }
2498 if(presetParams->wfdsType == eRejectSession)
2499 {
2500 // preset to reject Session request
2501 }
2502
2503 }
2504
2505 if (presetDone)
2506 {
2507 PresetParamsResp->status = STATUS_COMPLETE;
2508 }
2509 else
2510 {
2511 PresetParamsResp->status = STATUS_INVALID;
2512 }
Dake Zhao0a832172015-01-06 11:08:47 -08002513
2514 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2515 *respLen = WFA_TLV_HDR_LEN + 4;
2516
2517 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002518}
2519
2520int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2521{
2522 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2523
2524 v11nParamsResp->status = STATUS_COMPLETE;
2525 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2526 *respLen = WFA_TLV_HDR_LEN + 4;
2527 return WFA_SUCCESS;
2528}
2529int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2530{
2531 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2532
2533 staWirelessResp->status = STATUS_COMPLETE;
2534 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2535 *respLen = WFA_TLV_HDR_LEN + 4;
2536 return WFA_SUCCESS;
2537}
2538
2539int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2540{
2541 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2542
2543 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2544 *respLen = WFA_TLV_HDR_LEN + 4;
2545 return WFA_SUCCESS;
2546}
2547
2548int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2549{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002550 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002551
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002552 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2553 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002554
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002555 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002556}
2557
2558int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2559{
2560 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2561
2562 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2563 *respLen = WFA_TLV_HDR_LEN + 4;
2564
2565 return WFA_SUCCESS;
2566
2567}
2568
2569int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2570{
Dake Zhao0a832172015-01-06 11:08:47 -08002571 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2572 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002573
2574
Dake Zhao0a832172015-01-06 11:08:47 -08002575 // need to make your own command available for this, here is only an example
2576 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002577 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002578
Dake Zhao0a832172015-01-06 11:08:47 -08002579 ResetResp->status = STATUS_COMPLETE;
2580 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2581 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002582
Dake Zhao0a832172015-01-06 11:08:47 -08002583 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002584}
2585
2586#else
2587
2588int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2589{
2590 dutCmdResponse_t *staCmdResp = &gGenericResp;
2591
2592 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2593 *respLen = WFA_TLV_HDR_LEN + 4;
2594
2595 return WFA_SUCCESS;
2596}
2597#endif
2598
2599/*
2600 * This is used to send a frame or action frame
2601 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002602int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002603{
Dake Zhao0a832172015-01-06 11:08:47 -08002604 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2605 /* uncomment it if needed */
2606 // char *ifname = cmd->intf;
2607 dutCmdResponse_t *devSendResp = &gGenericResp;
2608 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002609
Dake Zhao0a832172015-01-06 11:08:47 -08002610 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2611 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002612
Dake Zhao0a832172015-01-06 11:08:47 -08002613 switch(sf->program)
2614 {
2615 case PROG_TYPE_PMF:
2616 {
2617 pmfFrame_t *pmf = &sf->frameType.pmf;
2618 switch(pmf->eFrameName)
2619 {
2620 case PMF_TYPE_DISASSOC:
2621 {
2622 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002623
Dake Zhao0a832172015-01-06 11:08:47 -08002624 }
2625 break;
2626 case PMF_TYPE_DEAUTH:
2627 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002628
Dake Zhao0a832172015-01-06 11:08:47 -08002629 }
2630 break;
2631 case PMF_TYPE_SAQUERY:
2632 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002633
Dake Zhao0a832172015-01-06 11:08:47 -08002634 }
2635 break;
2636 case PMF_TYPE_AUTH:
2637 {
2638 }
2639 break;
2640 case PMF_TYPE_ASSOCREQ:
2641 {
2642 }
2643 break;
2644 case PMF_TYPE_REASSOCREQ:
2645 {
2646 }
2647 break;
2648 }
2649 }
2650 break;
2651 case PROG_TYPE_TDLS:
2652 {
2653 tdlsFrame_t *tdls = &sf->frameType.tdls;
2654 switch(tdls->eFrameName)
2655 {
2656 case TDLS_TYPE_DISCOVERY:
2657 /* use the peer mac address to send the frame */
2658 break;
2659 case TDLS_TYPE_SETUP:
2660 break;
2661 case TDLS_TYPE_TEARDOWN:
2662 break;
2663 case TDLS_TYPE_CHANNELSWITCH:
2664 break;
2665 case TDLS_TYPE_NULLFRAME:
2666 break;
2667 }
2668 }
2669 break;
2670 case PROG_TYPE_VENT:
2671 {
2672 ventFrame_t *vent = &sf->frameType.vent;
2673 switch(vent->type)
2674 {
2675 case VENT_TYPE_NEIGREQ:
2676 break;
2677 case VENT_TYPE_TRANSMGMT:
2678 break;
2679 }
2680 }
2681 break;
2682 case PROG_TYPE_WFD:
2683 {
2684 wfdFrame_t *wfd = &sf->frameType.wfd;
2685 switch(wfd->eframe)
2686 {
2687 case WFD_FRAME_PRBREQ:
2688 {
2689 /* send probe req */
2690 }
2691 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002692
Dake Zhao0a832172015-01-06 11:08:47 -08002693 case WFD_FRAME_PRBREQ_TDLS_REQ:
2694 {
2695 /* send tunneled tdls probe req */
2696 }
2697 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002698
Dake Zhao0a832172015-01-06 11:08:47 -08002699 case WFD_FRAME_11V_TIMING_MSR_REQ:
2700 {
2701 /* send 11v timing mearurement request */
2702 }
2703 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002704
Dake Zhao0a832172015-01-06 11:08:47 -08002705 case WFD_FRAME_RTSP:
2706 {
2707 /* send WFD RTSP messages*/
2708 // fetch the type of RTSP message and send it.
2709 switch(wfd->eRtspMsgType)
2710 {
2711 case WFD_RTSP_PAUSE:
2712 break;
2713 case WFD_RTSP_PLAY:
2714 //send RTSP PLAY
2715 break;
2716 case WFD_RTSP_TEARDOWN:
2717 //send RTSP TEARDOWN
2718 break;
2719 case WFD_RTSP_TRIG_PAUSE:
2720 //send RTSP TRIGGER PAUSE
2721 break;
2722 case WFD_RTSP_TRIG_PLAY:
2723 //send RTSP TRIGGER PLAY
2724 break;
2725 case WFD_RTSP_TRIG_TEARDOWN:
2726 //send RTSP TRIGGER TEARDOWN
2727 break;
2728 case WFD_RTSP_SET_PARAMETER:
2729 //send RTSP SET PARAMETER
2730 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2731 {
2732 //send RTSP SET PARAMETER message for UIBC keyboard
2733 }
2734 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2735 {
2736 //send RTSP SET PARAMETER message for UIBC Mouse
2737 }
2738 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2739 {
2740 //send RTSP SET PARAMETER message Capability re-negotiation
2741 }
2742 else if (wfd->eSetParams == WFD_STANDBY)
2743 {
2744 //send RTSP SET PARAMETER message for standby
2745 }
2746 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2747 {
2748 //send RTSP SET PARAMETER message for UIBC settings enable
2749 }
2750 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2751 {
2752 //send RTSP SET PARAMETER message for UIBC settings disable
2753 }
2754 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2755 {
2756 //send RTSP SET PARAMETER message for route audio
2757 }
2758 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2759 {
2760 //send RTSP SET PARAMETER message for 3D video parameters
2761 }
2762 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2763 {
2764 //send RTSP SET PARAMETER message for 2D video parameters
2765 }
2766 break;
Dake Zhao97708202014-11-26 13:59:04 -08002767 }
Dake Zhao0a832172015-01-06 11:08:47 -08002768 }
2769 break;
2770 }
2771 }
2772 break;
2773 /* not need to support HS2 release 1, due to very short time period */
2774 case PROG_TYPE_HS2_R2:
2775 {
2776 /* type of frames */
2777 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2778 switch(hs2->eframe)
2779 {
2780 case HS2_FRAME_ANQPQuery:
2781 {
Dake Zhao97708202014-11-26 13:59:04 -08002782
Dake Zhao0a832172015-01-06 11:08:47 -08002783 }
2784 break;
2785 case HS2_FRAME_DLSRequest:
2786 {
Dake Zhao97708202014-11-26 13:59:04 -08002787
Dake Zhao0a832172015-01-06 11:08:47 -08002788 }
2789 break;
2790 case HS2_FRAME_GARPReq:
2791 {
Dake Zhao97708202014-11-26 13:59:04 -08002792
Dake Zhao0a832172015-01-06 11:08:47 -08002793 }
2794 break;
2795 case HS2_FRAME_GARPRes:
2796 {
2797 }
2798 break;
2799 case HS2_FRAME_NeighAdv:
2800 {
2801 }
2802 case HS2_FRAME_ARPProbe:
2803 {
2804 }
2805 case HS2_FRAME_ARPAnnounce:
2806 {
Dake Zhao97708202014-11-26 13:59:04 -08002807
Dake Zhao0a832172015-01-06 11:08:47 -08002808 }
2809 break;
2810 case HS2_FRAME_NeighSolicitReq:
2811 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002812
Dake Zhao0a832172015-01-06 11:08:47 -08002813 }
2814 break;
2815 case HS2_FRAME_ARPReply:
2816 {
2817
2818 }
2819 break;
2820 }
2821
2822 }/* PROG_TYPE_HS2-R2 */
2823 case PROG_TYPE_GEN:
2824 {
2825 /* General frames */
2826 }
2827
2828
2829 }
2830 devSendResp->status = STATUS_COMPLETE;
2831 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2832 *respLen = WFA_TLV_HDR_LEN + 4;
2833
2834 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002835}
2836
2837/*
2838 * This is used to set a temporary MAC address of an interface
2839 */
2840int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2841{
Dake Zhao0a832172015-01-06 11:08:47 -08002842 // Uncomment it if needed
2843 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2844 // char *ifname = cmd->intf;
2845 dutCmdResponse_t *staCmdResp = &gGenericResp;
2846 // Uncomment it if needed
2847 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002848
Dake Zhao0a832172015-01-06 11:08:47 -08002849 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2850 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002851
Dake Zhao0a832172015-01-06 11:08:47 -08002852 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002853}
2854
2855
2856int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2857{
2858 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2859 //char *intf = disc->intf;
2860 dutCmdResponse_t *staDiscResp = &gGenericResp;
2861
2862 // stop the supplicant
2863
2864 staDiscResp->status = STATUS_COMPLETE;
2865
2866 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2867 *respLen = WFA_TLV_HDR_LEN + 4;
2868
2869 return WFA_SUCCESS;
2870}
2871
2872/* Execute CLI, read the status from Environment variable */
2873int wfaExecuteCLI(char *CLI)
2874{
Dake Zhao0a832172015-01-06 11:08:47 -08002875 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002876
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002877 sret = systemWithLog(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002878
Dake Zhao0a832172015-01-06 11:08:47 -08002879 retstr = getenv("WFA_CLI_STATUS");
2880 printf("cli status %s\n", retstr);
2881 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002882}
2883
2884/* Supporting Functions */
2885
2886void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2887{
Dake Zhao97708202014-11-26 13:59:04 -08002888 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002889 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002890// char *addr = staPing->dipaddr;
2891#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002892 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002893 char bflag[] = "-b";
2894 char *tmpstr;
2895 int inum=0;
2896#else
2897 char bflag[] = " ";
2898#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002899
Ray Wang9b47f362014-03-19 16:51:10 -07002900 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002901
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002902#ifdef WFA_PC_CONSOLE
2903
Dake Zhao353c55e2015-07-20 18:54:45 -07002904 printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d",streamid);
2905
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002906 strcpy(addr,staPing->dipaddr);
Dake Zhao353c55e2015-07-20 18:54:45 -07002907 printf("\nCS :the addr is %s ",addr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002908 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2909 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002910 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002911 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002912 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002913 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002914 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002915 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002916 tmpstr = strtok(addr, ".");
2917 inum = atoi(tmpstr);
2918
2919 printf("interval %f\n", *interval);
2920
2921 if(inum >= 224 && inum <= 239) // multicast
2922 {
2923 }
2924 else // if not MC, check if it is BC address
2925 {
2926 printf("\nCS :Inside the BC address BLOCK");
2927 printf("\nCS :the inum %d",inum);
2928 strtok(NULL, ".");
2929 //strtok(NULL, ".");
2930 tmpstr = strtok(NULL, ".");
2931 printf("tmpstr %s\n", tmpstr);
2932 inum = atoi(tmpstr);
2933 printf("\nCS : The string is %s",tmpstr);
2934 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002935 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002936 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002937 }
2938#endif
Dake Zhao97708202014-11-26 13:59:04 -08002939 if ( staPing->dscp >= 0)
2940 {
Dake Zhao0a832172015-01-06 11:08:47 -08002941 tos= convertDscpToTos(staPing->dscp);
2942 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002943 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2944 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002945 printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n",streamid, staPing->iptype);
Dake Zhao97708202014-11-26 13:59:04 -08002946 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002947
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002948 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002949 {
Dake Zhao97708202014-11-26 13:59:04 -08002950 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002951 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",
2952 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002953 else
Dake Zhao0a832172015-01-06 11:08:47 -08002954 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",
2955 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002956 sret = systemWithLog(cmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002957 printf("\nCS : The command string is %s",cmdStr);
2958 }
2959 else
2960 {
Dake Zhao97708202014-11-26 13:59:04 -08002961 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002962 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",
2963 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002964 else
Dake Zhao0a832172015-01-06 11:08:47 -08002965 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",
2966 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002967 sret = systemWithLog(cmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002968 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002969 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002970 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002971 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002972 printf("\nCS : The command string is %s",cmdStr);
2973
2974}
2975
2976int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2977{
2978 char strout[256];
2979 FILE *tmpfile = NULL;
2980 char cmdStr[128];
Dake Zhao353c55e2015-07-20 18:54:45 -07002981 printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002982 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002983 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002984
2985 printf("\nCS : The command string is %s",cmdStr);
2986
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002987 sret = systemWithLog("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002988
2989 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002990 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002991
2992 printf("\nCS : The command string is %s",cmdStr);
2993
2994 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2995
2996 if(tmpfile == NULL)
2997 {
2998 return WFA_FAILURE;
2999 }
3000
3001 if(fscanf(tmpfile, "%s", strout) != EOF)
3002 {
3003 if(*strout == '\0')
3004 {
3005 stpResp->cmdru.pingStp.sendCnt = 0;
3006 }
3007
3008 else
3009 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
3010 }
3011
Dake Zhao353c55e2015-07-20 18:54:45 -07003012 printf("\nwfaStopPing after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003013
3014
3015 if(fscanf(tmpfile, "%s", strout) != EOF)
3016 {
3017 if(*strout == '\0')
3018 {
3019 stpResp->cmdru.pingStp.repliedCnt = 0;
3020 }
3021 else
3022 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
3023 }
Dake Zhao353c55e2015-07-20 18:54:45 -07003024 printf("wfaStopPing after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003025
3026 fclose(tmpfile);
3027
3028 return WFA_SUCCESS;
3029}
3030
Ankur Vachhanic485b712012-02-15 23:29:49 +00003031/*
Dake Zhao0a832172015-01-06 11:08:47 -08003032 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003033 */
3034int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3035{
Dake Zhao0a832172015-01-06 11:08:47 -08003036 dutCmdResponse_t infoResp;
3037 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003038
Dake Zhao0a832172015-01-06 11:08:47 -08003039 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003040
Dake Zhao0a832172015-01-06 11:08:47 -08003041 // Fetch the device ID and store into infoResp->cmdru.devid
3042 //strcpy(infoResp->cmdru.devid, str);
3043 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003044
Dake Zhao0a832172015-01-06 11:08:47 -08003045 infoResp.status = STATUS_COMPLETE;
3046 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3047 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3048
3049 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003050}
3051
3052
3053
3054/*
Dake Zhao0a832172015-01-06 11:08:47 -08003055 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003056 */
3057int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3058{
Dake Zhao0a832172015-01-06 11:08:47 -08003059 dutCmdResponse_t infoResp;
3060 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00003061
Dake Zhao0a832172015-01-06 11:08:47 -08003062 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003063
Dake Zhao0a832172015-01-06 11:08:47 -08003064 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003065
Dake Zhao0a832172015-01-06 11:08:47 -08003066 infoResp.status = STATUS_COMPLETE;
3067 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3068 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3069
3070 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003071}
3072/*
Dake Zhao0a832172015-01-06 11:08:47 -08003073 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003074 */
3075int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3076{
Dake Zhao0a832172015-01-06 11:08:47 -08003077 dutCmdResponse_t infoResp;
3078 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003079
Dake Zhao0a832172015-01-06 11:08:47 -08003080 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003081
Dake Zhao0a832172015-01-06 11:08:47 -08003082 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003083
Ankur Vachhanic485b712012-02-15 23:29:49 +00003084
Dake Zhao0a832172015-01-06 11:08:47 -08003085 infoResp.status = STATUS_COMPLETE;
3086 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3087 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3088
3089 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003090}
3091
3092/*
Dake Zhao0a832172015-01-06 11:08:47 -08003093 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003094 */
3095int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3096{
Dake Zhao0a832172015-01-06 11:08:47 -08003097 dutCmdResponse_t infoResp;
3098 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003099
Dake Zhao0a832172015-01-06 11:08:47 -08003100 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003101
Dake Zhao0a832172015-01-06 11:08:47 -08003102 // Fetch the group ID and store into infoResp->cmdru.grpid
3103 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003104
Dake Zhao0a832172015-01-06 11:08:47 -08003105 infoResp.status = STATUS_COMPLETE;
3106 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3107 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3108
3109 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003110}
3111
3112
3113
3114
3115/*
Dake Zhao0a832172015-01-06 11:08:47 -08003116 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003117 */
3118int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3119{
Dake Zhao0a832172015-01-06 11:08:47 -08003120 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003121
Dake Zhao0a832172015-01-06 11:08:47 -08003122 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003123
Dake Zhao0a832172015-01-06 11:08:47 -08003124 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3125 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003126
Ankur Vachhanic485b712012-02-15 23:29:49 +00003127
Dake Zhao0a832172015-01-06 11:08:47 -08003128 infoResp.status = STATUS_COMPLETE;
3129 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3130 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3131
3132 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003133}
3134
3135
3136/*
Dake Zhao0a832172015-01-06 11:08:47 -08003137 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003138 */
3139int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3140{
Dake Zhao0a832172015-01-06 11:08:47 -08003141 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003142
Dake Zhao0a832172015-01-06 11:08:47 -08003143 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003144
Dake Zhao0a832172015-01-06 11:08:47 -08003145 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003146
Dake Zhao0a832172015-01-06 11:08:47 -08003147 infoResp.status = STATUS_COMPLETE;
3148 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3149 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3150
3151 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003152}
3153
3154/*
Dake Zhao0a832172015-01-06 11:08:47 -08003155 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003156 */
3157int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3158{
Dake Zhao0a832172015-01-06 11:08:47 -08003159 dutCmdResponse_t infoResp;
3160 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003161
Dake Zhao0a832172015-01-06 11:08:47 -08003162 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003163
Dake Zhao0a832172015-01-06 11:08:47 -08003164 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003165
Dake Zhao0a832172015-01-06 11:08:47 -08003166 infoResp.status = STATUS_COMPLETE;
3167 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3168 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3169
3170 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003171}
3172
3173
3174/*
Dake Zhao0a832172015-01-06 11:08:47 -08003175 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003176 */
3177int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3178{
Dake Zhao0a832172015-01-06 11:08:47 -08003179 dutCmdResponse_t infoResp;
3180 /* uncomment and use it
3181 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3182 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003183
Dake Zhao0a832172015-01-06 11:08:47 -08003184 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003185
Dake Zhao0a832172015-01-06 11:08:47 -08003186 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003187
Dake Zhao0a832172015-01-06 11:08:47 -08003188 infoResp.status = STATUS_COMPLETE;
3189 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3190 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3191
3192 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003193}
3194
3195
3196/*
Dake Zhao0a832172015-01-06 11:08:47 -08003197 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003198 */
3199int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3200{
Dake Zhao0a832172015-01-06 11:08:47 -08003201 dutCmdResponse_t infoResp;
3202 /* uncomment and use it
3203 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3204 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003205
Dake Zhao0a832172015-01-06 11:08:47 -08003206 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003207
Dake Zhao0a832172015-01-06 11:08:47 -08003208 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003209
Dake Zhao0a832172015-01-06 11:08:47 -08003210 infoResp.status = STATUS_COMPLETE;
3211 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3212 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3213
3214 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003215}
3216
3217/*
Dake Zhao0a832172015-01-06 11:08:47 -08003218 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003219 */
3220int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3221{
Dake Zhao0a832172015-01-06 11:08:47 -08003222 dutCmdResponse_t infoResp;
3223 /* uncomment and use it
3224 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3225 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003226
Dake Zhao0a832172015-01-06 11:08:47 -08003227 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003228
Dake Zhao0a832172015-01-06 11:08:47 -08003229 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003230
Dake Zhao0a832172015-01-06 11:08:47 -08003231 infoResp.status = STATUS_COMPLETE;
3232 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3233 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3234
3235 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003236}
3237
3238/*
Dake Zhao0a832172015-01-06 11:08:47 -08003239 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003240 */
3241int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3242{
Dake Zhao0a832172015-01-06 11:08:47 -08003243 dutCmdResponse_t infoResp;
3244 /* uncomment and use it
3245 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3246 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003247
Dake Zhao0a832172015-01-06 11:08:47 -08003248 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003249
Dake Zhao0a832172015-01-06 11:08:47 -08003250 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3251 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3252 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003253
Ankur Vachhanic485b712012-02-15 23:29:49 +00003254
Dake Zhao0a832172015-01-06 11:08:47 -08003255 infoResp.status = STATUS_COMPLETE;
3256 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3257 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3258
3259 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003260}
3261
3262
3263
3264/*
Dake Zhao0a832172015-01-06 11:08:47 -08003265 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003266 */
3267int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3268{
Dake Zhao0a832172015-01-06 11:08:47 -08003269 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003270
Dake Zhao0a832172015-01-06 11:08:47 -08003271 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003272
Dake Zhao0a832172015-01-06 11:08:47 -08003273 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3274 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3275 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003276
Ankur Vachhanic485b712012-02-15 23:29:49 +00003277
Dake Zhao0a832172015-01-06 11:08:47 -08003278 infoResp.status = STATUS_COMPLETE;
3279 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3280 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3281
3282 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003283}
3284
3285
3286/*
Dake Zhao0a832172015-01-06 11:08:47 -08003287 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003288 */
3289int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3290{
Dake Zhao0a832172015-01-06 11:08:47 -08003291 dutCmdResponse_t infoResp;
3292 /* uncomment and use it
3293 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3294 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003295
Dake Zhao0a832172015-01-06 11:08:47 -08003296 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003297
Dake Zhao0a832172015-01-06 11:08:47 -08003298 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003299
Ankur Vachhanic485b712012-02-15 23:29:49 +00003300
Dake Zhao0a832172015-01-06 11:08:47 -08003301 infoResp.status = STATUS_COMPLETE;
3302 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3303 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3304
3305 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003306}
3307
3308
3309/*
Dake Zhao0a832172015-01-06 11:08:47 -08003310 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003311 */
3312int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3313{
Dake Zhao0a832172015-01-06 11:08:47 -08003314 dutCmdResponse_t infoResp;
3315 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003316
Dake Zhao0a832172015-01-06 11:08:47 -08003317 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003318
3319
Dake Zhao0a832172015-01-06 11:08:47 -08003320 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3321 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3322 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003323
Ankur Vachhanic485b712012-02-15 23:29:49 +00003324
Dake Zhao0a832172015-01-06 11:08:47 -08003325 infoResp.status = STATUS_COMPLETE;
3326 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3327 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3328
3329 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003330}
3331
3332/*
Dake Zhao0a832172015-01-06 11:08:47 -08003333 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003334 */
3335int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3336{
Dake Zhao0a832172015-01-06 11:08:47 -08003337 dutCmdResponse_t infoResp;
3338 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003339
Dake Zhao0a832172015-01-06 11:08:47 -08003340 printf("\n Entry wfaStaP2pReset... ");
3341 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003342
Dake Zhao0a832172015-01-06 11:08:47 -08003343 infoResp.status = STATUS_COMPLETE;
3344 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3345 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3346
3347 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003348}
3349
3350
3351
3352/*
Dake Zhao0a832172015-01-06 11:08:47 -08003353 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003354 */
3355int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3356{
Dake Zhao0a832172015-01-06 11:08:47 -08003357 dutCmdResponse_t infoResp;
3358 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003359
Dake Zhao0a832172015-01-06 11:08:47 -08003360 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003361
Dake Zhao0a832172015-01-06 11:08:47 -08003362 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003363
Dake Zhao0a832172015-01-06 11:08:47 -08003364 ifinfo->isDhcp =0;
3365 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3366 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3367 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3368 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3369
3370 infoResp.status = STATUS_COMPLETE;
3371 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3372 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3373
3374 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003375}
3376
3377
3378
3379
3380/*
Dake Zhao0a832172015-01-06 11:08:47 -08003381 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003382 */
3383int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3384{
Dake Zhao0a832172015-01-06 11:08:47 -08003385 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003386
Dake Zhao0a832172015-01-06 11:08:47 -08003387 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3388 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003389
Dake Zhao0a832172015-01-06 11:08:47 -08003390
3391 infoResp.status = STATUS_COMPLETE;
3392 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3393 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3394
3395 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003396}
3397
3398
3399
3400/*
Dake Zhao0a832172015-01-06 11:08:47 -08003401 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003402 */
3403int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3404{
Dake Zhao0a832172015-01-06 11:08:47 -08003405 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003406
Dake Zhao0a832172015-01-06 11:08:47 -08003407 infoResp.status = STATUS_COMPLETE;
3408 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3409 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003410
Dake Zhao0a832172015-01-06 11:08:47 -08003411 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003412}
3413
3414/*
Dake Zhao0a832172015-01-06 11:08:47 -08003415 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003416 */
3417int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3418{
Dake Zhao0a832172015-01-06 11:08:47 -08003419 dutCmdResponse_t infoResp;
3420 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003421
Dake Zhao0a832172015-01-06 11:08:47 -08003422 printf("\n Entry wfaStaSetSleepReq... ");
3423 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003424
Dake Zhao0a832172015-01-06 11:08:47 -08003425
3426 infoResp.status = STATUS_COMPLETE;
3427 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3428 *respLen = WFA_TLV_HDR_LEN +4;
3429
3430 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003431}
3432
3433/*
Dake Zhao0a832172015-01-06 11:08:47 -08003434 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003435 */
3436int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3437{
Dake Zhao0a832172015-01-06 11:08:47 -08003438 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003439
Dake Zhao0a832172015-01-06 11:08:47 -08003440 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3441 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003442
Dake Zhao0a832172015-01-06 11:08:47 -08003443
3444 infoResp.status = STATUS_COMPLETE;
3445 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3446 *respLen = WFA_TLV_HDR_LEN + 4;
3447
3448 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003449}
3450#ifndef WFA_STA_TB
3451/*
Dake Zhao0a832172015-01-06 11:08:47 -08003452 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003453 */
3454
3455int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3456{
Dake Zhao0a832172015-01-06 11:08:47 -08003457 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003458
Dake Zhao0a832172015-01-06 11:08:47 -08003459 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003460
Dake Zhao0a832172015-01-06 11:08:47 -08003461 // Implement the function and its sub commands
3462 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003463
Dake Zhao0a832172015-01-06 11:08:47 -08003464 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3465 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003466
Dake Zhao0a832172015-01-06 11:08:47 -08003467 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003468}
Dake Zhao0a832172015-01-06 11:08:47 -08003469int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003470{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003471
3472 dutCmdResponse_t infoResp;
3473 dutCmdResponse_t *v11nParamsResp = &infoResp;
3474
3475#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003476
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003477 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3478
3479 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003480
3481 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003482
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003483 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3484 {
Dake Zhao0a832172015-01-06 11:08:47 -08003485 // implement the funciton
3486 if(st != 0)
3487 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003488 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003489 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3490 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3491 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3492 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003493 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003494 }
Dake Zhao0a832172015-01-06 11:08:47 -08003495
Ankur Vachhanic485b712012-02-15 23:29:49 +00003496 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003497 {
Dake Zhao0a832172015-01-06 11:08:47 -08003498 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003499
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003500 if(st != 0)
3501 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003502 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003503 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3504 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3505 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3506 return FALSE;
3507 }
3508 }
3509
Ankur Vachhanic485b712012-02-15 23:29:49 +00003510 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 {
Dake Zhao0a832172015-01-06 11:08:47 -08003512 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003513 if(st != 0)
3514 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003515 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003516 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3517 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3518 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003519 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003520 }
3521 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003522
3523 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003524 {
3525 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003526 if(st != 0)
3527 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003528 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003529 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3530 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3531 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3532 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003533 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003534 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003535
3536 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003537 {
Dake Zhao0a832172015-01-06 11:08:47 -08003538 // implement the funciton
3539 //st = wfaExecuteCLI(gCmdStr);
3540 if(st != 0)
3541 {
3542 v11nParamsResp->status = STATUS_ERROR;
3543 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3544 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3545 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3546 return FALSE;
3547 }
3548 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003549 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3550 {
3551 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003552 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003553 if(st != 0)
3554 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003555 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003556 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003557 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3558 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003559 return FALSE;
3560 }
Dake Zhao0a832172015-01-06 11:08:47 -08003561 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003562 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3563 {
3564 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003565 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003566 if(st != 0)
3567 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003568 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003569 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003570 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3571 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003572 return FALSE;
3573 }
3574 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003575
3576 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003577 {
3578 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003579 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003580 if(st != 0)
3581 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003582 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003583 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003584 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3585 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003586 return FALSE;
3587 }
3588 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003589
3590 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003591 {
3592 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003593 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003594 if(st != 0)
3595 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003596 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003597 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3598 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3599 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3600 return FALSE;
3601 }
3602 }
3603
3604 if(v11nParams->smps != 0xFFFF)
3605 {
3606 if(v11nParams->smps == 0)
3607 {
Dake Zhao0a832172015-01-06 11:08:47 -08003608 // implement the funciton
3609 //st = wfaExecuteCLI(gCmdStr);
3610 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003611 else if(v11nParams->smps == 1)
3612 {
Dake Zhao0a832172015-01-06 11:08:47 -08003613 // implement the funciton
3614 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003615 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003616 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003617 else if(v11nParams->smps == 2)
3618 {
Dake Zhao0a832172015-01-06 11:08:47 -08003619 // implement the funciton
3620 //st = wfaExecuteCLI(gCmdStr);
3621 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003622 }
3623 if(st != 0)
3624 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003625 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003626 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3627 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3628 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3629 return FALSE;
3630 }
3631 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003632
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003633 if(v11nParams->stbc_rx != 0xFFFF)
3634 {
3635 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003636 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003637 if(st != 0)
3638 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003639 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003640 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003641 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3642 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003643 return FALSE;
3644 }
3645 }
Dake Zhao0a832172015-01-06 11:08:47 -08003646
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003647 if(v11nParams->width[0] != '\0')
3648 {
3649 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003650 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003651 if(st != 0)
3652 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003653 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003654 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3655 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3656 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3657 return FALSE;
3658 }
3659 }
Dake Zhao0a832172015-01-06 11:08:47 -08003660
Ankur Vachhanic485b712012-02-15 23:29:49 +00003661 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003662 {
3663 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003664 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003665 if(st != 0)
3666 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003667 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003668 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3669 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3670 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3671 return FALSE;
3672 }
3673 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003674
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003675 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3676 {
3677 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003678 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003679 if(st != 0)
3680 {
3681 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003682 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003683 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3684 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3685 return FALSE;
3686 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003687
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003688 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003689
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003690 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3691 {
3692 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003693 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003694 if(st != 0)
3695 {
3696 v11nParamsResp->status = STATUS_ERROR;
3697 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3698 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3699 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3700 return FALSE;
3701 }
3702 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003703
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003704#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003705
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003706 v11nParamsResp->status = STATUS_COMPLETE;
3707 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3708 *respLen = WFA_TLV_HDR_LEN + 4;
3709 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003710}
3711#endif
3712/*
Dake Zhao0a832172015-01-06 11:08:47 -08003713 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003714 */
3715int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3716{
Dake Zhao0a832172015-01-06 11:08:47 -08003717 dutCmdResponse_t infoResp;
3718 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003719
Dake Zhao0a832172015-01-06 11:08:47 -08003720 printf("\n Entry wfastaAddARPTableEntry... ");
3721 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003722
Dake Zhao0a832172015-01-06 11:08:47 -08003723 infoResp.status = STATUS_COMPLETE;
3724 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3725 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3726
3727 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003728}
3729
3730/*
Dake Zhao0a832172015-01-06 11:08:47 -08003731 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003732 */
3733int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3734{
Dake Zhao0a832172015-01-06 11:08:47 -08003735 dutCmdResponse_t infoResp;
3736 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003737
Dake Zhao0a832172015-01-06 11:08:47 -08003738 printf("\n Entry wfaStaBlockICMPResponse... ");
3739 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003740
Dake Zhao0a832172015-01-06 11:08:47 -08003741 infoResp.status = STATUS_COMPLETE;
3742 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3743 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3744
3745 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003746}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003747
3748/*
Dake Zhao0a832172015-01-06 11:08:47 -08003749 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003750 */
3751
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003752int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3753{
3754 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3755 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003756 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3757
3758 if(sr->mode == WFA_OFF)
3759 {
Dake Zhao0a832172015-01-06 11:08:47 -08003760 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003761 }
3762 else
3763 {
Dake Zhao0a832172015-01-06 11:08:47 -08003764 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003765 }
3766
3767 staCmdResp->status = STATUS_COMPLETE;
3768 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3769 *respLen = WFA_TLV_HDR_LEN + 4;
3770
3771 return WFA_SUCCESS;
3772}
3773
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003774/*
Dake Zhao0a832172015-01-06 11:08:47 -08003775 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003776 */
3777
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003778int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3779{
Dake Zhao0a832172015-01-06 11:08:47 -08003780 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3781 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3782 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003783
Dake Zhao0a832172015-01-06 11:08:47 -08003784 if(strcasecmp(rfeat->prog, "tdls") == 0)
3785 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003786
3787
Dake Zhao0a832172015-01-06 11:08:47 -08003788 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003789
Dake Zhao0a832172015-01-06 11:08:47 -08003790 caResp->status = STATUS_COMPLETE;
3791 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3792 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003793
Dake Zhao0a832172015-01-06 11:08:47 -08003794 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003795}
3796
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003797/*
Dake Zhao0a832172015-01-06 11:08:47 -08003798 * wfaStaStartWfdConnection():
3799 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003800int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3801{
Dake Zhao0a832172015-01-06 11:08:47 -08003802 dutCmdResponse_t infoResp;
3803 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003804
Dake Zhao0a832172015-01-06 11:08:47 -08003805 printf("\n Entry wfaStaStartWfdConnection... ");
3806
3807
3808 // Fetch the GrpId and WFD session and return
3809 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3810 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3811 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3812
3813 infoResp.status = STATUS_COMPLETE;
3814 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3815 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3816
3817 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003818}
3819/*
Dake Zhao0a832172015-01-06 11:08:47 -08003820 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003821 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003822
Ankur Vachhanic485b712012-02-15 23:29:49 +00003823int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3824{
Dake Zhao0a832172015-01-06 11:08:47 -08003825 char cmdName[32];
3826 char *pcmdStr=NULL, *str;
3827 int st = 1;
3828 char CmdStr[WFA_CMD_STR_SZ];
3829 FILE *wfaCliFd;
3830 char wfaCliBuff[64];
3831 char retstr[256];
3832 int CmdReturnFlag =0;
3833 char tmp[256];
Li Yincba7d352015-09-23 20:30:49 +08003834 FILE * sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003835 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003836
Dake Zhao0a832172015-01-06 11:08:47 -08003837 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3838 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3839 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003840
Dake Zhao0a832172015-01-06 11:08:47 -08003841 for(;;)
3842 {
3843 // construct CLI standard cmd string
3844 str = strtok_r(NULL, ",", &pcmdStr);
3845 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003846 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003847 else
3848 {
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003849 strcat(strcat(CmdStr, " /"), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003850 str = strtok_r(NULL, ",", &pcmdStr);
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003851 strcat(strcat(CmdStr, " "), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003852 }
3853 }
3854 // check the return process
3855 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3856 if(wfaCliFd!= NULL)
3857 {
3858 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3859 {
3860 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3861 if(ferror(wfaCliFd))
3862 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003863
Dake Zhao0a832172015-01-06 11:08:47 -08003864 str=strtok(wfaCliBuff,"-");
3865 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003866 {
Dake Zhao0a832172015-01-06 11:08:47 -08003867 str=strtok(NULL,",");
3868 if (str != NULL)
3869 {
3870 if(strcmp(str,"TRUE") == 0)
3871 CmdReturnFlag =1;
3872 }
3873 else
3874 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3875 break;
Dake Zhao97708202014-11-26 13:59:04 -08003876 }
Dake Zhao0a832172015-01-06 11:08:47 -08003877 }
3878 fclose(wfaCliFd);
3879 }
3880 else
3881 {
3882 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3883 goto cleanup;
3884 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003885
Dake Zhao0a832172015-01-06 11:08:47 -08003886 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3887 memset(&retstr[0],'\0',255);
3888 memset(&tmp[0],'\0',255);
3889 sprintf(gCmdStr, "%s", CmdStr);
3890 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003891
Dake Zhao0a832172015-01-06 11:08:47 -08003892 sh_pipe = popen(gCmdStr,"r");
3893 if(!sh_pipe)
3894 {
3895 printf ("Error in opening pipe\n");
3896 goto cleanup;
3897 }
Dake Zhao97708202014-11-26 13:59:04 -08003898
Dake Zhao0a832172015-01-06 11:08:47 -08003899 sleep(5);
3900 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3901 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3902 {
3903 printf("Getting NULL string in popen return\n");
3904 goto cleanup;
3905 }
3906 else
3907 printf("popen return str=%s\n",retstr);
3908
3909 sleep(2);
3910 if(pclose(sh_pipe) == -1)
3911 {
3912 printf("Error in closing shell cmd pipe\n");
3913 goto cleanup;
3914 }
Li Yincba7d352015-09-23 20:30:49 +08003915 sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003916 sleep(2);
3917
3918 // find status first in output
3919 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3920 if (str != NULL)
3921 {
3922 memset(tmp, 0, 10);
3923 memcpy(tmp, str, 2);
3924 printf("cli status=%s\n",tmp);
3925 if(strlen(tmp) > 0)
3926 st = atoi(tmp);
3927 else printf("Missing status code\n");
3928 }
3929 else
3930 {
3931 printf("wfaStaCliCommand no return code found\n");
3932 }
3933 infoResp.resFlag=CmdReturnFlag;
3934
Dake Zhao97708202014-11-26 13:59:04 -08003935cleanup:
Li Yincba7d352015-09-23 20:30:49 +08003936 if (sh_pipe)
3937 pclose(sh_pipe);
Dake Zhao0a832172015-01-06 11:08:47 -08003938
3939 switch(st)
3940 {
3941 case 0:
3942 infoResp.status = STATUS_COMPLETE;
3943 if (CmdReturnFlag)
3944 {
3945 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3946 {
3947 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003948 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 -08003949 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3950 }
3951 else
3952 {
Dake Zhao97708202014-11-26 13:59:04 -08003953 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003954 }
3955 }
3956 break;
3957 case 1:
3958 infoResp.status = STATUS_ERROR;
3959 break;
3960 case 2:
3961 infoResp.status = STATUS_INVALID;
3962 break;
3963 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003964
Dake Zhao0a832172015-01-06 11:08:47 -08003965 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3966 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003967
Dake Zhao0a832172015-01-06 11:08:47 -08003968 printf("Exit from wfaStaCliCommand\n");
3969 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003970
Ankur Vachhanic485b712012-02-15 23:29:49 +00003971}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003972/*
Dake Zhao0a832172015-01-06 11:08:47 -08003973 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003974 */
3975
3976int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3977{
3978 dutCmdResponse_t infoResp;
3979// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003980
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003981 printf("\n Entry wfaStaConnectGoStartWfd... ");
3982
Dake Zhao0a832172015-01-06 11:08:47 -08003983 // connect the specified GO and then establish the wfd session
3984
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003985 // Fetch WFD session and return
3986 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3987
3988 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003989 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003990 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003991
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003992 return WFA_SUCCESS;
3993}
3994
3995/*
Dake Zhao0a832172015-01-06 11:08:47 -08003996 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003997 */
3998
3999int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4000{
4001 dutCmdResponse_t infoResp;
4002 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
4003 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08004004
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004005 printf("\n Entry wfaStaGenerateEvent... ");
4006
4007
4008 // Geneate the specified action and return with complete/error.
4009 if(staGenerateEvent->program == PROG_TYPE_WFD)
4010 {
4011 wfdGenEvent = &staGenerateEvent->wfdEvent;
4012 if(wfdGenEvent ->type == eUibcGen)
4013 {
Dake Zhao0a832172015-01-06 11:08:47 -08004014 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004015 else if(wfdGenEvent ->type == eUibcHid)
4016 {
Dake Zhao0a832172015-01-06 11:08:47 -08004017 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004018 else if(wfdGenEvent ->type == eFrameSkip)
4019 {
4020
4021 }
4022 else if(wfdGenEvent ->type == eI2cRead)
4023 {
4024 }
4025 else if(wfdGenEvent ->type == eI2cWrite)
4026 {
Dake Zhao0a832172015-01-06 11:08:47 -08004027 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004028 else if(wfdGenEvent ->type == eInputContent)
4029 {
Dake Zhao0a832172015-01-06 11:08:47 -08004030 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004031 else if(wfdGenEvent ->type == eIdrReq)
4032 {
Dake Zhao0a832172015-01-06 11:08:47 -08004033 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004034 }
Dake Zhao0a832172015-01-06 11:08:47 -08004035
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004036 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004037 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004038 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004039
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004040 return WFA_SUCCESS;
4041}
4042
Dake Zhao0a832172015-01-06 11:08:47 -08004043
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004044
4045
4046/*
Dake Zhao0a832172015-01-06 11:08:47 -08004047 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004048 */
4049
4050int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4051{
4052 dutCmdResponse_t infoResp;
4053// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08004054
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004055 printf("\n Entry wfaStaReinvokeWfdSession... ");
4056
4057 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08004058
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004059
4060 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004061 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004062 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004063
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004064 return WFA_SUCCESS;
4065}
4066
4067
4068int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4069{
Dake Zhao0a832172015-01-06 11:08:47 -08004070 dutCmdResponse_t infoResp;
4071 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004072
4073
Dake Zhao0a832172015-01-06 11:08:47 -08004074 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004075
Dake Zhao0a832172015-01-06 11:08:47 -08004076 printf("\n Entry wfaStaGetParameter... ");
4077
4078 // Check the program type
4079 if(staGetParam->program == PROG_TYPE_WFD)
4080 {
4081 if(staGetParam->getParamValue == eDiscoveredDevList )
4082 {
4083 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4084 paramList->getParamType = eDiscoveredDevList;
4085 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4086 }
4087 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004088
Dake Zhao655efed2015-03-11 17:39:13 -07004089 if(staGetParam->program == PROG_TYPE_WFDS)
4090 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004091
Dake Zhao655efed2015-03-11 17:39:13 -07004092 if(staGetParam->getParamValue == eDiscoveredDevList )
4093 {
4094 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4095 paramList->getParamType = eDiscoveredDevList;
4096 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4097
4098 }
4099 if(staGetParam->getParamValue == eOpenPorts)
4100 {
4101 // Run the port checker tool
4102 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
4103 paramList->getParamType = eOpenPorts;
4104 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
4105
4106 }
4107
4108 }
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004109 if(staGetParam->program == PROG_TYPE_NAN)
4110 {
4111 if(staGetParam->getParamValue == eMasterPref )
4112 {
4113 // Get the master preference of the device and return the value
4114 paramList->getParamType = eMasterPref;
4115 strcpy((char *)&paramList->masterPref, "0xff");
4116 }
4117 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004118
Dake Zhao655efed2015-03-11 17:39:13 -07004119 infoResp.status = STATUS_COMPLETE;
4120 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4121 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4122
4123 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004124}
4125
Ankur Vachhanic485b712012-02-15 23:29:49 +00004126
Dake Zhao655efed2015-03-11 17:39:13 -07004127int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4128{
4129
4130 dutCmdResponse_t infoResp;
4131 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4132
4133 printf("\n Entry wfaStaNfcAction... ");
4134
4135 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4136 {
4137 printf("\n NfcAction - HandOver... ");
4138
4139 }
4140 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4141 {
4142 printf("\n NfcAction - Read Tag... ");
4143
4144 }
4145 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4146 {
4147 printf("\n NfcAction - Write Select... ");
4148
4149 }
4150 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4151 {
4152 printf("\n NfcAction - Write Config... ");
4153
4154 }
4155 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4156 {
4157 printf("\n NfcAction - Write Password... ");
4158
4159 }
4160 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4161 {
4162 printf("\n NfcAction - WPS Handover... ");
4163
4164 }
4165
4166 // Fetch the device mode and put in infoResp->cmdru.p2presult
4167 //strcpy(infoResp->cmdru.p2presult, "GO");
4168
4169 // Fetch the device grp id and put in infoResp->cmdru.grpid
4170 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4171
4172 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4173 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4174 infoResp.cmdru.staNfcAction.peerRole = 1;
4175
4176
4177
4178
4179 infoResp.status = STATUS_COMPLETE;
4180 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4181 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4182
4183 return WFA_SUCCESS;
4184}
4185
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004186int wfaStaExecAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4187{
4188
4189 dutCmdResponse_t infoResp;
4190 caStaExecAction_t *staExecAction = (caStaExecAction_t *)caCmdBuf; //comment if not used
4191
4192 printf("\n Entry wfaStaExecAction... ");
4193
4194 if(staExecAction->prog == PROG_TYPE_NAN)
4195 {
4196 // Perform necessary configurations and actions
4197 // return the MAC address conditionally as per CAPI specification
4198 }
4199
4200 infoResp.status = STATUS_COMPLETE;
4201 wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4202 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4203
4204 return WFA_SUCCESS;
4205}
4206
Dake Zhao655efed2015-03-11 17:39:13 -07004207int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4208{
4209
4210 dutCmdResponse_t infoResp;
4211 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4212
4213 printf("\n Entry wfaStaInvokeCommand... ");
4214
4215
4216 // based on the command type , invoke API or complete the required procedures
4217 // return the defined parameters based on the command that is received ( example response below)
4218
4219 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4220 {
4221 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4222 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4223 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4224 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4225 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4226 }
4227 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4228 {
4229 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4230 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4231 }
4232 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4233 {
4234 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4235 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4236 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4237 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4238
4239 }
4240 infoResp.status = STATUS_COMPLETE;
4241 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4242 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4243
4244 return WFA_SUCCESS;
4245}
4246
4247
4248int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4249{
4250
4251 dutCmdResponse_t infoResp;
4252 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4253
4254 printf("\n Entry wfaStaManageService... ");
4255
4256 // based on the manage service type , invoke API's or complete the required procedures
4257 // return the defined parameters based on the command that is received ( example response below)
4258 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4259 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4260 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4261
4262 infoResp.status = STATUS_COMPLETE;
4263 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4264 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4265
4266 return WFA_SUCCESS;
4267}
4268
4269
4270
4271int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4272{
4273
4274 dutCmdResponse_t infoResp;
Dake Zhao353c55e2015-07-20 18:54:45 -07004275 caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004276
4277 printf("\n Entry wfaStaGetEvents... ");
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004278
4279 if(staGetEvents->program == PROG_TYPE_NAN)
4280 {
4281 // Get all the events from the Log file or stored events
4282 // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac
4283 }
Dake Zhao655efed2015-03-11 17:39:13 -07004284
4285 // Get all the event from the Log file or stored events
4286 // return the received/recorded events as space seperated list ( example response below)
4287 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4288
4289 infoResp.status = STATUS_COMPLETE;
4290 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4291 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4292
4293 return WFA_SUCCESS;
4294}
4295
4296int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4297{
4298
4299 dutCmdResponse_t infoResp;
Li Yinf467b182015-09-23 21:21:30 +08004300 caStaGetEventDetails_t *getStaGetEventDetails = (caStaGetEventDetails_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004301
4302 printf("\n Entry wfaStaGetEventDetails... ");
4303
4304
4305 // based on the Requested Event type
4306 // return the latest corresponding evnet detailed parameters ( example response below)
4307
4308 if(getStaGetEventDetails->eventId== eSearchResult )
4309 {
4310 // fetch from log file or event history for the search result event and return the parameters
4311 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4312
4313 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4314 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4315 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4316 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4317
4318 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4319 }
4320 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4321 { // fetch from log file or event history for the search terminated event and return the parameters
4322 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4323 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4324 }
4325 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4326 {// fetch from log file or event history for the Advertise Status event and return the parameters
4327 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4328 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4329
4330 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4331 }
4332 else if (getStaGetEventDetails->eventId == eSessionRequest)
4333 {// fetch from log file or event history for the session request event and return the parameters
4334 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4335 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4336 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4337 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4338 }
4339 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4340 {// fetch from log file or event history for the session status event and return the parameters
4341 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4342 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4343 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4344 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4345 }
4346 else if (getStaGetEventDetails->eventId == eConnectStatus)
4347 {
4348 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4349 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4350 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4351 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4352
4353 }
4354 else if (getStaGetEventDetails->eventId == ePortStatus)
4355 {
4356 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4357 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4358 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4359 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4360 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4361 }
4362
4363
4364
4365 infoResp.status = STATUS_COMPLETE;
4366 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4367 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4368
4369 return WFA_SUCCESS;
4370}
4371
4372
4373
4374