blob: d357dae58769b6c70d256fad8413d12268ff5e29 [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
93/*
94 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
95 * input: cmd --- not used
96 * valLen -- not used
97 * output: parms -- a buffer to store the version info response.
98 */
99int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
100{
101 dutCmdResponse_t *getverResp = &gGenericResp;
102
103 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
104
105 getverResp->status = STATUS_COMPLETE;
106 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
107
108 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
109
110 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
111
112 return WFA_SUCCESS;
113}
114
115/*
116 * wfaStaAssociate():
Dake Zhao0a832172015-01-06 11:08:47 -0800117 * The function is to force the station wireless I/F to re/associate
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000118 * with the AP.
119 */
120int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
121{
Dake Zhao0a832172015-01-06 11:08:47 -0800122 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
123 char *ifname = assoc->intf;
124 dutCmdResponse_t *staAssocResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000125
Dake Zhao0a832172015-01-06 11:08:47 -0800126 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
127 /*
128 * if bssid appears, station should associate with the specific
129 * BSSID AP at its initial association.
130 * If it is different to the current associating AP, it will be forced to
131 * roam the new AP
132 */
133 if(assoc->cmdsu.assoc.bssid[0] != '\0')
134 {
135 /* if (the first association) */
136 /* just do initial association to the BSSID */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000137
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000138
Dake Zhao0a832172015-01-06 11:08:47 -0800139 /* else (station already associate to an AP) */
140 /* Do forced roaming */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000141
Dake Zhao0a832172015-01-06 11:08:47 -0800142 }
143 else
144 {
145 /* use 'ifconfig' command to bring down the interface (linux specific) */
Ray Wangd11ca032015-05-29 18:25:46 -0700146 //sprintf(gCmdStr, "ifconfig %s down", ifname);
147 //sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000148
Dake Zhao0a832172015-01-06 11:08:47 -0800149 /* use 'ifconfig' command to bring up the interface (linux specific) */
Ray Wangd11ca032015-05-29 18:25:46 -0700150 //sprintf(gCmdStr, "ifconfig %s up", ifname);
151 //sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000152
Dake Zhao0a832172015-01-06 11:08:47 -0800153 /*
154 * use 'wpa_cli' command to force a 802.11 re/associate
155 * (wpa_supplicant specific)
156 */
157 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
158 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000159 }
160
161 /*
162 * Then report back to control PC for completion.
163 * This does not have failed/error status. The result only tells
164 * a completion.
165 */
166 staAssocResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -0800167 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000168 *respLen = WFA_TLV_HDR_LEN + 4;
169
Dake Zhao0a832172015-01-06 11:08:47 -0800170 return WFA_SUCCESS;
171}
172
173/*
174 * wfaStaReAssociate():
175 * The function is to force the station wireless I/F to re/associate
176 * with the AP.
177 */
178int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
179{
180 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
181 char *ifname = assoc->intf;
182 dutCmdResponse_t *staAssocResp = &gGenericResp;
183
184 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
185 /*
186 * if bssid appears, station should associate with the specific
187 * BSSID AP at its initial association.
188 * If it is different to the current associating AP, it will be forced to
189 * roam the new AP
190 */
191 if(assoc->cmdsu.assoc.bssid[0] != '\0')
192 {
193 /* if (the first association) */
194 /* just do initial association to the BSSID */
195
196
197 /* else (station already associate to an AP) */
198 /* Do forced roaming */
199
200 }
201 else
202 {
203 /* use 'ifconfig' command to bring down the interface (linux specific) */
204 sprintf(gCmdStr, "ifconfig %s down", ifname);
205 sret = system(gCmdStr);
206
207 /* use 'ifconfig' command to bring up the interface (linux specific) */
208 sprintf(gCmdStr, "ifconfig %s up", ifname);
209
210 /*
211 * use 'wpa_cli' command to force a 802.11 re/associate
212 * (wpa_supplicant specific)
213 */
214 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
215 sret = system(gCmdStr);
216 }
217
218 /*
219 * Then report back to control PC for completion.
220 * This does not have failed/error status. The result only tells
221 * a completion.
222 */
223 staAssocResp->status = STATUS_COMPLETE;
224 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
225 *respLen = WFA_TLV_HDR_LEN + 4;
226
227 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000228}
229
230/*
231 * wfaStaIsConnected():
Dake Zhao0a832172015-01-06 11:08:47 -0800232 * The function is to check whether the station's wireless I/F has
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000233 * already connected to an AP.
234 */
235int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
236{
Dake Zhao0a832172015-01-06 11:08:47 -0800237 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
238 dutCmdResponse_t *staConnectResp = &gGenericResp;
239 char *ifname = connStat->intf;
240 FILE *tmpfile = NULL;
241 char result[32];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000242
243
Dake Zhao0a832172015-01-06 11:08:47 -0800244 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000245
246#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800247 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
248 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000249
Dake Zhao0a832172015-01-06 11:08:47 -0800250 if(chk_ret_status() == WFA_SUCCESS)
251 staConnectResp->cmdru.connected = 1;
252 else
253 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000254#else
Dake Zhao0a832172015-01-06 11:08:47 -0800255 /*
256 * use 'wpa_cli' command to check the interface status
257 * none, scanning or complete (wpa_supplicant specific)
258 */
Mickael GARDET29b28ce2020-04-08 18:33:47 +0200259 sprintf(gCmdStr, "wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
Dake Zhao0a832172015-01-06 11:08:47 -0800260 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000261
Dake Zhao0a832172015-01-06 11:08:47 -0800262 /*
263 * the status is saved in a file. Open the file and check it.
264 */
265 tmpfile = fopen("/tmp/.isConnected", "r+");
266 if(tmpfile == NULL)
267 {
268 staConnectResp->status = STATUS_ERROR;
269 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
270 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000271
Dake Zhao0a832172015-01-06 11:08:47 -0800272 DPRINT_ERR(WFA_ERR, "file open failed\n");
273 return WFA_FAILURE;
274 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000275
Dake Zhao0a832172015-01-06 11:08:47 -0800276 sret = fscanf(tmpfile, "%s", (char *)result);
Li Yincba7d352015-09-23 20:30:49 +0800277 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000278
Dake Zhao0a832172015-01-06 11:08:47 -0800279 if(strncmp(result, "COMPLETED", 9) == 0)
280 staConnectResp->cmdru.connected = 1;
281 else
282 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000283#endif
284
Dake Zhao0a832172015-01-06 11:08:47 -0800285 /*
286 * Report back the status: Complete or Failed.
287 */
288 staConnectResp->status = STATUS_COMPLETE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000289
Dake Zhao0a832172015-01-06 11:08:47 -0800290 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
291 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
292
293 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000294}
295
296/*
297 * wfaStaGetIpConfig():
298 * This function is to retriev the ip info including
299 * 1. dhcp enable
300 * 2. ip address
Dake Zhao0a832172015-01-06 11:08:47 -0800301 * 3. mask
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000302 * 4. primary-dns
303 * 5. secondary-dns
304 *
305 * The current implementation is to use a script to find these information
Dake Zhao0a832172015-01-06 11:08:47 -0800306 * and store them in a file.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000307 */
308int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
309{
310 int slen, ret, i = 0;
311 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
Dake Zhao0a832172015-01-06 11:08:47 -0800312 dutCmdResponse_t *ipconfigResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000313 char *ifname = getIpConf->intf;
314 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
315
316 FILE *tmpfd;
317 char string[256];
318 char *str;
319
320 /*
321 * check a script file (the current implementation specific)
322 */
323 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
324 if(ret == -1)
325 {
Dake Zhao0a832172015-01-06 11:08:47 -0800326 ipconfigResp->status = STATUS_ERROR;
327 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
328 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000329
Dake Zhao0a832172015-01-06 11:08:47 -0800330 DPRINT_ERR(WFA_ERR, "file not exist\n");
331 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000332
333 }
334
335 strcpy(ifinfo->dns[0], "0");
336 strcpy(ifinfo->dns[1], "0");
Dake Zhao0a832172015-01-06 11:08:47 -0800337
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000338 /*
Dake Zhao0a832172015-01-06 11:08:47 -0800339 * Run the script file "getipconfig.sh" to check the ip status
340 * (current implementation specific).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000341 * note: "getipconfig.sh" is only defined for the current implementation
342 */
Dake Zhao0a832172015-01-06 11:08:47 -0800343 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000344
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800345 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000346
347 /* open the output result and scan/retrieve the info */
348 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
349
350 if(tmpfd == NULL)
351 {
Dake Zhao0a832172015-01-06 11:08:47 -0800352 ipconfigResp->status = STATUS_ERROR;
353 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
354 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000355
Dake Zhao0a832172015-01-06 11:08:47 -0800356 DPRINT_ERR(WFA_ERR, "file open failed\n");
357 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000358 }
359
360 for(;;)
361 {
362 if(fgets(string, 256, tmpfd) == NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800363 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000364
365 /* check dhcp enabled */
366 if(strncmp(string, "dhcpcli", 7) ==0)
367 {
368 str = strtok(string, "=");
369 str = strtok(NULL, "=");
370 if(str != NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800371 ifinfo->isDhcp = 1;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000372 else
Dake Zhao0a832172015-01-06 11:08:47 -0800373 ifinfo->isDhcp = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000374 }
375
376 /* find out the ip address */
377 if(strncmp(string, "ipaddr", 6) == 0)
378 {
379 str = strtok(string, "=");
380 str = strtok(NULL, " ");
381 if(str != NULL)
382 {
Dake Zhao0a832172015-01-06 11:08:47 -0800383 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800384
Dake Zhao0a832172015-01-06 11:08:47 -0800385 ifinfo->ipaddr[15]='\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000386 }
387 else
Dake Zhao0a832172015-01-06 11:08:47 -0800388 wSTRNCPY(ifinfo->ipaddr, "none", 15);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000389 }
390
391 /* check the mask */
392 if(strncmp(string, "mask", 4) == 0)
393 {
394 char ttstr[16];
395 char *ttp = ttstr;
396
397 str = strtok_r(string, "=", &ttp);
398 if(*ttp != '\0')
399 {
Dake Zhao0a832172015-01-06 11:08:47 -0800400 strcpy(ifinfo->mask, ttp);
401 slen = strlen(ifinfo->mask);
402 ifinfo->mask[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000403 }
404 else
Dake Zhao0a832172015-01-06 11:08:47 -0800405 strcpy(ifinfo->mask, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000406 }
407
408 /* find out the dns server ip address */
409 if(strncmp(string, "nameserv", 8) == 0)
410 {
411 char ttstr[16];
412 char *ttp = ttstr;
Dake Zhao0a832172015-01-06 11:08:47 -0800413
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000414 str = strtok_r(string, " ", &ttp);
415 if(str != NULL && i < 2)
416 {
Dake Zhao0a832172015-01-06 11:08:47 -0800417 strcpy(ifinfo->dns[i], ttp);
418 slen = strlen(ifinfo->dns[i]);
419 ifinfo->dns[i][slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000420 }
421 else
Dake Zhao0a832172015-01-06 11:08:47 -0800422 strcpy(ifinfo->dns[i], "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000423
424 i++;
425 }
Dake Zhao0a832172015-01-06 11:08:47 -0800426 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000427
Dake Zhao0a832172015-01-06 11:08:47 -0800428 /*
429 * Report back the results
430 */
431 ipconfigResp->status = STATUS_COMPLETE;
432 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000433
Dake Zhao0a832172015-01-06 11:08:47 -0800434 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000435
436#if 0
Dake Zhao0a832172015-01-06 11:08:47 -0800437 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
438 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
439 ifinfo->dns[0], ifinfo->dns[1], *respLen);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000440#endif
441
Dake Zhao0a832172015-01-06 11:08:47 -0800442 fclose(tmpfd);
443 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000444}
445
446/*
447 * wfaStaSetIpConfig():
448 * The function is to set the ip configuration to a wireless I/F.
449 * 1. IP address
450 * 2. Mac address
451 * 3. default gateway
Dake Zhao0a832172015-01-06 11:08:47 -0800452 * 4. dns nameserver (pri and sec).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000453 */
454int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
455{
Dake Zhao0a832172015-01-06 11:08:47 -0800456 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
457 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
458 dutCmdResponse_t *staSetIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000459
Dake Zhao0a832172015-01-06 11:08:47 -0800460 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000461
Dake Zhao0a832172015-01-06 11:08:47 -0800462 /*
463 * Use command 'ifconfig' to configure the interface ip address, mask.
464 * (Linux specific).
465 */
466 sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
467 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000468
Dake Zhao0a832172015-01-06 11:08:47 -0800469 /* use command 'route add' to set set gatewway (linux specific) */
470 if(ipconfig->defGateway[0] != '\0')
471 {
472 sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway);
473 sret = system(gCmdStr);
474 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000475
Dake Zhao0a832172015-01-06 11:08:47 -0800476 /* set dns (linux specific) */
477 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
478 sret = system(gCmdStr);
479 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
480 sret = system(gCmdStr);
481 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
482 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000483
Dake Zhao0a832172015-01-06 11:08:47 -0800484 /*
485 * report status
486 */
487 staSetIpResp->status = STATUS_COMPLETE;
488 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
489 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000490
Dake Zhao0a832172015-01-06 11:08:47 -0800491 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000492}
493
494/*
495 * wfaStaVerifyIpConnection():
496 * The function is to verify if the station has IP connection with an AP by
497 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800498 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000499int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
500{
Dake Zhao0a832172015-01-06 11:08:47 -0800501 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
502 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000503
504#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800505 char strout[64], *pcnt;
506 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000507
Dake Zhao0a832172015-01-06 11:08:47 -0800508 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
509
510 /* set timeout value in case not set */
511 if(verip->cmdsu.verifyIp.timeout <= 0)
512 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000513 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800514 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000515
Dake Zhao0a832172015-01-06 11:08:47 -0800516 /* execute the ping command and pipe the result to a tmp file */
517 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);
518 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000519
Dake Zhao0a832172015-01-06 11:08:47 -0800520 /* scan/check the output */
521 tmpfile = fopen("/tmp/pingout.txt", "r+");
522 if(tmpfile == NULL)
523 {
524 verifyIpResp->status = STATUS_ERROR;
525 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
526 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000527
Dake Zhao0a832172015-01-06 11:08:47 -0800528 DPRINT_ERR(WFA_ERR, "file open failed\n");
529 return WFA_FAILURE;
530 }
531
532 verifyIpResp->status = STATUS_COMPLETE;
533 if(fscanf(tmpfile, "%s", strout) == EOF)
534 verifyIpResp->cmdru.connected = 0;
535 else
536 {
537 pcnt = strtok(strout, "%");
538
539 /* if the loss rate is 100%, not able to connect */
540 if(atoi(pcnt) == 100)
541 verifyIpResp->cmdru.connected = 0;
542 else
543 verifyIpResp->cmdru.connected = 1;
544 }
545
546 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000547#else
Dake Zhao0a832172015-01-06 11:08:47 -0800548 int btSockfd;
549 struct pollfd fds[2];
550 int timeout = 2000;
551 char anyBuf[64];
552 struct sockaddr_in toAddr;
553 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000554
Dake Zhao0a832172015-01-06 11:08:47 -0800555 verifyIpResp->status = STATUS_COMPLETE;
556 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000557
Dake Zhao0a832172015-01-06 11:08:47 -0800558 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000559
Dake Zhao0a832172015-01-06 11:08:47 -0800560 if(btSockfd == -1)
561 {
562 verifyIpResp->status = STATUS_ERROR;
563 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
564 *respLen = WFA_TLV_HDR_LEN + 4;
565 return WFA_FAILURE;;
566 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000567
Dake Zhao0a832172015-01-06 11:08:47 -0800568 toAddr.sin_family = AF_INET;
569 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
570 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000571
Dake Zhao0a832172015-01-06 11:08:47 -0800572 while(done)
573 {
574 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
575 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000576
Dake Zhao0a832172015-01-06 11:08:47 -0800577 fds[0].fd = btSockfd;
578 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000579
Dake Zhao0a832172015-01-06 11:08:47 -0800580 ret = poll(fds, 1, timeout);
581 switch(ret)
582 {
583 case 0:
584 /* it is time out, count a packet lost*/
585 break;
586 case -1:
587 /* it is an error */
588 default:
589 {
590 switch(fds[0].revents)
591 {
592 case POLLIN:
593 case POLLPRI:
594 case POLLOUT:
595 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
596 if(nbytes != 0)
597 verifyIpResp->cmdru.connected = 1;
598 done = 0;
599 break;
600 default:
601 /* errors but not care */
602 ;
603 }
604 }
605 }
606 if(cnt == 3)
607 {
608 done = 0;
609 }
610 }
611
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000612#endif
613
Dake Zhao0a832172015-01-06 11:08:47 -0800614 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000615
Dake Zhao0a832172015-01-06 11:08:47 -0800616 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
617
618 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000619}
620
621/*
622 * wfaStaGetMacAddress()
623 * This function is to retrieve the MAC address of a wireless I/F.
624 */
625int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
626{
627 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
628 dutCmdResponse_t *getmacResp = &gGenericResp;
629 char *str;
630 char *ifname = getMac->intf;
631
632 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800633 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000634
635 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
636 /*
637 * run the script "getipconfig.sh" to find out the mac
638 */
Dake Zhao0a832172015-01-06 11:08:47 -0800639 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800640 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000641
642 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
643 if(tmpfd == NULL)
644 {
Dake Zhao0a832172015-01-06 11:08:47 -0800645 getmacResp->status = STATUS_ERROR;
646 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
647 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000648
Dake Zhao0a832172015-01-06 11:08:47 -0800649 DPRINT_ERR(WFA_ERR, "file open failed\n");
650 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000651 }
652
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800653 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
654 {
Dake Zhao0a832172015-01-06 11:08:47 -0800655 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000656 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800657
658 str = strtok(string, " ");
659 while(str && ((strcmp(str,"HWaddr")) != 0))
660 {
Dake Zhao0a832172015-01-06 11:08:47 -0800661 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800662 }
Dake Zhao0a832172015-01-06 11:08:47 -0800663
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800664 /* get mac */
665 if(str)
666 {
667 str = strtok(NULL, " ");
668 strcpy(getmacResp->cmdru.mac, str);
669 getmacResp->status = STATUS_COMPLETE;
670 }
Dake Zhao0a832172015-01-06 11:08:47 -0800671
672 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000673
674 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
675
676 fclose(tmpfd);
677 return WFA_SUCCESS;
678}
679
680/*
681 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800682 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000683 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800684 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000685 */
686int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
687{
Dake Zhao0a832172015-01-06 11:08:47 -0800688 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000689
Dake Zhao0a832172015-01-06 11:08:47 -0800690 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000691
Dake Zhao0a832172015-01-06 11:08:47 -0800692 statsResp->status = STATUS_ERROR;
693 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
694 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000695
696
Dake Zhao0a832172015-01-06 11:08:47 -0800697 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000698}
699
700/*
701 * wfaSetEncryption():
702 * The function is to set the wireless interface with WEP or none.
703 *
Dake Zhao0a832172015-01-06 11:08:47 -0800704 * Since WEP is optional test, current function is only used for
705 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000706 * this function should be replaced by the next one (wfaSetEncryption1())
707 *
Dake Zhao0a832172015-01-06 11:08:47 -0800708 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000709 * 1. I/F
710 * 2. ssid
711 * 3. encpType - wep or none
712 * Optional:
713 * 4. key1
714 * 5. key2
715 * 6. key3
716 * 7. key4
717 * 8. activeKey Index
718 */
719
720int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
721{
Dake Zhao0a832172015-01-06 11:08:47 -0800722 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
723 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000724
Dake Zhao0a832172015-01-06 11:08:47 -0800725 /*
726 * disable the network first
727 */
728 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
729 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000730
Dake Zhao0a832172015-01-06 11:08:47 -0800731 /*
732 * set SSID
733 */
734 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
735 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000736
Dake Zhao0a832172015-01-06 11:08:47 -0800737 /*
738 * Tell the supplicant for infrastructure mode (1)
739 */
740 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
741 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000742
Dake Zhao0a832172015-01-06 11:08:47 -0800743 /*
744 * set Key management to NONE (NO WPA) for plaintext or WEP
745 */
746 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
747 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000748
Dake Zhao0a832172015-01-06 11:08:47 -0800749 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
750 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000751
Dake Zhao0a832172015-01-06 11:08:47 -0800752 setEncrypResp->status = STATUS_COMPLETE;
753 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
754 *respLen = WFA_TLV_HDR_LEN + 4;
755
756 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000757}
758
759/*
760 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800761 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000762 */
763int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
764{
Dake Zhao0a832172015-01-06 11:08:47 -0800765 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
766 dutCmdResponse_t *setEncrypResp = &gGenericResp;
767 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000768
Dake Zhao0a832172015-01-06 11:08:47 -0800769 /*
770 * disable the network first
771 */
772 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
773 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000774
Dake Zhao0a832172015-01-06 11:08:47 -0800775 /*
776 * set SSID
777 */
778 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
779 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000780
Dake Zhao0a832172015-01-06 11:08:47 -0800781 /*
782 * Tell the supplicant for infrastructure mode (1)
783 */
784 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
785 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000786
Dake Zhao0a832172015-01-06 11:08:47 -0800787 /*
788 * set Key management to NONE (NO WPA) for plaintext or WEP
789 */
790 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
791 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000792
Dake Zhao0a832172015-01-06 11:08:47 -0800793 /* set keys */
794 if(setEncryp->encpType == 1)
795 {
796 for(i=0; i<4; i++)
797 {
798 if(setEncryp->keys[i][0] != '\0')
799 {
800 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
801 setEncryp->intf, i, setEncryp->keys[i]);
802 sret = system(gCmdStr);
803 }
804 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000805
Dake Zhao0a832172015-01-06 11:08:47 -0800806 /* set active key */
807 i = setEncryp->activeKeyIdx;
808 if(setEncryp->keys[i][0] != '\0')
809 {
810 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
811 setEncryp->intf, setEncryp->activeKeyIdx);
812 sret = system(gCmdStr);
813 }
814 }
815 else /* clearly remove the keys -- reported by p.schwann */
816 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000817
Dake Zhao0a832172015-01-06 11:08:47 -0800818 for(i = 0; i < 4; i++)
819 {
820 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
821 sret = system(gCmdStr);
822 }
823 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000824
Dake Zhao0a832172015-01-06 11:08:47 -0800825 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
826 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000827
Dake Zhao0a832172015-01-06 11:08:47 -0800828 setEncrypResp->status = STATUS_COMPLETE;
829 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
830 *respLen = WFA_TLV_HDR_LEN + 4;
831
832 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000833}
834
835int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
836{
837 int ret = WFA_SUCCESS;
838
839 return ret;
840}
841
842/*
843 * wfaStaSetEapTLS():
844 * This is to set
845 * 1. ssid
846 * 2. encrypType - tkip or aes-ccmp
847 * 3. keyManagementType - wpa or wpa2
848 * 4. trustedRootCA
849 * 5. clientCertificate
850 */
851int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
852{
Dake Zhao0a832172015-01-06 11:08:47 -0800853 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
854 char *ifname = setTLS->intf;
855 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000856
Dake Zhao0a832172015-01-06 11:08:47 -0800857 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000858
Dake Zhao0a832172015-01-06 11:08:47 -0800859 /*
860 * need to store the trustedROOTCA and clientCertificate into a file first.
861 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000862#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800863 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
864 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000865#else
866
Dake Zhao0a832172015-01-06 11:08:47 -0800867 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
868 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000869
Dake Zhao0a832172015-01-06 11:08:47 -0800870 /* ssid */
871 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
872 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000873
Dake Zhao0a832172015-01-06 11:08:47 -0800874 /* key management */
875 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
876 {
877 }
878 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
879 {
880 }
881 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
882 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000883
Dake Zhao0a832172015-01-06 11:08:47 -0800884 }
885 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
886 {
887 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
888 }
889 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
890 {
891 // to take all and device to pick any one supported.
892 }
893 else
894 {
895 // ??
896 }
897 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000898
Dake Zhao0a832172015-01-06 11:08:47 -0800899 /* protocol WPA */
900 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
901 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000902
Dake Zhao0a832172015-01-06 11:08:47 -0800903 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
904 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000905
Dake Zhao0a832172015-01-06 11:08:47 -0800906 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
907 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000908
Dake Zhao0a832172015-01-06 11:08:47 -0800909 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
910 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000911
Dake Zhao0a832172015-01-06 11:08:47 -0800912 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
913 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000914
Dake Zhao0a832172015-01-06 11:08:47 -0800915 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
916 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000917
Dake Zhao0a832172015-01-06 11:08:47 -0800918 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
919 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000920#endif
921
Dake Zhao0a832172015-01-06 11:08:47 -0800922 setEapTlsResp->status = STATUS_COMPLETE;
923 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
924 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000925
Dake Zhao0a832172015-01-06 11:08:47 -0800926 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000927}
928
929/*
Dake Zhao0a832172015-01-06 11:08:47 -0800930 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000931 * 1. ssid
932 * 2. passPhrase
933 * 3. keyMangementType - wpa/wpa2
934 * 4. encrypType - tkip or aes-ccmp
935 */
936int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -0800937{
938 /*Incompleted function*/
939 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000940
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800941#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -0800942 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000943#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800944 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
945 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000946#else
Dake Zhao0a832172015-01-06 11:08:47 -0800947 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
948 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000949
Dake Zhao0a832172015-01-06 11:08:47 -0800950 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
951 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
952 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
953 {
954 // take all and device to pick it supported.
955 }
956 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
957 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000958
Dake Zhao0a832172015-01-06 11:08:47 -0800959 }
960 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
961 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000962
Dake Zhao0a832172015-01-06 11:08:47 -0800963 }
964 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
965 {
Ray Wang9c508692014-04-01 17:04:59 -0700966
Dake Zhao0a832172015-01-06 11:08:47 -0800967 }
968 else
969 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800970
Dake Zhao0a832172015-01-06 11:08:47 -0800971 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000972
Dake Zhao0a832172015-01-06 11:08:47 -0800973 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
974 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000975
Dake Zhao0a832172015-01-06 11:08:47 -0800976 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
977 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000978
Dake Zhao0a832172015-01-06 11:08:47 -0800979 /* if PMF enable */
980 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
981 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000982
Dake Zhao0a832172015-01-06 11:08:47 -0800983 }
984 else if(setPSK->pmf == WFA_REQUIRED)
985 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000986
Dake Zhao0a832172015-01-06 11:08:47 -0800987 }
988 else if(setPSK->pmf == WFA_F_REQUIRED)
989 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000990
Dake Zhao0a832172015-01-06 11:08:47 -0800991 }
992 else if(setPSK->pmf == WFA_F_DISABLED)
993 {
994
995 }
996 else
997 {
998 /* Disable PMF */
999
1000 }
1001
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001002#endif
1003
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001004#endif
1005
Dake Zhao0a832172015-01-06 11:08:47 -08001006 setPskResp->status = STATUS_COMPLETE;
1007 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1008 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001009
Dake Zhao0a832172015-01-06 11:08:47 -08001010 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001011}
1012
1013/*
Dake Zhao0a832172015-01-06 11:08:47 -08001014 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001015 * Get vendor specific information in name/value pair by a wireless I/F.
1016 */
1017int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1018{
Dake Zhao0a832172015-01-06 11:08:47 -08001019 dutCmdResponse_t infoResp;
1020 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001021 FILE *tmpfd;
1022 char vendor[256];
1023 const char* vendorFileName = "/tmp/ifvendor.txt";
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001024
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001025 sprintf(gCmdStr, "getifvendor.sh %s %s\n", getInfo->intf, vendorFileName);
1026
1027 if (system(gCmdStr) == -1)
1028 {
1029 infoResp.status = STATUS_ERROR;
1030 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1031 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1032
1033 DPRINT_ERR(WFA_ERR, "script %s failed\n", vendorFileName);
1034 return WFA_FAILURE;
1035 }
1036
1037 /* open the output result and scan/retrieve the info */
1038 tmpfd = fopen(vendorFileName, "r+");
1039
1040 if(tmpfd == NULL || fgets(vendor, 256, tmpfd) == NULL)
1041 {
1042 infoResp.status = STATUS_ERROR;
1043 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1044 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1045
1046 DPRINT_ERR(WFA_ERR, "file read failed\n");
1047
1048 if (tmpfd != NULL)
1049 {
1050 fclose(tmpfd);
1051 remove(vendorFileName);
1052 }
1053
1054 return WFA_FAILURE;
1055 }
1056
1057 snprintf(infoResp.cmdru.info, sizeof(infoResp.cmdru.info), "interface,%s,description,%s",
1058 getInfo->intf, vendor);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001059
Dake Zhao0a832172015-01-06 11:08:47 -08001060 infoResp.status = STATUS_COMPLETE;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001061 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1062 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1063
1064 fclose(tmpfd);
1065 remove(vendorFileName);
Dake Zhao0a832172015-01-06 11:08:47 -08001066
1067 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001068}
1069
1070/*
1071 * wfaStaSetEapTTLS():
1072 * This is to set
1073 * 1. ssid
1074 * 2. username
1075 * 3. passwd
1076 * 4. encrypType - tkip or aes-ccmp
1077 * 5. keyManagementType - wpa or wpa2
1078 * 6. trustedRootCA
1079 */
1080int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1081{
Dake Zhao0a832172015-01-06 11:08:47 -08001082 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1083 char *ifname = setTTLS->intf;
1084 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001085
1086#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001087 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
1088 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001089#else
1090
Dake Zhao0a832172015-01-06 11:08:47 -08001091 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1092 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001093
Dake Zhao0a832172015-01-06 11:08:47 -08001094 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
1095 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001096
Dake Zhao0a832172015-01-06 11:08:47 -08001097 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
1098 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001099
Dake Zhao0a832172015-01-06 11:08:47 -08001100 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
1101 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001102
Dake Zhao0a832172015-01-06 11:08:47 -08001103 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1104 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001105
Dake Zhao0a832172015-01-06 11:08:47 -08001106 /* This may not need to set. if it is not set, default to take all */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001107// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001108 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1109 {
1110 }
1111 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1112 {
1113 }
1114 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1115 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001116
Dake Zhao0a832172015-01-06 11:08:47 -08001117 }
1118 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1119 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001120
Dake Zhao0a832172015-01-06 11:08:47 -08001121 }
1122 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1123 {
1124 // to take all and device to pick one it supported
1125 }
1126 else
1127 {
1128 // ??
1129 }
1130 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001131
Dake Zhao0a832172015-01-06 11:08:47 -08001132 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
1133 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001134
Dake Zhao0a832172015-01-06 11:08:47 -08001135 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
1136 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001137
Dake Zhao0a832172015-01-06 11:08:47 -08001138 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1139 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001140
Dake Zhao0a832172015-01-06 11:08:47 -08001141 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
1142 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001143
Dake Zhao0a832172015-01-06 11:08:47 -08001144 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1145 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001146#endif
1147
Dake Zhao0a832172015-01-06 11:08:47 -08001148 setEapTtlsResp->status = STATUS_COMPLETE;
1149 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1150 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001151
Dake Zhao0a832172015-01-06 11:08:47 -08001152 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001153}
1154
1155/*
1156 * wfaStaSetEapSIM():
1157 * This is to set
1158 * 1. ssid
1159 * 2. user name
1160 * 3. passwd
1161 * 4. encrypType - tkip or aes-ccmp
1162 * 5. keyMangementType - wpa or wpa2
1163 */
1164int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1165{
Dake Zhao0a832172015-01-06 11:08:47 -08001166 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1167 char *ifname = setSIM->intf;
1168 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001169
1170#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001171 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
1172 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001173#else
1174
Dake Zhao0a832172015-01-06 11:08:47 -08001175 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1176 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001177
Dake Zhao0a832172015-01-06 11:08:47 -08001178 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
1179 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001180
1181
Dake Zhao0a832172015-01-06 11:08:47 -08001182 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
1183 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001184
Dake Zhao0a832172015-01-06 11:08:47 -08001185 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
1186 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001187
Dake Zhao0a832172015-01-06 11:08:47 -08001188 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
1189 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001190
Dake Zhao0a832172015-01-06 11:08:47 -08001191 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1192 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001193
Dake Zhao0a832172015-01-06 11:08:47 -08001194 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1195 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001196
Dake Zhao0a832172015-01-06 11:08:47 -08001197 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1198 {
1199 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1200 }
1201 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1202 {
1203 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1204 }
1205 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1206 {
1207 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1208 }
1209 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1210 {
1211 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1212 }
1213 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1214 {
1215 // take all and device to pick one which is supported.
1216 }
1217 else
1218 {
1219 // ??
1220 }
1221 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001222
1223#endif
1224
Dake Zhao0a832172015-01-06 11:08:47 -08001225 setEapSimResp->status = STATUS_COMPLETE;
1226 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1227 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001228
Dake Zhao0a832172015-01-06 11:08:47 -08001229 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001230}
1231
1232/*
1233 * wfaStaSetPEAP()
1234 * This is to set
1235 * 1. ssid
1236 * 2. user name
1237 * 3. passwd
1238 * 4. encryType - tkip or aes-ccmp
1239 * 5. keyMgmtType - wpa or wpa2
1240 * 6. trustedRootCA
1241 * 7. innerEAP
1242 * 8. peapVersion
1243 */
1244int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1245{
Dake Zhao0a832172015-01-06 11:08:47 -08001246 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1247 char *ifname = setPEAP->intf;
1248 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001249
1250#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001251 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1252 setPEAP->passwd, setPEAP->trustedRootCA,
1253 setPEAP->encrptype, setPEAP->peapVersion,
1254 setPEAP->innerEAP);
1255 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001256#else
1257
Dake Zhao0a832172015-01-06 11:08:47 -08001258 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1259 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001260
Dake Zhao0a832172015-01-06 11:08:47 -08001261 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
1262 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001263
Dake Zhao0a832172015-01-06 11:08:47 -08001264 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
1265 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001266
Dake Zhao0a832172015-01-06 11:08:47 -08001267 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
1268 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001269
Dake Zhao0a832172015-01-06 11:08:47 -08001270 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
1271 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001272
Dake Zhao0a832172015-01-06 11:08:47 -08001273 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
1274 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001275
Dake Zhao0a832172015-01-06 11:08:47 -08001276 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
1277 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001278
Dake Zhao0a832172015-01-06 11:08:47 -08001279 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1280 {
1281 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1282 }
1283 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1284 {
1285 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1286 }
1287 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1288 {
1289 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1290 }
1291 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1292 {
1293 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1294 }
1295 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1296 {
1297 // take all and device to pick one which is supported.
1298 }
1299 else
1300 {
1301 // ??
1302 }
1303 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001304
Dake Zhao0a832172015-01-06 11:08:47 -08001305 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
1306 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001307
Dake Zhao0a832172015-01-06 11:08:47 -08001308 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
1309 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001310
Dake Zhao0a832172015-01-06 11:08:47 -08001311 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1312 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001313#endif
1314
Dake Zhao0a832172015-01-06 11:08:47 -08001315 setPeapResp->status = STATUS_COMPLETE;
1316 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1317 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001318
Dake Zhao0a832172015-01-06 11:08:47 -08001319 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001320}
1321
1322/*
1323 * wfaStaSetUAPSD()
1324 * This is to set
1325 * 1. acBE
1326 * 2. acBK
1327 * 3. acVI
1328 * 4. acVO
1329 */
1330int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1331{
Dake Zhao0a832172015-01-06 11:08:47 -08001332 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001333#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001334 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1335 char *ifname = setUAPSD->intf;
1336 char tmpStr[10];
1337 char line[100];
1338 char *pathl="/etc/Wireless/RT61STA";
1339 BYTE acBE=1;
1340 BYTE acBK=1;
1341 BYTE acVO=1;
1342 BYTE acVI=1;
1343 BYTE APSDCapable;
1344 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001345
Dake Zhao0a832172015-01-06 11:08:47 -08001346 /*
1347 * A series of setting need to be done before doing WMM-PS
1348 * Additional steps of configuration may be needed.
1349 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001350
Dake Zhao0a832172015-01-06 11:08:47 -08001351 /*
1352 * bring down the interface
1353 */
1354 sprintf(gCmdStr, "ifconfig %s down",ifname);
1355 sret = system(gCmdStr);
1356 /*
1357 * Unload the Driver
1358 */
1359 sprintf(gCmdStr, "rmmod rt61");
1360 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001361#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001362 if(setUAPSD->acBE != 1)
1363 acBE=setUAPSD->acBE = 0;
1364 if(setUAPSD->acBK != 1)
1365 acBK=setUAPSD->acBK = 0;
1366 if(setUAPSD->acVO != 1)
1367 acVO=setUAPSD->acVO = 0;
1368 if(setUAPSD->acVI != 1)
1369 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001370#else
Dake Zhao0a832172015-01-06 11:08:47 -08001371 acBE=setUAPSD->acBE;
1372 acBK=setUAPSD->acBK;
1373 acVO=setUAPSD->acVO;
1374 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001375#endif
1376
Dake Zhao0a832172015-01-06 11:08:47 -08001377 APSDCapable = acBE||acBK||acVO||acVI;
1378 /*
1379 * set other AC parameters
1380 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001381
Dake Zhao0a832172015-01-06 11:08:47 -08001382 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1383 sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl);
1384 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001385
Dake Zhao0a832172015-01-06 11:08:47 -08001386 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
1387 sret = system(gCmdStr);
1388 pipe = popen("uname -r", "r");
1389 /* Read into line the output of uname*/
1390 fscanf(pipe,"%s",line);
1391 pclose(pipe);
1392
1393 /*
1394 * load the Driver
1395 */
1396 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
1397 sret = system(gCmdStr);
1398
1399 sprintf(gCmdStr, "ifconfig %s up",ifname);
1400 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001401#endif
1402
Dake Zhao0a832172015-01-06 11:08:47 -08001403 setUAPSDResp->status = STATUS_COMPLETE;
1404 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1405 *respLen = WFA_TLV_HDR_LEN + 4;
1406 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001407}
1408
1409int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1410{
Dake Zhao0a832172015-01-06 11:08:47 -08001411 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1412 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1413 dutCmdResponse_t *infoResp = &gGenericResp;
1414 /*a vendor can fill in the proper info or anything non-disclosure */
1415 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001416
Dake Zhao0a832172015-01-06 11:08:47 -08001417 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001418
Dake Zhao0a832172015-01-06 11:08:47 -08001419 if(devInfo->fw == 0)
1420 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1421 else
1422 {
1423 // Call internal API to pull the version ID */
Li Yin1ac40782015-09-23 20:38:07 +08001424 strncpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
Dake Zhao0a832172015-01-06 11:08:47 -08001425 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001426
Dake Zhao0a832172015-01-06 11:08:47 -08001427 infoResp->status = STATUS_COMPLETE;
1428 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1429 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001430
Dake Zhao0a832172015-01-06 11:08:47 -08001431 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001432
1433}
1434
1435/*
1436 * This funciton is to retrieve a list of interfaces and return
1437 * the list back to Agent control.
1438 * ********************************************************************
1439 * Note: We intend to make this WLAN interface name as a hardcode name.
1440 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001441 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1442 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001443 * likely is hardcoded just for CAPI command responses.
1444 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001445 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001446 */
1447int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1448{
Dake Zhao0a832172015-01-06 11:08:47 -08001449 dutCmdResponse_t *infoResp = &gGenericResp;
1450 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1451 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001452
Dake Zhao0a832172015-01-06 11:08:47 -08001453 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001454
Dake Zhao0a832172015-01-06 11:08:47 -08001455 switch(ifList->cmdsu.iftype)
1456 {
1457 case IF_80211:
1458 infoResp->status = STATUS_COMPLETE;
1459 ifListResp->iftype = IF_80211;
1460 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1461 strcpy(ifListResp->ifs[1], "NULL");
1462 strcpy(ifListResp->ifs[2], "NULL");
1463 break;
1464 case IF_ETH:
1465 infoResp->status = STATUS_COMPLETE;
1466 ifListResp->iftype = IF_ETH;
1467 strcpy(ifListResp->ifs[0], "eth0");
1468 strcpy(ifListResp->ifs[1], "NULL");
1469 strcpy(ifListResp->ifs[2], "NULL");
1470 break;
1471 default:
1472 {
1473 infoResp->status = STATUS_ERROR;
1474 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1475 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001476
Dake Zhao0a832172015-01-06 11:08:47 -08001477 return WFA_SUCCESS;
1478 }
1479 }
1480
1481 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1482 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1483
1484 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001485}
1486
1487int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1488{
Dake Zhao0a832172015-01-06 11:08:47 -08001489 dutCmdResponse_t *debugResp = &gGenericResp;
1490 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001491
Dake Zhao0a832172015-01-06 11:08:47 -08001492 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001493
Dake Zhao0a832172015-01-06 11:08:47 -08001494 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1495 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1496 else
1497 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001498
Dake Zhao0a832172015-01-06 11:08:47 -08001499 debugResp->status = STATUS_COMPLETE;
1500 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1501 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001502
1503
Dake Zhao0a832172015-01-06 11:08:47 -08001504 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001505}
1506
1507
1508/*
1509 * wfaStaGetBSSID():
1510 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001511 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001512int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1513{
Dake Zhao0a832172015-01-06 11:08:47 -08001514 char string[64];
1515 char *str;
1516 FILE *tmpfd;
1517 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001518
Dake Zhao0a832172015-01-06 11:08:47 -08001519 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1520 /* retrieve the BSSID */
1521 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001522
Dake Zhao0a832172015-01-06 11:08:47 -08001523 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001524
Dake Zhao0a832172015-01-06 11:08:47 -08001525 tmpfd = fopen("/tmp/bssid.txt", "r+");
1526 if(tmpfd == NULL)
1527 {
1528 bssidResp->status = STATUS_ERROR;
1529 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1530 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001531
Dake Zhao0a832172015-01-06 11:08:47 -08001532 DPRINT_ERR(WFA_ERR, "file open failed\n");
1533 return WFA_FAILURE;
1534 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001535
Dake Zhao0a832172015-01-06 11:08:47 -08001536 for(;;)
1537 {
1538 if(fscanf(tmpfd, "%s", string) == EOF)
1539 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001540 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001541 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001542 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001543 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001544
Dake Zhao0a832172015-01-06 11:08:47 -08001545 if(strncmp(string, "bssid", 5) == 0)
1546 {
1547 str = strtok(string, "=");
1548 str = strtok(NULL, "=");
1549 if(str != NULL)
1550 {
1551 strcpy(bssidResp->cmdru.bssid, str);
1552 bssidResp->status = STATUS_COMPLETE;
1553 break;
1554 }
1555 }
1556 }
1557
1558 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1559 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1560
1561 fclose(tmpfd);
1562 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001563}
1564
1565/*
1566 * wfaStaSetIBSS()
1567 * This is to set
1568 * 1. ssid
1569 * 2. channel
1570 * 3. encrypType - none or wep
1571 * optional
1572 * 4. key1
1573 * 5. key2
1574 * 6. key3
1575 * 7. key4
1576 * 8. activeIndex - 1, 2, 3, or 4
1577 */
1578int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1579{
Dake Zhao0a832172015-01-06 11:08:47 -08001580 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1581 dutCmdResponse_t *setIbssResp = &gGenericResp;
1582 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001583
Dake Zhao0a832172015-01-06 11:08:47 -08001584 /*
1585 * disable the network first
1586 */
1587 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
1588 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001589
Dake Zhao0a832172015-01-06 11:08:47 -08001590 /*
1591 * set SSID
1592 */
1593 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
1594 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001595
Dake Zhao0a832172015-01-06 11:08:47 -08001596 /*
1597 * Set channel for IBSS
1598 */
1599 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
1600 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001601
Dake Zhao0a832172015-01-06 11:08:47 -08001602 /*
1603 * Tell the supplicant for IBSS mode (1)
1604 */
1605 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
1606 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001607
Dake Zhao0a832172015-01-06 11:08:47 -08001608 /*
1609 * set Key management to NONE (NO WPA) for plaintext or WEP
1610 */
1611 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
1612 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001613
Dake Zhao0a832172015-01-06 11:08:47 -08001614 if(setIBSS->encpType == 1)
1615 {
1616 for(i=0; i<4; i++)
1617 {
1618 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1619 {
1620 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1621 setIBSS->intf, i, setIBSS->keys[i]);
1622 sret = system(gCmdStr);
1623 }
1624 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001625
Dake Zhao0a832172015-01-06 11:08:47 -08001626 i = setIBSS->activeKeyIdx;
1627 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1628 {
1629 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1630 setIBSS->intf, setIBSS->activeKeyIdx);
1631 sret = system(gCmdStr);
1632 }
1633 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001634
Dake Zhao0a832172015-01-06 11:08:47 -08001635 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
1636 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001637
Dake Zhao0a832172015-01-06 11:08:47 -08001638 setIbssResp->status = STATUS_COMPLETE;
1639 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1640 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001641
Dake Zhao0a832172015-01-06 11:08:47 -08001642 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001643}
1644
1645/*
1646 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001647 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001648 * adhoc)
1649 * Input parameters:
1650 * 1. I/F
1651 * 2. ssid
1652 * 3. mode adhoc or managed
1653 * 4. encType
1654 * 5. channel
1655 * 6. key(s)
1656 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001657 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001658int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1659{
Dake Zhao0a832172015-01-06 11:08:47 -08001660 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1661 dutCmdResponse_t *SetModeResp = &gGenericResp;
1662 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001663
Dake Zhao0a832172015-01-06 11:08:47 -08001664 /*
1665 * bring down the interface
1666 */
1667 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
1668 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001669
Dake Zhao0a832172015-01-06 11:08:47 -08001670 /*
1671 * distroy the interface
1672 */
1673 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
1674 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001675
1676
Dake Zhao0a832172015-01-06 11:08:47 -08001677 /*
1678 * re-create the interface with the given mode
1679 */
1680 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001681 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001682 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001683 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1684
Dake Zhao0a832172015-01-06 11:08:47 -08001685 sret = system(gCmdStr);
1686 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001687 {
Dake Zhao0a832172015-01-06 11:08:47 -08001688 int j = setmode->activeKeyIdx;
1689 for(i=0; i<4; i++)
1690 {
1691 if(setmode->keys[i][0] != '\0')
1692 {
1693 sprintf(gCmdStr, "iwconfig %s key s:%s",
1694 setmode->intf, setmode->keys[i]);
1695 sret = system(gCmdStr);
1696 }
1697 /* set active key */
1698 if(setmode->keys[j][0] != '\0')
1699 sprintf(gCmdStr, "iwconfig %s key s:%s",
1700 setmode->intf, setmode->keys[j]);
1701 sret = system(gCmdStr);
1702 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001703
1704 }
Dake Zhao0a832172015-01-06 11:08:47 -08001705 /*
1706 * Set channel for IBSS
1707 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001708 if(setmode->channel)
1709 {
Dake Zhao0a832172015-01-06 11:08:47 -08001710 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
1711 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001712 }
1713
1714
Dake Zhao0a832172015-01-06 11:08:47 -08001715 /*
1716 * set SSID
1717 */
1718 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
1719 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001720
Dake Zhao0a832172015-01-06 11:08:47 -08001721 /*
1722 * bring up the interface
1723 */
1724 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
1725 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001726
Dake Zhao0a832172015-01-06 11:08:47 -08001727 SetModeResp->status = STATUS_COMPLETE;
1728 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1729 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001730
Dake Zhao0a832172015-01-06 11:08:47 -08001731 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001732}
1733
1734int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1735{
Dake Zhao0a832172015-01-06 11:08:47 -08001736 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1737 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001738
Dake Zhao0a832172015-01-06 11:08:47 -08001739 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
1740 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001741
1742
Dake Zhao0a832172015-01-06 11:08:47 -08001743 SetPSResp->status = STATUS_COMPLETE;
1744 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1745 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001746
Dake Zhao0a832172015-01-06 11:08:47 -08001747 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001748}
1749
1750int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1751{
Dake Zhao0a832172015-01-06 11:08:47 -08001752 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1753 dutCmdResponse_t *upLoadResp = &gGenericResp;
1754 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001755
Dake Zhao0a832172015-01-06 11:08:47 -08001756 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1757 {
1758 int rbytes;
1759 /*
1760 * if asked for the first packet, always to open the file
1761 */
1762 if(upload->next == 1)
1763 {
1764 if(e2efp != NULL)
1765 {
1766 fclose(e2efp);
1767 e2efp = NULL;
1768 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001769
Dake Zhao0a832172015-01-06 11:08:47 -08001770 e2efp = fopen(e2eResults, "r");
1771 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001772
Dake Zhao0a832172015-01-06 11:08:47 -08001773 if(e2efp == NULL)
1774 {
1775 upLoadResp->status = STATUS_ERROR;
1776 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1777 *respLen = WFA_TLV_HDR_LEN + 4;
1778 return WFA_FAILURE;
1779 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001780
Dake Zhao0a832172015-01-06 11:08:47 -08001781 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001782
Dake Zhao0a832172015-01-06 11:08:47 -08001783 if(rbytes < 256)
1784 {
1785 /*
1786 * this means no more bytes after this read
1787 */
1788 upld->seqnum = 0;
1789 fclose(e2efp);
1790 e2efp=NULL;
1791 }
1792 else
1793 {
1794 upld->seqnum = upload->next;
1795 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001796
Dake Zhao0a832172015-01-06 11:08:47 -08001797 upld->nbytes = rbytes;
1798
1799 upLoadResp->status = STATUS_COMPLETE;
1800 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1801 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1802 }
1803 else
1804 {
1805 upLoadResp->status = STATUS_ERROR;
1806 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1807 *respLen = WFA_TLV_HDR_LEN + 4;
1808 }
1809
1810 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001811}
1812/*
1813 * wfaStaSetWMM()
1814 * TO be ported on a specific plaform for the DUT
1815 * This is to set the WMM related parameters at the DUT.
1816 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1817 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1818 */
1819int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1820{
1821#ifdef WFA_WMM_AC
1822 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1823 char *ifname = setwmm->intf;
1824 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001825
1826 switch(setwmm->group)
1827 {
1828 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001829 if (setwmm->send_trig)
1830 {
1831 int Sockfd;
1832 struct sockaddr_in psToAddr;
1833 unsigned int TxMsg[512];
1834
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001835 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001836 memset(&psToAddr, 0, sizeof(psToAddr));
1837 psToAddr.sin_family = AF_INET;
1838 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1839 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001840
1841
Dake Zhao0a832172015-01-06 11:08:47 -08001842 switch (setwmm->trig_ac)
1843 {
1844 case WMMAC_AC_VO:
1845 wfaTGSetPrio(Sockfd, 7);
1846 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1847 printf("\r\nSending AC_VO trigger packet\n");
1848 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001849
Dake Zhao0a832172015-01-06 11:08:47 -08001850 case WMMAC_AC_VI:
1851 wfaTGSetPrio(Sockfd, 5);
1852 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1853 printf("\r\nSending AC_VI trigger packet\n");
1854 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001855
Dake Zhao0a832172015-01-06 11:08:47 -08001856 case WMMAC_AC_BK:
1857 wfaTGSetPrio(Sockfd, 2);
1858 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1859 printf("\r\nSending AC_BK trigger packet\n");
1860 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001861
Dake Zhao0a832172015-01-06 11:08:47 -08001862 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001863 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001864 wfaTGSetPrio(Sockfd, 0);
1865 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1866 printf("\r\nSending AC_BE trigger packet\n");
1867 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001868 }
1869
Dake Zhao0a832172015-01-06 11:08:47 -08001870 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1871 sizeof(struct sockaddr));
1872 close(Sockfd);
1873 usleep(1000000);
1874 }
1875 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001876 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001877 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001878 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1879 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1880 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1881 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1882 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1883 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1884 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1885 setwmm->actions.addts.dialog_token,
1886 setwmm->actions.addts.tspec.tsinfo.TID,
1887 setwmm->actions.addts.tspec.tsinfo.direction,
1888 setwmm->actions.addts.tspec.tsinfo.PSB,
1889 setwmm->actions.addts.tspec.tsinfo.UP,
1890 setwmm->actions.addts.tspec.tsinfo.infoAck,
1891 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1892 setwmm->actions.addts.tspec.Fixed,
1893 setwmm->actions.addts.tspec.size,
1894 setwmm->actions.addts.tspec.maxsize,
1895 setwmm->actions.addts.tspec.min_srvc,
1896 setwmm->actions.addts.tspec.max_srvc,
1897 setwmm->actions.addts.tspec.inactivity,
1898 setwmm->actions.addts.tspec.suspension,
1899 setwmm->actions.addts.tspec.srvc_strt_tim,
1900 setwmm->actions.addts.tspec.mindatarate,
1901 setwmm->actions.addts.tspec.meandatarate,
1902 setwmm->actions.addts.tspec.peakdatarate,
1903 setwmm->actions.addts.tspec.burstsize,
1904 setwmm->actions.addts.tspec.delaybound,
1905 setwmm->actions.addts.tspec.PHYrate,
1906 setwmm->actions.addts.tspec.sba,
1907 setwmm->actions.addts.tspec.medium_time,
1908 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001909
Dake Zhao862c94b2014-12-08 14:35:35 -08001910 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001911
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001912 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001913 }
1914 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08001915 {
1916 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001917 }
1918
1919 setwmmResp->status = STATUS_COMPLETE;
1920 break;
1921
1922 case GROUP_WMMCONF:
1923 sprintf(gCmdStr, "iwconfig %s rts %d",
1924 ifname,setwmm->actions.config.rts_thr);
1925
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001926 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001927 sprintf(gCmdStr, "iwconfig %s frag %d",
1928 ifname,setwmm->actions.config.frag_thr);
1929
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001930 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001931 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1932 ifname, setwmm->actions.config.wmm);
1933
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001934 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001935 setwmmResp->status = STATUS_COMPLETE;
1936 break;
1937
1938 default:
1939 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1940 setwmmResp->status = STATUS_ERROR;
1941 break;
1942
1943 }
1944
1945 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1946 *respLen = WFA_TLV_HDR_LEN + 4;
1947#endif
1948
1949 return WFA_SUCCESS;
1950}
1951
1952int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1953{
Dake Zhao0a832172015-01-06 11:08:47 -08001954 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001955
Dake Zhao0a832172015-01-06 11:08:47 -08001956 /*
1957 * run your device to send NEIGREQ
1958 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001959
Dake Zhao0a832172015-01-06 11:08:47 -08001960 sendNeigReqResp->status = STATUS_COMPLETE;
1961 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
1962 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001963
Dake Zhao0a832172015-01-06 11:08:47 -08001964 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001965}
1966
1967int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1968{
1969 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
1970 char *ifname = setFAST->intf;
1971 dutCmdResponse_t *setEapFastResp = &gGenericResp;
1972
1973#ifdef WFA_NEW_CLI_FORMAT
1974 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08001975 setFAST->passwd, setFAST->pacFileName,
1976 setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001977 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001978#else
1979
1980 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001981 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001982
1983 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001984 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001985
1986 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001987 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001988
1989 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001990 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001991
1992 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
1993 {
1994 }
1995 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
1996 {
1997 }
1998 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
1999 {
Dake Zhao0a832172015-01-06 11:08:47 -08002000
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002001 }
2002 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2003 {
Dake Zhao0a832172015-01-06 11:08:47 -08002004 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002005 }
2006 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2007 {
Dake Zhao0a832172015-01-06 11:08:47 -08002008 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002009 }
2010 else
2011 {
Dake Zhao0a832172015-01-06 11:08:47 -08002012 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002013 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002014 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002015
2016 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002017 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002018
2019 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002020 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002021
2022 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002023 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002024
2025 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002026 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002027
2028 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002029 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002030
2031 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002032 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002033#endif
2034
2035 setEapFastResp->status = STATUS_COMPLETE;
2036 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2037 *respLen = WFA_TLV_HDR_LEN + 4;
2038
2039 return WFA_SUCCESS;
2040}
2041
2042int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2043{
2044 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2045 char *ifname = setAKA->intf;
2046 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2047
2048#ifdef WFA_NEW_CLI_FORMAT
2049 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002050 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002051#else
2052
2053 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002054 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002055
2056 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002057 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002058
2059 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2060 {
2061 }
2062 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2063 {
2064 }
2065 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2066 {
Dake Zhao0a832172015-01-06 11:08:47 -08002067
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002068 }
2069 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2070 {
Dake Zhao0a832172015-01-06 11:08:47 -08002071 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002072 }
2073 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2074 {
Dake Zhao0a832172015-01-06 11:08:47 -08002075 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002076 }
2077 else
2078 {
Dake Zhao0a832172015-01-06 11:08:47 -08002079 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002080 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002081 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002082
2083 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002084 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002085 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002086 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002087
2088 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002089 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002090
2091 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002092 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002093
2094 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002095 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002096
2097 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002098 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002099
2100 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002101 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002102#endif
2103
2104 setEapAkaResp->status = STATUS_COMPLETE;
2105 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2106 *respLen = WFA_TLV_HDR_LEN + 4;
2107
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002108 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002109}
2110
2111int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2112{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002113 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2114 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002115
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002116 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002117
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002118 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2119 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002120
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002121 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2122 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002123
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002124 setSystimeResp->status = STATUS_COMPLETE;
2125 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2126 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002127
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002128 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002129}
2130
2131#ifdef WFA_STA_TB
2132int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2133{
Dake Zhao0a832172015-01-06 11:08:47 -08002134 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2135 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2136 BYTE presetDone = 1;
2137 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002138 char cmdStr[128];
2139 char string[256];
2140 FILE *tmpfd = NULL;
2141 long val;
2142 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002143
Dake Zhao0a832172015-01-06 11:08:47 -08002144 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002145
Ray Wangd11ca032015-05-29 18:25:46 -07002146 if (presetParams->supplicant == eWpaSupplicant)
2147 {
2148 st = access("/tmp/processid.txt", F_OK);
2149 if (st != -1)
2150 {
2151 st = remove("/tmp/processid.txt");
2152 }
2153
2154 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
2155 st = system(cmdStr);
2156
2157 tmpfd = fopen("/tmp/processid.txt", "r+");
2158 if (tmpfd == NULL)
2159 {
2160 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2161 return WFA_FAILURE;
2162 }
2163
2164 for (;;)
2165 {
2166 if (fgets(string, 256, tmpfd) == NULL)
2167 break;
2168
2169 errno = 0;
2170 val = strtol(string, &endptr, 10);
2171 if (errno != 0 && val == 0)
2172 {
2173 DPRINT_ERR(WFA_ERR, "strtol error\n");
2174 return WFA_FAILURE;
2175 }
2176
2177 if (endptr == string)
2178 {
2179 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2180 }
2181
2182 presetDone = 1;
2183 }
2184 }
2185
Dake Zhao0a832172015-01-06 11:08:47 -08002186 if(presetParams->wmmFlag)
2187 {
2188 st = wfaExecuteCLI(gCmdStr);
2189 switch(st)
2190 {
2191 case 0:
2192 presetDone = 1;
2193 break;
2194 case 1:
2195 presetDone = 0;
2196 break;
2197 case 2:
2198 presetDone = 0;
2199 break;
2200 }
2201 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002202
Dake Zhao0a832172015-01-06 11:08:47 -08002203 if(presetParams->modeFlag != 0)
2204 {
2205 switch(presetParams->wirelessMode)
2206 {
2207 default:
2208 printf("other mode does not need to support\n");
2209 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002210
Dake Zhao0a832172015-01-06 11:08:47 -08002211 st = wfaExecuteCLI(gCmdStr);
2212 switch(st)
2213 {
2214 case 0:
2215 presetDone = 1;
2216 break;
2217 case 1:
2218 presetDone = 0;
2219 case 2:
2220 presetDone = 0;
2221 break;
2222 }
2223 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002224
2225
Dake Zhao0a832172015-01-06 11:08:47 -08002226 if(presetParams->psFlag)
2227 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002228
Dake Zhao0a832172015-01-06 11:08:47 -08002229 printf("%s\n", gCmdStr);
2230 sret = system(gCmdStr);
2231 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002232
Dake Zhao0a832172015-01-06 11:08:47 -08002233 /************the followings are used for Voice Enterprise **************/
2234 if(presetParams->program == PROG_TYPE_VENT)
2235 {
2236 if(presetParams->ftoa == eEnable)
2237 {
2238 // enable Fast BSS Transition Over the Air
2239 }
2240 else
2241 {
2242 // disable Fast BSS Transition Over the Air
2243 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002244
Dake Zhao0a832172015-01-06 11:08:47 -08002245 if(presetParams->ftds == eEnable)
2246 {
2247 // enable Fast BSS Transition Over the DS
2248 }
2249 else
2250 {
2251 // disable Fast BSS Transition Over the DS
2252 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002253
Dake Zhao0a832172015-01-06 11:08:47 -08002254 if(presetParams->activescan == eEnable)
2255 {
2256 // Enable Active Scan on STA
2257 }
2258 else
2259 {
2260 // disable Active Scan on STA
2261 }
2262 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002263
Dake Zhao0a832172015-01-06 11:08:47 -08002264 /************the followings are used for Wi-Fi Display *************/
2265 if(presetParams->program == PROG_TYPE_WFD)
2266 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002267
Dake Zhao0a832172015-01-06 11:08:47 -08002268 if(presetParams->tdlsFlag)
2269 {
2270 // enable / disable tdls based on tdls
2271 }
2272 if(presetParams->wfdDevTypeFlag)
2273 {
2274 // set WFD device type to source/sink/dual based on wfdDevType
2275 }
2276 if(presetParams->wfdUibcGenFlag)
2277 {
2278 // enable / disable the feature
2279 }
2280 if(presetParams->wfdUibcHidFlag)
2281 {
2282 // enable / disable feature
2283 }
2284 if(presetParams->wfdUiInputFlag)
2285 {
2286 // set the UI input as mentioned
2287 }
2288 if(presetParams->wfdHdcpFlag)
2289 {
2290 // enable / disable feature
2291 }
2292 if(presetParams->wfdFrameSkipFlag)
2293 {
2294 // enable / disable feature
2295 }
2296 if(presetParams->wfdAvChangeFlag)
2297 {
2298 // enable / disable feature
2299 }
2300 if(presetParams->wfdStandByFlag)
2301 {
2302 // enable / disable feature
2303 }
2304 if(presetParams->wfdInVideoFlag)
2305 {
2306 // select the input vide as protecteed or non-protetcted or protected audio
2307 // or unprotected audio etc.
2308 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002309
Dake Zhao0a832172015-01-06 11:08:47 -08002310 if(presetParams->wfdVideoFmatFlag)
2311 {
2312 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002313
Dake Zhao0a832172015-01-06 11:08:47 -08002314 //switch(presetParams->wfdVideoFmt )
2315 //{
2316 // case e640x480p60:
2317 // ;
2318 // default:
2319 // set the mandatory
2320 // }
2321 }
2322 if(presetParams->wfdAudioFmatFlag)
2323 {
2324 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002325
Dake Zhao0a832172015-01-06 11:08:47 -08002326 //switch(presetParams->wfdAudioFmt )
2327 //{
2328 // case eMandatoryAudioMode:
2329 // ;
2330 // case eDefaultAudioMode:
2331 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002332
Dake Zhao0a832172015-01-06 11:08:47 -08002333 // default:
2334 // set the mandatory
2335 // }
2336 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002337
Dake Zhao0a832172015-01-06 11:08:47 -08002338 if(presetParams->wfdI2cFlag)
2339 {
2340 // enable / disable feature
2341 }
2342 if(presetParams->wfdVideoRecoveryFlag)
2343 {
2344 // enable / disable feature
2345 }
2346 if(presetParams->wfdPrefDisplayFlag)
2347 {
2348 // enable / disable feature
2349 }
2350 if(presetParams->wfdServiceDiscoveryFlag)
2351 {
2352 // enable / disable feature
2353 }
2354 if(presetParams->wfd3dVideoFlag)
2355 {
2356 // enable / disable feature
2357 }
2358 if(presetParams->wfdMultiTxStreamFlag)
2359 {
2360 // enable / disable feature
2361 }
2362 if(presetParams->wfdTimeSyncFlag)
2363 {
2364 // enable / disable feature
2365 }
2366 if(presetParams->wfdEDIDFlag)
2367 {
2368 // enable / disable feature
2369 }
2370 if(presetParams->wfdUIBCPrepareFlag)
2371 {
2372 // Provdes information to start valid WFD session to check UIBC operation.
2373 }
2374 if(presetParams->wfdCoupledCapFlag)
2375 {
2376 // enable / disable feature
2377 }
2378 if(presetParams->wfdOptionalFeatureFlag)
2379 {
2380 // disable all program specific optional features
2381 }
2382 if(presetParams->wfdSessionAvailFlag)
2383 {
2384 // enable / disable session available bit
2385 }
2386 if(presetParams->wfdDeviceDiscoverabilityFlag)
2387 {
2388 // enable / disable feature
2389 }
2390 }
2391
Dake Zhao655efed2015-03-11 17:39:13 -07002392 if(presetParams->program == PROG_TYPE_WFDS)
2393 {
2394
2395 if(presetParams->wfdsType == eAcceptPD)
2396 {
2397 // preset to accept PD request
2398 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2399 {
2400 // use presetParams->wfdsConnectionCapability and set role accordingly
2401 }
2402
2403 }
2404 if(presetParams->wfdsType == eRejectPD)
2405 {
2406 // preset to Reject PD request
2407 }
2408 if(presetParams->wfdsType == eIgnorePD)
2409 {
2410 // preset to Ignore PD request
2411 }
2412 if(presetParams->wfdsType == eRejectSession)
2413 {
2414 // preset to reject Session request
2415 }
2416
2417 }
2418
2419 if (presetDone)
2420 {
2421 PresetParamsResp->status = STATUS_COMPLETE;
2422 }
2423 else
2424 {
2425 PresetParamsResp->status = STATUS_INVALID;
2426 }
Dake Zhao0a832172015-01-06 11:08:47 -08002427
2428 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2429 *respLen = WFA_TLV_HDR_LEN + 4;
2430
2431 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002432}
2433
2434int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2435{
2436 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2437
2438 v11nParamsResp->status = STATUS_COMPLETE;
2439 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2440 *respLen = WFA_TLV_HDR_LEN + 4;
2441 return WFA_SUCCESS;
2442}
2443int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2444{
2445 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2446
2447 staWirelessResp->status = STATUS_COMPLETE;
2448 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2449 *respLen = WFA_TLV_HDR_LEN + 4;
2450 return WFA_SUCCESS;
2451}
2452
2453int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2454{
2455 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2456
2457 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2458 *respLen = WFA_TLV_HDR_LEN + 4;
2459 return WFA_SUCCESS;
2460}
2461
2462int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2463{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002464 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002465
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002466 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2467 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002468
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002469 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002470}
2471
2472int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2473{
2474 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2475
2476 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2477 *respLen = WFA_TLV_HDR_LEN + 4;
2478
2479 return WFA_SUCCESS;
2480
2481}
2482
2483int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2484{
Dake Zhao0a832172015-01-06 11:08:47 -08002485 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2486 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002487
2488
Dake Zhao0a832172015-01-06 11:08:47 -08002489 // need to make your own command available for this, here is only an example
2490 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2491 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002492
Dake Zhao0a832172015-01-06 11:08:47 -08002493 ResetResp->status = STATUS_COMPLETE;
2494 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2495 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002496
Dake Zhao0a832172015-01-06 11:08:47 -08002497 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002498}
2499
2500#else
2501
2502int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2503{
2504 dutCmdResponse_t *staCmdResp = &gGenericResp;
2505
2506 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2507 *respLen = WFA_TLV_HDR_LEN + 4;
2508
2509 return WFA_SUCCESS;
2510}
2511#endif
2512
2513/*
2514 * This is used to send a frame or action frame
2515 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002516int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002517{
Dake Zhao0a832172015-01-06 11:08:47 -08002518 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2519 /* uncomment it if needed */
2520 // char *ifname = cmd->intf;
2521 dutCmdResponse_t *devSendResp = &gGenericResp;
2522 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002523
Dake Zhao0a832172015-01-06 11:08:47 -08002524 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2525 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002526
Dake Zhao0a832172015-01-06 11:08:47 -08002527 switch(sf->program)
2528 {
2529 case PROG_TYPE_PMF:
2530 {
2531 pmfFrame_t *pmf = &sf->frameType.pmf;
2532 switch(pmf->eFrameName)
2533 {
2534 case PMF_TYPE_DISASSOC:
2535 {
2536 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002537
Dake Zhao0a832172015-01-06 11:08:47 -08002538 }
2539 break;
2540 case PMF_TYPE_DEAUTH:
2541 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002542
Dake Zhao0a832172015-01-06 11:08:47 -08002543 }
2544 break;
2545 case PMF_TYPE_SAQUERY:
2546 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002547
Dake Zhao0a832172015-01-06 11:08:47 -08002548 }
2549 break;
2550 case PMF_TYPE_AUTH:
2551 {
2552 }
2553 break;
2554 case PMF_TYPE_ASSOCREQ:
2555 {
2556 }
2557 break;
2558 case PMF_TYPE_REASSOCREQ:
2559 {
2560 }
2561 break;
2562 }
2563 }
2564 break;
2565 case PROG_TYPE_TDLS:
2566 {
2567 tdlsFrame_t *tdls = &sf->frameType.tdls;
2568 switch(tdls->eFrameName)
2569 {
2570 case TDLS_TYPE_DISCOVERY:
2571 /* use the peer mac address to send the frame */
2572 break;
2573 case TDLS_TYPE_SETUP:
2574 break;
2575 case TDLS_TYPE_TEARDOWN:
2576 break;
2577 case TDLS_TYPE_CHANNELSWITCH:
2578 break;
2579 case TDLS_TYPE_NULLFRAME:
2580 break;
2581 }
2582 }
2583 break;
2584 case PROG_TYPE_VENT:
2585 {
2586 ventFrame_t *vent = &sf->frameType.vent;
2587 switch(vent->type)
2588 {
2589 case VENT_TYPE_NEIGREQ:
2590 break;
2591 case VENT_TYPE_TRANSMGMT:
2592 break;
2593 }
2594 }
2595 break;
2596 case PROG_TYPE_WFD:
2597 {
2598 wfdFrame_t *wfd = &sf->frameType.wfd;
2599 switch(wfd->eframe)
2600 {
2601 case WFD_FRAME_PRBREQ:
2602 {
2603 /* send probe req */
2604 }
2605 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002606
Dake Zhao0a832172015-01-06 11:08:47 -08002607 case WFD_FRAME_PRBREQ_TDLS_REQ:
2608 {
2609 /* send tunneled tdls probe req */
2610 }
2611 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002612
Dake Zhao0a832172015-01-06 11:08:47 -08002613 case WFD_FRAME_11V_TIMING_MSR_REQ:
2614 {
2615 /* send 11v timing mearurement request */
2616 }
2617 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002618
Dake Zhao0a832172015-01-06 11:08:47 -08002619 case WFD_FRAME_RTSP:
2620 {
2621 /* send WFD RTSP messages*/
2622 // fetch the type of RTSP message and send it.
2623 switch(wfd->eRtspMsgType)
2624 {
2625 case WFD_RTSP_PAUSE:
2626 break;
2627 case WFD_RTSP_PLAY:
2628 //send RTSP PLAY
2629 break;
2630 case WFD_RTSP_TEARDOWN:
2631 //send RTSP TEARDOWN
2632 break;
2633 case WFD_RTSP_TRIG_PAUSE:
2634 //send RTSP TRIGGER PAUSE
2635 break;
2636 case WFD_RTSP_TRIG_PLAY:
2637 //send RTSP TRIGGER PLAY
2638 break;
2639 case WFD_RTSP_TRIG_TEARDOWN:
2640 //send RTSP TRIGGER TEARDOWN
2641 break;
2642 case WFD_RTSP_SET_PARAMETER:
2643 //send RTSP SET PARAMETER
2644 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2645 {
2646 //send RTSP SET PARAMETER message for UIBC keyboard
2647 }
2648 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2649 {
2650 //send RTSP SET PARAMETER message for UIBC Mouse
2651 }
2652 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2653 {
2654 //send RTSP SET PARAMETER message Capability re-negotiation
2655 }
2656 else if (wfd->eSetParams == WFD_STANDBY)
2657 {
2658 //send RTSP SET PARAMETER message for standby
2659 }
2660 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2661 {
2662 //send RTSP SET PARAMETER message for UIBC settings enable
2663 }
2664 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2665 {
2666 //send RTSP SET PARAMETER message for UIBC settings disable
2667 }
2668 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2669 {
2670 //send RTSP SET PARAMETER message for route audio
2671 }
2672 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2673 {
2674 //send RTSP SET PARAMETER message for 3D video parameters
2675 }
2676 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2677 {
2678 //send RTSP SET PARAMETER message for 2D video parameters
2679 }
2680 break;
Dake Zhao97708202014-11-26 13:59:04 -08002681 }
Dake Zhao0a832172015-01-06 11:08:47 -08002682 }
2683 break;
2684 }
2685 }
2686 break;
2687 /* not need to support HS2 release 1, due to very short time period */
2688 case PROG_TYPE_HS2_R2:
2689 {
2690 /* type of frames */
2691 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2692 switch(hs2->eframe)
2693 {
2694 case HS2_FRAME_ANQPQuery:
2695 {
Dake Zhao97708202014-11-26 13:59:04 -08002696
Dake Zhao0a832172015-01-06 11:08:47 -08002697 }
2698 break;
2699 case HS2_FRAME_DLSRequest:
2700 {
Dake Zhao97708202014-11-26 13:59:04 -08002701
Dake Zhao0a832172015-01-06 11:08:47 -08002702 }
2703 break;
2704 case HS2_FRAME_GARPReq:
2705 {
Dake Zhao97708202014-11-26 13:59:04 -08002706
Dake Zhao0a832172015-01-06 11:08:47 -08002707 }
2708 break;
2709 case HS2_FRAME_GARPRes:
2710 {
2711 }
2712 break;
2713 case HS2_FRAME_NeighAdv:
2714 {
2715 }
2716 case HS2_FRAME_ARPProbe:
2717 {
2718 }
2719 case HS2_FRAME_ARPAnnounce:
2720 {
Dake Zhao97708202014-11-26 13:59:04 -08002721
Dake Zhao0a832172015-01-06 11:08:47 -08002722 }
2723 break;
2724 case HS2_FRAME_NeighSolicitReq:
2725 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002726
Dake Zhao0a832172015-01-06 11:08:47 -08002727 }
2728 break;
2729 case HS2_FRAME_ARPReply:
2730 {
2731
2732 }
2733 break;
2734 }
2735
2736 }/* PROG_TYPE_HS2-R2 */
2737 case PROG_TYPE_GEN:
2738 {
2739 /* General frames */
2740 }
2741
2742
2743 }
2744 devSendResp->status = STATUS_COMPLETE;
2745 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2746 *respLen = WFA_TLV_HDR_LEN + 4;
2747
2748 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002749}
2750
2751/*
2752 * This is used to set a temporary MAC address of an interface
2753 */
2754int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2755{
Dake Zhao0a832172015-01-06 11:08:47 -08002756 // Uncomment it if needed
2757 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2758 // char *ifname = cmd->intf;
2759 dutCmdResponse_t *staCmdResp = &gGenericResp;
2760 // Uncomment it if needed
2761 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002762
Dake Zhao0a832172015-01-06 11:08:47 -08002763 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2764 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002765
Dake Zhao0a832172015-01-06 11:08:47 -08002766 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002767}
2768
2769
2770int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2771{
2772 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2773 //char *intf = disc->intf;
2774 dutCmdResponse_t *staDiscResp = &gGenericResp;
2775
2776 // stop the supplicant
2777
2778 staDiscResp->status = STATUS_COMPLETE;
2779
2780 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2781 *respLen = WFA_TLV_HDR_LEN + 4;
2782
2783 return WFA_SUCCESS;
2784}
2785
2786/* Execute CLI, read the status from Environment variable */
2787int wfaExecuteCLI(char *CLI)
2788{
Dake Zhao0a832172015-01-06 11:08:47 -08002789 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002790
Dake Zhao0a832172015-01-06 11:08:47 -08002791 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002792
Dake Zhao0a832172015-01-06 11:08:47 -08002793 retstr = getenv("WFA_CLI_STATUS");
2794 printf("cli status %s\n", retstr);
2795 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002796}
2797
2798/* Supporting Functions */
2799
2800void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2801{
Dake Zhao97708202014-11-26 13:59:04 -08002802 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002803 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002804// char *addr = staPing->dipaddr;
2805#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002806 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002807 char bflag[] = "-b";
2808 char *tmpstr;
2809 int inum=0;
2810#else
2811 char bflag[] = " ";
2812#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002813
Ray Wang9b47f362014-03-19 16:51:10 -07002814 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002815
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002816#ifdef WFA_PC_CONSOLE
2817
Dake Zhao353c55e2015-07-20 18:54:45 -07002818 printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d",streamid);
2819
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002820 strcpy(addr,staPing->dipaddr);
Dake Zhao353c55e2015-07-20 18:54:45 -07002821 printf("\nCS :the addr is %s ",addr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002822 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2823 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002824 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002825 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002826 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002827 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002828 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002829 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002830 tmpstr = strtok(addr, ".");
2831 inum = atoi(tmpstr);
2832
2833 printf("interval %f\n", *interval);
2834
2835 if(inum >= 224 && inum <= 239) // multicast
2836 {
2837 }
2838 else // if not MC, check if it is BC address
2839 {
2840 printf("\nCS :Inside the BC address BLOCK");
2841 printf("\nCS :the inum %d",inum);
2842 strtok(NULL, ".");
2843 //strtok(NULL, ".");
2844 tmpstr = strtok(NULL, ".");
2845 printf("tmpstr %s\n", tmpstr);
2846 inum = atoi(tmpstr);
2847 printf("\nCS : The string is %s",tmpstr);
2848 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002849 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002850 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002851 }
2852#endif
Dake Zhao97708202014-11-26 13:59:04 -08002853 if ( staPing->dscp >= 0)
2854 {
Dake Zhao0a832172015-01-06 11:08:47 -08002855 tos= convertDscpToTos(staPing->dscp);
2856 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002857 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2858 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002859 printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n",streamid, staPing->iptype);
Dake Zhao97708202014-11-26 13:59:04 -08002860 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002861
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002862 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002863 {
Dake Zhao97708202014-11-26 13:59:04 -08002864 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002865 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",
2866 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002867 else
Dake Zhao0a832172015-01-06 11:08:47 -08002868 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",
2869 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002870 sret = system(cmdStr);
2871 printf("\nCS : The command string is %s",cmdStr);
2872 }
2873 else
2874 {
Dake Zhao97708202014-11-26 13:59:04 -08002875 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002876 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",
2877 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002878 else
Dake Zhao0a832172015-01-06 11:08:47 -08002879 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",
2880 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002881 sret = system(cmdStr);
2882 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002883 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002884 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002885 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002886 printf("\nCS : The command string is %s",cmdStr);
2887
2888}
2889
2890int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2891{
2892 char strout[256];
2893 FILE *tmpfile = NULL;
2894 char cmdStr[128];
Dake Zhao353c55e2015-07-20 18:54:45 -07002895 printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002896 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002897 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002898
2899 printf("\nCS : The command string is %s",cmdStr);
2900
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002901 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002902
2903 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002904 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002905
2906 printf("\nCS : The command string is %s",cmdStr);
2907
2908 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2909
2910 if(tmpfile == NULL)
2911 {
2912 return WFA_FAILURE;
2913 }
2914
2915 if(fscanf(tmpfile, "%s", strout) != EOF)
2916 {
2917 if(*strout == '\0')
2918 {
2919 stpResp->cmdru.pingStp.sendCnt = 0;
2920 }
2921
2922 else
2923 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2924 }
2925
Dake Zhao353c55e2015-07-20 18:54:45 -07002926 printf("\nwfaStopPing after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002927
2928
2929 if(fscanf(tmpfile, "%s", strout) != EOF)
2930 {
2931 if(*strout == '\0')
2932 {
2933 stpResp->cmdru.pingStp.repliedCnt = 0;
2934 }
2935 else
2936 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2937 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002938 printf("wfaStopPing after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002939
2940 fclose(tmpfile);
2941
2942 return WFA_SUCCESS;
2943}
2944
Ankur Vachhanic485b712012-02-15 23:29:49 +00002945/*
Dake Zhao0a832172015-01-06 11:08:47 -08002946 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002947 */
2948int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2949{
Dake Zhao0a832172015-01-06 11:08:47 -08002950 dutCmdResponse_t infoResp;
2951 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002952
Dake Zhao0a832172015-01-06 11:08:47 -08002953 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002954
Dake Zhao0a832172015-01-06 11:08:47 -08002955 // Fetch the device ID and store into infoResp->cmdru.devid
2956 //strcpy(infoResp->cmdru.devid, str);
2957 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002958
Dake Zhao0a832172015-01-06 11:08:47 -08002959 infoResp.status = STATUS_COMPLETE;
2960 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2961 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2962
2963 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002964}
2965
2966
2967
2968/*
Dake Zhao0a832172015-01-06 11:08:47 -08002969 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002970 */
2971int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2972{
Dake Zhao0a832172015-01-06 11:08:47 -08002973 dutCmdResponse_t infoResp;
2974 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00002975
Dake Zhao0a832172015-01-06 11:08:47 -08002976 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002977
Dake Zhao0a832172015-01-06 11:08:47 -08002978 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002979
Dake Zhao0a832172015-01-06 11:08:47 -08002980 infoResp.status = STATUS_COMPLETE;
2981 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2982 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2983
2984 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002985}
2986/*
Dake Zhao0a832172015-01-06 11:08:47 -08002987 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002988 */
2989int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2990{
Dake Zhao0a832172015-01-06 11:08:47 -08002991 dutCmdResponse_t infoResp;
2992 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002993
Dake Zhao0a832172015-01-06 11:08:47 -08002994 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002995
Dake Zhao0a832172015-01-06 11:08:47 -08002996 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002997
Ankur Vachhanic485b712012-02-15 23:29:49 +00002998
Dake Zhao0a832172015-01-06 11:08:47 -08002999 infoResp.status = STATUS_COMPLETE;
3000 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3001 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3002
3003 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003004}
3005
3006/*
Dake Zhao0a832172015-01-06 11:08:47 -08003007 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003008 */
3009int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3010{
Dake Zhao0a832172015-01-06 11:08:47 -08003011 dutCmdResponse_t infoResp;
3012 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003013
Dake Zhao0a832172015-01-06 11:08:47 -08003014 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003015
Dake Zhao0a832172015-01-06 11:08:47 -08003016 // Fetch the group ID and store into infoResp->cmdru.grpid
3017 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003018
Dake Zhao0a832172015-01-06 11:08:47 -08003019 infoResp.status = STATUS_COMPLETE;
3020 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3021 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3022
3023 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003024}
3025
3026
3027
3028
3029/*
Dake Zhao0a832172015-01-06 11:08:47 -08003030 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003031 */
3032int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3033{
Dake Zhao0a832172015-01-06 11:08:47 -08003034 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003035
Dake Zhao0a832172015-01-06 11:08:47 -08003036 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003037
Dake Zhao0a832172015-01-06 11:08:47 -08003038 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3039 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003040
Ankur Vachhanic485b712012-02-15 23:29:49 +00003041
Dake Zhao0a832172015-01-06 11:08:47 -08003042 infoResp.status = STATUS_COMPLETE;
3043 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3044 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3045
3046 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003047}
3048
3049
3050/*
Dake Zhao0a832172015-01-06 11:08:47 -08003051 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003052 */
3053int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3054{
Dake Zhao0a832172015-01-06 11:08:47 -08003055 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003056
Dake Zhao0a832172015-01-06 11:08:47 -08003057 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003058
Dake Zhao0a832172015-01-06 11:08:47 -08003059 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003060
Dake Zhao0a832172015-01-06 11:08:47 -08003061 infoResp.status = STATUS_COMPLETE;
3062 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3063 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3064
3065 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003066}
3067
3068/*
Dake Zhao0a832172015-01-06 11:08:47 -08003069 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003070 */
3071int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3072{
Dake Zhao0a832172015-01-06 11:08:47 -08003073 dutCmdResponse_t infoResp;
3074 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003075
Dake Zhao0a832172015-01-06 11:08:47 -08003076 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003077
Dake Zhao0a832172015-01-06 11:08:47 -08003078 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003079
Dake Zhao0a832172015-01-06 11:08:47 -08003080 infoResp.status = STATUS_COMPLETE;
3081 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3082 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3083
3084 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003085}
3086
3087
3088/*
Dake Zhao0a832172015-01-06 11:08:47 -08003089 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003090 */
3091int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3092{
Dake Zhao0a832172015-01-06 11:08:47 -08003093 dutCmdResponse_t infoResp;
3094 /* uncomment and use it
3095 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3096 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003097
Dake Zhao0a832172015-01-06 11:08:47 -08003098 printf("\n Entry wfaStaAcceptP2pInvReq... ");
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_ACCEPT_INV_REQ_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
3110/*
Dake Zhao0a832172015-01-06 11:08:47 -08003111 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003112 */
3113int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3114{
Dake Zhao0a832172015-01-06 11:08:47 -08003115 dutCmdResponse_t infoResp;
3116 /* uncomment and use it
3117 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3118 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003119
Dake Zhao0a832172015-01-06 11:08:47 -08003120 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003121
Dake Zhao0a832172015-01-06 11:08:47 -08003122 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003123
Dake Zhao0a832172015-01-06 11:08:47 -08003124 infoResp.status = STATUS_COMPLETE;
3125 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3126 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3127
3128 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003129}
3130
3131/*
Dake Zhao0a832172015-01-06 11:08:47 -08003132 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003133 */
3134int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3135{
Dake Zhao0a832172015-01-06 11:08:47 -08003136 dutCmdResponse_t infoResp;
3137 /* uncomment and use it
3138 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3139 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003140
Dake Zhao0a832172015-01-06 11:08:47 -08003141 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003142
Dake Zhao0a832172015-01-06 11:08:47 -08003143 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003144
Dake Zhao0a832172015-01-06 11:08:47 -08003145 infoResp.status = STATUS_COMPLETE;
3146 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3147 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3148
3149 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003150}
3151
3152/*
Dake Zhao0a832172015-01-06 11:08:47 -08003153 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003154 */
3155int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3156{
Dake Zhao0a832172015-01-06 11:08:47 -08003157 dutCmdResponse_t infoResp;
3158 /* uncomment and use it
3159 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3160 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003161
Dake Zhao0a832172015-01-06 11:08:47 -08003162 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003163
Dake Zhao0a832172015-01-06 11:08:47 -08003164 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3165 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3166 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003167
Ankur Vachhanic485b712012-02-15 23:29:49 +00003168
Dake Zhao0a832172015-01-06 11:08:47 -08003169 infoResp.status = STATUS_COMPLETE;
3170 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3171 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3172
3173 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003174}
3175
3176
3177
3178/*
Dake Zhao0a832172015-01-06 11:08:47 -08003179 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003180 */
3181int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3182{
Dake Zhao0a832172015-01-06 11:08:47 -08003183 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003184
Dake Zhao0a832172015-01-06 11:08:47 -08003185 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003186
Dake Zhao0a832172015-01-06 11:08:47 -08003187 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3188 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3189 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003190
Ankur Vachhanic485b712012-02-15 23:29:49 +00003191
Dake Zhao0a832172015-01-06 11:08:47 -08003192 infoResp.status = STATUS_COMPLETE;
3193 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3194 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3195
3196 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003197}
3198
3199
3200/*
Dake Zhao0a832172015-01-06 11:08:47 -08003201 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003202 */
3203int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3204{
Dake Zhao0a832172015-01-06 11:08:47 -08003205 dutCmdResponse_t infoResp;
3206 /* uncomment and use it
3207 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3208 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003209
Dake Zhao0a832172015-01-06 11:08:47 -08003210 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003211
Dake Zhao0a832172015-01-06 11:08:47 -08003212 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003213
Ankur Vachhanic485b712012-02-15 23:29:49 +00003214
Dake Zhao0a832172015-01-06 11:08:47 -08003215 infoResp.status = STATUS_COMPLETE;
3216 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3217 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3218
3219 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003220}
3221
3222
3223/*
Dake Zhao0a832172015-01-06 11:08:47 -08003224 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003225 */
3226int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3227{
Dake Zhao0a832172015-01-06 11:08:47 -08003228 dutCmdResponse_t infoResp;
3229 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003230
Dake Zhao0a832172015-01-06 11:08:47 -08003231 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003232
3233
Dake Zhao0a832172015-01-06 11:08:47 -08003234 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3235 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3236 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003237
Ankur Vachhanic485b712012-02-15 23:29:49 +00003238
Dake Zhao0a832172015-01-06 11:08:47 -08003239 infoResp.status = STATUS_COMPLETE;
3240 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3241 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3242
3243 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003244}
3245
3246/*
Dake Zhao0a832172015-01-06 11:08:47 -08003247 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003248 */
3249int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3250{
Dake Zhao0a832172015-01-06 11:08:47 -08003251 dutCmdResponse_t infoResp;
3252 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003253
Dake Zhao0a832172015-01-06 11:08:47 -08003254 printf("\n Entry wfaStaP2pReset... ");
3255 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003256
Dake Zhao0a832172015-01-06 11:08:47 -08003257 infoResp.status = STATUS_COMPLETE;
3258 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3259 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3260
3261 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003262}
3263
3264
3265
3266/*
Dake Zhao0a832172015-01-06 11:08:47 -08003267 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003268 */
3269int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3270{
Dake Zhao0a832172015-01-06 11:08:47 -08003271 dutCmdResponse_t infoResp;
3272 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003273
Dake Zhao0a832172015-01-06 11:08:47 -08003274 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003275
Dake Zhao0a832172015-01-06 11:08:47 -08003276 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003277
Dake Zhao0a832172015-01-06 11:08:47 -08003278 ifinfo->isDhcp =0;
3279 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3280 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3281 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3282 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3283
3284 infoResp.status = STATUS_COMPLETE;
3285 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3286 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3287
3288 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003289}
3290
3291
3292
3293
3294/*
Dake Zhao0a832172015-01-06 11:08:47 -08003295 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003296 */
3297int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3298{
Dake Zhao0a832172015-01-06 11:08:47 -08003299 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003300
Dake Zhao0a832172015-01-06 11:08:47 -08003301 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3302 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003303
Dake Zhao0a832172015-01-06 11:08:47 -08003304
3305 infoResp.status = STATUS_COMPLETE;
3306 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3307 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3308
3309 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003310}
3311
3312
3313
3314/*
Dake Zhao0a832172015-01-06 11:08:47 -08003315 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003316 */
3317int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3318{
Dake Zhao0a832172015-01-06 11:08:47 -08003319 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003320
Dake Zhao0a832172015-01-06 11:08:47 -08003321 infoResp.status = STATUS_COMPLETE;
3322 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3323 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003324
Dake Zhao0a832172015-01-06 11:08:47 -08003325 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003326}
3327
3328/*
Dake Zhao0a832172015-01-06 11:08:47 -08003329 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003330 */
3331int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3332{
Dake Zhao0a832172015-01-06 11:08:47 -08003333 dutCmdResponse_t infoResp;
3334 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003335
Dake Zhao0a832172015-01-06 11:08:47 -08003336 printf("\n Entry wfaStaSetSleepReq... ");
3337 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003338
Dake Zhao0a832172015-01-06 11:08:47 -08003339
3340 infoResp.status = STATUS_COMPLETE;
3341 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3342 *respLen = WFA_TLV_HDR_LEN +4;
3343
3344 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003345}
3346
3347/*
Dake Zhao0a832172015-01-06 11:08:47 -08003348 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003349 */
3350int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3351{
Dake Zhao0a832172015-01-06 11:08:47 -08003352 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003353
Dake Zhao0a832172015-01-06 11:08:47 -08003354 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3355 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003356
Dake Zhao0a832172015-01-06 11:08:47 -08003357
3358 infoResp.status = STATUS_COMPLETE;
3359 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3360 *respLen = WFA_TLV_HDR_LEN + 4;
3361
3362 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003363}
3364#ifndef WFA_STA_TB
3365/*
Dake Zhao0a832172015-01-06 11:08:47 -08003366 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003367 */
3368
3369int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3370{
Dake Zhao0a832172015-01-06 11:08:47 -08003371 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003372
Dake Zhao0a832172015-01-06 11:08:47 -08003373 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003374
Dake Zhao0a832172015-01-06 11:08:47 -08003375 // Implement the function and its sub commands
3376 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003377
Dake Zhao0a832172015-01-06 11:08:47 -08003378 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3379 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003380
Dake Zhao0a832172015-01-06 11:08:47 -08003381 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003382}
Dake Zhao0a832172015-01-06 11:08:47 -08003383int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003384{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003385
3386 dutCmdResponse_t infoResp;
3387 dutCmdResponse_t *v11nParamsResp = &infoResp;
3388
3389#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003390
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003391 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3392
3393 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003394
3395 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003396
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003397 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3398 {
Dake Zhao0a832172015-01-06 11:08:47 -08003399 // implement the funciton
3400 if(st != 0)
3401 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003402 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003403 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3404 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3405 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3406 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003407 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003408 }
Dake Zhao0a832172015-01-06 11:08:47 -08003409
Ankur Vachhanic485b712012-02-15 23:29:49 +00003410 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003411 {
Dake Zhao0a832172015-01-06 11:08:47 -08003412 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003413
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003414 if(st != 0)
3415 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003416 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003417 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3418 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3419 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3420 return FALSE;
3421 }
3422 }
3423
Ankur Vachhanic485b712012-02-15 23:29:49 +00003424 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003425 {
Dake Zhao0a832172015-01-06 11:08:47 -08003426 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003427 if(st != 0)
3428 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003429 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003430 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3431 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3432 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003433 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003434 }
3435 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003436
3437 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003438 {
3439 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003440 if(st != 0)
3441 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003442 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003443 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3444 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3445 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3446 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003447 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003448 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003449
3450 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003451 {
Dake Zhao0a832172015-01-06 11:08:47 -08003452 // implement the funciton
3453 //st = wfaExecuteCLI(gCmdStr);
3454 if(st != 0)
3455 {
3456 v11nParamsResp->status = STATUS_ERROR;
3457 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3458 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3459 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3460 return FALSE;
3461 }
3462 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003463 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3464 {
3465 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003466 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003467 if(st != 0)
3468 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003469 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003470 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003471 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3472 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003473 return FALSE;
3474 }
Dake Zhao0a832172015-01-06 11:08:47 -08003475 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003476 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3477 {
3478 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003479 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003480 if(st != 0)
3481 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003482 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003483 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003484 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3485 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003486 return FALSE;
3487 }
3488 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003489
3490 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003491 {
3492 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003493 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003494 if(st != 0)
3495 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003496 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003497 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003498 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3499 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003500 return FALSE;
3501 }
3502 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003503
3504 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003505 {
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_sgi20 failed");
3512 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3513 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3514 return FALSE;
3515 }
3516 }
3517
3518 if(v11nParams->smps != 0xFFFF)
3519 {
3520 if(v11nParams->smps == 0)
3521 {
Dake Zhao0a832172015-01-06 11:08:47 -08003522 // implement the funciton
3523 //st = wfaExecuteCLI(gCmdStr);
3524 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003525 else if(v11nParams->smps == 1)
3526 {
Dake Zhao0a832172015-01-06 11:08:47 -08003527 // implement the funciton
3528 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003529 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003530 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003531 else if(v11nParams->smps == 2)
3532 {
Dake Zhao0a832172015-01-06 11:08:47 -08003533 // implement the funciton
3534 //st = wfaExecuteCLI(gCmdStr);
3535 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003536 }
3537 if(st != 0)
3538 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003539 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003540 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3541 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3542 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3543 return FALSE;
3544 }
3545 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003546
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003547 if(v11nParams->stbc_rx != 0xFFFF)
3548 {
3549 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003550 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003551 if(st != 0)
3552 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003553 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003554 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003555 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3556 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003557 return FALSE;
3558 }
3559 }
Dake Zhao0a832172015-01-06 11:08:47 -08003560
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003561 if(v11nParams->width[0] != '\0')
3562 {
3563 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003564 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003565 if(st != 0)
3566 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003567 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003568 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3569 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3570 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3571 return FALSE;
3572 }
3573 }
Dake Zhao0a832172015-01-06 11:08:47 -08003574
Ankur Vachhanic485b712012-02-15 23:29:49 +00003575 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003576 {
3577 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003578 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003579 if(st != 0)
3580 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003581 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003582 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3583 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3584 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3585 return FALSE;
3586 }
3587 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003588
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003589 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3590 {
3591 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003592 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003593 if(st != 0)
3594 {
3595 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003596 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003597 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3598 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3599 return FALSE;
3600 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003601
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003602 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003603
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003604 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3605 {
3606 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003607 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003608 if(st != 0)
3609 {
3610 v11nParamsResp->status = STATUS_ERROR;
3611 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3612 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3613 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3614 return FALSE;
3615 }
3616 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003617
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003618#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003619
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003620 v11nParamsResp->status = STATUS_COMPLETE;
3621 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3622 *respLen = WFA_TLV_HDR_LEN + 4;
3623 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003624}
3625#endif
3626/*
Dake Zhao0a832172015-01-06 11:08:47 -08003627 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003628 */
3629int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3630{
Dake Zhao0a832172015-01-06 11:08:47 -08003631 dutCmdResponse_t infoResp;
3632 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003633
Dake Zhao0a832172015-01-06 11:08:47 -08003634 printf("\n Entry wfastaAddARPTableEntry... ");
3635 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003636
Dake Zhao0a832172015-01-06 11:08:47 -08003637 infoResp.status = STATUS_COMPLETE;
3638 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3639 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3640
3641 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003642}
3643
3644/*
Dake Zhao0a832172015-01-06 11:08:47 -08003645 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003646 */
3647int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3648{
Dake Zhao0a832172015-01-06 11:08:47 -08003649 dutCmdResponse_t infoResp;
3650 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003651
Dake Zhao0a832172015-01-06 11:08:47 -08003652 printf("\n Entry wfaStaBlockICMPResponse... ");
3653 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003654
Dake Zhao0a832172015-01-06 11:08:47 -08003655 infoResp.status = STATUS_COMPLETE;
3656 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3657 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3658
3659 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003660}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003661
3662/*
Dake Zhao0a832172015-01-06 11:08:47 -08003663 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003664 */
3665
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003666int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3667{
3668 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3669 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003670 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3671
3672 if(sr->mode == WFA_OFF)
3673 {
Dake Zhao0a832172015-01-06 11:08:47 -08003674 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003675 }
3676 else
3677 {
Dake Zhao0a832172015-01-06 11:08:47 -08003678 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003679 }
3680
3681 staCmdResp->status = STATUS_COMPLETE;
3682 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3683 *respLen = WFA_TLV_HDR_LEN + 4;
3684
3685 return WFA_SUCCESS;
3686}
3687
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003688/*
Dake Zhao0a832172015-01-06 11:08:47 -08003689 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003690 */
3691
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003692int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3693{
Dake Zhao0a832172015-01-06 11:08:47 -08003694 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3695 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3696 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003697
Dake Zhao0a832172015-01-06 11:08:47 -08003698 if(strcasecmp(rfeat->prog, "tdls") == 0)
3699 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003700
3701
Dake Zhao0a832172015-01-06 11:08:47 -08003702 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003703
Dake Zhao0a832172015-01-06 11:08:47 -08003704 caResp->status = STATUS_COMPLETE;
3705 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3706 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003707
Dake Zhao0a832172015-01-06 11:08:47 -08003708 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003709}
3710
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003711/*
Dake Zhao0a832172015-01-06 11:08:47 -08003712 * wfaStaStartWfdConnection():
3713 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003714int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3715{
Dake Zhao0a832172015-01-06 11:08:47 -08003716 dutCmdResponse_t infoResp;
3717 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003718
Dake Zhao0a832172015-01-06 11:08:47 -08003719 printf("\n Entry wfaStaStartWfdConnection... ");
3720
3721
3722 // Fetch the GrpId and WFD session and return
3723 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3724 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3725 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3726
3727 infoResp.status = STATUS_COMPLETE;
3728 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3729 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3730
3731 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003732}
3733/*
Dake Zhao0a832172015-01-06 11:08:47 -08003734 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003735 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003736
Ankur Vachhanic485b712012-02-15 23:29:49 +00003737int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3738{
Dake Zhao0a832172015-01-06 11:08:47 -08003739 char cmdName[32];
3740 char *pcmdStr=NULL, *str;
3741 int st = 1;
3742 char CmdStr[WFA_CMD_STR_SZ];
3743 FILE *wfaCliFd;
3744 char wfaCliBuff[64];
3745 char retstr[256];
3746 int CmdReturnFlag =0;
3747 char tmp[256];
Li Yincba7d352015-09-23 20:30:49 +08003748 FILE * sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003749 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003750
Dake Zhao0a832172015-01-06 11:08:47 -08003751 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3752 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3753 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003754
Dake Zhao0a832172015-01-06 11:08:47 -08003755 for(;;)
3756 {
3757 // construct CLI standard cmd string
3758 str = strtok_r(NULL, ",", &pcmdStr);
3759 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003760 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003761 else
3762 {
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003763 strcat(strcat(CmdStr, " /"), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003764 str = strtok_r(NULL, ",", &pcmdStr);
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003765 strcat(strcat(CmdStr, " "), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003766 }
3767 }
3768 // check the return process
3769 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3770 if(wfaCliFd!= NULL)
3771 {
3772 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3773 {
3774 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3775 if(ferror(wfaCliFd))
3776 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003777
Dake Zhao0a832172015-01-06 11:08:47 -08003778 str=strtok(wfaCliBuff,"-");
3779 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003780 {
Dake Zhao0a832172015-01-06 11:08:47 -08003781 str=strtok(NULL,",");
3782 if (str != NULL)
3783 {
3784 if(strcmp(str,"TRUE") == 0)
3785 CmdReturnFlag =1;
3786 }
3787 else
3788 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3789 break;
Dake Zhao97708202014-11-26 13:59:04 -08003790 }
Dake Zhao0a832172015-01-06 11:08:47 -08003791 }
3792 fclose(wfaCliFd);
3793 }
3794 else
3795 {
3796 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3797 goto cleanup;
3798 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003799
Dake Zhao0a832172015-01-06 11:08:47 -08003800 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3801 memset(&retstr[0],'\0',255);
3802 memset(&tmp[0],'\0',255);
3803 sprintf(gCmdStr, "%s", CmdStr);
3804 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003805
Dake Zhao0a832172015-01-06 11:08:47 -08003806 sh_pipe = popen(gCmdStr,"r");
3807 if(!sh_pipe)
3808 {
3809 printf ("Error in opening pipe\n");
3810 goto cleanup;
3811 }
Dake Zhao97708202014-11-26 13:59:04 -08003812
Dake Zhao0a832172015-01-06 11:08:47 -08003813 sleep(5);
3814 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3815 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3816 {
3817 printf("Getting NULL string in popen return\n");
3818 goto cleanup;
3819 }
3820 else
3821 printf("popen return str=%s\n",retstr);
3822
3823 sleep(2);
3824 if(pclose(sh_pipe) == -1)
3825 {
3826 printf("Error in closing shell cmd pipe\n");
3827 goto cleanup;
3828 }
Li Yincba7d352015-09-23 20:30:49 +08003829 sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003830 sleep(2);
3831
3832 // find status first in output
3833 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3834 if (str != NULL)
3835 {
3836 memset(tmp, 0, 10);
3837 memcpy(tmp, str, 2);
3838 printf("cli status=%s\n",tmp);
3839 if(strlen(tmp) > 0)
3840 st = atoi(tmp);
3841 else printf("Missing status code\n");
3842 }
3843 else
3844 {
3845 printf("wfaStaCliCommand no return code found\n");
3846 }
3847 infoResp.resFlag=CmdReturnFlag;
3848
Dake Zhao97708202014-11-26 13:59:04 -08003849cleanup:
Li Yincba7d352015-09-23 20:30:49 +08003850 if (sh_pipe)
3851 pclose(sh_pipe);
Dake Zhao0a832172015-01-06 11:08:47 -08003852
3853 switch(st)
3854 {
3855 case 0:
3856 infoResp.status = STATUS_COMPLETE;
3857 if (CmdReturnFlag)
3858 {
3859 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3860 {
3861 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003862 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 -08003863 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3864 }
3865 else
3866 {
Dake Zhao97708202014-11-26 13:59:04 -08003867 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003868 }
3869 }
3870 break;
3871 case 1:
3872 infoResp.status = STATUS_ERROR;
3873 break;
3874 case 2:
3875 infoResp.status = STATUS_INVALID;
3876 break;
3877 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003878
Dake Zhao0a832172015-01-06 11:08:47 -08003879 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3880 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003881
Dake Zhao0a832172015-01-06 11:08:47 -08003882 printf("Exit from wfaStaCliCommand\n");
3883 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003884
Ankur Vachhanic485b712012-02-15 23:29:49 +00003885}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003886/*
Dake Zhao0a832172015-01-06 11:08:47 -08003887 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003888 */
3889
3890int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3891{
3892 dutCmdResponse_t infoResp;
3893// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003894
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003895 printf("\n Entry wfaStaConnectGoStartWfd... ");
3896
Dake Zhao0a832172015-01-06 11:08:47 -08003897 // connect the specified GO and then establish the wfd session
3898
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003899 // Fetch WFD session and return
3900 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3901
3902 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003903 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003904 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003905
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003906 return WFA_SUCCESS;
3907}
3908
3909/*
Dake Zhao0a832172015-01-06 11:08:47 -08003910 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003911 */
3912
3913int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3914{
3915 dutCmdResponse_t infoResp;
3916 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3917 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003918
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003919 printf("\n Entry wfaStaGenerateEvent... ");
3920
3921
3922 // Geneate the specified action and return with complete/error.
3923 if(staGenerateEvent->program == PROG_TYPE_WFD)
3924 {
3925 wfdGenEvent = &staGenerateEvent->wfdEvent;
3926 if(wfdGenEvent ->type == eUibcGen)
3927 {
Dake Zhao0a832172015-01-06 11:08:47 -08003928 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003929 else if(wfdGenEvent ->type == eUibcHid)
3930 {
Dake Zhao0a832172015-01-06 11:08:47 -08003931 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003932 else if(wfdGenEvent ->type == eFrameSkip)
3933 {
3934
3935 }
3936 else if(wfdGenEvent ->type == eI2cRead)
3937 {
3938 }
3939 else if(wfdGenEvent ->type == eI2cWrite)
3940 {
Dake Zhao0a832172015-01-06 11:08:47 -08003941 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003942 else if(wfdGenEvent ->type == eInputContent)
3943 {
Dake Zhao0a832172015-01-06 11:08:47 -08003944 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003945 else if(wfdGenEvent ->type == eIdrReq)
3946 {
Dake Zhao0a832172015-01-06 11:08:47 -08003947 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003948 }
Dake Zhao0a832172015-01-06 11:08:47 -08003949
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003950 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003951 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003952 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003953
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003954 return WFA_SUCCESS;
3955}
3956
Dake Zhao0a832172015-01-06 11:08:47 -08003957
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003958
3959
3960/*
Dake Zhao0a832172015-01-06 11:08:47 -08003961 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003962 */
3963
3964int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3965{
3966 dutCmdResponse_t infoResp;
3967// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003968
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003969 printf("\n Entry wfaStaReinvokeWfdSession... ");
3970
3971 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08003972
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003973
3974 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003975 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003976 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003977
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003978 return WFA_SUCCESS;
3979}
3980
3981
3982int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3983{
Dake Zhao0a832172015-01-06 11:08:47 -08003984 dutCmdResponse_t infoResp;
3985 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003986
3987
Dake Zhao0a832172015-01-06 11:08:47 -08003988 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003989
Dake Zhao0a832172015-01-06 11:08:47 -08003990 printf("\n Entry wfaStaGetParameter... ");
3991
3992 // Check the program type
3993 if(staGetParam->program == PROG_TYPE_WFD)
3994 {
3995 if(staGetParam->getParamValue == eDiscoveredDevList )
3996 {
3997 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3998 paramList->getParamType = eDiscoveredDevList;
3999 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4000 }
4001 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004002
Dake Zhao655efed2015-03-11 17:39:13 -07004003 if(staGetParam->program == PROG_TYPE_WFDS)
4004 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004005
Dake Zhao655efed2015-03-11 17:39:13 -07004006 if(staGetParam->getParamValue == eDiscoveredDevList )
4007 {
4008 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4009 paramList->getParamType = eDiscoveredDevList;
4010 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4011
4012 }
4013 if(staGetParam->getParamValue == eOpenPorts)
4014 {
4015 // Run the port checker tool
4016 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
4017 paramList->getParamType = eOpenPorts;
4018 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
4019
4020 }
4021
4022 }
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004023 if(staGetParam->program == PROG_TYPE_NAN)
4024 {
4025 if(staGetParam->getParamValue == eMasterPref )
4026 {
4027 // Get the master preference of the device and return the value
4028 paramList->getParamType = eMasterPref;
4029 strcpy((char *)&paramList->masterPref, "0xff");
4030 }
4031 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004032
Dake Zhao655efed2015-03-11 17:39:13 -07004033 infoResp.status = STATUS_COMPLETE;
4034 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4035 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4036
4037 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004038}
4039
Ankur Vachhanic485b712012-02-15 23:29:49 +00004040
Dake Zhao655efed2015-03-11 17:39:13 -07004041int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4042{
4043
4044 dutCmdResponse_t infoResp;
4045 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4046
4047 printf("\n Entry wfaStaNfcAction... ");
4048
4049 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4050 {
4051 printf("\n NfcAction - HandOver... ");
4052
4053 }
4054 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4055 {
4056 printf("\n NfcAction - Read Tag... ");
4057
4058 }
4059 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4060 {
4061 printf("\n NfcAction - Write Select... ");
4062
4063 }
4064 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4065 {
4066 printf("\n NfcAction - Write Config... ");
4067
4068 }
4069 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4070 {
4071 printf("\n NfcAction - Write Password... ");
4072
4073 }
4074 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4075 {
4076 printf("\n NfcAction - WPS Handover... ");
4077
4078 }
4079
4080 // Fetch the device mode and put in infoResp->cmdru.p2presult
4081 //strcpy(infoResp->cmdru.p2presult, "GO");
4082
4083 // Fetch the device grp id and put in infoResp->cmdru.grpid
4084 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4085
4086 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4087 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4088 infoResp.cmdru.staNfcAction.peerRole = 1;
4089
4090
4091
4092
4093 infoResp.status = STATUS_COMPLETE;
4094 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4095 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4096
4097 return WFA_SUCCESS;
4098}
4099
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004100int wfaStaExecAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4101{
4102
4103 dutCmdResponse_t infoResp;
4104 caStaExecAction_t *staExecAction = (caStaExecAction_t *)caCmdBuf; //comment if not used
4105
4106 printf("\n Entry wfaStaExecAction... ");
4107
4108 if(staExecAction->prog == PROG_TYPE_NAN)
4109 {
4110 // Perform necessary configurations and actions
4111 // return the MAC address conditionally as per CAPI specification
4112 }
4113
4114 infoResp.status = STATUS_COMPLETE;
4115 wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4116 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4117
4118 return WFA_SUCCESS;
4119}
4120
Dake Zhao655efed2015-03-11 17:39:13 -07004121int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4122{
4123
4124 dutCmdResponse_t infoResp;
4125 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4126
4127 printf("\n Entry wfaStaInvokeCommand... ");
4128
4129
4130 // based on the command type , invoke API or complete the required procedures
4131 // return the defined parameters based on the command that is received ( example response below)
4132
4133 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4134 {
4135 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4136 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4137 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4138 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4139 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4140 }
4141 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4142 {
4143 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4144 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4145 }
4146 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4147 {
4148 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4149 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4150 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4151 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4152
4153 }
4154 infoResp.status = STATUS_COMPLETE;
4155 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4156 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4157
4158 return WFA_SUCCESS;
4159}
4160
4161
4162int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4163{
4164
4165 dutCmdResponse_t infoResp;
4166 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4167
4168 printf("\n Entry wfaStaManageService... ");
4169
4170 // based on the manage service type , invoke API's or complete the required procedures
4171 // return the defined parameters based on the command that is received ( example response below)
4172 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4173 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4174 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4175
4176 infoResp.status = STATUS_COMPLETE;
4177 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4178 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4179
4180 return WFA_SUCCESS;
4181}
4182
4183
4184
4185int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4186{
4187
4188 dutCmdResponse_t infoResp;
Dake Zhao353c55e2015-07-20 18:54:45 -07004189 caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004190
4191 printf("\n Entry wfaStaGetEvents... ");
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004192
4193 if(staGetEvents->program == PROG_TYPE_NAN)
4194 {
4195 // Get all the events from the Log file or stored events
4196 // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac
4197 }
Dake Zhao655efed2015-03-11 17:39:13 -07004198
4199 // Get all the event from the Log file or stored events
4200 // return the received/recorded events as space seperated list ( example response below)
4201 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4202
4203 infoResp.status = STATUS_COMPLETE;
4204 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4205 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4206
4207 return WFA_SUCCESS;
4208}
4209
4210int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4211{
4212
4213 dutCmdResponse_t infoResp;
Li Yinf467b182015-09-23 21:21:30 +08004214 caStaGetEventDetails_t *getStaGetEventDetails = (caStaGetEventDetails_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004215
4216 printf("\n Entry wfaStaGetEventDetails... ");
4217
4218
4219 // based on the Requested Event type
4220 // return the latest corresponding evnet detailed parameters ( example response below)
4221
4222 if(getStaGetEventDetails->eventId== eSearchResult )
4223 {
4224 // fetch from log file or event history for the search result event and return the parameters
4225 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4226
4227 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4228 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4229 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4230 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4231
4232 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4233 }
4234 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4235 { // fetch from log file or event history for the search terminated event and return the parameters
4236 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4237 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4238 }
4239 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4240 {// fetch from log file or event history for the Advertise Status event and return the parameters
4241 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4242 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4243
4244 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4245 }
4246 else if (getStaGetEventDetails->eventId == eSessionRequest)
4247 {// fetch from log file or event history for the session request event and return the parameters
4248 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4249 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4250 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4251 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4252 }
4253 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4254 {// fetch from log file or event history for the session status event and return the parameters
4255 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4256 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4257 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4258 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4259 }
4260 else if (getStaGetEventDetails->eventId == eConnectStatus)
4261 {
4262 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4263 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4264 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4265 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4266
4267 }
4268 else if (getStaGetEventDetails->eventId == ePortStatus)
4269 {
4270 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4271 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4272 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4273 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4274 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4275 }
4276
4277
4278
4279 infoResp.status = STATUS_COMPLETE;
4280 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4281 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4282
4283 return WFA_SUCCESS;
4284}
4285
4286
4287
4288