blob: 051a1546012ec1b285a962438ca0187bf4c69462 [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>
40#include <sys/socket.h>
41#include <arpa/inet.h>
42#include <linux/types.h>
43#include <linux/socket.h>
44#include <poll.h>
45
46#include "wfa_portall.h"
47#include "wfa_debug.h"
48#include "wfa_ver.h"
49#include "wfa_main.h"
50#include "wfa_types.h"
51#include "wfa_ca.h"
52#include "wfa_tlv.h"
53#include "wfa_sock.h"
54#include "wfa_tg.h"
55#include "wfa_cmds.h"
56#include "wfa_rsp.h"
57#include "wfa_utils.h"
58#ifdef WFA_WMM_PS_EXT
59#include "wfa_wmmps.h"
60#endif
61
62#define CERTIFICATES_PATH "/etc/wpa_supplicant"
63
64/* Some device may only support UDP ECHO, activate this line */
65//#define WFA_PING_UDP_ECHO_ONLY 1
66
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080067#define WFA_ENABLED 1
68
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000069extern unsigned short wfa_defined_debug;
70int wfaExecuteCLI(char *CLI);
71
72/* Since the two definitions are used all over the CA function */
73char gCmdStr[WFA_CMD_STR_SZ];
74dutCmdResponse_t gGenericResp;
75int wfaTGSetPrio(int sockfd, int tgClass);
76void create_apts_msg(int msg, unsigned int txbuf[],int id);
77
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080078int sret = 0;
79
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000080extern char e2eResults[];
Dake Zhao862c94b2014-12-08 14:35:35 -080081
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000082FILE *e2efp = NULL;
83int chk_ret_status()
84{
85 char *ret = getenv(WFA_RET_ENV);
86
87 if(*ret == '1')
Dake Zhao0a832172015-01-06 11:08:47 -080088 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000089 else
Dake Zhao0a832172015-01-06 11:08:47 -080090 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000091}
92
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +020093static int systemWithLog(char* command) {
94 DPRINT_INFO(WFA_OUT, "exec: %s\n", command);
95 int ret = system(command);
96 if (ret != 0) {
97 DPRINT_INFO(WFA_OUT, "exit code %d\n", ret);
98 }
99 return ret;
100}
101
102
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000103/*
104 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
105 * input: cmd --- not used
106 * valLen -- not used
107 * output: parms -- a buffer to store the version info response.
108 */
109int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
110{
111 dutCmdResponse_t *getverResp = &gGenericResp;
112
113 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
114
115 getverResp->status = STATUS_COMPLETE;
116 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
117
118 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
119
120 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
121
122 return WFA_SUCCESS;
123}
124
125/*
126 * wfaStaAssociate():
Dake Zhao0a832172015-01-06 11:08:47 -0800127 * The function is to force the station wireless I/F to re/associate
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000128 * with the AP.
129 */
130int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
131{
Dake Zhao0a832172015-01-06 11:08:47 -0800132 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
133 char *ifname = assoc->intf;
134 dutCmdResponse_t *staAssocResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000135
Dake Zhao0a832172015-01-06 11:08:47 -0800136 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
137 /*
138 * if bssid appears, station should associate with the specific
139 * BSSID AP at its initial association.
140 * If it is different to the current associating AP, it will be forced to
141 * roam the new AP
142 */
143 if(assoc->cmdsu.assoc.bssid[0] != '\0')
144 {
145 /* if (the first association) */
146 /* just do initial association to the BSSID */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000147
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000148
Dake Zhao0a832172015-01-06 11:08:47 -0800149 /* else (station already associate to an AP) */
150 /* Do forced roaming */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000151
Dake Zhao0a832172015-01-06 11:08:47 -0800152 }
153 else
154 {
155 /* use 'ifconfig' command to bring down the interface (linux specific) */
Ray Wangd11ca032015-05-29 18:25:46 -0700156 //sprintf(gCmdStr, "ifconfig %s down", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200157 //sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000158
Dake Zhao0a832172015-01-06 11:08:47 -0800159 /* use 'ifconfig' command to bring up the interface (linux specific) */
Ray Wangd11ca032015-05-29 18:25:46 -0700160 //sprintf(gCmdStr, "ifconfig %s up", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200161 //sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000162
Dake Zhao0a832172015-01-06 11:08:47 -0800163 /*
164 * use 'wpa_cli' command to force a 802.11 re/associate
165 * (wpa_supplicant specific)
166 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200167 sprintf(gCmdStr, "wpa_cli.sh -i%s reassociate", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200168 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000169 }
170
171 /*
172 * Then report back to control PC for completion.
173 * This does not have failed/error status. The result only tells
174 * a completion.
175 */
176 staAssocResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -0800177 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000178 *respLen = WFA_TLV_HDR_LEN + 4;
179
Dake Zhao0a832172015-01-06 11:08:47 -0800180 return WFA_SUCCESS;
181}
182
183/*
184 * wfaStaReAssociate():
185 * The function is to force the station wireless I/F to re/associate
186 * with the AP.
187 */
188int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
189{
190 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
191 char *ifname = assoc->intf;
192 dutCmdResponse_t *staAssocResp = &gGenericResp;
193
194 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
195 /*
196 * if bssid appears, station should associate with the specific
197 * BSSID AP at its initial association.
198 * If it is different to the current associating AP, it will be forced to
199 * roam the new AP
200 */
201 if(assoc->cmdsu.assoc.bssid[0] != '\0')
202 {
203 /* if (the first association) */
204 /* just do initial association to the BSSID */
205
206
207 /* else (station already associate to an AP) */
208 /* Do forced roaming */
209
210 }
211 else
212 {
213 /* use 'ifconfig' command to bring down the interface (linux specific) */
214 sprintf(gCmdStr, "ifconfig %s down", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200215 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800216
217 /* use 'ifconfig' command to bring up the interface (linux specific) */
218 sprintf(gCmdStr, "ifconfig %s up", ifname);
219
220 /*
221 * use 'wpa_cli' command to force a 802.11 re/associate
222 * (wpa_supplicant specific)
223 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200224 sprintf(gCmdStr, "wpa_cli.sh -i%s reassociate", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200225 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800226 }
227
228 /*
229 * Then report back to control PC for completion.
230 * This does not have failed/error status. The result only tells
231 * a completion.
232 */
233 staAssocResp->status = STATUS_COMPLETE;
234 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
235 *respLen = WFA_TLV_HDR_LEN + 4;
236
237 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000238}
239
240/*
241 * wfaStaIsConnected():
Dake Zhao0a832172015-01-06 11:08:47 -0800242 * The function is to check whether the station's wireless I/F has
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000243 * already connected to an AP.
244 */
245int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
246{
Dake Zhao0a832172015-01-06 11:08:47 -0800247 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
248 dutCmdResponse_t *staConnectResp = &gGenericResp;
249 char *ifname = connStat->intf;
250 FILE *tmpfile = NULL;
251 char result[32];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000252
253
Dake Zhao0a832172015-01-06 11:08:47 -0800254 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000255
256#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800257 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200258 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000259
Dake Zhao0a832172015-01-06 11:08:47 -0800260 if(chk_ret_status() == WFA_SUCCESS)
261 staConnectResp->cmdru.connected = 1;
262 else
263 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000264#else
Dake Zhao0a832172015-01-06 11:08:47 -0800265 /*
266 * use 'wpa_cli' command to check the interface status
267 * none, scanning or complete (wpa_supplicant specific)
268 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200269 sprintf(gCmdStr, "wpa_cli.sh -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200270 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000271
Dake Zhao0a832172015-01-06 11:08:47 -0800272 /*
273 * the status is saved in a file. Open the file and check it.
274 */
275 tmpfile = fopen("/tmp/.isConnected", "r+");
276 if(tmpfile == NULL)
277 {
278 staConnectResp->status = STATUS_ERROR;
279 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
280 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000281
Dake Zhao0a832172015-01-06 11:08:47 -0800282 DPRINT_ERR(WFA_ERR, "file open failed\n");
283 return WFA_FAILURE;
284 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000285
Dake Zhao0a832172015-01-06 11:08:47 -0800286 sret = fscanf(tmpfile, "%s", (char *)result);
Li Yincba7d352015-09-23 20:30:49 +0800287 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000288
Dake Zhao0a832172015-01-06 11:08:47 -0800289 if(strncmp(result, "COMPLETED", 9) == 0)
290 staConnectResp->cmdru.connected = 1;
291 else
292 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000293#endif
294
Dake Zhao0a832172015-01-06 11:08:47 -0800295 /*
296 * Report back the status: Complete or Failed.
297 */
298 staConnectResp->status = STATUS_COMPLETE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000299
Dake Zhao0a832172015-01-06 11:08:47 -0800300 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
301 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
302
303 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000304}
305
306/*
307 * wfaStaGetIpConfig():
308 * This function is to retriev the ip info including
309 * 1. dhcp enable
310 * 2. ip address
Dake Zhao0a832172015-01-06 11:08:47 -0800311 * 3. mask
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000312 * 4. primary-dns
313 * 5. secondary-dns
314 *
315 * The current implementation is to use a script to find these information
Dake Zhao0a832172015-01-06 11:08:47 -0800316 * and store them in a file.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000317 */
318int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
319{
320 int slen, ret, i = 0;
321 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
Dake Zhao0a832172015-01-06 11:08:47 -0800322 dutCmdResponse_t *ipconfigResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000323 char *ifname = getIpConf->intf;
324 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
325
326 FILE *tmpfd;
327 char string[256];
328 char *str;
329
330 /*
331 * check a script file (the current implementation specific)
332 */
333 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
334 if(ret == -1)
335 {
Dake Zhao0a832172015-01-06 11:08:47 -0800336 ipconfigResp->status = STATUS_ERROR;
337 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
338 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000339
Dake Zhao0a832172015-01-06 11:08:47 -0800340 DPRINT_ERR(WFA_ERR, "file not exist\n");
341 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000342
343 }
344
345 strcpy(ifinfo->dns[0], "0");
346 strcpy(ifinfo->dns[1], "0");
Dake Zhao0a832172015-01-06 11:08:47 -0800347
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000348 /*
Dake Zhao0a832172015-01-06 11:08:47 -0800349 * Run the script file "getipconfig.sh" to check the ip status
350 * (current implementation specific).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000351 * note: "getipconfig.sh" is only defined for the current implementation
352 */
Dake Zhao0a832172015-01-06 11:08:47 -0800353 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000354
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200355 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000356
357 /* open the output result and scan/retrieve the info */
358 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
359
360 if(tmpfd == NULL)
361 {
Dake Zhao0a832172015-01-06 11:08:47 -0800362 ipconfigResp->status = STATUS_ERROR;
363 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
364 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000365
Dake Zhao0a832172015-01-06 11:08:47 -0800366 DPRINT_ERR(WFA_ERR, "file open failed\n");
367 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000368 }
369
370 for(;;)
371 {
372 if(fgets(string, 256, tmpfd) == NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800373 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000374
375 /* check dhcp enabled */
376 if(strncmp(string, "dhcpcli", 7) ==0)
377 {
378 str = strtok(string, "=");
379 str = strtok(NULL, "=");
380 if(str != NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800381 ifinfo->isDhcp = 1;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000382 else
Dake Zhao0a832172015-01-06 11:08:47 -0800383 ifinfo->isDhcp = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000384 }
385
386 /* find out the ip address */
387 if(strncmp(string, "ipaddr", 6) == 0)
388 {
389 str = strtok(string, "=");
390 str = strtok(NULL, " ");
391 if(str != NULL)
392 {
Dake Zhao0a832172015-01-06 11:08:47 -0800393 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800394
Dake Zhao0a832172015-01-06 11:08:47 -0800395 ifinfo->ipaddr[15]='\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000396 }
397 else
Dake Zhao0a832172015-01-06 11:08:47 -0800398 wSTRNCPY(ifinfo->ipaddr, "none", 15);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000399 }
400
401 /* check the mask */
402 if(strncmp(string, "mask", 4) == 0)
403 {
404 char ttstr[16];
405 char *ttp = ttstr;
406
407 str = strtok_r(string, "=", &ttp);
408 if(*ttp != '\0')
409 {
Dake Zhao0a832172015-01-06 11:08:47 -0800410 strcpy(ifinfo->mask, ttp);
411 slen = strlen(ifinfo->mask);
412 ifinfo->mask[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000413 }
414 else
Dake Zhao0a832172015-01-06 11:08:47 -0800415 strcpy(ifinfo->mask, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000416 }
417
418 /* find out the dns server ip address */
419 if(strncmp(string, "nameserv", 8) == 0)
420 {
421 char ttstr[16];
422 char *ttp = ttstr;
Dake Zhao0a832172015-01-06 11:08:47 -0800423
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000424 str = strtok_r(string, " ", &ttp);
425 if(str != NULL && i < 2)
426 {
Dake Zhao0a832172015-01-06 11:08:47 -0800427 strcpy(ifinfo->dns[i], ttp);
428 slen = strlen(ifinfo->dns[i]);
429 ifinfo->dns[i][slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000430 }
431 else
Dake Zhao0a832172015-01-06 11:08:47 -0800432 strcpy(ifinfo->dns[i], "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000433
434 i++;
435 }
Dake Zhao0a832172015-01-06 11:08:47 -0800436 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000437
Dake Zhao0a832172015-01-06 11:08:47 -0800438 /*
439 * Report back the results
440 */
441 ipconfigResp->status = STATUS_COMPLETE;
442 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000443
Dake Zhao0a832172015-01-06 11:08:47 -0800444 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000445
446#if 0
Dake Zhao0a832172015-01-06 11:08:47 -0800447 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
448 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
449 ifinfo->dns[0], ifinfo->dns[1], *respLen);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000450#endif
451
Dake Zhao0a832172015-01-06 11:08:47 -0800452 fclose(tmpfd);
453 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000454}
455
456/*
457 * wfaStaSetIpConfig():
458 * The function is to set the ip configuration to a wireless I/F.
459 * 1. IP address
460 * 2. Mac address
461 * 3. default gateway
Dake Zhao0a832172015-01-06 11:08:47 -0800462 * 4. dns nameserver (pri and sec).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000463 */
464int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
465{
Dake Zhao0a832172015-01-06 11:08:47 -0800466 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
467 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
468 dutCmdResponse_t *staSetIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000469
Dake Zhao0a832172015-01-06 11:08:47 -0800470 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200471
472 if (ipconfig->isDhcp) {
473 DPRINT_INFO(WFA_OUT, "error: dhcp not supported\n");
474 staSetIpResp->status = STATUS_INVALID;
475 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
476 *respLen = WFA_TLV_HDR_LEN + 4;
477
478 return WFA_FAILURE;
479 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000480
Dake Zhao0a832172015-01-06 11:08:47 -0800481 /*
482 * Use command 'ifconfig' to configure the interface ip address, mask.
483 * (Linux specific).
484 */
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200485 sprintf(gCmdStr, "ifconfig %s %s netmask %s >/tmp/ifconfig.log 2>&1", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
486 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200487 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200488 if (sret != 0) {
489 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
490 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000491
Dake Zhao0a832172015-01-06 11:08:47 -0800492 /* use command 'route add' to set set gatewway (linux specific) */
493 if(ipconfig->defGateway[0] != '\0')
494 {
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200495 sprintf(gCmdStr, "route add default gw %s >/tmp/route.log 2>&1", ipconfig->defGateway);
496 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200497 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200498 if (sret != 0) {
499 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
500 }
Dake Zhao0a832172015-01-06 11:08:47 -0800501 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000502
Dake Zhao0a832172015-01-06 11:08:47 -0800503 /* set dns (linux specific) */
504 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200505 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200506 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200507 if (sret != 0) {
508 DPRINT_INFO(WFA_OUT, "exit code %d backing up resolv.conf\n", sret);
509 }
Dake Zhao0a832172015-01-06 11:08:47 -0800510 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200511 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200512 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200513 if (sret != 0) {
514 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
515 }
516 if (strlen(ipconfig->sec_dns) > 0) {
517 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
518 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200519 sret = systemWithLog(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200520 if (sret != 0) {
521 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
522 }
523 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000524
Dake Zhao0a832172015-01-06 11:08:47 -0800525 /*
526 * report status
527 */
528 staSetIpResp->status = STATUS_COMPLETE;
529 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
530 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000531
Dake Zhao0a832172015-01-06 11:08:47 -0800532 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000533}
534
535/*
536 * wfaStaVerifyIpConnection():
537 * The function is to verify if the station has IP connection with an AP by
538 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800539 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000540int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
541{
Dake Zhao0a832172015-01-06 11:08:47 -0800542 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
543 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000544
545#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800546 char strout[64], *pcnt;
547 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000548
Dake Zhao0a832172015-01-06 11:08:47 -0800549 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
550
551 /* set timeout value in case not set */
552 if(verip->cmdsu.verifyIp.timeout <= 0)
553 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000554 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800555 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000556
Dake Zhao0a832172015-01-06 11:08:47 -0800557 /* execute the ping command and pipe the result to a tmp file */
558 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 +0200559 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000560
Dake Zhao0a832172015-01-06 11:08:47 -0800561 /* scan/check the output */
562 tmpfile = fopen("/tmp/pingout.txt", "r+");
563 if(tmpfile == NULL)
564 {
565 verifyIpResp->status = STATUS_ERROR;
566 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
567 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000568
Dake Zhao0a832172015-01-06 11:08:47 -0800569 DPRINT_ERR(WFA_ERR, "file open failed\n");
570 return WFA_FAILURE;
571 }
572
573 verifyIpResp->status = STATUS_COMPLETE;
574 if(fscanf(tmpfile, "%s", strout) == EOF)
575 verifyIpResp->cmdru.connected = 0;
576 else
577 {
578 pcnt = strtok(strout, "%");
579
580 /* if the loss rate is 100%, not able to connect */
581 if(atoi(pcnt) == 100)
582 verifyIpResp->cmdru.connected = 0;
583 else
584 verifyIpResp->cmdru.connected = 1;
585 }
586
587 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000588#else
Dake Zhao0a832172015-01-06 11:08:47 -0800589 int btSockfd;
590 struct pollfd fds[2];
591 int timeout = 2000;
592 char anyBuf[64];
593 struct sockaddr_in toAddr;
594 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000595
Dake Zhao0a832172015-01-06 11:08:47 -0800596 verifyIpResp->status = STATUS_COMPLETE;
597 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000598
Dake Zhao0a832172015-01-06 11:08:47 -0800599 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000600
Dake Zhao0a832172015-01-06 11:08:47 -0800601 if(btSockfd == -1)
602 {
603 verifyIpResp->status = STATUS_ERROR;
604 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
605 *respLen = WFA_TLV_HDR_LEN + 4;
606 return WFA_FAILURE;;
607 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000608
Dake Zhao0a832172015-01-06 11:08:47 -0800609 toAddr.sin_family = AF_INET;
610 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
611 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000612
Dake Zhao0a832172015-01-06 11:08:47 -0800613 while(done)
614 {
615 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
616 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000617
Dake Zhao0a832172015-01-06 11:08:47 -0800618 fds[0].fd = btSockfd;
619 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000620
Dake Zhao0a832172015-01-06 11:08:47 -0800621 ret = poll(fds, 1, timeout);
622 switch(ret)
623 {
624 case 0:
625 /* it is time out, count a packet lost*/
626 break;
627 case -1:
628 /* it is an error */
629 default:
630 {
631 switch(fds[0].revents)
632 {
633 case POLLIN:
634 case POLLPRI:
635 case POLLOUT:
636 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
637 if(nbytes != 0)
638 verifyIpResp->cmdru.connected = 1;
639 done = 0;
640 break;
641 default:
642 /* errors but not care */
643 ;
644 }
645 }
646 }
647 if(cnt == 3)
648 {
649 done = 0;
650 }
651 }
652
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000653#endif
654
Dake Zhao0a832172015-01-06 11:08:47 -0800655 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000656
Dake Zhao0a832172015-01-06 11:08:47 -0800657 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
658
659 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000660}
661
662/*
663 * wfaStaGetMacAddress()
664 * This function is to retrieve the MAC address of a wireless I/F.
665 */
666int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
667{
668 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
669 dutCmdResponse_t *getmacResp = &gGenericResp;
670 char *str;
671 char *ifname = getMac->intf;
672
673 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800674 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000675
676 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
677 /*
678 * run the script "getipconfig.sh" to find out the mac
679 */
Dake Zhao0a832172015-01-06 11:08:47 -0800680 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200681 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000682
683 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
684 if(tmpfd == NULL)
685 {
Dake Zhao0a832172015-01-06 11:08:47 -0800686 getmacResp->status = STATUS_ERROR;
687 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
688 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000689
Dake Zhao0a832172015-01-06 11:08:47 -0800690 DPRINT_ERR(WFA_ERR, "file open failed\n");
691 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000692 }
693
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800694 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
695 {
Dake Zhao0a832172015-01-06 11:08:47 -0800696 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000697 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800698
699 str = strtok(string, " ");
700 while(str && ((strcmp(str,"HWaddr")) != 0))
701 {
Dake Zhao0a832172015-01-06 11:08:47 -0800702 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800703 }
Dake Zhao0a832172015-01-06 11:08:47 -0800704
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800705 /* get mac */
706 if(str)
707 {
708 str = strtok(NULL, " ");
709 strcpy(getmacResp->cmdru.mac, str);
710 getmacResp->status = STATUS_COMPLETE;
711 }
Dake Zhao0a832172015-01-06 11:08:47 -0800712
713 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000714
715 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
716
717 fclose(tmpfd);
718 return WFA_SUCCESS;
719}
720
721/*
722 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800723 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000724 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800725 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000726 */
727int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
728{
Dake Zhao0a832172015-01-06 11:08:47 -0800729 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000730
Dake Zhao0a832172015-01-06 11:08:47 -0800731 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000732
Dake Zhao0a832172015-01-06 11:08:47 -0800733 statsResp->status = STATUS_ERROR;
734 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
735 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000736
737
Dake Zhao0a832172015-01-06 11:08:47 -0800738 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000739}
740
741/*
742 * wfaSetEncryption():
743 * The function is to set the wireless interface with WEP or none.
744 *
Dake Zhao0a832172015-01-06 11:08:47 -0800745 * Since WEP is optional test, current function is only used for
746 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000747 * this function should be replaced by the next one (wfaSetEncryption1())
748 *
Dake Zhao0a832172015-01-06 11:08:47 -0800749 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000750 * 1. I/F
751 * 2. ssid
752 * 3. encpType - wep or none
753 * Optional:
754 * 4. key1
755 * 5. key2
756 * 6. key3
757 * 7. key4
758 * 8. activeKey Index
759 */
760
761int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
762{
Dake Zhao0a832172015-01-06 11:08:47 -0800763 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
764 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000765
Dake Zhao0a832172015-01-06 11:08:47 -0800766 /*
767 * disable the network first
768 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200769 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200770 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000771
Dake Zhao0a832172015-01-06 11:08:47 -0800772 /*
773 * set SSID
774 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200775 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200776 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000777
Dake Zhao0a832172015-01-06 11:08:47 -0800778 /*
779 * Tell the supplicant for infrastructure mode (1)
780 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200781 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200782 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000783
Dake Zhao0a832172015-01-06 11:08:47 -0800784 /*
785 * set Key management to NONE (NO WPA) for plaintext or WEP
786 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200787 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200788 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000789
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200790 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setEncryp->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200791 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000792
Dake Zhao0a832172015-01-06 11:08:47 -0800793 setEncrypResp->status = STATUS_COMPLETE;
794 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
795 *respLen = WFA_TLV_HDR_LEN + 4;
796
797 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000798}
799
800/*
801 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800802 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000803 */
804int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
805{
Dake Zhao0a832172015-01-06 11:08:47 -0800806 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
807 dutCmdResponse_t *setEncrypResp = &gGenericResp;
808 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000809
Dake Zhao0a832172015-01-06 11:08:47 -0800810 /*
811 * disable the network first
812 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200813 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setEncryp->intf);
814 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000815
Dake Zhao0a832172015-01-06 11:08:47 -0800816 /*
817 * set SSID
818 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200819 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
820 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000821
Dake Zhao0a832172015-01-06 11:08:47 -0800822 /*
823 * Tell the supplicant for infrastructure mode (1)
824 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200825 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 0", setEncryp->intf);
826 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000827
Dake Zhao0a832172015-01-06 11:08:47 -0800828 /*
829 * set Key management to NONE (NO WPA) for plaintext or WEP
830 */
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200831 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
832 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000833
Dake Zhao0a832172015-01-06 11:08:47 -0800834 /* set keys */
835 if(setEncryp->encpType == 1)
836 {
837 for(i=0; i<4; i++)
838 {
839 if(setEncryp->keys[i][0] != '\0')
840 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200841 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i %s",
Dake Zhao0a832172015-01-06 11:08:47 -0800842 setEncryp->intf, i, setEncryp->keys[i]);
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200843 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800844 }
845 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000846
Dake Zhao0a832172015-01-06 11:08:47 -0800847 /* set active key */
848 i = setEncryp->activeKeyIdx;
849 if(setEncryp->keys[i][0] != '\0')
850 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200851 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_tx_keyidx %i",
Dake Zhao0a832172015-01-06 11:08:47 -0800852 setEncryp->intf, setEncryp->activeKeyIdx);
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200853 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800854 }
855 }
856 else /* clearly remove the keys -- reported by p.schwann */
857 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000858
Dake Zhao0a832172015-01-06 11:08:47 -0800859 for(i = 0; i < 4; i++)
860 {
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200861 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
862 systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800863 }
864 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000865
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200866 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setEncryp->intf);
867 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000868
Dake Zhao0a832172015-01-06 11:08:47 -0800869 setEncrypResp->status = STATUS_COMPLETE;
Wojciech Jakobczykaf6d2332020-08-26 14:48:52 +0200870 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, sizeof(setEncrypResp->status), (BYTE *)setEncrypResp, respBuf);
871 *respLen = WFA_TLV_HDR_LEN + sizeof(setEncrypResp->status);
Dake Zhao0a832172015-01-06 11:08:47 -0800872
873 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000874}
875
876int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
877{
878 int ret = WFA_SUCCESS;
879
880 return ret;
881}
882
883/*
884 * wfaStaSetEapTLS():
885 * This is to set
886 * 1. ssid
887 * 2. encrypType - tkip or aes-ccmp
888 * 3. keyManagementType - wpa or wpa2
889 * 4. trustedRootCA
890 * 5. clientCertificate
891 */
892int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
893{
Dake Zhao0a832172015-01-06 11:08:47 -0800894 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
895 char *ifname = setTLS->intf;
896 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000897
Dake Zhao0a832172015-01-06 11:08:47 -0800898 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000899
Dake Zhao0a832172015-01-06 11:08:47 -0800900 /*
901 * need to store the trustedROOTCA and clientCertificate into a file first.
902 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000903#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800904 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200905 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000906#else
907
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200908 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200909 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000910
Dake Zhao0a832172015-01-06 11:08:47 -0800911 /* ssid */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200912 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200913 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000914
Dake Zhao0a832172015-01-06 11:08:47 -0800915 /* key management */
916 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
917 {
918 }
919 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
920 {
921 }
922 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
923 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000924
Dake Zhao0a832172015-01-06 11:08:47 -0800925 }
926 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
927 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200928 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -0800929 }
930 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
931 {
932 // to take all and device to pick any one supported.
933 }
934 else
935 {
936 // ??
937 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200938 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000939
Dake Zhao0a832172015-01-06 11:08:47 -0800940 /* protocol WPA */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200941 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200942 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000943
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200944 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap TLS", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200945 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000946
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200947 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200948 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000949
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200950 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200951 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000952
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200953 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 +0200954 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000955
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200956 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200957 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000958
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200959 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200960 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000961#endif
962
Dake Zhao0a832172015-01-06 11:08:47 -0800963 setEapTlsResp->status = STATUS_COMPLETE;
964 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
965 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000966
Dake Zhao0a832172015-01-06 11:08:47 -0800967 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000968}
969
970/*
Dake Zhao0a832172015-01-06 11:08:47 -0800971 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000972 * 1. ssid
973 * 2. passPhrase
974 * 3. keyMangementType - wpa/wpa2
975 * 4. encrypType - tkip or aes-ccmp
976 */
977int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -0800978{
979 /*Incompleted function*/
980 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000981
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800982#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -0800983 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000984#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800985 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200986 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000987#else
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200988 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +0200989 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000990
Dake Zhao0a832172015-01-06 11:08:47 -0800991 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +0200992 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
Dake Zhao0a832172015-01-06 11:08:47 -0800993 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
994 {
995 // take all and device to pick it supported.
996 }
997 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
998 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000999
Dake Zhao0a832172015-01-06 11:08:47 -08001000 }
1001 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
1002 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001003
Dake Zhao0a832172015-01-06 11:08:47 -08001004 }
1005 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
1006 {
Ray Wang9c508692014-04-01 17:04:59 -07001007
Dake Zhao0a832172015-01-06 11:08:47 -08001008 }
1009 else
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001010 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001011
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001012 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001013
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001014 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001015 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001016
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001017 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setPSK->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001018 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001019
Dake Zhao0a832172015-01-06 11:08:47 -08001020 /* if PMF enable */
1021 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
1022 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001023
Dake Zhao0a832172015-01-06 11:08:47 -08001024 }
1025 else if(setPSK->pmf == WFA_REQUIRED)
1026 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001027
Dake Zhao0a832172015-01-06 11:08:47 -08001028 }
1029 else if(setPSK->pmf == WFA_F_REQUIRED)
1030 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001031
Dake Zhao0a832172015-01-06 11:08:47 -08001032 }
1033 else if(setPSK->pmf == WFA_F_DISABLED)
1034 {
1035
1036 }
1037 else
1038 {
1039 /* Disable PMF */
1040
1041 }
1042
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001043#endif
1044
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001045#endif
1046
Dake Zhao0a832172015-01-06 11:08:47 -08001047 setPskResp->status = STATUS_COMPLETE;
1048 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1049 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001050
Dake Zhao0a832172015-01-06 11:08:47 -08001051 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001052}
1053
1054/*
Dake Zhao0a832172015-01-06 11:08:47 -08001055 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001056 * Get vendor specific information in name/value pair by a wireless I/F.
1057 */
1058int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1059{
Dake Zhao0a832172015-01-06 11:08:47 -08001060 dutCmdResponse_t infoResp;
1061 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001062 FILE *tmpfd;
1063 char vendor[256];
1064 const char* vendorFileName = "/tmp/ifvendor.txt";
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001065
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001066 sprintf(gCmdStr, "getifvendor.sh %s %s\n", getInfo->intf, vendorFileName);
1067
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001068 if (systemWithLog(gCmdStr) == -1)
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001069 {
1070 infoResp.status = STATUS_ERROR;
1071 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1072 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1073
1074 DPRINT_ERR(WFA_ERR, "script %s failed\n", vendorFileName);
1075 return WFA_FAILURE;
1076 }
1077
1078 /* open the output result and scan/retrieve the info */
1079 tmpfd = fopen(vendorFileName, "r+");
1080
1081 if(tmpfd == NULL || fgets(vendor, 256, tmpfd) == NULL)
1082 {
1083 infoResp.status = STATUS_ERROR;
1084 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1085 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1086
1087 DPRINT_ERR(WFA_ERR, "file read failed\n");
1088
1089 if (tmpfd != NULL)
1090 {
1091 fclose(tmpfd);
1092 remove(vendorFileName);
1093 }
1094
1095 return WFA_FAILURE;
1096 }
1097
1098 snprintf(infoResp.cmdru.info, sizeof(infoResp.cmdru.info), "interface,%s,description,%s",
1099 getInfo->intf, vendor);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001100
Dake Zhao0a832172015-01-06 11:08:47 -08001101 infoResp.status = STATUS_COMPLETE;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001102 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1103 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1104
1105 fclose(tmpfd);
1106 remove(vendorFileName);
Dake Zhao0a832172015-01-06 11:08:47 -08001107
1108 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001109}
1110
1111/*
1112 * wfaStaSetEapTTLS():
1113 * This is to set
1114 * 1. ssid
1115 * 2. username
1116 * 3. passwd
1117 * 4. encrypType - tkip or aes-ccmp
1118 * 5. keyManagementType - wpa or wpa2
1119 * 6. trustedRootCA
1120 */
1121int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1122{
Dake Zhao0a832172015-01-06 11:08:47 -08001123 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1124 char *ifname = setTTLS->intf;
1125 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001126
1127#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001128 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 +02001129 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001130#else
1131
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001132 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001133 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001134
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001135 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001136 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001137
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001138 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001139 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001140
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001141 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001142 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001143
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001144 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001145 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001146
Dake Zhao0a832172015-01-06 11:08:47 -08001147 /* This may not need to set. if it is not set, default to take all */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001148// sprintf(cmdStr, "wpa_cli.sh -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001149 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1150 {
1151 }
1152 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1153 {
1154 }
1155 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1156 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001157
Dake Zhao0a832172015-01-06 11:08:47 -08001158 }
1159 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1160 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001161
Dake Zhao0a832172015-01-06 11:08:47 -08001162 }
1163 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1164 {
1165 // to take all and device to pick one it supported
1166 }
1167 else
1168 {
1169 // ??
1170 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001171 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001172
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001173 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap TTLS", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001174 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001175
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001176 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 +02001177 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001178
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001179 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001180 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001181
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001182 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001183 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001184
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001185 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001186 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001187#endif
1188
Dake Zhao0a832172015-01-06 11:08:47 -08001189 setEapTtlsResp->status = STATUS_COMPLETE;
1190 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1191 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001192
Dake Zhao0a832172015-01-06 11:08:47 -08001193 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001194}
1195
1196/*
1197 * wfaStaSetEapSIM():
1198 * This is to set
1199 * 1. ssid
1200 * 2. user name
1201 * 3. passwd
1202 * 4. encrypType - tkip or aes-ccmp
1203 * 5. keyMangementType - wpa or wpa2
1204 */
1205int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1206{
Dake Zhao0a832172015-01-06 11:08:47 -08001207 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1208 char *ifname = setSIM->intf;
1209 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001210
1211#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001212 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001213 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001214#else
1215
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001216 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001217 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001218
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001219 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001220 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001221
1222
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001223 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001224 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001225
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001226 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001227 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001228
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001229 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap SIM", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001230 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001231
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001232 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001233 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001234
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001235 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001236 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001237
Dake Zhao0a832172015-01-06 11:08:47 -08001238 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1239 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001240 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001241 }
1242 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1243 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001244 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001245 }
1246 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1247 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001248 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-FT", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001249 }
1250 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1251 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001252 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001253 }
1254 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1255 {
1256 // take all and device to pick one which is supported.
1257 }
1258 else
1259 {
1260 // ??
1261 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001262 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001263
1264#endif
1265
Dake Zhao0a832172015-01-06 11:08:47 -08001266 setEapSimResp->status = STATUS_COMPLETE;
1267 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1268 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001269
Dake Zhao0a832172015-01-06 11:08:47 -08001270 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001271}
1272
1273/*
1274 * wfaStaSetPEAP()
1275 * This is to set
1276 * 1. ssid
1277 * 2. user name
1278 * 3. passwd
1279 * 4. encryType - tkip or aes-ccmp
1280 * 5. keyMgmtType - wpa or wpa2
1281 * 6. trustedRootCA
1282 * 7. innerEAP
1283 * 8. peapVersion
1284 */
1285int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1286{
Dake Zhao0a832172015-01-06 11:08:47 -08001287 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1288 char *ifname = setPEAP->intf;
1289 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001290
1291#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001292 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1293 setPEAP->passwd, setPEAP->trustedRootCA,
1294 setPEAP->encrptype, setPEAP->peapVersion,
1295 setPEAP->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001296 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001297#else
1298
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001299 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001300 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001301
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001302 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001303 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001304
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001305 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap PEAP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001306 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001307
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001308 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001309 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001310
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001311 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001312 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001313
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001314 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001315 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001316
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001317 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 +02001318 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001319
Dake Zhao0a832172015-01-06 11:08:47 -08001320 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1321 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001322 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001323 }
1324 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1325 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001326 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001327 }
1328 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1329 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001330 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-FT", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001331 }
1332 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1333 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001334 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -08001335 }
1336 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1337 {
1338 // take all and device to pick one which is supported.
1339 }
1340 else
1341 {
1342 // ??
1343 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001344 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001345
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001346 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001347 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001348
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001349 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001350 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001351
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001352 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001353 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001354#endif
1355
Dake Zhao0a832172015-01-06 11:08:47 -08001356 setPeapResp->status = STATUS_COMPLETE;
1357 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1358 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001359
Dake Zhao0a832172015-01-06 11:08:47 -08001360 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001361}
1362
1363/*
1364 * wfaStaSetUAPSD()
1365 * This is to set
1366 * 1. acBE
1367 * 2. acBK
1368 * 3. acVI
1369 * 4. acVO
1370 */
1371int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1372{
Dake Zhao0a832172015-01-06 11:08:47 -08001373 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001374#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001375 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1376 char *ifname = setUAPSD->intf;
1377 char tmpStr[10];
1378 char line[100];
1379 char *pathl="/etc/Wireless/RT61STA";
1380 BYTE acBE=1;
1381 BYTE acBK=1;
1382 BYTE acVO=1;
1383 BYTE acVI=1;
1384 BYTE APSDCapable;
1385 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001386
Dake Zhao0a832172015-01-06 11:08:47 -08001387 /*
1388 * A series of setting need to be done before doing WMM-PS
1389 * Additional steps of configuration may be needed.
1390 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001391
Dake Zhao0a832172015-01-06 11:08:47 -08001392 /*
1393 * bring down the interface
1394 */
1395 sprintf(gCmdStr, "ifconfig %s down",ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001396 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001397 /*
1398 * Unload the Driver
1399 */
1400 sprintf(gCmdStr, "rmmod rt61");
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001401 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001402#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001403 if(setUAPSD->acBE != 1)
1404 acBE=setUAPSD->acBE = 0;
1405 if(setUAPSD->acBK != 1)
1406 acBK=setUAPSD->acBK = 0;
1407 if(setUAPSD->acVO != 1)
1408 acVO=setUAPSD->acVO = 0;
1409 if(setUAPSD->acVI != 1)
1410 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001411#else
Dake Zhao0a832172015-01-06 11:08:47 -08001412 acBE=setUAPSD->acBE;
1413 acBK=setUAPSD->acBK;
1414 acVO=setUAPSD->acVO;
1415 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001416#endif
1417
Dake Zhao0a832172015-01-06 11:08:47 -08001418 APSDCapable = acBE||acBK||acVO||acVI;
1419 /*
1420 * set other AC parameters
1421 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001422
Dake Zhao0a832172015-01-06 11:08:47 -08001423 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1424 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 +02001425 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001426
Dake Zhao0a832172015-01-06 11:08:47 -08001427 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001428 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001429 pipe = popen("uname -r", "r");
1430 /* Read into line the output of uname*/
1431 fscanf(pipe,"%s",line);
1432 pclose(pipe);
1433
1434 /*
1435 * load the Driver
1436 */
1437 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001438 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001439
1440 sprintf(gCmdStr, "ifconfig %s up",ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001441 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001442#endif
1443
Dake Zhao0a832172015-01-06 11:08:47 -08001444 setUAPSDResp->status = STATUS_COMPLETE;
1445 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1446 *respLen = WFA_TLV_HDR_LEN + 4;
1447 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001448}
1449
1450int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1451{
Dake Zhao0a832172015-01-06 11:08:47 -08001452 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1453 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1454 dutCmdResponse_t *infoResp = &gGenericResp;
1455 /*a vendor can fill in the proper info or anything non-disclosure */
1456 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001457
Dake Zhao0a832172015-01-06 11:08:47 -08001458 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001459
Dake Zhao0a832172015-01-06 11:08:47 -08001460 if(devInfo->fw == 0)
1461 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1462 else
1463 {
1464 // Call internal API to pull the version ID */
Li Yin1ac40782015-09-23 20:38:07 +08001465 strncpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
Dake Zhao0a832172015-01-06 11:08:47 -08001466 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001467
Dake Zhao0a832172015-01-06 11:08:47 -08001468 infoResp->status = STATUS_COMPLETE;
1469 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1470 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001471
Dake Zhao0a832172015-01-06 11:08:47 -08001472 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001473
1474}
1475
1476/*
1477 * This funciton is to retrieve a list of interfaces and return
1478 * the list back to Agent control.
1479 * ********************************************************************
1480 * Note: We intend to make this WLAN interface name as a hardcode name.
1481 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001482 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1483 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001484 * likely is hardcoded just for CAPI command responses.
1485 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001486 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001487 */
1488int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1489{
Dake Zhao0a832172015-01-06 11:08:47 -08001490 dutCmdResponse_t *infoResp = &gGenericResp;
1491 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1492 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001493
Dake Zhao0a832172015-01-06 11:08:47 -08001494 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001495
Dake Zhao0a832172015-01-06 11:08:47 -08001496 switch(ifList->cmdsu.iftype)
1497 {
1498 case IF_80211:
1499 infoResp->status = STATUS_COMPLETE;
1500 ifListResp->iftype = IF_80211;
1501 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1502 strcpy(ifListResp->ifs[1], "NULL");
1503 strcpy(ifListResp->ifs[2], "NULL");
1504 break;
1505 case IF_ETH:
1506 infoResp->status = STATUS_COMPLETE;
1507 ifListResp->iftype = IF_ETH;
1508 strcpy(ifListResp->ifs[0], "eth0");
1509 strcpy(ifListResp->ifs[1], "NULL");
1510 strcpy(ifListResp->ifs[2], "NULL");
1511 break;
1512 default:
1513 {
1514 infoResp->status = STATUS_ERROR;
1515 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1516 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001517
Dake Zhao0a832172015-01-06 11:08:47 -08001518 return WFA_SUCCESS;
1519 }
1520 }
1521
1522 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1523 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1524
1525 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001526}
1527
1528int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1529{
Dake Zhao0a832172015-01-06 11:08:47 -08001530 dutCmdResponse_t *debugResp = &gGenericResp;
1531 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001532
Dake Zhao0a832172015-01-06 11:08:47 -08001533 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001534
Dake Zhao0a832172015-01-06 11:08:47 -08001535 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1536 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1537 else
1538 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001539
Dake Zhao0a832172015-01-06 11:08:47 -08001540 debugResp->status = STATUS_COMPLETE;
1541 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1542 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001543
1544
Dake Zhao0a832172015-01-06 11:08:47 -08001545 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001546}
1547
1548
1549/*
1550 * wfaStaGetBSSID():
1551 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001552 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001553int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1554{
Dake Zhao0a832172015-01-06 11:08:47 -08001555 char string[64];
1556 char *str;
1557 FILE *tmpfd;
1558 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001559
Dake Zhao0a832172015-01-06 11:08:47 -08001560 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1561 /* retrieve the BSSID */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001562 sprintf(gCmdStr, "wpa_cli.sh status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001563
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001564 systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001565
Dake Zhao0a832172015-01-06 11:08:47 -08001566 tmpfd = fopen("/tmp/bssid.txt", "r+");
1567 if(tmpfd == NULL)
1568 {
1569 bssidResp->status = STATUS_ERROR;
1570 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1571 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001572
Dake Zhao0a832172015-01-06 11:08:47 -08001573 DPRINT_ERR(WFA_ERR, "file open failed\n");
1574 return WFA_FAILURE;
1575 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001576
Dake Zhao0a832172015-01-06 11:08:47 -08001577 for(;;)
1578 {
1579 if(fscanf(tmpfd, "%s", string) == EOF)
1580 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001581 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001582 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001583 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001584 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001585
Dake Zhao0a832172015-01-06 11:08:47 -08001586 if(strncmp(string, "bssid", 5) == 0)
1587 {
1588 str = strtok(string, "=");
1589 str = strtok(NULL, "=");
1590 if(str != NULL)
1591 {
1592 strcpy(bssidResp->cmdru.bssid, str);
1593 bssidResp->status = STATUS_COMPLETE;
1594 break;
1595 }
1596 }
1597 }
1598
1599 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1600 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1601
1602 fclose(tmpfd);
1603 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001604}
1605
1606/*
1607 * wfaStaSetIBSS()
1608 * This is to set
1609 * 1. ssid
1610 * 2. channel
1611 * 3. encrypType - none or wep
1612 * optional
1613 * 4. key1
1614 * 5. key2
1615 * 6. key3
1616 * 7. key4
1617 * 8. activeIndex - 1, 2, 3, or 4
1618 */
1619int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1620{
Dake Zhao0a832172015-01-06 11:08:47 -08001621 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1622 dutCmdResponse_t *setIbssResp = &gGenericResp;
1623 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001624
Dake Zhao0a832172015-01-06 11:08:47 -08001625 /*
1626 * disable the network first
1627 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001628 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001629 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001630
Dake Zhao0a832172015-01-06 11:08:47 -08001631 /*
1632 * set SSID
1633 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001634 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001635 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001636
Dake Zhao0a832172015-01-06 11:08:47 -08001637 /*
1638 * Set channel for IBSS
1639 */
1640 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001641 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001642
Dake Zhao0a832172015-01-06 11:08:47 -08001643 /*
1644 * Tell the supplicant for IBSS mode (1)
1645 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001646 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 mode 1", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001647 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001648
Dake Zhao0a832172015-01-06 11:08:47 -08001649 /*
1650 * set Key management to NONE (NO WPA) for plaintext or WEP
1651 */
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001652 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001653 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001654
Dake Zhao0a832172015-01-06 11:08:47 -08001655 if(setIBSS->encpType == 1)
1656 {
1657 for(i=0; i<4; i++)
1658 {
1659 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1660 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001661 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_key%i \"%s\"",
Dake Zhao0a832172015-01-06 11:08:47 -08001662 setIBSS->intf, i, setIBSS->keys[i]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001663 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001664 }
1665 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001666
Dake Zhao0a832172015-01-06 11:08:47 -08001667 i = setIBSS->activeKeyIdx;
1668 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1669 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001670 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 wep_tx_keyidx %i",
Dake Zhao0a832172015-01-06 11:08:47 -08001671 setIBSS->intf, setIBSS->activeKeyIdx);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001672 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001673 }
1674 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001675
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02001676 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", setIBSS->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001677 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001678
Dake Zhao0a832172015-01-06 11:08:47 -08001679 setIbssResp->status = STATUS_COMPLETE;
1680 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1681 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001682
Dake Zhao0a832172015-01-06 11:08:47 -08001683 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001684}
1685
1686/*
1687 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001688 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001689 * adhoc)
1690 * Input parameters:
1691 * 1. I/F
1692 * 2. ssid
1693 * 3. mode adhoc or managed
1694 * 4. encType
1695 * 5. channel
1696 * 6. key(s)
1697 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001698 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001699int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1700{
Dake Zhao0a832172015-01-06 11:08:47 -08001701 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1702 dutCmdResponse_t *SetModeResp = &gGenericResp;
1703 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001704
Dake Zhao0a832172015-01-06 11:08:47 -08001705 /*
1706 * bring down the interface
1707 */
1708 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001709 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001710
Dake Zhao0a832172015-01-06 11:08:47 -08001711 /*
1712 * distroy the interface
1713 */
1714 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001715 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001716
1717
Dake Zhao0a832172015-01-06 11:08:47 -08001718 /*
1719 * re-create the interface with the given mode
1720 */
1721 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001722 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001723 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001724 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1725
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001726 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001727 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001728 {
Dake Zhao0a832172015-01-06 11:08:47 -08001729 int j = setmode->activeKeyIdx;
1730 for(i=0; i<4; i++)
1731 {
1732 if(setmode->keys[i][0] != '\0')
1733 {
1734 sprintf(gCmdStr, "iwconfig %s key s:%s",
1735 setmode->intf, setmode->keys[i]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001736 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001737 }
1738 /* set active key */
1739 if(setmode->keys[j][0] != '\0')
1740 sprintf(gCmdStr, "iwconfig %s key s:%s",
1741 setmode->intf, setmode->keys[j]);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001742 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08001743 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001744
1745 }
Dake Zhao0a832172015-01-06 11:08:47 -08001746 /*
1747 * Set channel for IBSS
1748 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001749 if(setmode->channel)
1750 {
Dake Zhao0a832172015-01-06 11:08:47 -08001751 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001752 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001753 }
1754
1755
Dake Zhao0a832172015-01-06 11:08:47 -08001756 /*
1757 * set SSID
1758 */
1759 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001760 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001761
Dake Zhao0a832172015-01-06 11:08:47 -08001762 /*
1763 * bring up the interface
1764 */
1765 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001766 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001767
Dake Zhao0a832172015-01-06 11:08:47 -08001768 SetModeResp->status = STATUS_COMPLETE;
1769 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1770 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001771
Dake Zhao0a832172015-01-06 11:08:47 -08001772 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001773}
1774
1775int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1776{
Dake Zhao0a832172015-01-06 11:08:47 -08001777 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1778 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001779
Dake Zhao0a832172015-01-06 11:08:47 -08001780 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001781 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001782
1783
Dake Zhao0a832172015-01-06 11:08:47 -08001784 SetPSResp->status = STATUS_COMPLETE;
1785 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1786 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001787
Dake Zhao0a832172015-01-06 11:08:47 -08001788 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001789}
1790
1791int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1792{
Dake Zhao0a832172015-01-06 11:08:47 -08001793 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1794 dutCmdResponse_t *upLoadResp = &gGenericResp;
1795 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001796
Dake Zhao0a832172015-01-06 11:08:47 -08001797 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1798 {
1799 int rbytes;
1800 /*
1801 * if asked for the first packet, always to open the file
1802 */
1803 if(upload->next == 1)
1804 {
1805 if(e2efp != NULL)
1806 {
1807 fclose(e2efp);
1808 e2efp = NULL;
1809 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001810
Dake Zhao0a832172015-01-06 11:08:47 -08001811 e2efp = fopen(e2eResults, "r");
1812 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001813
Dake Zhao0a832172015-01-06 11:08:47 -08001814 if(e2efp == NULL)
1815 {
1816 upLoadResp->status = STATUS_ERROR;
1817 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1818 *respLen = WFA_TLV_HDR_LEN + 4;
1819 return WFA_FAILURE;
1820 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001821
Dake Zhao0a832172015-01-06 11:08:47 -08001822 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001823
Dake Zhao0a832172015-01-06 11:08:47 -08001824 if(rbytes < 256)
1825 {
1826 /*
1827 * this means no more bytes after this read
1828 */
1829 upld->seqnum = 0;
1830 fclose(e2efp);
1831 e2efp=NULL;
1832 }
1833 else
1834 {
1835 upld->seqnum = upload->next;
1836 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001837
Dake Zhao0a832172015-01-06 11:08:47 -08001838 upld->nbytes = rbytes;
1839
1840 upLoadResp->status = STATUS_COMPLETE;
1841 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1842 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1843 }
1844 else
1845 {
1846 upLoadResp->status = STATUS_ERROR;
1847 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1848 *respLen = WFA_TLV_HDR_LEN + 4;
1849 }
1850
1851 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001852}
1853/*
1854 * wfaStaSetWMM()
1855 * TO be ported on a specific plaform for the DUT
1856 * This is to set the WMM related parameters at the DUT.
1857 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1858 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1859 */
1860int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1861{
1862#ifdef WFA_WMM_AC
1863 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1864 char *ifname = setwmm->intf;
1865 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001866
1867 switch(setwmm->group)
1868 {
1869 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001870 if (setwmm->send_trig)
1871 {
1872 int Sockfd;
1873 struct sockaddr_in psToAddr;
1874 unsigned int TxMsg[512];
1875
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001876 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001877 memset(&psToAddr, 0, sizeof(psToAddr));
1878 psToAddr.sin_family = AF_INET;
1879 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1880 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001881
1882
Dake Zhao0a832172015-01-06 11:08:47 -08001883 switch (setwmm->trig_ac)
1884 {
1885 case WMMAC_AC_VO:
1886 wfaTGSetPrio(Sockfd, 7);
1887 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1888 printf("\r\nSending AC_VO trigger packet\n");
1889 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001890
Dake Zhao0a832172015-01-06 11:08:47 -08001891 case WMMAC_AC_VI:
1892 wfaTGSetPrio(Sockfd, 5);
1893 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1894 printf("\r\nSending AC_VI trigger packet\n");
1895 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001896
Dake Zhao0a832172015-01-06 11:08:47 -08001897 case WMMAC_AC_BK:
1898 wfaTGSetPrio(Sockfd, 2);
1899 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1900 printf("\r\nSending AC_BK trigger packet\n");
1901 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001902
Dake Zhao0a832172015-01-06 11:08:47 -08001903 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001904 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001905 wfaTGSetPrio(Sockfd, 0);
1906 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1907 printf("\r\nSending AC_BE trigger packet\n");
1908 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001909 }
1910
Dake Zhao0a832172015-01-06 11:08:47 -08001911 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1912 sizeof(struct sockaddr));
1913 close(Sockfd);
1914 usleep(1000000);
1915 }
1916 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001917 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001918 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001919 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1920 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1921 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1922 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1923 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1924 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1925 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1926 setwmm->actions.addts.dialog_token,
1927 setwmm->actions.addts.tspec.tsinfo.TID,
1928 setwmm->actions.addts.tspec.tsinfo.direction,
1929 setwmm->actions.addts.tspec.tsinfo.PSB,
1930 setwmm->actions.addts.tspec.tsinfo.UP,
1931 setwmm->actions.addts.tspec.tsinfo.infoAck,
1932 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1933 setwmm->actions.addts.tspec.Fixed,
1934 setwmm->actions.addts.tspec.size,
1935 setwmm->actions.addts.tspec.maxsize,
1936 setwmm->actions.addts.tspec.min_srvc,
1937 setwmm->actions.addts.tspec.max_srvc,
1938 setwmm->actions.addts.tspec.inactivity,
1939 setwmm->actions.addts.tspec.suspension,
1940 setwmm->actions.addts.tspec.srvc_strt_tim,
1941 setwmm->actions.addts.tspec.mindatarate,
1942 setwmm->actions.addts.tspec.meandatarate,
1943 setwmm->actions.addts.tspec.peakdatarate,
1944 setwmm->actions.addts.tspec.burstsize,
1945 setwmm->actions.addts.tspec.delaybound,
1946 setwmm->actions.addts.tspec.PHYrate,
1947 setwmm->actions.addts.tspec.sba,
1948 setwmm->actions.addts.tspec.medium_time,
1949 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001950
Dake Zhao862c94b2014-12-08 14:35:35 -08001951 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001952
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001953 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001954 }
1955 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08001956 {
1957 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001958 }
1959
1960 setwmmResp->status = STATUS_COMPLETE;
1961 break;
1962
1963 case GROUP_WMMCONF:
1964 sprintf(gCmdStr, "iwconfig %s rts %d",
1965 ifname,setwmm->actions.config.rts_thr);
1966
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001967 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001968 sprintf(gCmdStr, "iwconfig %s frag %d",
1969 ifname,setwmm->actions.config.frag_thr);
1970
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001971 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001972 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1973 ifname, setwmm->actions.config.wmm);
1974
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02001975 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001976 setwmmResp->status = STATUS_COMPLETE;
1977 break;
1978
1979 default:
1980 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1981 setwmmResp->status = STATUS_ERROR;
1982 break;
1983
1984 }
1985
1986 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1987 *respLen = WFA_TLV_HDR_LEN + 4;
1988#endif
1989
1990 return WFA_SUCCESS;
1991}
1992
1993int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1994{
Dake Zhao0a832172015-01-06 11:08:47 -08001995 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001996
Dake Zhao0a832172015-01-06 11:08:47 -08001997 /*
1998 * run your device to send NEIGREQ
1999 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002000
Dake Zhao0a832172015-01-06 11:08:47 -08002001 sendNeigReqResp->status = STATUS_COMPLETE;
2002 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
2003 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002004
Dake Zhao0a832172015-01-06 11:08:47 -08002005 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002006}
2007
2008int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2009{
2010 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
2011 char *ifname = setFAST->intf;
2012 dutCmdResponse_t *setEapFastResp = &gGenericResp;
2013
2014#ifdef WFA_NEW_CLI_FORMAT
2015 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08002016 setFAST->passwd, setFAST->pacFileName,
2017 setFAST->innerEAP);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002018 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002019#else
2020
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002021 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002022 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002023
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002024 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002025 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002026
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002027 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002028 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002029
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002030 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002031 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002032
2033 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
2034 {
2035 }
2036 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
2037 {
2038 }
2039 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
2040 {
Dake Zhao0a832172015-01-06 11:08:47 -08002041
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002042 }
2043 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2044 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002045 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002046 }
2047 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2048 {
Dake Zhao0a832172015-01-06 11:08:47 -08002049 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002050 }
2051 else
2052 {
Dake Zhao0a832172015-01-06 11:08:47 -08002053 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002054 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002055 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002056
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002057 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap FAST", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002058 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002059
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002060 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 +02002061 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002062
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002063 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002064 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002065
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002066 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", 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 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
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 enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002073 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002074#endif
2075
2076 setEapFastResp->status = STATUS_COMPLETE;
2077 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2078 *respLen = WFA_TLV_HDR_LEN + 4;
2079
2080 return WFA_SUCCESS;
2081}
2082
2083int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2084{
2085 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2086 char *ifname = setAKA->intf;
2087 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2088
2089#ifdef WFA_NEW_CLI_FORMAT
2090 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002091 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002092#else
2093
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002094 sprintf(gCmdStr, "wpa_cli.sh -i %s disable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002095 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002096
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002097 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002098 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002099
2100 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2101 {
2102 }
2103 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2104 {
2105 }
2106 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2107 {
Dake Zhao0a832172015-01-06 11:08:47 -08002108
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002109 }
2110 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2111 {
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002112 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002113 }
2114 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2115 {
Dake Zhao0a832172015-01-06 11:08:47 -08002116 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002117 }
2118 else
2119 {
Dake Zhao0a832172015-01-06 11:08:47 -08002120 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002121 }
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002122 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002123
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002124 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto WPA2", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002125 sret = systemWithLog(gCmdStr);
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002126 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 proto CCMP", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002127 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002128
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002129 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 eap AKA", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002130 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002131
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002132 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002133 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002134
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002135 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002136 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002137
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002138 sprintf(gCmdStr, "wpa_cli.sh -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002139 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002140
Wojciech Jakobczyk249c1a02020-08-27 12:38:28 +02002141 sprintf(gCmdStr, "wpa_cli.sh -i %s enable_network 0", ifname);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002142 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002143#endif
2144
2145 setEapAkaResp->status = STATUS_COMPLETE;
2146 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2147 *respLen = WFA_TLV_HDR_LEN + 4;
2148
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002149 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002150}
2151
2152int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2153{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002154 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2155 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002156
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002157 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002158
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002159 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002160 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002161
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002162 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002163 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002164
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002165 setSystimeResp->status = STATUS_COMPLETE;
2166 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2167 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002168
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002169 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002170}
2171
2172#ifdef WFA_STA_TB
2173int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2174{
Dake Zhao0a832172015-01-06 11:08:47 -08002175 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2176 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2177 BYTE presetDone = 1;
2178 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002179 char cmdStr[128];
2180 char string[256];
2181 FILE *tmpfd = NULL;
2182 long val;
2183 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002184
Dake Zhao0a832172015-01-06 11:08:47 -08002185 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002186
Ray Wangd11ca032015-05-29 18:25:46 -07002187 if (presetParams->supplicant == eWpaSupplicant)
2188 {
2189 st = access("/tmp/processid.txt", F_OK);
2190 if (st != -1)
2191 {
2192 st = remove("/tmp/processid.txt");
2193 }
2194
2195 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002196 st = systemWithLog(cmdStr);
Ray Wangd11ca032015-05-29 18:25:46 -07002197
2198 tmpfd = fopen("/tmp/processid.txt", "r+");
2199 if (tmpfd == NULL)
2200 {
2201 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2202 return WFA_FAILURE;
2203 }
2204
2205 for (;;)
2206 {
2207 if (fgets(string, 256, tmpfd) == NULL)
2208 break;
2209
2210 errno = 0;
2211 val = strtol(string, &endptr, 10);
2212 if (errno != 0 && val == 0)
2213 {
2214 DPRINT_ERR(WFA_ERR, "strtol error\n");
2215 return WFA_FAILURE;
2216 }
2217
2218 if (endptr == string)
2219 {
2220 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2221 }
2222
2223 presetDone = 1;
2224 }
2225 }
2226
Dake Zhao0a832172015-01-06 11:08:47 -08002227 if(presetParams->wmmFlag)
2228 {
2229 st = wfaExecuteCLI(gCmdStr);
2230 switch(st)
2231 {
2232 case 0:
2233 presetDone = 1;
2234 break;
2235 case 1:
2236 presetDone = 0;
2237 break;
2238 case 2:
2239 presetDone = 0;
2240 break;
2241 }
2242 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002243
Dake Zhao0a832172015-01-06 11:08:47 -08002244 if(presetParams->modeFlag != 0)
2245 {
2246 switch(presetParams->wirelessMode)
2247 {
2248 default:
2249 printf("other mode does not need to support\n");
2250 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002251
Dake Zhao0a832172015-01-06 11:08:47 -08002252 st = wfaExecuteCLI(gCmdStr);
2253 switch(st)
2254 {
2255 case 0:
2256 presetDone = 1;
2257 break;
2258 case 1:
2259 presetDone = 0;
2260 case 2:
2261 presetDone = 0;
2262 break;
2263 }
2264 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002265
2266
Dake Zhao0a832172015-01-06 11:08:47 -08002267 if(presetParams->psFlag)
2268 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002269
Dake Zhao0a832172015-01-06 11:08:47 -08002270 printf("%s\n", gCmdStr);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002271 sret = systemWithLog(gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002272 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002273
Dake Zhao0a832172015-01-06 11:08:47 -08002274 /************the followings are used for Voice Enterprise **************/
2275 if(presetParams->program == PROG_TYPE_VENT)
2276 {
2277 if(presetParams->ftoa == eEnable)
2278 {
2279 // enable Fast BSS Transition Over the Air
2280 }
2281 else
2282 {
2283 // disable Fast BSS Transition Over the Air
2284 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002285
Dake Zhao0a832172015-01-06 11:08:47 -08002286 if(presetParams->ftds == eEnable)
2287 {
2288 // enable Fast BSS Transition Over the DS
2289 }
2290 else
2291 {
2292 // disable Fast BSS Transition Over the DS
2293 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002294
Dake Zhao0a832172015-01-06 11:08:47 -08002295 if(presetParams->activescan == eEnable)
2296 {
2297 // Enable Active Scan on STA
2298 }
2299 else
2300 {
2301 // disable Active Scan on STA
2302 }
2303 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002304
Dake Zhao0a832172015-01-06 11:08:47 -08002305 /************the followings are used for Wi-Fi Display *************/
2306 if(presetParams->program == PROG_TYPE_WFD)
2307 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002308
Dake Zhao0a832172015-01-06 11:08:47 -08002309 if(presetParams->tdlsFlag)
2310 {
2311 // enable / disable tdls based on tdls
2312 }
2313 if(presetParams->wfdDevTypeFlag)
2314 {
2315 // set WFD device type to source/sink/dual based on wfdDevType
2316 }
2317 if(presetParams->wfdUibcGenFlag)
2318 {
2319 // enable / disable the feature
2320 }
2321 if(presetParams->wfdUibcHidFlag)
2322 {
2323 // enable / disable feature
2324 }
2325 if(presetParams->wfdUiInputFlag)
2326 {
2327 // set the UI input as mentioned
2328 }
2329 if(presetParams->wfdHdcpFlag)
2330 {
2331 // enable / disable feature
2332 }
2333 if(presetParams->wfdFrameSkipFlag)
2334 {
2335 // enable / disable feature
2336 }
2337 if(presetParams->wfdAvChangeFlag)
2338 {
2339 // enable / disable feature
2340 }
2341 if(presetParams->wfdStandByFlag)
2342 {
2343 // enable / disable feature
2344 }
2345 if(presetParams->wfdInVideoFlag)
2346 {
2347 // select the input vide as protecteed or non-protetcted or protected audio
2348 // or unprotected audio etc.
2349 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002350
Dake Zhao0a832172015-01-06 11:08:47 -08002351 if(presetParams->wfdVideoFmatFlag)
2352 {
2353 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002354
Dake Zhao0a832172015-01-06 11:08:47 -08002355 //switch(presetParams->wfdVideoFmt )
2356 //{
2357 // case e640x480p60:
2358 // ;
2359 // default:
2360 // set the mandatory
2361 // }
2362 }
2363 if(presetParams->wfdAudioFmatFlag)
2364 {
2365 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002366
Dake Zhao0a832172015-01-06 11:08:47 -08002367 //switch(presetParams->wfdAudioFmt )
2368 //{
2369 // case eMandatoryAudioMode:
2370 // ;
2371 // case eDefaultAudioMode:
2372 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002373
Dake Zhao0a832172015-01-06 11:08:47 -08002374 // default:
2375 // set the mandatory
2376 // }
2377 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002378
Dake Zhao0a832172015-01-06 11:08:47 -08002379 if(presetParams->wfdI2cFlag)
2380 {
2381 // enable / disable feature
2382 }
2383 if(presetParams->wfdVideoRecoveryFlag)
2384 {
2385 // enable / disable feature
2386 }
2387 if(presetParams->wfdPrefDisplayFlag)
2388 {
2389 // enable / disable feature
2390 }
2391 if(presetParams->wfdServiceDiscoveryFlag)
2392 {
2393 // enable / disable feature
2394 }
2395 if(presetParams->wfd3dVideoFlag)
2396 {
2397 // enable / disable feature
2398 }
2399 if(presetParams->wfdMultiTxStreamFlag)
2400 {
2401 // enable / disable feature
2402 }
2403 if(presetParams->wfdTimeSyncFlag)
2404 {
2405 // enable / disable feature
2406 }
2407 if(presetParams->wfdEDIDFlag)
2408 {
2409 // enable / disable feature
2410 }
2411 if(presetParams->wfdUIBCPrepareFlag)
2412 {
2413 // Provdes information to start valid WFD session to check UIBC operation.
2414 }
2415 if(presetParams->wfdCoupledCapFlag)
2416 {
2417 // enable / disable feature
2418 }
2419 if(presetParams->wfdOptionalFeatureFlag)
2420 {
2421 // disable all program specific optional features
2422 }
2423 if(presetParams->wfdSessionAvailFlag)
2424 {
2425 // enable / disable session available bit
2426 }
2427 if(presetParams->wfdDeviceDiscoverabilityFlag)
2428 {
2429 // enable / disable feature
2430 }
2431 }
2432
Dake Zhao655efed2015-03-11 17:39:13 -07002433 if(presetParams->program == PROG_TYPE_WFDS)
2434 {
2435
2436 if(presetParams->wfdsType == eAcceptPD)
2437 {
2438 // preset to accept PD request
2439 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2440 {
2441 // use presetParams->wfdsConnectionCapability and set role accordingly
2442 }
2443
2444 }
2445 if(presetParams->wfdsType == eRejectPD)
2446 {
2447 // preset to Reject PD request
2448 }
2449 if(presetParams->wfdsType == eIgnorePD)
2450 {
2451 // preset to Ignore PD request
2452 }
2453 if(presetParams->wfdsType == eRejectSession)
2454 {
2455 // preset to reject Session request
2456 }
2457
2458 }
2459
2460 if (presetDone)
2461 {
2462 PresetParamsResp->status = STATUS_COMPLETE;
2463 }
2464 else
2465 {
2466 PresetParamsResp->status = STATUS_INVALID;
2467 }
Dake Zhao0a832172015-01-06 11:08:47 -08002468
2469 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2470 *respLen = WFA_TLV_HDR_LEN + 4;
2471
2472 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002473}
2474
2475int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2476{
2477 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2478
2479 v11nParamsResp->status = STATUS_COMPLETE;
2480 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2481 *respLen = WFA_TLV_HDR_LEN + 4;
2482 return WFA_SUCCESS;
2483}
2484int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2485{
2486 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2487
2488 staWirelessResp->status = STATUS_COMPLETE;
2489 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2490 *respLen = WFA_TLV_HDR_LEN + 4;
2491 return WFA_SUCCESS;
2492}
2493
2494int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2495{
2496 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2497
2498 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2499 *respLen = WFA_TLV_HDR_LEN + 4;
2500 return WFA_SUCCESS;
2501}
2502
2503int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2504{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002505 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002506
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002507 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2508 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002509
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002510 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002511}
2512
2513int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2514{
2515 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2516
2517 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2518 *respLen = WFA_TLV_HDR_LEN + 4;
2519
2520 return WFA_SUCCESS;
2521
2522}
2523
2524int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2525{
Dake Zhao0a832172015-01-06 11:08:47 -08002526 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2527 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002528
2529
Dake Zhao0a832172015-01-06 11:08:47 -08002530 // need to make your own command available for this, here is only an example
2531 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002532 sret = systemWithLog(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002533
Dake Zhao0a832172015-01-06 11:08:47 -08002534 ResetResp->status = STATUS_COMPLETE;
2535 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2536 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002537
Dake Zhao0a832172015-01-06 11:08:47 -08002538 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002539}
2540
2541#else
2542
2543int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2544{
2545 dutCmdResponse_t *staCmdResp = &gGenericResp;
2546
2547 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2548 *respLen = WFA_TLV_HDR_LEN + 4;
2549
2550 return WFA_SUCCESS;
2551}
2552#endif
2553
2554/*
2555 * This is used to send a frame or action frame
2556 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002557int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002558{
Dake Zhao0a832172015-01-06 11:08:47 -08002559 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2560 /* uncomment it if needed */
2561 // char *ifname = cmd->intf;
2562 dutCmdResponse_t *devSendResp = &gGenericResp;
2563 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002564
Dake Zhao0a832172015-01-06 11:08:47 -08002565 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2566 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002567
Dake Zhao0a832172015-01-06 11:08:47 -08002568 switch(sf->program)
2569 {
2570 case PROG_TYPE_PMF:
2571 {
2572 pmfFrame_t *pmf = &sf->frameType.pmf;
2573 switch(pmf->eFrameName)
2574 {
2575 case PMF_TYPE_DISASSOC:
2576 {
2577 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002578
Dake Zhao0a832172015-01-06 11:08:47 -08002579 }
2580 break;
2581 case PMF_TYPE_DEAUTH:
2582 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002583
Dake Zhao0a832172015-01-06 11:08:47 -08002584 }
2585 break;
2586 case PMF_TYPE_SAQUERY:
2587 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002588
Dake Zhao0a832172015-01-06 11:08:47 -08002589 }
2590 break;
2591 case PMF_TYPE_AUTH:
2592 {
2593 }
2594 break;
2595 case PMF_TYPE_ASSOCREQ:
2596 {
2597 }
2598 break;
2599 case PMF_TYPE_REASSOCREQ:
2600 {
2601 }
2602 break;
2603 }
2604 }
2605 break;
2606 case PROG_TYPE_TDLS:
2607 {
2608 tdlsFrame_t *tdls = &sf->frameType.tdls;
2609 switch(tdls->eFrameName)
2610 {
2611 case TDLS_TYPE_DISCOVERY:
2612 /* use the peer mac address to send the frame */
2613 break;
2614 case TDLS_TYPE_SETUP:
2615 break;
2616 case TDLS_TYPE_TEARDOWN:
2617 break;
2618 case TDLS_TYPE_CHANNELSWITCH:
2619 break;
2620 case TDLS_TYPE_NULLFRAME:
2621 break;
2622 }
2623 }
2624 break;
2625 case PROG_TYPE_VENT:
2626 {
2627 ventFrame_t *vent = &sf->frameType.vent;
2628 switch(vent->type)
2629 {
2630 case VENT_TYPE_NEIGREQ:
2631 break;
2632 case VENT_TYPE_TRANSMGMT:
2633 break;
2634 }
2635 }
2636 break;
2637 case PROG_TYPE_WFD:
2638 {
2639 wfdFrame_t *wfd = &sf->frameType.wfd;
2640 switch(wfd->eframe)
2641 {
2642 case WFD_FRAME_PRBREQ:
2643 {
2644 /* send probe req */
2645 }
2646 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002647
Dake Zhao0a832172015-01-06 11:08:47 -08002648 case WFD_FRAME_PRBREQ_TDLS_REQ:
2649 {
2650 /* send tunneled tdls probe req */
2651 }
2652 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002653
Dake Zhao0a832172015-01-06 11:08:47 -08002654 case WFD_FRAME_11V_TIMING_MSR_REQ:
2655 {
2656 /* send 11v timing mearurement request */
2657 }
2658 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002659
Dake Zhao0a832172015-01-06 11:08:47 -08002660 case WFD_FRAME_RTSP:
2661 {
2662 /* send WFD RTSP messages*/
2663 // fetch the type of RTSP message and send it.
2664 switch(wfd->eRtspMsgType)
2665 {
2666 case WFD_RTSP_PAUSE:
2667 break;
2668 case WFD_RTSP_PLAY:
2669 //send RTSP PLAY
2670 break;
2671 case WFD_RTSP_TEARDOWN:
2672 //send RTSP TEARDOWN
2673 break;
2674 case WFD_RTSP_TRIG_PAUSE:
2675 //send RTSP TRIGGER PAUSE
2676 break;
2677 case WFD_RTSP_TRIG_PLAY:
2678 //send RTSP TRIGGER PLAY
2679 break;
2680 case WFD_RTSP_TRIG_TEARDOWN:
2681 //send RTSP TRIGGER TEARDOWN
2682 break;
2683 case WFD_RTSP_SET_PARAMETER:
2684 //send RTSP SET PARAMETER
2685 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2686 {
2687 //send RTSP SET PARAMETER message for UIBC keyboard
2688 }
2689 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2690 {
2691 //send RTSP SET PARAMETER message for UIBC Mouse
2692 }
2693 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2694 {
2695 //send RTSP SET PARAMETER message Capability re-negotiation
2696 }
2697 else if (wfd->eSetParams == WFD_STANDBY)
2698 {
2699 //send RTSP SET PARAMETER message for standby
2700 }
2701 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2702 {
2703 //send RTSP SET PARAMETER message for UIBC settings enable
2704 }
2705 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2706 {
2707 //send RTSP SET PARAMETER message for UIBC settings disable
2708 }
2709 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2710 {
2711 //send RTSP SET PARAMETER message for route audio
2712 }
2713 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2714 {
2715 //send RTSP SET PARAMETER message for 3D video parameters
2716 }
2717 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2718 {
2719 //send RTSP SET PARAMETER message for 2D video parameters
2720 }
2721 break;
Dake Zhao97708202014-11-26 13:59:04 -08002722 }
Dake Zhao0a832172015-01-06 11:08:47 -08002723 }
2724 break;
2725 }
2726 }
2727 break;
2728 /* not need to support HS2 release 1, due to very short time period */
2729 case PROG_TYPE_HS2_R2:
2730 {
2731 /* type of frames */
2732 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2733 switch(hs2->eframe)
2734 {
2735 case HS2_FRAME_ANQPQuery:
2736 {
Dake Zhao97708202014-11-26 13:59:04 -08002737
Dake Zhao0a832172015-01-06 11:08:47 -08002738 }
2739 break;
2740 case HS2_FRAME_DLSRequest:
2741 {
Dake Zhao97708202014-11-26 13:59:04 -08002742
Dake Zhao0a832172015-01-06 11:08:47 -08002743 }
2744 break;
2745 case HS2_FRAME_GARPReq:
2746 {
Dake Zhao97708202014-11-26 13:59:04 -08002747
Dake Zhao0a832172015-01-06 11:08:47 -08002748 }
2749 break;
2750 case HS2_FRAME_GARPRes:
2751 {
2752 }
2753 break;
2754 case HS2_FRAME_NeighAdv:
2755 {
2756 }
2757 case HS2_FRAME_ARPProbe:
2758 {
2759 }
2760 case HS2_FRAME_ARPAnnounce:
2761 {
Dake Zhao97708202014-11-26 13:59:04 -08002762
Dake Zhao0a832172015-01-06 11:08:47 -08002763 }
2764 break;
2765 case HS2_FRAME_NeighSolicitReq:
2766 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002767
Dake Zhao0a832172015-01-06 11:08:47 -08002768 }
2769 break;
2770 case HS2_FRAME_ARPReply:
2771 {
2772
2773 }
2774 break;
2775 }
2776
2777 }/* PROG_TYPE_HS2-R2 */
2778 case PROG_TYPE_GEN:
2779 {
2780 /* General frames */
2781 }
2782
2783
2784 }
2785 devSendResp->status = STATUS_COMPLETE;
2786 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2787 *respLen = WFA_TLV_HDR_LEN + 4;
2788
2789 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002790}
2791
2792/*
2793 * This is used to set a temporary MAC address of an interface
2794 */
2795int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2796{
Dake Zhao0a832172015-01-06 11:08:47 -08002797 // Uncomment it if needed
2798 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2799 // char *ifname = cmd->intf;
2800 dutCmdResponse_t *staCmdResp = &gGenericResp;
2801 // Uncomment it if needed
2802 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002803
Dake Zhao0a832172015-01-06 11:08:47 -08002804 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2805 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002806
Dake Zhao0a832172015-01-06 11:08:47 -08002807 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002808}
2809
2810
2811int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2812{
2813 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2814 //char *intf = disc->intf;
2815 dutCmdResponse_t *staDiscResp = &gGenericResp;
2816
2817 // stop the supplicant
2818
2819 staDiscResp->status = STATUS_COMPLETE;
2820
2821 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2822 *respLen = WFA_TLV_HDR_LEN + 4;
2823
2824 return WFA_SUCCESS;
2825}
2826
2827/* Execute CLI, read the status from Environment variable */
2828int wfaExecuteCLI(char *CLI)
2829{
Dake Zhao0a832172015-01-06 11:08:47 -08002830 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002831
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002832 sret = systemWithLog(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002833
Dake Zhao0a832172015-01-06 11:08:47 -08002834 retstr = getenv("WFA_CLI_STATUS");
2835 printf("cli status %s\n", retstr);
2836 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002837}
2838
2839/* Supporting Functions */
2840
2841void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2842{
Dake Zhao97708202014-11-26 13:59:04 -08002843 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002844 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002845// char *addr = staPing->dipaddr;
2846#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002847 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002848 char bflag[] = "-b";
2849 char *tmpstr;
2850 int inum=0;
2851#else
2852 char bflag[] = " ";
2853#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002854
Ray Wang9b47f362014-03-19 16:51:10 -07002855 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002856
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002857#ifdef WFA_PC_CONSOLE
2858
Dake Zhao353c55e2015-07-20 18:54:45 -07002859 printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d",streamid);
2860
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002861 strcpy(addr,staPing->dipaddr);
Dake Zhao353c55e2015-07-20 18:54:45 -07002862 printf("\nCS :the addr is %s ",addr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002863 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2864 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002865 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002866 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002867 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002868 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002869 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002870 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002871 tmpstr = strtok(addr, ".");
2872 inum = atoi(tmpstr);
2873
2874 printf("interval %f\n", *interval);
2875
2876 if(inum >= 224 && inum <= 239) // multicast
2877 {
2878 }
2879 else // if not MC, check if it is BC address
2880 {
2881 printf("\nCS :Inside the BC address BLOCK");
2882 printf("\nCS :the inum %d",inum);
2883 strtok(NULL, ".");
2884 //strtok(NULL, ".");
2885 tmpstr = strtok(NULL, ".");
2886 printf("tmpstr %s\n", tmpstr);
2887 inum = atoi(tmpstr);
2888 printf("\nCS : The string is %s",tmpstr);
2889 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002890 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002891 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002892 }
2893#endif
Dake Zhao97708202014-11-26 13:59:04 -08002894 if ( staPing->dscp >= 0)
2895 {
Dake Zhao0a832172015-01-06 11:08:47 -08002896 tos= convertDscpToTos(staPing->dscp);
2897 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002898 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2899 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002900 printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n",streamid, staPing->iptype);
Dake Zhao97708202014-11-26 13:59:04 -08002901 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002902
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002903 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002904 {
Dake Zhao97708202014-11-26 13:59:04 -08002905 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002906 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",
2907 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002908 else
Dake Zhao0a832172015-01-06 11:08:47 -08002909 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",
2910 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002911 sret = systemWithLog(cmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002912 printf("\nCS : The command string is %s",cmdStr);
2913 }
2914 else
2915 {
Dake Zhao97708202014-11-26 13:59:04 -08002916 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002917 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",
2918 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002919 else
Dake Zhao0a832172015-01-06 11:08:47 -08002920 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",
2921 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002922 sret = systemWithLog(cmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002923 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002924 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002925 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002926 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002927 printf("\nCS : The command string is %s",cmdStr);
2928
2929}
2930
2931int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2932{
2933 char strout[256];
2934 FILE *tmpfile = NULL;
2935 char cmdStr[128];
Dake Zhao353c55e2015-07-20 18:54:45 -07002936 printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002937 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002938 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002939
2940 printf("\nCS : The command string is %s",cmdStr);
2941
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002942 sret = systemWithLog("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002943
2944 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Wojciech Jakobczyk317dc712020-08-27 12:46:16 +02002945 sret = systemWithLog(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002946
2947 printf("\nCS : The command string is %s",cmdStr);
2948
2949 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2950
2951 if(tmpfile == NULL)
2952 {
2953 return WFA_FAILURE;
2954 }
2955
2956 if(fscanf(tmpfile, "%s", strout) != EOF)
2957 {
2958 if(*strout == '\0')
2959 {
2960 stpResp->cmdru.pingStp.sendCnt = 0;
2961 }
2962
2963 else
2964 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2965 }
2966
Dake Zhao353c55e2015-07-20 18:54:45 -07002967 printf("\nwfaStopPing after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002968
2969
2970 if(fscanf(tmpfile, "%s", strout) != EOF)
2971 {
2972 if(*strout == '\0')
2973 {
2974 stpResp->cmdru.pingStp.repliedCnt = 0;
2975 }
2976 else
2977 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2978 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002979 printf("wfaStopPing after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002980
2981 fclose(tmpfile);
2982
2983 return WFA_SUCCESS;
2984}
2985
Ankur Vachhanic485b712012-02-15 23:29:49 +00002986/*
Dake Zhao0a832172015-01-06 11:08:47 -08002987 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002988 */
2989int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2990{
Dake Zhao0a832172015-01-06 11:08:47 -08002991 dutCmdResponse_t infoResp;
2992 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002993
Dake Zhao0a832172015-01-06 11:08:47 -08002994 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002995
Dake Zhao0a832172015-01-06 11:08:47 -08002996 // Fetch the device ID and store into infoResp->cmdru.devid
2997 //strcpy(infoResp->cmdru.devid, str);
2998 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002999
Dake Zhao0a832172015-01-06 11:08:47 -08003000 infoResp.status = STATUS_COMPLETE;
3001 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3002 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3003
3004 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003005}
3006
3007
3008
3009/*
Dake Zhao0a832172015-01-06 11:08:47 -08003010 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003011 */
3012int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3013{
Dake Zhao0a832172015-01-06 11:08:47 -08003014 dutCmdResponse_t infoResp;
3015 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00003016
Dake Zhao0a832172015-01-06 11:08:47 -08003017 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003018
Dake Zhao0a832172015-01-06 11:08:47 -08003019 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003020
Dake Zhao0a832172015-01-06 11:08:47 -08003021 infoResp.status = STATUS_COMPLETE;
3022 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3023 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3024
3025 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003026}
3027/*
Dake Zhao0a832172015-01-06 11:08:47 -08003028 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003029 */
3030int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3031{
Dake Zhao0a832172015-01-06 11:08:47 -08003032 dutCmdResponse_t infoResp;
3033 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003034
Dake Zhao0a832172015-01-06 11:08:47 -08003035 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003036
Dake Zhao0a832172015-01-06 11:08:47 -08003037 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003038
Ankur Vachhanic485b712012-02-15 23:29:49 +00003039
Dake Zhao0a832172015-01-06 11:08:47 -08003040 infoResp.status = STATUS_COMPLETE;
3041 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3042 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3043
3044 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003045}
3046
3047/*
Dake Zhao0a832172015-01-06 11:08:47 -08003048 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003049 */
3050int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3051{
Dake Zhao0a832172015-01-06 11:08:47 -08003052 dutCmdResponse_t infoResp;
3053 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003054
Dake Zhao0a832172015-01-06 11:08:47 -08003055 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003056
Dake Zhao0a832172015-01-06 11:08:47 -08003057 // Fetch the group ID and store into infoResp->cmdru.grpid
3058 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003059
Dake Zhao0a832172015-01-06 11:08:47 -08003060 infoResp.status = STATUS_COMPLETE;
3061 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3062 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3063
3064 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003065}
3066
3067
3068
3069
3070/*
Dake Zhao0a832172015-01-06 11:08:47 -08003071 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003072 */
3073int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3074{
Dake Zhao0a832172015-01-06 11:08:47 -08003075 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003076
Dake Zhao0a832172015-01-06 11:08:47 -08003077 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003078
Dake Zhao0a832172015-01-06 11:08:47 -08003079 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3080 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003081
Ankur Vachhanic485b712012-02-15 23:29:49 +00003082
Dake Zhao0a832172015-01-06 11:08:47 -08003083 infoResp.status = STATUS_COMPLETE;
3084 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3085 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3086
3087 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003088}
3089
3090
3091/*
Dake Zhao0a832172015-01-06 11:08:47 -08003092 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003093 */
3094int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3095{
Dake Zhao0a832172015-01-06 11:08:47 -08003096 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003097
Dake Zhao0a832172015-01-06 11:08:47 -08003098 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003099
Dake Zhao0a832172015-01-06 11:08:47 -08003100 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003101
Dake Zhao0a832172015-01-06 11:08:47 -08003102 infoResp.status = STATUS_COMPLETE;
3103 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3104 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3105
3106 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003107}
3108
3109/*
Dake Zhao0a832172015-01-06 11:08:47 -08003110 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003111 */
3112int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3113{
Dake Zhao0a832172015-01-06 11:08:47 -08003114 dutCmdResponse_t infoResp;
3115 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003116
Dake Zhao0a832172015-01-06 11:08:47 -08003117 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003118
Dake Zhao0a832172015-01-06 11:08:47 -08003119 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003120
Dake Zhao0a832172015-01-06 11:08:47 -08003121 infoResp.status = STATUS_COMPLETE;
3122 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3123 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3124
3125 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003126}
3127
3128
3129/*
Dake Zhao0a832172015-01-06 11:08:47 -08003130 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003131 */
3132int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3133{
Dake Zhao0a832172015-01-06 11:08:47 -08003134 dutCmdResponse_t infoResp;
3135 /* uncomment and use it
3136 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3137 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003138
Dake Zhao0a832172015-01-06 11:08:47 -08003139 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003140
Dake Zhao0a832172015-01-06 11:08:47 -08003141 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003142
Dake Zhao0a832172015-01-06 11:08:47 -08003143 infoResp.status = STATUS_COMPLETE;
3144 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3145 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3146
3147 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003148}
3149
3150
3151/*
Dake Zhao0a832172015-01-06 11:08:47 -08003152 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003153 */
3154int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3155{
Dake Zhao0a832172015-01-06 11:08:47 -08003156 dutCmdResponse_t infoResp;
3157 /* uncomment and use it
3158 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3159 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003160
Dake Zhao0a832172015-01-06 11:08:47 -08003161 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003162
Dake Zhao0a832172015-01-06 11:08:47 -08003163 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003164
Dake Zhao0a832172015-01-06 11:08:47 -08003165 infoResp.status = STATUS_COMPLETE;
3166 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3167 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3168
3169 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003170}
3171
3172/*
Dake Zhao0a832172015-01-06 11:08:47 -08003173 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003174 */
3175int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3176{
Dake Zhao0a832172015-01-06 11:08:47 -08003177 dutCmdResponse_t infoResp;
3178 /* uncomment and use it
3179 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3180 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003181
Dake Zhao0a832172015-01-06 11:08:47 -08003182 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003183
Dake Zhao0a832172015-01-06 11:08:47 -08003184 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003185
Dake Zhao0a832172015-01-06 11:08:47 -08003186 infoResp.status = STATUS_COMPLETE;
3187 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3188 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3189
3190 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003191}
3192
3193/*
Dake Zhao0a832172015-01-06 11:08:47 -08003194 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003195 */
3196int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3197{
Dake Zhao0a832172015-01-06 11:08:47 -08003198 dutCmdResponse_t infoResp;
3199 /* uncomment and use it
3200 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3201 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003202
Dake Zhao0a832172015-01-06 11:08:47 -08003203 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003204
Dake Zhao0a832172015-01-06 11:08:47 -08003205 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3206 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3207 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003208
Ankur Vachhanic485b712012-02-15 23:29:49 +00003209
Dake Zhao0a832172015-01-06 11:08:47 -08003210 infoResp.status = STATUS_COMPLETE;
3211 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_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
3218
3219/*
Dake Zhao0a832172015-01-06 11:08:47 -08003220 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003221 */
3222int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3223{
Dake Zhao0a832172015-01-06 11:08:47 -08003224 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003225
Dake Zhao0a832172015-01-06 11:08:47 -08003226 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003227
Dake Zhao0a832172015-01-06 11:08:47 -08003228 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3229 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3230 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003231
Ankur Vachhanic485b712012-02-15 23:29:49 +00003232
Dake Zhao0a832172015-01-06 11:08:47 -08003233 infoResp.status = STATUS_COMPLETE;
3234 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3235 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3236
3237 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003238}
3239
3240
3241/*
Dake Zhao0a832172015-01-06 11:08:47 -08003242 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003243 */
3244int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3245{
Dake Zhao0a832172015-01-06 11:08:47 -08003246 dutCmdResponse_t infoResp;
3247 /* uncomment and use it
3248 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3249 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003250
Dake Zhao0a832172015-01-06 11:08:47 -08003251 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003252
Dake Zhao0a832172015-01-06 11:08:47 -08003253 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003254
Ankur Vachhanic485b712012-02-15 23:29:49 +00003255
Dake Zhao0a832172015-01-06 11:08:47 -08003256 infoResp.status = STATUS_COMPLETE;
3257 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3258 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3259
3260 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003261}
3262
3263
3264/*
Dake Zhao0a832172015-01-06 11:08:47 -08003265 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003266 */
3267int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3268{
Dake Zhao0a832172015-01-06 11:08:47 -08003269 dutCmdResponse_t infoResp;
3270 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003271
Dake Zhao0a832172015-01-06 11:08:47 -08003272 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003273
3274
Dake Zhao0a832172015-01-06 11:08:47 -08003275 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3276 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3277 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003278
Ankur Vachhanic485b712012-02-15 23:29:49 +00003279
Dake Zhao0a832172015-01-06 11:08:47 -08003280 infoResp.status = STATUS_COMPLETE;
3281 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3282 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3283
3284 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003285}
3286
3287/*
Dake Zhao0a832172015-01-06 11:08:47 -08003288 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003289 */
3290int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3291{
Dake Zhao0a832172015-01-06 11:08:47 -08003292 dutCmdResponse_t infoResp;
3293 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003294
Dake Zhao0a832172015-01-06 11:08:47 -08003295 printf("\n Entry wfaStaP2pReset... ");
3296 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003297
Dake Zhao0a832172015-01-06 11:08:47 -08003298 infoResp.status = STATUS_COMPLETE;
3299 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3300 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3301
3302 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003303}
3304
3305
3306
3307/*
Dake Zhao0a832172015-01-06 11:08:47 -08003308 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003309 */
3310int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3311{
Dake Zhao0a832172015-01-06 11:08:47 -08003312 dutCmdResponse_t infoResp;
3313 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003314
Dake Zhao0a832172015-01-06 11:08:47 -08003315 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003316
Dake Zhao0a832172015-01-06 11:08:47 -08003317 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003318
Dake Zhao0a832172015-01-06 11:08:47 -08003319 ifinfo->isDhcp =0;
3320 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3321 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3322 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3323 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3324
3325 infoResp.status = STATUS_COMPLETE;
3326 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_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
3333
3334
3335/*
Dake Zhao0a832172015-01-06 11:08:47 -08003336 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003337 */
3338int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3339{
Dake Zhao0a832172015-01-06 11:08:47 -08003340 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003341
Dake Zhao0a832172015-01-06 11:08:47 -08003342 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3343 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003344
Dake Zhao0a832172015-01-06 11:08:47 -08003345
3346 infoResp.status = STATUS_COMPLETE;
3347 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3348 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3349
3350 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003351}
3352
3353
3354
3355/*
Dake Zhao0a832172015-01-06 11:08:47 -08003356 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003357 */
3358int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3359{
Dake Zhao0a832172015-01-06 11:08:47 -08003360 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003361
Dake Zhao0a832172015-01-06 11:08:47 -08003362 infoResp.status = STATUS_COMPLETE;
3363 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3364 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003365
Dake Zhao0a832172015-01-06 11:08:47 -08003366 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003367}
3368
3369/*
Dake Zhao0a832172015-01-06 11:08:47 -08003370 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003371 */
3372int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3373{
Dake Zhao0a832172015-01-06 11:08:47 -08003374 dutCmdResponse_t infoResp;
3375 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003376
Dake Zhao0a832172015-01-06 11:08:47 -08003377 printf("\n Entry wfaStaSetSleepReq... ");
3378 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003379
Dake Zhao0a832172015-01-06 11:08:47 -08003380
3381 infoResp.status = STATUS_COMPLETE;
3382 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3383 *respLen = WFA_TLV_HDR_LEN +4;
3384
3385 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003386}
3387
3388/*
Dake Zhao0a832172015-01-06 11:08:47 -08003389 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003390 */
3391int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3392{
Dake Zhao0a832172015-01-06 11:08:47 -08003393 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003394
Dake Zhao0a832172015-01-06 11:08:47 -08003395 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3396 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003397
Dake Zhao0a832172015-01-06 11:08:47 -08003398
3399 infoResp.status = STATUS_COMPLETE;
3400 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3401 *respLen = WFA_TLV_HDR_LEN + 4;
3402
3403 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003404}
3405#ifndef WFA_STA_TB
3406/*
Dake Zhao0a832172015-01-06 11:08:47 -08003407 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003408 */
3409
3410int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3411{
Dake Zhao0a832172015-01-06 11:08:47 -08003412 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003413
Dake Zhao0a832172015-01-06 11:08:47 -08003414 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003415
Dake Zhao0a832172015-01-06 11:08:47 -08003416 // Implement the function and its sub commands
3417 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003418
Dake Zhao0a832172015-01-06 11:08:47 -08003419 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3420 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003421
Dake Zhao0a832172015-01-06 11:08:47 -08003422 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003423}
Dake Zhao0a832172015-01-06 11:08:47 -08003424int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003425{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003426
3427 dutCmdResponse_t infoResp;
3428 dutCmdResponse_t *v11nParamsResp = &infoResp;
3429
3430#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003431
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003432 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3433
3434 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003435
3436 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003437
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003438 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3439 {
Dake Zhao0a832172015-01-06 11:08:47 -08003440 // implement the funciton
3441 if(st != 0)
3442 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003443 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003444 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3445 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3446 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3447 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003448 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003449 }
Dake Zhao0a832172015-01-06 11:08:47 -08003450
Ankur Vachhanic485b712012-02-15 23:29:49 +00003451 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003452 {
Dake Zhao0a832172015-01-06 11:08:47 -08003453 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003454
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003455 if(st != 0)
3456 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003457 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003458 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3459 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3460 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3461 return FALSE;
3462 }
3463 }
3464
Ankur Vachhanic485b712012-02-15 23:29:49 +00003465 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003466 {
Dake Zhao0a832172015-01-06 11:08:47 -08003467 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003468 if(st != 0)
3469 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003470 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003471 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3472 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3473 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003474 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003475 }
3476 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003477
3478 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003479 {
3480 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003481 if(st != 0)
3482 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003483 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003484 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3485 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3486 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3487 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003488 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003489 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003490
3491 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003492 {
Dake Zhao0a832172015-01-06 11:08:47 -08003493 // implement the funciton
3494 //st = wfaExecuteCLI(gCmdStr);
3495 if(st != 0)
3496 {
3497 v11nParamsResp->status = STATUS_ERROR;
3498 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3499 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3500 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3501 return FALSE;
3502 }
3503 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003504 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3505 {
3506 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003507 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003508 if(st != 0)
3509 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003510 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003512 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3513 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003514 return FALSE;
3515 }
Dake Zhao0a832172015-01-06 11:08:47 -08003516 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003517 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3518 {
3519 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003520 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003521 if(st != 0)
3522 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003523 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003524 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003525 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3526 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003527 return FALSE;
3528 }
3529 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003530
3531 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003532 {
3533 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003534 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003535 if(st != 0)
3536 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003537 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003538 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003539 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3540 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003541 return FALSE;
3542 }
3543 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003544
3545 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003546 {
3547 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003548 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003549 if(st != 0)
3550 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003551 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003552 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3553 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3554 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3555 return FALSE;
3556 }
3557 }
3558
3559 if(v11nParams->smps != 0xFFFF)
3560 {
3561 if(v11nParams->smps == 0)
3562 {
Dake Zhao0a832172015-01-06 11:08:47 -08003563 // implement the funciton
3564 //st = wfaExecuteCLI(gCmdStr);
3565 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003566 else if(v11nParams->smps == 1)
3567 {
Dake Zhao0a832172015-01-06 11:08:47 -08003568 // implement the funciton
3569 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003570 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003571 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003572 else if(v11nParams->smps == 2)
3573 {
Dake Zhao0a832172015-01-06 11:08:47 -08003574 // implement the funciton
3575 //st = wfaExecuteCLI(gCmdStr);
3576 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003577 }
3578 if(st != 0)
3579 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003580 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003581 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3582 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3583 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3584 return FALSE;
3585 }
3586 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003587
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003588 if(v11nParams->stbc_rx != 0xFFFF)
3589 {
3590 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003591 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003592 if(st != 0)
3593 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003594 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003595 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003596 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3597 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003598 return FALSE;
3599 }
3600 }
Dake Zhao0a832172015-01-06 11:08:47 -08003601
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003602 if(v11nParams->width[0] != '\0')
3603 {
3604 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003605 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003606 if(st != 0)
3607 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003608 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003609 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3610 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3611 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3612 return FALSE;
3613 }
3614 }
Dake Zhao0a832172015-01-06 11:08:47 -08003615
Ankur Vachhanic485b712012-02-15 23:29:49 +00003616 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003617 {
3618 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003619 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003620 if(st != 0)
3621 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003622 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003623 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3624 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3625 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3626 return FALSE;
3627 }
3628 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003629
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003630 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3631 {
3632 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003633 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003634 if(st != 0)
3635 {
3636 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003637 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003638 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3639 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3640 return FALSE;
3641 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003642
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003643 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003644
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003645 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3646 {
3647 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003648 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003649 if(st != 0)
3650 {
3651 v11nParamsResp->status = STATUS_ERROR;
3652 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3653 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3654 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3655 return FALSE;
3656 }
3657 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003658
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003659#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003660
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003661 v11nParamsResp->status = STATUS_COMPLETE;
3662 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3663 *respLen = WFA_TLV_HDR_LEN + 4;
3664 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003665}
3666#endif
3667/*
Dake Zhao0a832172015-01-06 11:08:47 -08003668 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003669 */
3670int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3671{
Dake Zhao0a832172015-01-06 11:08:47 -08003672 dutCmdResponse_t infoResp;
3673 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003674
Dake Zhao0a832172015-01-06 11:08:47 -08003675 printf("\n Entry wfastaAddARPTableEntry... ");
3676 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003677
Dake Zhao0a832172015-01-06 11:08:47 -08003678 infoResp.status = STATUS_COMPLETE;
3679 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3680 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3681
3682 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003683}
3684
3685/*
Dake Zhao0a832172015-01-06 11:08:47 -08003686 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003687 */
3688int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3689{
Dake Zhao0a832172015-01-06 11:08:47 -08003690 dutCmdResponse_t infoResp;
3691 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003692
Dake Zhao0a832172015-01-06 11:08:47 -08003693 printf("\n Entry wfaStaBlockICMPResponse... ");
3694 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003695
Dake Zhao0a832172015-01-06 11:08:47 -08003696 infoResp.status = STATUS_COMPLETE;
3697 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3698 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3699
3700 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003701}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003702
3703/*
Dake Zhao0a832172015-01-06 11:08:47 -08003704 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003705 */
3706
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003707int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3708{
3709 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3710 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003711 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3712
3713 if(sr->mode == WFA_OFF)
3714 {
Dake Zhao0a832172015-01-06 11:08:47 -08003715 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003716 }
3717 else
3718 {
Dake Zhao0a832172015-01-06 11:08:47 -08003719 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003720 }
3721
3722 staCmdResp->status = STATUS_COMPLETE;
3723 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3724 *respLen = WFA_TLV_HDR_LEN + 4;
3725
3726 return WFA_SUCCESS;
3727}
3728
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003729/*
Dake Zhao0a832172015-01-06 11:08:47 -08003730 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003731 */
3732
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003733int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3734{
Dake Zhao0a832172015-01-06 11:08:47 -08003735 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3736 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3737 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003738
Dake Zhao0a832172015-01-06 11:08:47 -08003739 if(strcasecmp(rfeat->prog, "tdls") == 0)
3740 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003741
3742
Dake Zhao0a832172015-01-06 11:08:47 -08003743 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003744
Dake Zhao0a832172015-01-06 11:08:47 -08003745 caResp->status = STATUS_COMPLETE;
3746 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3747 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003748
Dake Zhao0a832172015-01-06 11:08:47 -08003749 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003750}
3751
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003752/*
Dake Zhao0a832172015-01-06 11:08:47 -08003753 * wfaStaStartWfdConnection():
3754 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003755int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3756{
Dake Zhao0a832172015-01-06 11:08:47 -08003757 dutCmdResponse_t infoResp;
3758 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003759
Dake Zhao0a832172015-01-06 11:08:47 -08003760 printf("\n Entry wfaStaStartWfdConnection... ");
3761
3762
3763 // Fetch the GrpId and WFD session and return
3764 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3765 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3766 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3767
3768 infoResp.status = STATUS_COMPLETE;
3769 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3770 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3771
3772 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003773}
3774/*
Dake Zhao0a832172015-01-06 11:08:47 -08003775 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003776 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003777
Ankur Vachhanic485b712012-02-15 23:29:49 +00003778int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3779{
Dake Zhao0a832172015-01-06 11:08:47 -08003780 char cmdName[32];
3781 char *pcmdStr=NULL, *str;
3782 int st = 1;
3783 char CmdStr[WFA_CMD_STR_SZ];
3784 FILE *wfaCliFd;
3785 char wfaCliBuff[64];
3786 char retstr[256];
3787 int CmdReturnFlag =0;
3788 char tmp[256];
Li Yincba7d352015-09-23 20:30:49 +08003789 FILE * sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003790 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003791
Dake Zhao0a832172015-01-06 11:08:47 -08003792 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3793 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3794 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003795
Dake Zhao0a832172015-01-06 11:08:47 -08003796 for(;;)
3797 {
3798 // construct CLI standard cmd string
3799 str = strtok_r(NULL, ",", &pcmdStr);
3800 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003801 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003802 else
3803 {
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003804 strcat(strcat(CmdStr, " /"), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003805 str = strtok_r(NULL, ",", &pcmdStr);
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003806 strcat(strcat(CmdStr, " "), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003807 }
3808 }
3809 // check the return process
3810 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3811 if(wfaCliFd!= NULL)
3812 {
3813 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3814 {
3815 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3816 if(ferror(wfaCliFd))
3817 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003818
Dake Zhao0a832172015-01-06 11:08:47 -08003819 str=strtok(wfaCliBuff,"-");
3820 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003821 {
Dake Zhao0a832172015-01-06 11:08:47 -08003822 str=strtok(NULL,",");
3823 if (str != NULL)
3824 {
3825 if(strcmp(str,"TRUE") == 0)
3826 CmdReturnFlag =1;
3827 }
3828 else
3829 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3830 break;
Dake Zhao97708202014-11-26 13:59:04 -08003831 }
Dake Zhao0a832172015-01-06 11:08:47 -08003832 }
3833 fclose(wfaCliFd);
3834 }
3835 else
3836 {
3837 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3838 goto cleanup;
3839 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003840
Dake Zhao0a832172015-01-06 11:08:47 -08003841 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3842 memset(&retstr[0],'\0',255);
3843 memset(&tmp[0],'\0',255);
3844 sprintf(gCmdStr, "%s", CmdStr);
3845 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003846
Dake Zhao0a832172015-01-06 11:08:47 -08003847 sh_pipe = popen(gCmdStr,"r");
3848 if(!sh_pipe)
3849 {
3850 printf ("Error in opening pipe\n");
3851 goto cleanup;
3852 }
Dake Zhao97708202014-11-26 13:59:04 -08003853
Dake Zhao0a832172015-01-06 11:08:47 -08003854 sleep(5);
3855 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3856 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3857 {
3858 printf("Getting NULL string in popen return\n");
3859 goto cleanup;
3860 }
3861 else
3862 printf("popen return str=%s\n",retstr);
3863
3864 sleep(2);
3865 if(pclose(sh_pipe) == -1)
3866 {
3867 printf("Error in closing shell cmd pipe\n");
3868 goto cleanup;
3869 }
Li Yincba7d352015-09-23 20:30:49 +08003870 sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003871 sleep(2);
3872
3873 // find status first in output
3874 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3875 if (str != NULL)
3876 {
3877 memset(tmp, 0, 10);
3878 memcpy(tmp, str, 2);
3879 printf("cli status=%s\n",tmp);
3880 if(strlen(tmp) > 0)
3881 st = atoi(tmp);
3882 else printf("Missing status code\n");
3883 }
3884 else
3885 {
3886 printf("wfaStaCliCommand no return code found\n");
3887 }
3888 infoResp.resFlag=CmdReturnFlag;
3889
Dake Zhao97708202014-11-26 13:59:04 -08003890cleanup:
Li Yincba7d352015-09-23 20:30:49 +08003891 if (sh_pipe)
3892 pclose(sh_pipe);
Dake Zhao0a832172015-01-06 11:08:47 -08003893
3894 switch(st)
3895 {
3896 case 0:
3897 infoResp.status = STATUS_COMPLETE;
3898 if (CmdReturnFlag)
3899 {
3900 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3901 {
3902 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003903 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 -08003904 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3905 }
3906 else
3907 {
Dake Zhao97708202014-11-26 13:59:04 -08003908 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003909 }
3910 }
3911 break;
3912 case 1:
3913 infoResp.status = STATUS_ERROR;
3914 break;
3915 case 2:
3916 infoResp.status = STATUS_INVALID;
3917 break;
3918 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003919
Dake Zhao0a832172015-01-06 11:08:47 -08003920 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3921 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003922
Dake Zhao0a832172015-01-06 11:08:47 -08003923 printf("Exit from wfaStaCliCommand\n");
3924 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003925
Ankur Vachhanic485b712012-02-15 23:29:49 +00003926}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003927/*
Dake Zhao0a832172015-01-06 11:08:47 -08003928 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003929 */
3930
3931int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3932{
3933 dutCmdResponse_t infoResp;
3934// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003935
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003936 printf("\n Entry wfaStaConnectGoStartWfd... ");
3937
Dake Zhao0a832172015-01-06 11:08:47 -08003938 // connect the specified GO and then establish the wfd session
3939
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003940 // Fetch WFD session and return
3941 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3942
3943 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003944 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003945 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003946
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003947 return WFA_SUCCESS;
3948}
3949
3950/*
Dake Zhao0a832172015-01-06 11:08:47 -08003951 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003952 */
3953
3954int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3955{
3956 dutCmdResponse_t infoResp;
3957 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3958 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003959
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003960 printf("\n Entry wfaStaGenerateEvent... ");
3961
3962
3963 // Geneate the specified action and return with complete/error.
3964 if(staGenerateEvent->program == PROG_TYPE_WFD)
3965 {
3966 wfdGenEvent = &staGenerateEvent->wfdEvent;
3967 if(wfdGenEvent ->type == eUibcGen)
3968 {
Dake Zhao0a832172015-01-06 11:08:47 -08003969 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003970 else if(wfdGenEvent ->type == eUibcHid)
3971 {
Dake Zhao0a832172015-01-06 11:08:47 -08003972 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003973 else if(wfdGenEvent ->type == eFrameSkip)
3974 {
3975
3976 }
3977 else if(wfdGenEvent ->type == eI2cRead)
3978 {
3979 }
3980 else if(wfdGenEvent ->type == eI2cWrite)
3981 {
Dake Zhao0a832172015-01-06 11:08:47 -08003982 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003983 else if(wfdGenEvent ->type == eInputContent)
3984 {
Dake Zhao0a832172015-01-06 11:08:47 -08003985 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003986 else if(wfdGenEvent ->type == eIdrReq)
3987 {
Dake Zhao0a832172015-01-06 11:08:47 -08003988 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003989 }
Dake Zhao0a832172015-01-06 11:08:47 -08003990
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003991 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003992 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003993 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003994
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003995 return WFA_SUCCESS;
3996}
3997
Dake Zhao0a832172015-01-06 11:08:47 -08003998
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003999
4000
4001/*
Dake Zhao0a832172015-01-06 11:08:47 -08004002 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004003 */
4004
4005int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4006{
4007 dutCmdResponse_t infoResp;
4008// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08004009
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004010 printf("\n Entry wfaStaReinvokeWfdSession... ");
4011
4012 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08004013
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004014
4015 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004016 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004017 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004018
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004019 return WFA_SUCCESS;
4020}
4021
4022
4023int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4024{
Dake Zhao0a832172015-01-06 11:08:47 -08004025 dutCmdResponse_t infoResp;
4026 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004027
4028
Dake Zhao0a832172015-01-06 11:08:47 -08004029 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004030
Dake Zhao0a832172015-01-06 11:08:47 -08004031 printf("\n Entry wfaStaGetParameter... ");
4032
4033 // Check the program type
4034 if(staGetParam->program == PROG_TYPE_WFD)
4035 {
4036 if(staGetParam->getParamValue == eDiscoveredDevList )
4037 {
4038 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4039 paramList->getParamType = eDiscoveredDevList;
4040 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4041 }
4042 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004043
Dake Zhao655efed2015-03-11 17:39:13 -07004044 if(staGetParam->program == PROG_TYPE_WFDS)
4045 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004046
Dake Zhao655efed2015-03-11 17:39:13 -07004047 if(staGetParam->getParamValue == eDiscoveredDevList )
4048 {
4049 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4050 paramList->getParamType = eDiscoveredDevList;
4051 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4052
4053 }
4054 if(staGetParam->getParamValue == eOpenPorts)
4055 {
4056 // Run the port checker tool
4057 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
4058 paramList->getParamType = eOpenPorts;
4059 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
4060
4061 }
4062
4063 }
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004064 if(staGetParam->program == PROG_TYPE_NAN)
4065 {
4066 if(staGetParam->getParamValue == eMasterPref )
4067 {
4068 // Get the master preference of the device and return the value
4069 paramList->getParamType = eMasterPref;
4070 strcpy((char *)&paramList->masterPref, "0xff");
4071 }
4072 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004073
Dake Zhao655efed2015-03-11 17:39:13 -07004074 infoResp.status = STATUS_COMPLETE;
4075 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4076 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4077
4078 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004079}
4080
Ankur Vachhanic485b712012-02-15 23:29:49 +00004081
Dake Zhao655efed2015-03-11 17:39:13 -07004082int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4083{
4084
4085 dutCmdResponse_t infoResp;
4086 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4087
4088 printf("\n Entry wfaStaNfcAction... ");
4089
4090 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4091 {
4092 printf("\n NfcAction - HandOver... ");
4093
4094 }
4095 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4096 {
4097 printf("\n NfcAction - Read Tag... ");
4098
4099 }
4100 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4101 {
4102 printf("\n NfcAction - Write Select... ");
4103
4104 }
4105 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4106 {
4107 printf("\n NfcAction - Write Config... ");
4108
4109 }
4110 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4111 {
4112 printf("\n NfcAction - Write Password... ");
4113
4114 }
4115 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4116 {
4117 printf("\n NfcAction - WPS Handover... ");
4118
4119 }
4120
4121 // Fetch the device mode and put in infoResp->cmdru.p2presult
4122 //strcpy(infoResp->cmdru.p2presult, "GO");
4123
4124 // Fetch the device grp id and put in infoResp->cmdru.grpid
4125 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4126
4127 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4128 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4129 infoResp.cmdru.staNfcAction.peerRole = 1;
4130
4131
4132
4133
4134 infoResp.status = STATUS_COMPLETE;
4135 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4136 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4137
4138 return WFA_SUCCESS;
4139}
4140
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004141int wfaStaExecAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4142{
4143
4144 dutCmdResponse_t infoResp;
4145 caStaExecAction_t *staExecAction = (caStaExecAction_t *)caCmdBuf; //comment if not used
4146
4147 printf("\n Entry wfaStaExecAction... ");
4148
4149 if(staExecAction->prog == PROG_TYPE_NAN)
4150 {
4151 // Perform necessary configurations and actions
4152 // return the MAC address conditionally as per CAPI specification
4153 }
4154
4155 infoResp.status = STATUS_COMPLETE;
4156 wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4157 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4158
4159 return WFA_SUCCESS;
4160}
4161
Dake Zhao655efed2015-03-11 17:39:13 -07004162int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4163{
4164
4165 dutCmdResponse_t infoResp;
4166 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4167
4168 printf("\n Entry wfaStaInvokeCommand... ");
4169
4170
4171 // based on the command type , invoke API or complete the required procedures
4172 // return the defined parameters based on the command that is received ( example response below)
4173
4174 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4175 {
4176 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4177 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4178 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4179 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4180 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4181 }
4182 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4183 {
4184 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4185 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4186 }
4187 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4188 {
4189 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4190 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4191 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4192 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4193
4194 }
4195 infoResp.status = STATUS_COMPLETE;
4196 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4197 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4198
4199 return WFA_SUCCESS;
4200}
4201
4202
4203int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4204{
4205
4206 dutCmdResponse_t infoResp;
4207 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4208
4209 printf("\n Entry wfaStaManageService... ");
4210
4211 // based on the manage service type , invoke API's or complete the required procedures
4212 // return the defined parameters based on the command that is received ( example response below)
4213 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4214 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4215 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4216
4217 infoResp.status = STATUS_COMPLETE;
4218 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4219 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4220
4221 return WFA_SUCCESS;
4222}
4223
4224
4225
4226int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4227{
4228
4229 dutCmdResponse_t infoResp;
Dake Zhao353c55e2015-07-20 18:54:45 -07004230 caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004231
4232 printf("\n Entry wfaStaGetEvents... ");
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004233
4234 if(staGetEvents->program == PROG_TYPE_NAN)
4235 {
4236 // Get all the events from the Log file or stored events
4237 // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac
4238 }
Dake Zhao655efed2015-03-11 17:39:13 -07004239
4240 // Get all the event from the Log file or stored events
4241 // return the received/recorded events as space seperated list ( example response below)
4242 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4243
4244 infoResp.status = STATUS_COMPLETE;
4245 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4246 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4247
4248 return WFA_SUCCESS;
4249}
4250
4251int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4252{
4253
4254 dutCmdResponse_t infoResp;
Li Yinf467b182015-09-23 21:21:30 +08004255 caStaGetEventDetails_t *getStaGetEventDetails = (caStaGetEventDetails_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004256
4257 printf("\n Entry wfaStaGetEventDetails... ");
4258
4259
4260 // based on the Requested Event type
4261 // return the latest corresponding evnet detailed parameters ( example response below)
4262
4263 if(getStaGetEventDetails->eventId== eSearchResult )
4264 {
4265 // fetch from log file or event history for the search result event and return the parameters
4266 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4267
4268 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4269 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4270 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4271 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4272
4273 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4274 }
4275 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4276 { // fetch from log file or event history for the search terminated event and return the parameters
4277 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4278 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4279 }
4280 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4281 {// fetch from log file or event history for the Advertise Status event and return the parameters
4282 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4283 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4284
4285 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4286 }
4287 else if (getStaGetEventDetails->eventId == eSessionRequest)
4288 {// fetch from log file or event history for the session request event and return the parameters
4289 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4290 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4291 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4292 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4293 }
4294 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4295 {// fetch from log file or event history for the session status event and return the parameters
4296 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4297 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4298 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4299 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4300 }
4301 else if (getStaGetEventDetails->eventId == eConnectStatus)
4302 {
4303 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4304 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4305 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4306 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4307
4308 }
4309 else if (getStaGetEventDetails->eventId == ePortStatus)
4310 {
4311 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4312 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4313 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4314 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4315 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4316 }
4317
4318
4319
4320 infoResp.status = STATUS_COMPLETE;
4321 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4322 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4323
4324 return WFA_SUCCESS;
4325}
4326
4327
4328
4329