blob: 430bb77ffecbcc8f34969eaceff6c0a8aee94eb3 [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");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200461
462 if (ipconfig->isDhcp) {
463 DPRINT_INFO(WFA_OUT, "error: dhcp not supported\n");
464 staSetIpResp->status = STATUS_INVALID;
465 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
466 *respLen = WFA_TLV_HDR_LEN + 4;
467
468 return WFA_FAILURE;
469 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000470
Dake Zhao0a832172015-01-06 11:08:47 -0800471 /*
472 * Use command 'ifconfig' to configure the interface ip address, mask.
473 * (Linux specific).
474 */
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200475 sprintf(gCmdStr, "ifconfig %s %s netmask %s >/tmp/ifconfig.log 2>&1", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
476 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
477 sret = system(gCmdStr);
478 if (sret != 0) {
479 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
480 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000481
Dake Zhao0a832172015-01-06 11:08:47 -0800482 /* use command 'route add' to set set gatewway (linux specific) */
483 if(ipconfig->defGateway[0] != '\0')
484 {
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200485 sprintf(gCmdStr, "route add default gw %s >/tmp/route.log 2>&1", ipconfig->defGateway);
486 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800487 sret = system(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200488 if (sret != 0) {
489 DPRINT_INFO(WFA_OUT, "exit code %d\n", sret);
490 }
Dake Zhao0a832172015-01-06 11:08:47 -0800491 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000492
Dake Zhao0a832172015-01-06 11:08:47 -0800493 /* set dns (linux specific) */
494 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200495 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800496 sret = system(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200497 if (sret != 0) {
498 DPRINT_INFO(WFA_OUT, "exit code %d backing up resolv.conf\n", sret);
499 }
Dake Zhao0a832172015-01-06 11:08:47 -0800500 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200501 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -0800502 sret = system(gCmdStr);
Wojciech Jakobczykfc3b0112020-08-26 11:30:55 +0200503 if (sret != 0) {
504 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
505 }
506 if (strlen(ipconfig->sec_dns) > 0) {
507 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
508 DPRINT_INFO(WFA_OUT, "exec: %s\n", gCmdStr);
509 sret = system(gCmdStr);
510 if (sret != 0) {
511 DPRINT_INFO(WFA_OUT, "exit code %d writing resolv.conf\n", sret);
512 }
513 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000514
Dake Zhao0a832172015-01-06 11:08:47 -0800515 /*
516 * report status
517 */
518 staSetIpResp->status = STATUS_COMPLETE;
519 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
520 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000521
Dake Zhao0a832172015-01-06 11:08:47 -0800522 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000523}
524
525/*
526 * wfaStaVerifyIpConnection():
527 * The function is to verify if the station has IP connection with an AP by
528 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800529 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000530int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
531{
Dake Zhao0a832172015-01-06 11:08:47 -0800532 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
533 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000534
535#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800536 char strout[64], *pcnt;
537 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000538
Dake Zhao0a832172015-01-06 11:08:47 -0800539 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
540
541 /* set timeout value in case not set */
542 if(verip->cmdsu.verifyIp.timeout <= 0)
543 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000544 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800545 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000546
Dake Zhao0a832172015-01-06 11:08:47 -0800547 /* execute the ping command and pipe the result to a tmp file */
548 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);
549 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000550
Dake Zhao0a832172015-01-06 11:08:47 -0800551 /* scan/check the output */
552 tmpfile = fopen("/tmp/pingout.txt", "r+");
553 if(tmpfile == NULL)
554 {
555 verifyIpResp->status = STATUS_ERROR;
556 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
557 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000558
Dake Zhao0a832172015-01-06 11:08:47 -0800559 DPRINT_ERR(WFA_ERR, "file open failed\n");
560 return WFA_FAILURE;
561 }
562
563 verifyIpResp->status = STATUS_COMPLETE;
564 if(fscanf(tmpfile, "%s", strout) == EOF)
565 verifyIpResp->cmdru.connected = 0;
566 else
567 {
568 pcnt = strtok(strout, "%");
569
570 /* if the loss rate is 100%, not able to connect */
571 if(atoi(pcnt) == 100)
572 verifyIpResp->cmdru.connected = 0;
573 else
574 verifyIpResp->cmdru.connected = 1;
575 }
576
577 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000578#else
Dake Zhao0a832172015-01-06 11:08:47 -0800579 int btSockfd;
580 struct pollfd fds[2];
581 int timeout = 2000;
582 char anyBuf[64];
583 struct sockaddr_in toAddr;
584 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000585
Dake Zhao0a832172015-01-06 11:08:47 -0800586 verifyIpResp->status = STATUS_COMPLETE;
587 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000588
Dake Zhao0a832172015-01-06 11:08:47 -0800589 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000590
Dake Zhao0a832172015-01-06 11:08:47 -0800591 if(btSockfd == -1)
592 {
593 verifyIpResp->status = STATUS_ERROR;
594 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
595 *respLen = WFA_TLV_HDR_LEN + 4;
596 return WFA_FAILURE;;
597 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000598
Dake Zhao0a832172015-01-06 11:08:47 -0800599 toAddr.sin_family = AF_INET;
600 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
601 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000602
Dake Zhao0a832172015-01-06 11:08:47 -0800603 while(done)
604 {
605 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
606 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000607
Dake Zhao0a832172015-01-06 11:08:47 -0800608 fds[0].fd = btSockfd;
609 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000610
Dake Zhao0a832172015-01-06 11:08:47 -0800611 ret = poll(fds, 1, timeout);
612 switch(ret)
613 {
614 case 0:
615 /* it is time out, count a packet lost*/
616 break;
617 case -1:
618 /* it is an error */
619 default:
620 {
621 switch(fds[0].revents)
622 {
623 case POLLIN:
624 case POLLPRI:
625 case POLLOUT:
626 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
627 if(nbytes != 0)
628 verifyIpResp->cmdru.connected = 1;
629 done = 0;
630 break;
631 default:
632 /* errors but not care */
633 ;
634 }
635 }
636 }
637 if(cnt == 3)
638 {
639 done = 0;
640 }
641 }
642
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000643#endif
644
Dake Zhao0a832172015-01-06 11:08:47 -0800645 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000646
Dake Zhao0a832172015-01-06 11:08:47 -0800647 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
648
649 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000650}
651
652/*
653 * wfaStaGetMacAddress()
654 * This function is to retrieve the MAC address of a wireless I/F.
655 */
656int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
657{
658 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
659 dutCmdResponse_t *getmacResp = &gGenericResp;
660 char *str;
661 char *ifname = getMac->intf;
662
663 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800664 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000665
666 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
667 /*
668 * run the script "getipconfig.sh" to find out the mac
669 */
Dake Zhao0a832172015-01-06 11:08:47 -0800670 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800671 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000672
673 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
674 if(tmpfd == NULL)
675 {
Dake Zhao0a832172015-01-06 11:08:47 -0800676 getmacResp->status = STATUS_ERROR;
677 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
678 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000679
Dake Zhao0a832172015-01-06 11:08:47 -0800680 DPRINT_ERR(WFA_ERR, "file open failed\n");
681 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000682 }
683
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800684 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
685 {
Dake Zhao0a832172015-01-06 11:08:47 -0800686 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000687 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800688
689 str = strtok(string, " ");
690 while(str && ((strcmp(str,"HWaddr")) != 0))
691 {
Dake Zhao0a832172015-01-06 11:08:47 -0800692 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800693 }
Dake Zhao0a832172015-01-06 11:08:47 -0800694
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800695 /* get mac */
696 if(str)
697 {
698 str = strtok(NULL, " ");
699 strcpy(getmacResp->cmdru.mac, str);
700 getmacResp->status = STATUS_COMPLETE;
701 }
Dake Zhao0a832172015-01-06 11:08:47 -0800702
703 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000704
705 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
706
707 fclose(tmpfd);
708 return WFA_SUCCESS;
709}
710
711/*
712 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800713 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000714 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800715 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000716 */
717int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
718{
Dake Zhao0a832172015-01-06 11:08:47 -0800719 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000720
Dake Zhao0a832172015-01-06 11:08:47 -0800721 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000722
Dake Zhao0a832172015-01-06 11:08:47 -0800723 statsResp->status = STATUS_ERROR;
724 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
725 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000726
727
Dake Zhao0a832172015-01-06 11:08:47 -0800728 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000729}
730
731/*
732 * wfaSetEncryption():
733 * The function is to set the wireless interface with WEP or none.
734 *
Dake Zhao0a832172015-01-06 11:08:47 -0800735 * Since WEP is optional test, current function is only used for
736 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000737 * this function should be replaced by the next one (wfaSetEncryption1())
738 *
Dake Zhao0a832172015-01-06 11:08:47 -0800739 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000740 * 1. I/F
741 * 2. ssid
742 * 3. encpType - wep or none
743 * Optional:
744 * 4. key1
745 * 5. key2
746 * 6. key3
747 * 7. key4
748 * 8. activeKey Index
749 */
750
751int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
752{
Dake Zhao0a832172015-01-06 11:08:47 -0800753 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
754 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000755
Dake Zhao0a832172015-01-06 11:08:47 -0800756 /*
757 * disable the network first
758 */
759 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
760 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000761
Dake Zhao0a832172015-01-06 11:08:47 -0800762 /*
763 * set SSID
764 */
765 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
766 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000767
Dake Zhao0a832172015-01-06 11:08:47 -0800768 /*
769 * Tell the supplicant for infrastructure mode (1)
770 */
771 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
772 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000773
Dake Zhao0a832172015-01-06 11:08:47 -0800774 /*
775 * set Key management to NONE (NO WPA) for plaintext or WEP
776 */
777 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
778 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000779
Dake Zhao0a832172015-01-06 11:08:47 -0800780 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
781 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000782
Dake Zhao0a832172015-01-06 11:08:47 -0800783 setEncrypResp->status = STATUS_COMPLETE;
784 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
785 *respLen = WFA_TLV_HDR_LEN + 4;
786
787 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000788}
789
790/*
791 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800792 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000793 */
794int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
795{
Dake Zhao0a832172015-01-06 11:08:47 -0800796 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
797 dutCmdResponse_t *setEncrypResp = &gGenericResp;
798 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000799
Dake Zhao0a832172015-01-06 11:08:47 -0800800 /*
801 * disable the network first
802 */
803 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
804 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000805
Dake Zhao0a832172015-01-06 11:08:47 -0800806 /*
807 * set SSID
808 */
809 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
810 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000811
Dake Zhao0a832172015-01-06 11:08:47 -0800812 /*
813 * Tell the supplicant for infrastructure mode (1)
814 */
815 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
816 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000817
Dake Zhao0a832172015-01-06 11:08:47 -0800818 /*
819 * set Key management to NONE (NO WPA) for plaintext or WEP
820 */
821 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
822 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000823
Dake Zhao0a832172015-01-06 11:08:47 -0800824 /* set keys */
825 if(setEncryp->encpType == 1)
826 {
827 for(i=0; i<4; i++)
828 {
829 if(setEncryp->keys[i][0] != '\0')
830 {
831 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
832 setEncryp->intf, i, setEncryp->keys[i]);
833 sret = system(gCmdStr);
834 }
835 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000836
Dake Zhao0a832172015-01-06 11:08:47 -0800837 /* set active key */
838 i = setEncryp->activeKeyIdx;
839 if(setEncryp->keys[i][0] != '\0')
840 {
841 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
842 setEncryp->intf, setEncryp->activeKeyIdx);
843 sret = system(gCmdStr);
844 }
845 }
846 else /* clearly remove the keys -- reported by p.schwann */
847 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000848
Dake Zhao0a832172015-01-06 11:08:47 -0800849 for(i = 0; i < 4; i++)
850 {
851 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
852 sret = system(gCmdStr);
853 }
854 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000855
Dake Zhao0a832172015-01-06 11:08:47 -0800856 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
857 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000858
Dake Zhao0a832172015-01-06 11:08:47 -0800859 setEncrypResp->status = STATUS_COMPLETE;
860 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
861 *respLen = WFA_TLV_HDR_LEN + 4;
862
863 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000864}
865
866int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
867{
868 int ret = WFA_SUCCESS;
869
870 return ret;
871}
872
873/*
874 * wfaStaSetEapTLS():
875 * This is to set
876 * 1. ssid
877 * 2. encrypType - tkip or aes-ccmp
878 * 3. keyManagementType - wpa or wpa2
879 * 4. trustedRootCA
880 * 5. clientCertificate
881 */
882int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
883{
Dake Zhao0a832172015-01-06 11:08:47 -0800884 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
885 char *ifname = setTLS->intf;
886 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000887
Dake Zhao0a832172015-01-06 11:08:47 -0800888 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000889
Dake Zhao0a832172015-01-06 11:08:47 -0800890 /*
891 * need to store the trustedROOTCA and clientCertificate into a file first.
892 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000893#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800894 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
895 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000896#else
897
Dake Zhao0a832172015-01-06 11:08:47 -0800898 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
899 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000900
Dake Zhao0a832172015-01-06 11:08:47 -0800901 /* ssid */
902 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
903 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000904
Dake Zhao0a832172015-01-06 11:08:47 -0800905 /* key management */
906 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
907 {
908 }
909 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
910 {
911 }
912 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
913 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000914
Dake Zhao0a832172015-01-06 11:08:47 -0800915 }
916 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
917 {
918 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
919 }
920 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
921 {
922 // to take all and device to pick any one supported.
923 }
924 else
925 {
926 // ??
927 }
928 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000929
Dake Zhao0a832172015-01-06 11:08:47 -0800930 /* protocol WPA */
931 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
932 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000933
Dake Zhao0a832172015-01-06 11:08:47 -0800934 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
935 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000936
Dake Zhao0a832172015-01-06 11:08:47 -0800937 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
938 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000939
Dake Zhao0a832172015-01-06 11:08:47 -0800940 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
941 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000942
Dake Zhao0a832172015-01-06 11:08:47 -0800943 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
944 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000945
Dake Zhao0a832172015-01-06 11:08:47 -0800946 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
947 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000948
Dake Zhao0a832172015-01-06 11:08:47 -0800949 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
950 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000951#endif
952
Dake Zhao0a832172015-01-06 11:08:47 -0800953 setEapTlsResp->status = STATUS_COMPLETE;
954 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
955 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000956
Dake Zhao0a832172015-01-06 11:08:47 -0800957 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000958}
959
960/*
Dake Zhao0a832172015-01-06 11:08:47 -0800961 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000962 * 1. ssid
963 * 2. passPhrase
964 * 3. keyMangementType - wpa/wpa2
965 * 4. encrypType - tkip or aes-ccmp
966 */
967int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -0800968{
969 /*Incompleted function*/
970 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000971
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800972#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -0800973 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000974#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800975 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
976 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000977#else
Dake Zhao0a832172015-01-06 11:08:47 -0800978 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
979 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000980
Dake Zhao0a832172015-01-06 11:08:47 -0800981 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
982 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
983 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
984 {
985 // take all and device to pick it supported.
986 }
987 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
988 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000989
Dake Zhao0a832172015-01-06 11:08:47 -0800990 }
991 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
992 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000993
Dake Zhao0a832172015-01-06 11:08:47 -0800994 }
995 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
996 {
Ray Wang9c508692014-04-01 17:04:59 -0700997
Dake Zhao0a832172015-01-06 11:08:47 -0800998 }
999 else
1000 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001001
Dake Zhao0a832172015-01-06 11:08:47 -08001002 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001003
Dake Zhao0a832172015-01-06 11:08:47 -08001004 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
1005 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001006
Dake Zhao0a832172015-01-06 11:08:47 -08001007 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
1008 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001009
Dake Zhao0a832172015-01-06 11:08:47 -08001010 /* if PMF enable */
1011 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
1012 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001013
Dake Zhao0a832172015-01-06 11:08:47 -08001014 }
1015 else if(setPSK->pmf == WFA_REQUIRED)
1016 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001017
Dake Zhao0a832172015-01-06 11:08:47 -08001018 }
1019 else if(setPSK->pmf == WFA_F_REQUIRED)
1020 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001021
Dake Zhao0a832172015-01-06 11:08:47 -08001022 }
1023 else if(setPSK->pmf == WFA_F_DISABLED)
1024 {
1025
1026 }
1027 else
1028 {
1029 /* Disable PMF */
1030
1031 }
1032
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001033#endif
1034
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001035#endif
1036
Dake Zhao0a832172015-01-06 11:08:47 -08001037 setPskResp->status = STATUS_COMPLETE;
1038 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1039 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001040
Dake Zhao0a832172015-01-06 11:08:47 -08001041 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001042}
1043
1044/*
Dake Zhao0a832172015-01-06 11:08:47 -08001045 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001046 * Get vendor specific information in name/value pair by a wireless I/F.
1047 */
1048int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1049{
Dake Zhao0a832172015-01-06 11:08:47 -08001050 dutCmdResponse_t infoResp;
1051 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001052 FILE *tmpfd;
1053 char vendor[256];
1054 const char* vendorFileName = "/tmp/ifvendor.txt";
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001055
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001056 sprintf(gCmdStr, "getifvendor.sh %s %s\n", getInfo->intf, vendorFileName);
1057
1058 if (system(gCmdStr) == -1)
1059 {
1060 infoResp.status = STATUS_ERROR;
1061 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1062 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1063
1064 DPRINT_ERR(WFA_ERR, "script %s failed\n", vendorFileName);
1065 return WFA_FAILURE;
1066 }
1067
1068 /* open the output result and scan/retrieve the info */
1069 tmpfd = fopen(vendorFileName, "r+");
1070
1071 if(tmpfd == NULL || fgets(vendor, 256, tmpfd) == NULL)
1072 {
1073 infoResp.status = STATUS_ERROR;
1074 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1075 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1076
1077 DPRINT_ERR(WFA_ERR, "file read failed\n");
1078
1079 if (tmpfd != NULL)
1080 {
1081 fclose(tmpfd);
1082 remove(vendorFileName);
1083 }
1084
1085 return WFA_FAILURE;
1086 }
1087
1088 snprintf(infoResp.cmdru.info, sizeof(infoResp.cmdru.info), "interface,%s,description,%s",
1089 getInfo->intf, vendor);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001090
Dake Zhao0a832172015-01-06 11:08:47 -08001091 infoResp.status = STATUS_COMPLETE;
Wojciech Jakobczykb8af9922020-08-25 14:49:44 +02001092 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp.status), (BYTE *)&infoResp, respBuf);
1093 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp.status);
1094
1095 fclose(tmpfd);
1096 remove(vendorFileName);
Dake Zhao0a832172015-01-06 11:08:47 -08001097
1098 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001099}
1100
1101/*
1102 * wfaStaSetEapTTLS():
1103 * This is to set
1104 * 1. ssid
1105 * 2. username
1106 * 3. passwd
1107 * 4. encrypType - tkip or aes-ccmp
1108 * 5. keyManagementType - wpa or wpa2
1109 * 6. trustedRootCA
1110 */
1111int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1112{
Dake Zhao0a832172015-01-06 11:08:47 -08001113 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1114 char *ifname = setTTLS->intf;
1115 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001116
1117#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001118 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
1119 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001120#else
1121
Dake Zhao0a832172015-01-06 11:08:47 -08001122 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1123 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001124
Dake Zhao0a832172015-01-06 11:08:47 -08001125 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
1126 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001127
Dake Zhao0a832172015-01-06 11:08:47 -08001128 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
1129 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001130
Dake Zhao0a832172015-01-06 11:08:47 -08001131 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
1132 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001133
Dake Zhao0a832172015-01-06 11:08:47 -08001134 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1135 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001136
Dake Zhao0a832172015-01-06 11:08:47 -08001137 /* This may not need to set. if it is not set, default to take all */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001138// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001139 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1140 {
1141 }
1142 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1143 {
1144 }
1145 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1146 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001147
Dake Zhao0a832172015-01-06 11:08:47 -08001148 }
1149 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1150 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001151
Dake Zhao0a832172015-01-06 11:08:47 -08001152 }
1153 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1154 {
1155 // to take all and device to pick one it supported
1156 }
1157 else
1158 {
1159 // ??
1160 }
1161 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001162
Dake Zhao0a832172015-01-06 11:08:47 -08001163 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
1164 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001165
Dake Zhao0a832172015-01-06 11:08:47 -08001166 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
1167 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001168
Dake Zhao0a832172015-01-06 11:08:47 -08001169 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1170 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001171
Dake Zhao0a832172015-01-06 11:08:47 -08001172 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
1173 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001174
Dake Zhao0a832172015-01-06 11:08:47 -08001175 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1176 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001177#endif
1178
Dake Zhao0a832172015-01-06 11:08:47 -08001179 setEapTtlsResp->status = STATUS_COMPLETE;
1180 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1181 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001182
Dake Zhao0a832172015-01-06 11:08:47 -08001183 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001184}
1185
1186/*
1187 * wfaStaSetEapSIM():
1188 * This is to set
1189 * 1. ssid
1190 * 2. user name
1191 * 3. passwd
1192 * 4. encrypType - tkip or aes-ccmp
1193 * 5. keyMangementType - wpa or wpa2
1194 */
1195int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1196{
Dake Zhao0a832172015-01-06 11:08:47 -08001197 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1198 char *ifname = setSIM->intf;
1199 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001200
1201#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001202 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
1203 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001204#else
1205
Dake Zhao0a832172015-01-06 11:08:47 -08001206 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1207 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001208
Dake Zhao0a832172015-01-06 11:08:47 -08001209 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
1210 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001211
1212
Dake Zhao0a832172015-01-06 11:08:47 -08001213 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
1214 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001215
Dake Zhao0a832172015-01-06 11:08:47 -08001216 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
1217 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001218
Dake Zhao0a832172015-01-06 11:08:47 -08001219 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
1220 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001221
Dake Zhao0a832172015-01-06 11:08:47 -08001222 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1223 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001224
Dake Zhao0a832172015-01-06 11:08:47 -08001225 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1226 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001227
Dake Zhao0a832172015-01-06 11:08:47 -08001228 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1229 {
1230 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1231 }
1232 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1233 {
1234 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1235 }
1236 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1237 {
1238 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1239 }
1240 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1241 {
1242 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1243 }
1244 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1245 {
1246 // take all and device to pick one which is supported.
1247 }
1248 else
1249 {
1250 // ??
1251 }
1252 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001253
1254#endif
1255
Dake Zhao0a832172015-01-06 11:08:47 -08001256 setEapSimResp->status = STATUS_COMPLETE;
1257 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1258 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001259
Dake Zhao0a832172015-01-06 11:08:47 -08001260 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001261}
1262
1263/*
1264 * wfaStaSetPEAP()
1265 * This is to set
1266 * 1. ssid
1267 * 2. user name
1268 * 3. passwd
1269 * 4. encryType - tkip or aes-ccmp
1270 * 5. keyMgmtType - wpa or wpa2
1271 * 6. trustedRootCA
1272 * 7. innerEAP
1273 * 8. peapVersion
1274 */
1275int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1276{
Dake Zhao0a832172015-01-06 11:08:47 -08001277 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1278 char *ifname = setPEAP->intf;
1279 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001280
1281#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001282 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1283 setPEAP->passwd, setPEAP->trustedRootCA,
1284 setPEAP->encrptype, setPEAP->peapVersion,
1285 setPEAP->innerEAP);
1286 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001287#else
1288
Dake Zhao0a832172015-01-06 11:08:47 -08001289 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1290 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001291
Dake Zhao0a832172015-01-06 11:08:47 -08001292 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
1293 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001294
Dake Zhao0a832172015-01-06 11:08:47 -08001295 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
1296 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001297
Dake Zhao0a832172015-01-06 11:08:47 -08001298 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
1299 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001300
Dake Zhao0a832172015-01-06 11:08:47 -08001301 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
1302 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001303
Dake Zhao0a832172015-01-06 11:08:47 -08001304 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
1305 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001306
Dake Zhao0a832172015-01-06 11:08:47 -08001307 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
1308 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001309
Dake Zhao0a832172015-01-06 11:08:47 -08001310 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1311 {
1312 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1313 }
1314 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1315 {
1316 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1317 }
1318 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1319 {
1320 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1321 }
1322 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1323 {
1324 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1325 }
1326 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1327 {
1328 // take all and device to pick one which is supported.
1329 }
1330 else
1331 {
1332 // ??
1333 }
1334 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001335
Dake Zhao0a832172015-01-06 11:08:47 -08001336 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
1337 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001338
Dake Zhao0a832172015-01-06 11:08:47 -08001339 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
1340 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001341
Dake Zhao0a832172015-01-06 11:08:47 -08001342 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1343 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001344#endif
1345
Dake Zhao0a832172015-01-06 11:08:47 -08001346 setPeapResp->status = STATUS_COMPLETE;
1347 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1348 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001349
Dake Zhao0a832172015-01-06 11:08:47 -08001350 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001351}
1352
1353/*
1354 * wfaStaSetUAPSD()
1355 * This is to set
1356 * 1. acBE
1357 * 2. acBK
1358 * 3. acVI
1359 * 4. acVO
1360 */
1361int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1362{
Dake Zhao0a832172015-01-06 11:08:47 -08001363 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001364#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001365 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1366 char *ifname = setUAPSD->intf;
1367 char tmpStr[10];
1368 char line[100];
1369 char *pathl="/etc/Wireless/RT61STA";
1370 BYTE acBE=1;
1371 BYTE acBK=1;
1372 BYTE acVO=1;
1373 BYTE acVI=1;
1374 BYTE APSDCapable;
1375 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001376
Dake Zhao0a832172015-01-06 11:08:47 -08001377 /*
1378 * A series of setting need to be done before doing WMM-PS
1379 * Additional steps of configuration may be needed.
1380 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001381
Dake Zhao0a832172015-01-06 11:08:47 -08001382 /*
1383 * bring down the interface
1384 */
1385 sprintf(gCmdStr, "ifconfig %s down",ifname);
1386 sret = system(gCmdStr);
1387 /*
1388 * Unload the Driver
1389 */
1390 sprintf(gCmdStr, "rmmod rt61");
1391 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001392#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001393 if(setUAPSD->acBE != 1)
1394 acBE=setUAPSD->acBE = 0;
1395 if(setUAPSD->acBK != 1)
1396 acBK=setUAPSD->acBK = 0;
1397 if(setUAPSD->acVO != 1)
1398 acVO=setUAPSD->acVO = 0;
1399 if(setUAPSD->acVI != 1)
1400 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001401#else
Dake Zhao0a832172015-01-06 11:08:47 -08001402 acBE=setUAPSD->acBE;
1403 acBK=setUAPSD->acBK;
1404 acVO=setUAPSD->acVO;
1405 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001406#endif
1407
Dake Zhao0a832172015-01-06 11:08:47 -08001408 APSDCapable = acBE||acBK||acVO||acVI;
1409 /*
1410 * set other AC parameters
1411 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001412
Dake Zhao0a832172015-01-06 11:08:47 -08001413 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1414 sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl);
1415 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001416
Dake Zhao0a832172015-01-06 11:08:47 -08001417 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
1418 sret = system(gCmdStr);
1419 pipe = popen("uname -r", "r");
1420 /* Read into line the output of uname*/
1421 fscanf(pipe,"%s",line);
1422 pclose(pipe);
1423
1424 /*
1425 * load the Driver
1426 */
1427 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
1428 sret = system(gCmdStr);
1429
1430 sprintf(gCmdStr, "ifconfig %s up",ifname);
1431 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001432#endif
1433
Dake Zhao0a832172015-01-06 11:08:47 -08001434 setUAPSDResp->status = STATUS_COMPLETE;
1435 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1436 *respLen = WFA_TLV_HDR_LEN + 4;
1437 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001438}
1439
1440int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1441{
Dake Zhao0a832172015-01-06 11:08:47 -08001442 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1443 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1444 dutCmdResponse_t *infoResp = &gGenericResp;
1445 /*a vendor can fill in the proper info or anything non-disclosure */
1446 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001447
Dake Zhao0a832172015-01-06 11:08:47 -08001448 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001449
Dake Zhao0a832172015-01-06 11:08:47 -08001450 if(devInfo->fw == 0)
1451 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1452 else
1453 {
1454 // Call internal API to pull the version ID */
Li Yin1ac40782015-09-23 20:38:07 +08001455 strncpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
Dake Zhao0a832172015-01-06 11:08:47 -08001456 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001457
Dake Zhao0a832172015-01-06 11:08:47 -08001458 infoResp->status = STATUS_COMPLETE;
1459 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1460 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001461
Dake Zhao0a832172015-01-06 11:08:47 -08001462 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001463
1464}
1465
1466/*
1467 * This funciton is to retrieve a list of interfaces and return
1468 * the list back to Agent control.
1469 * ********************************************************************
1470 * Note: We intend to make this WLAN interface name as a hardcode name.
1471 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001472 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1473 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001474 * likely is hardcoded just for CAPI command responses.
1475 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001476 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001477 */
1478int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1479{
Dake Zhao0a832172015-01-06 11:08:47 -08001480 dutCmdResponse_t *infoResp = &gGenericResp;
1481 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1482 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001483
Dake Zhao0a832172015-01-06 11:08:47 -08001484 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001485
Dake Zhao0a832172015-01-06 11:08:47 -08001486 switch(ifList->cmdsu.iftype)
1487 {
1488 case IF_80211:
1489 infoResp->status = STATUS_COMPLETE;
1490 ifListResp->iftype = IF_80211;
1491 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1492 strcpy(ifListResp->ifs[1], "NULL");
1493 strcpy(ifListResp->ifs[2], "NULL");
1494 break;
1495 case IF_ETH:
1496 infoResp->status = STATUS_COMPLETE;
1497 ifListResp->iftype = IF_ETH;
1498 strcpy(ifListResp->ifs[0], "eth0");
1499 strcpy(ifListResp->ifs[1], "NULL");
1500 strcpy(ifListResp->ifs[2], "NULL");
1501 break;
1502 default:
1503 {
1504 infoResp->status = STATUS_ERROR;
1505 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1506 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001507
Dake Zhao0a832172015-01-06 11:08:47 -08001508 return WFA_SUCCESS;
1509 }
1510 }
1511
1512 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1513 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1514
1515 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001516}
1517
1518int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1519{
Dake Zhao0a832172015-01-06 11:08:47 -08001520 dutCmdResponse_t *debugResp = &gGenericResp;
1521 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001522
Dake Zhao0a832172015-01-06 11:08:47 -08001523 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001524
Dake Zhao0a832172015-01-06 11:08:47 -08001525 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1526 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1527 else
1528 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001529
Dake Zhao0a832172015-01-06 11:08:47 -08001530 debugResp->status = STATUS_COMPLETE;
1531 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1532 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001533
1534
Dake Zhao0a832172015-01-06 11:08:47 -08001535 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001536}
1537
1538
1539/*
1540 * wfaStaGetBSSID():
1541 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001542 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001543int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1544{
Dake Zhao0a832172015-01-06 11:08:47 -08001545 char string[64];
1546 char *str;
1547 FILE *tmpfd;
1548 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001549
Dake Zhao0a832172015-01-06 11:08:47 -08001550 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1551 /* retrieve the BSSID */
1552 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001553
Dake Zhao0a832172015-01-06 11:08:47 -08001554 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001555
Dake Zhao0a832172015-01-06 11:08:47 -08001556 tmpfd = fopen("/tmp/bssid.txt", "r+");
1557 if(tmpfd == NULL)
1558 {
1559 bssidResp->status = STATUS_ERROR;
1560 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1561 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001562
Dake Zhao0a832172015-01-06 11:08:47 -08001563 DPRINT_ERR(WFA_ERR, "file open failed\n");
1564 return WFA_FAILURE;
1565 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001566
Dake Zhao0a832172015-01-06 11:08:47 -08001567 for(;;)
1568 {
1569 if(fscanf(tmpfd, "%s", string) == EOF)
1570 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001571 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001572 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001573 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001574 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001575
Dake Zhao0a832172015-01-06 11:08:47 -08001576 if(strncmp(string, "bssid", 5) == 0)
1577 {
1578 str = strtok(string, "=");
1579 str = strtok(NULL, "=");
1580 if(str != NULL)
1581 {
1582 strcpy(bssidResp->cmdru.bssid, str);
1583 bssidResp->status = STATUS_COMPLETE;
1584 break;
1585 }
1586 }
1587 }
1588
1589 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1590 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1591
1592 fclose(tmpfd);
1593 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001594}
1595
1596/*
1597 * wfaStaSetIBSS()
1598 * This is to set
1599 * 1. ssid
1600 * 2. channel
1601 * 3. encrypType - none or wep
1602 * optional
1603 * 4. key1
1604 * 5. key2
1605 * 6. key3
1606 * 7. key4
1607 * 8. activeIndex - 1, 2, 3, or 4
1608 */
1609int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1610{
Dake Zhao0a832172015-01-06 11:08:47 -08001611 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1612 dutCmdResponse_t *setIbssResp = &gGenericResp;
1613 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001614
Dake Zhao0a832172015-01-06 11:08:47 -08001615 /*
1616 * disable the network first
1617 */
1618 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
1619 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001620
Dake Zhao0a832172015-01-06 11:08:47 -08001621 /*
1622 * set SSID
1623 */
1624 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
1625 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001626
Dake Zhao0a832172015-01-06 11:08:47 -08001627 /*
1628 * Set channel for IBSS
1629 */
1630 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
1631 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001632
Dake Zhao0a832172015-01-06 11:08:47 -08001633 /*
1634 * Tell the supplicant for IBSS mode (1)
1635 */
1636 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
1637 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001638
Dake Zhao0a832172015-01-06 11:08:47 -08001639 /*
1640 * set Key management to NONE (NO WPA) for plaintext or WEP
1641 */
1642 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
1643 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001644
Dake Zhao0a832172015-01-06 11:08:47 -08001645 if(setIBSS->encpType == 1)
1646 {
1647 for(i=0; i<4; i++)
1648 {
1649 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1650 {
1651 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1652 setIBSS->intf, i, setIBSS->keys[i]);
1653 sret = system(gCmdStr);
1654 }
1655 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001656
Dake Zhao0a832172015-01-06 11:08:47 -08001657 i = setIBSS->activeKeyIdx;
1658 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1659 {
1660 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1661 setIBSS->intf, setIBSS->activeKeyIdx);
1662 sret = system(gCmdStr);
1663 }
1664 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001665
Dake Zhao0a832172015-01-06 11:08:47 -08001666 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
1667 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001668
Dake Zhao0a832172015-01-06 11:08:47 -08001669 setIbssResp->status = STATUS_COMPLETE;
1670 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1671 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001672
Dake Zhao0a832172015-01-06 11:08:47 -08001673 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001674}
1675
1676/*
1677 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001678 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001679 * adhoc)
1680 * Input parameters:
1681 * 1. I/F
1682 * 2. ssid
1683 * 3. mode adhoc or managed
1684 * 4. encType
1685 * 5. channel
1686 * 6. key(s)
1687 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001688 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001689int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1690{
Dake Zhao0a832172015-01-06 11:08:47 -08001691 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1692 dutCmdResponse_t *SetModeResp = &gGenericResp;
1693 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001694
Dake Zhao0a832172015-01-06 11:08:47 -08001695 /*
1696 * bring down the interface
1697 */
1698 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
1699 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001700
Dake Zhao0a832172015-01-06 11:08:47 -08001701 /*
1702 * distroy the interface
1703 */
1704 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
1705 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001706
1707
Dake Zhao0a832172015-01-06 11:08:47 -08001708 /*
1709 * re-create the interface with the given mode
1710 */
1711 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001712 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001713 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001714 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1715
Dake Zhao0a832172015-01-06 11:08:47 -08001716 sret = system(gCmdStr);
1717 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001718 {
Dake Zhao0a832172015-01-06 11:08:47 -08001719 int j = setmode->activeKeyIdx;
1720 for(i=0; i<4; i++)
1721 {
1722 if(setmode->keys[i][0] != '\0')
1723 {
1724 sprintf(gCmdStr, "iwconfig %s key s:%s",
1725 setmode->intf, setmode->keys[i]);
1726 sret = system(gCmdStr);
1727 }
1728 /* set active key */
1729 if(setmode->keys[j][0] != '\0')
1730 sprintf(gCmdStr, "iwconfig %s key s:%s",
1731 setmode->intf, setmode->keys[j]);
1732 sret = system(gCmdStr);
1733 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001734
1735 }
Dake Zhao0a832172015-01-06 11:08:47 -08001736 /*
1737 * Set channel for IBSS
1738 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001739 if(setmode->channel)
1740 {
Dake Zhao0a832172015-01-06 11:08:47 -08001741 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
1742 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001743 }
1744
1745
Dake Zhao0a832172015-01-06 11:08:47 -08001746 /*
1747 * set SSID
1748 */
1749 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
1750 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001751
Dake Zhao0a832172015-01-06 11:08:47 -08001752 /*
1753 * bring up the interface
1754 */
1755 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
1756 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001757
Dake Zhao0a832172015-01-06 11:08:47 -08001758 SetModeResp->status = STATUS_COMPLETE;
1759 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1760 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001761
Dake Zhao0a832172015-01-06 11:08:47 -08001762 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001763}
1764
1765int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1766{
Dake Zhao0a832172015-01-06 11:08:47 -08001767 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1768 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001769
Dake Zhao0a832172015-01-06 11:08:47 -08001770 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
1771 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001772
1773
Dake Zhao0a832172015-01-06 11:08:47 -08001774 SetPSResp->status = STATUS_COMPLETE;
1775 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1776 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001777
Dake Zhao0a832172015-01-06 11:08:47 -08001778 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001779}
1780
1781int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1782{
Dake Zhao0a832172015-01-06 11:08:47 -08001783 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1784 dutCmdResponse_t *upLoadResp = &gGenericResp;
1785 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001786
Dake Zhao0a832172015-01-06 11:08:47 -08001787 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1788 {
1789 int rbytes;
1790 /*
1791 * if asked for the first packet, always to open the file
1792 */
1793 if(upload->next == 1)
1794 {
1795 if(e2efp != NULL)
1796 {
1797 fclose(e2efp);
1798 e2efp = NULL;
1799 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001800
Dake Zhao0a832172015-01-06 11:08:47 -08001801 e2efp = fopen(e2eResults, "r");
1802 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001803
Dake Zhao0a832172015-01-06 11:08:47 -08001804 if(e2efp == NULL)
1805 {
1806 upLoadResp->status = STATUS_ERROR;
1807 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1808 *respLen = WFA_TLV_HDR_LEN + 4;
1809 return WFA_FAILURE;
1810 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001811
Dake Zhao0a832172015-01-06 11:08:47 -08001812 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001813
Dake Zhao0a832172015-01-06 11:08:47 -08001814 if(rbytes < 256)
1815 {
1816 /*
1817 * this means no more bytes after this read
1818 */
1819 upld->seqnum = 0;
1820 fclose(e2efp);
1821 e2efp=NULL;
1822 }
1823 else
1824 {
1825 upld->seqnum = upload->next;
1826 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001827
Dake Zhao0a832172015-01-06 11:08:47 -08001828 upld->nbytes = rbytes;
1829
1830 upLoadResp->status = STATUS_COMPLETE;
1831 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1832 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1833 }
1834 else
1835 {
1836 upLoadResp->status = STATUS_ERROR;
1837 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1838 *respLen = WFA_TLV_HDR_LEN + 4;
1839 }
1840
1841 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001842}
1843/*
1844 * wfaStaSetWMM()
1845 * TO be ported on a specific plaform for the DUT
1846 * This is to set the WMM related parameters at the DUT.
1847 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1848 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1849 */
1850int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1851{
1852#ifdef WFA_WMM_AC
1853 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1854 char *ifname = setwmm->intf;
1855 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001856
1857 switch(setwmm->group)
1858 {
1859 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001860 if (setwmm->send_trig)
1861 {
1862 int Sockfd;
1863 struct sockaddr_in psToAddr;
1864 unsigned int TxMsg[512];
1865
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001866 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001867 memset(&psToAddr, 0, sizeof(psToAddr));
1868 psToAddr.sin_family = AF_INET;
1869 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1870 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001871
1872
Dake Zhao0a832172015-01-06 11:08:47 -08001873 switch (setwmm->trig_ac)
1874 {
1875 case WMMAC_AC_VO:
1876 wfaTGSetPrio(Sockfd, 7);
1877 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1878 printf("\r\nSending AC_VO trigger packet\n");
1879 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001880
Dake Zhao0a832172015-01-06 11:08:47 -08001881 case WMMAC_AC_VI:
1882 wfaTGSetPrio(Sockfd, 5);
1883 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1884 printf("\r\nSending AC_VI trigger packet\n");
1885 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001886
Dake Zhao0a832172015-01-06 11:08:47 -08001887 case WMMAC_AC_BK:
1888 wfaTGSetPrio(Sockfd, 2);
1889 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1890 printf("\r\nSending AC_BK trigger packet\n");
1891 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001892
Dake Zhao0a832172015-01-06 11:08:47 -08001893 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001894 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001895 wfaTGSetPrio(Sockfd, 0);
1896 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1897 printf("\r\nSending AC_BE trigger packet\n");
1898 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001899 }
1900
Dake Zhao0a832172015-01-06 11:08:47 -08001901 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1902 sizeof(struct sockaddr));
1903 close(Sockfd);
1904 usleep(1000000);
1905 }
1906 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001907 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001908 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001909 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1910 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1911 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1912 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1913 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1914 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1915 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1916 setwmm->actions.addts.dialog_token,
1917 setwmm->actions.addts.tspec.tsinfo.TID,
1918 setwmm->actions.addts.tspec.tsinfo.direction,
1919 setwmm->actions.addts.tspec.tsinfo.PSB,
1920 setwmm->actions.addts.tspec.tsinfo.UP,
1921 setwmm->actions.addts.tspec.tsinfo.infoAck,
1922 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1923 setwmm->actions.addts.tspec.Fixed,
1924 setwmm->actions.addts.tspec.size,
1925 setwmm->actions.addts.tspec.maxsize,
1926 setwmm->actions.addts.tspec.min_srvc,
1927 setwmm->actions.addts.tspec.max_srvc,
1928 setwmm->actions.addts.tspec.inactivity,
1929 setwmm->actions.addts.tspec.suspension,
1930 setwmm->actions.addts.tspec.srvc_strt_tim,
1931 setwmm->actions.addts.tspec.mindatarate,
1932 setwmm->actions.addts.tspec.meandatarate,
1933 setwmm->actions.addts.tspec.peakdatarate,
1934 setwmm->actions.addts.tspec.burstsize,
1935 setwmm->actions.addts.tspec.delaybound,
1936 setwmm->actions.addts.tspec.PHYrate,
1937 setwmm->actions.addts.tspec.sba,
1938 setwmm->actions.addts.tspec.medium_time,
1939 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001940
Dake Zhao862c94b2014-12-08 14:35:35 -08001941 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001942
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001943 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001944 }
1945 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08001946 {
1947 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001948 }
1949
1950 setwmmResp->status = STATUS_COMPLETE;
1951 break;
1952
1953 case GROUP_WMMCONF:
1954 sprintf(gCmdStr, "iwconfig %s rts %d",
1955 ifname,setwmm->actions.config.rts_thr);
1956
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001957 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001958 sprintf(gCmdStr, "iwconfig %s frag %d",
1959 ifname,setwmm->actions.config.frag_thr);
1960
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001961 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001962 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1963 ifname, setwmm->actions.config.wmm);
1964
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001965 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001966 setwmmResp->status = STATUS_COMPLETE;
1967 break;
1968
1969 default:
1970 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1971 setwmmResp->status = STATUS_ERROR;
1972 break;
1973
1974 }
1975
1976 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1977 *respLen = WFA_TLV_HDR_LEN + 4;
1978#endif
1979
1980 return WFA_SUCCESS;
1981}
1982
1983int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1984{
Dake Zhao0a832172015-01-06 11:08:47 -08001985 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001986
Dake Zhao0a832172015-01-06 11:08:47 -08001987 /*
1988 * run your device to send NEIGREQ
1989 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001990
Dake Zhao0a832172015-01-06 11:08:47 -08001991 sendNeigReqResp->status = STATUS_COMPLETE;
1992 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
1993 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001994
Dake Zhao0a832172015-01-06 11:08:47 -08001995 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001996}
1997
1998int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1999{
2000 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
2001 char *ifname = setFAST->intf;
2002 dutCmdResponse_t *setEapFastResp = &gGenericResp;
2003
2004#ifdef WFA_NEW_CLI_FORMAT
2005 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08002006 setFAST->passwd, setFAST->pacFileName,
2007 setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002008 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002009#else
2010
2011 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002012 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002013
2014 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002015 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002016
2017 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002018 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002019
2020 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002021 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002022
2023 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
2024 {
2025 }
2026 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
2027 {
2028 }
2029 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
2030 {
Dake Zhao0a832172015-01-06 11:08:47 -08002031
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002032 }
2033 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2034 {
Dake Zhao0a832172015-01-06 11:08:47 -08002035 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002036 }
2037 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2038 {
Dake Zhao0a832172015-01-06 11:08:47 -08002039 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002040 }
2041 else
2042 {
Dake Zhao0a832172015-01-06 11:08:47 -08002043 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002044 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002045 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002046
2047 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002048 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002049
2050 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 -08002051 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002052
2053 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", 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 phase1 '\"fast_provisioning=1\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002057 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002058
2059 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002060 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002061
2062 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002063 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002064#endif
2065
2066 setEapFastResp->status = STATUS_COMPLETE;
2067 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2068 *respLen = WFA_TLV_HDR_LEN + 4;
2069
2070 return WFA_SUCCESS;
2071}
2072
2073int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2074{
2075 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2076 char *ifname = setAKA->intf;
2077 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2078
2079#ifdef WFA_NEW_CLI_FORMAT
2080 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002081 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002082#else
2083
2084 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002085 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002086
2087 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002088 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002089
2090 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2091 {
2092 }
2093 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2094 {
2095 }
2096 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2097 {
Dake Zhao0a832172015-01-06 11:08:47 -08002098
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002099 }
2100 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2101 {
Dake Zhao0a832172015-01-06 11:08:47 -08002102 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002103 }
2104 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2105 {
Dake Zhao0a832172015-01-06 11:08:47 -08002106 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002107 }
2108 else
2109 {
Dake Zhao0a832172015-01-06 11:08:47 -08002110 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002111 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002112 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002113
2114 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002115 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002116 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002117 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002118
2119 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002120 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002121
2122 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002123 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002124
2125 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002126 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002127
2128 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002129 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002130
2131 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002132 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002133#endif
2134
2135 setEapAkaResp->status = STATUS_COMPLETE;
2136 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2137 *respLen = WFA_TLV_HDR_LEN + 4;
2138
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002139 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002140}
2141
2142int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2143{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002144 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2145 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002146
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002147 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002148
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002149 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2150 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002151
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002152 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2153 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002154
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002155 setSystimeResp->status = STATUS_COMPLETE;
2156 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2157 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002158
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002159 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002160}
2161
2162#ifdef WFA_STA_TB
2163int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2164{
Dake Zhao0a832172015-01-06 11:08:47 -08002165 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2166 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2167 BYTE presetDone = 1;
2168 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002169 char cmdStr[128];
2170 char string[256];
2171 FILE *tmpfd = NULL;
2172 long val;
2173 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002174
Dake Zhao0a832172015-01-06 11:08:47 -08002175 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002176
Ray Wangd11ca032015-05-29 18:25:46 -07002177 if (presetParams->supplicant == eWpaSupplicant)
2178 {
2179 st = access("/tmp/processid.txt", F_OK);
2180 if (st != -1)
2181 {
2182 st = remove("/tmp/processid.txt");
2183 }
2184
2185 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
2186 st = system(cmdStr);
2187
2188 tmpfd = fopen("/tmp/processid.txt", "r+");
2189 if (tmpfd == NULL)
2190 {
2191 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2192 return WFA_FAILURE;
2193 }
2194
2195 for (;;)
2196 {
2197 if (fgets(string, 256, tmpfd) == NULL)
2198 break;
2199
2200 errno = 0;
2201 val = strtol(string, &endptr, 10);
2202 if (errno != 0 && val == 0)
2203 {
2204 DPRINT_ERR(WFA_ERR, "strtol error\n");
2205 return WFA_FAILURE;
2206 }
2207
2208 if (endptr == string)
2209 {
2210 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2211 }
2212
2213 presetDone = 1;
2214 }
2215 }
2216
Dake Zhao0a832172015-01-06 11:08:47 -08002217 if(presetParams->wmmFlag)
2218 {
2219 st = wfaExecuteCLI(gCmdStr);
2220 switch(st)
2221 {
2222 case 0:
2223 presetDone = 1;
2224 break;
2225 case 1:
2226 presetDone = 0;
2227 break;
2228 case 2:
2229 presetDone = 0;
2230 break;
2231 }
2232 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002233
Dake Zhao0a832172015-01-06 11:08:47 -08002234 if(presetParams->modeFlag != 0)
2235 {
2236 switch(presetParams->wirelessMode)
2237 {
2238 default:
2239 printf("other mode does not need to support\n");
2240 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002241
Dake Zhao0a832172015-01-06 11:08:47 -08002242 st = wfaExecuteCLI(gCmdStr);
2243 switch(st)
2244 {
2245 case 0:
2246 presetDone = 1;
2247 break;
2248 case 1:
2249 presetDone = 0;
2250 case 2:
2251 presetDone = 0;
2252 break;
2253 }
2254 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002255
2256
Dake Zhao0a832172015-01-06 11:08:47 -08002257 if(presetParams->psFlag)
2258 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002259
Dake Zhao0a832172015-01-06 11:08:47 -08002260 printf("%s\n", gCmdStr);
2261 sret = system(gCmdStr);
2262 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002263
Dake Zhao0a832172015-01-06 11:08:47 -08002264 /************the followings are used for Voice Enterprise **************/
2265 if(presetParams->program == PROG_TYPE_VENT)
2266 {
2267 if(presetParams->ftoa == eEnable)
2268 {
2269 // enable Fast BSS Transition Over the Air
2270 }
2271 else
2272 {
2273 // disable Fast BSS Transition Over the Air
2274 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002275
Dake Zhao0a832172015-01-06 11:08:47 -08002276 if(presetParams->ftds == eEnable)
2277 {
2278 // enable Fast BSS Transition Over the DS
2279 }
2280 else
2281 {
2282 // disable Fast BSS Transition Over the DS
2283 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002284
Dake Zhao0a832172015-01-06 11:08:47 -08002285 if(presetParams->activescan == eEnable)
2286 {
2287 // Enable Active Scan on STA
2288 }
2289 else
2290 {
2291 // disable Active Scan on STA
2292 }
2293 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002294
Dake Zhao0a832172015-01-06 11:08:47 -08002295 /************the followings are used for Wi-Fi Display *************/
2296 if(presetParams->program == PROG_TYPE_WFD)
2297 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002298
Dake Zhao0a832172015-01-06 11:08:47 -08002299 if(presetParams->tdlsFlag)
2300 {
2301 // enable / disable tdls based on tdls
2302 }
2303 if(presetParams->wfdDevTypeFlag)
2304 {
2305 // set WFD device type to source/sink/dual based on wfdDevType
2306 }
2307 if(presetParams->wfdUibcGenFlag)
2308 {
2309 // enable / disable the feature
2310 }
2311 if(presetParams->wfdUibcHidFlag)
2312 {
2313 // enable / disable feature
2314 }
2315 if(presetParams->wfdUiInputFlag)
2316 {
2317 // set the UI input as mentioned
2318 }
2319 if(presetParams->wfdHdcpFlag)
2320 {
2321 // enable / disable feature
2322 }
2323 if(presetParams->wfdFrameSkipFlag)
2324 {
2325 // enable / disable feature
2326 }
2327 if(presetParams->wfdAvChangeFlag)
2328 {
2329 // enable / disable feature
2330 }
2331 if(presetParams->wfdStandByFlag)
2332 {
2333 // enable / disable feature
2334 }
2335 if(presetParams->wfdInVideoFlag)
2336 {
2337 // select the input vide as protecteed or non-protetcted or protected audio
2338 // or unprotected audio etc.
2339 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002340
Dake Zhao0a832172015-01-06 11:08:47 -08002341 if(presetParams->wfdVideoFmatFlag)
2342 {
2343 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002344
Dake Zhao0a832172015-01-06 11:08:47 -08002345 //switch(presetParams->wfdVideoFmt )
2346 //{
2347 // case e640x480p60:
2348 // ;
2349 // default:
2350 // set the mandatory
2351 // }
2352 }
2353 if(presetParams->wfdAudioFmatFlag)
2354 {
2355 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002356
Dake Zhao0a832172015-01-06 11:08:47 -08002357 //switch(presetParams->wfdAudioFmt )
2358 //{
2359 // case eMandatoryAudioMode:
2360 // ;
2361 // case eDefaultAudioMode:
2362 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002363
Dake Zhao0a832172015-01-06 11:08:47 -08002364 // default:
2365 // set the mandatory
2366 // }
2367 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002368
Dake Zhao0a832172015-01-06 11:08:47 -08002369 if(presetParams->wfdI2cFlag)
2370 {
2371 // enable / disable feature
2372 }
2373 if(presetParams->wfdVideoRecoveryFlag)
2374 {
2375 // enable / disable feature
2376 }
2377 if(presetParams->wfdPrefDisplayFlag)
2378 {
2379 // enable / disable feature
2380 }
2381 if(presetParams->wfdServiceDiscoveryFlag)
2382 {
2383 // enable / disable feature
2384 }
2385 if(presetParams->wfd3dVideoFlag)
2386 {
2387 // enable / disable feature
2388 }
2389 if(presetParams->wfdMultiTxStreamFlag)
2390 {
2391 // enable / disable feature
2392 }
2393 if(presetParams->wfdTimeSyncFlag)
2394 {
2395 // enable / disable feature
2396 }
2397 if(presetParams->wfdEDIDFlag)
2398 {
2399 // enable / disable feature
2400 }
2401 if(presetParams->wfdUIBCPrepareFlag)
2402 {
2403 // Provdes information to start valid WFD session to check UIBC operation.
2404 }
2405 if(presetParams->wfdCoupledCapFlag)
2406 {
2407 // enable / disable feature
2408 }
2409 if(presetParams->wfdOptionalFeatureFlag)
2410 {
2411 // disable all program specific optional features
2412 }
2413 if(presetParams->wfdSessionAvailFlag)
2414 {
2415 // enable / disable session available bit
2416 }
2417 if(presetParams->wfdDeviceDiscoverabilityFlag)
2418 {
2419 // enable / disable feature
2420 }
2421 }
2422
Dake Zhao655efed2015-03-11 17:39:13 -07002423 if(presetParams->program == PROG_TYPE_WFDS)
2424 {
2425
2426 if(presetParams->wfdsType == eAcceptPD)
2427 {
2428 // preset to accept PD request
2429 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2430 {
2431 // use presetParams->wfdsConnectionCapability and set role accordingly
2432 }
2433
2434 }
2435 if(presetParams->wfdsType == eRejectPD)
2436 {
2437 // preset to Reject PD request
2438 }
2439 if(presetParams->wfdsType == eIgnorePD)
2440 {
2441 // preset to Ignore PD request
2442 }
2443 if(presetParams->wfdsType == eRejectSession)
2444 {
2445 // preset to reject Session request
2446 }
2447
2448 }
2449
2450 if (presetDone)
2451 {
2452 PresetParamsResp->status = STATUS_COMPLETE;
2453 }
2454 else
2455 {
2456 PresetParamsResp->status = STATUS_INVALID;
2457 }
Dake Zhao0a832172015-01-06 11:08:47 -08002458
2459 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2460 *respLen = WFA_TLV_HDR_LEN + 4;
2461
2462 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002463}
2464
2465int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2466{
2467 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2468
2469 v11nParamsResp->status = STATUS_COMPLETE;
2470 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2471 *respLen = WFA_TLV_HDR_LEN + 4;
2472 return WFA_SUCCESS;
2473}
2474int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2475{
2476 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2477
2478 staWirelessResp->status = STATUS_COMPLETE;
2479 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2480 *respLen = WFA_TLV_HDR_LEN + 4;
2481 return WFA_SUCCESS;
2482}
2483
2484int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2485{
2486 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2487
2488 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2489 *respLen = WFA_TLV_HDR_LEN + 4;
2490 return WFA_SUCCESS;
2491}
2492
2493int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2494{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002495 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002496
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002497 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2498 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002499
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002500 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002501}
2502
2503int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2504{
2505 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2506
2507 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2508 *respLen = WFA_TLV_HDR_LEN + 4;
2509
2510 return WFA_SUCCESS;
2511
2512}
2513
2514int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2515{
Dake Zhao0a832172015-01-06 11:08:47 -08002516 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2517 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002518
2519
Dake Zhao0a832172015-01-06 11:08:47 -08002520 // need to make your own command available for this, here is only an example
2521 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2522 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002523
Dake Zhao0a832172015-01-06 11:08:47 -08002524 ResetResp->status = STATUS_COMPLETE;
2525 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2526 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002527
Dake Zhao0a832172015-01-06 11:08:47 -08002528 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002529}
2530
2531#else
2532
2533int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2534{
2535 dutCmdResponse_t *staCmdResp = &gGenericResp;
2536
2537 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2538 *respLen = WFA_TLV_HDR_LEN + 4;
2539
2540 return WFA_SUCCESS;
2541}
2542#endif
2543
2544/*
2545 * This is used to send a frame or action frame
2546 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002547int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002548{
Dake Zhao0a832172015-01-06 11:08:47 -08002549 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2550 /* uncomment it if needed */
2551 // char *ifname = cmd->intf;
2552 dutCmdResponse_t *devSendResp = &gGenericResp;
2553 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002554
Dake Zhao0a832172015-01-06 11:08:47 -08002555 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2556 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002557
Dake Zhao0a832172015-01-06 11:08:47 -08002558 switch(sf->program)
2559 {
2560 case PROG_TYPE_PMF:
2561 {
2562 pmfFrame_t *pmf = &sf->frameType.pmf;
2563 switch(pmf->eFrameName)
2564 {
2565 case PMF_TYPE_DISASSOC:
2566 {
2567 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002568
Dake Zhao0a832172015-01-06 11:08:47 -08002569 }
2570 break;
2571 case PMF_TYPE_DEAUTH:
2572 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002573
Dake Zhao0a832172015-01-06 11:08:47 -08002574 }
2575 break;
2576 case PMF_TYPE_SAQUERY:
2577 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002578
Dake Zhao0a832172015-01-06 11:08:47 -08002579 }
2580 break;
2581 case PMF_TYPE_AUTH:
2582 {
2583 }
2584 break;
2585 case PMF_TYPE_ASSOCREQ:
2586 {
2587 }
2588 break;
2589 case PMF_TYPE_REASSOCREQ:
2590 {
2591 }
2592 break;
2593 }
2594 }
2595 break;
2596 case PROG_TYPE_TDLS:
2597 {
2598 tdlsFrame_t *tdls = &sf->frameType.tdls;
2599 switch(tdls->eFrameName)
2600 {
2601 case TDLS_TYPE_DISCOVERY:
2602 /* use the peer mac address to send the frame */
2603 break;
2604 case TDLS_TYPE_SETUP:
2605 break;
2606 case TDLS_TYPE_TEARDOWN:
2607 break;
2608 case TDLS_TYPE_CHANNELSWITCH:
2609 break;
2610 case TDLS_TYPE_NULLFRAME:
2611 break;
2612 }
2613 }
2614 break;
2615 case PROG_TYPE_VENT:
2616 {
2617 ventFrame_t *vent = &sf->frameType.vent;
2618 switch(vent->type)
2619 {
2620 case VENT_TYPE_NEIGREQ:
2621 break;
2622 case VENT_TYPE_TRANSMGMT:
2623 break;
2624 }
2625 }
2626 break;
2627 case PROG_TYPE_WFD:
2628 {
2629 wfdFrame_t *wfd = &sf->frameType.wfd;
2630 switch(wfd->eframe)
2631 {
2632 case WFD_FRAME_PRBREQ:
2633 {
2634 /* send probe req */
2635 }
2636 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002637
Dake Zhao0a832172015-01-06 11:08:47 -08002638 case WFD_FRAME_PRBREQ_TDLS_REQ:
2639 {
2640 /* send tunneled tdls probe req */
2641 }
2642 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002643
Dake Zhao0a832172015-01-06 11:08:47 -08002644 case WFD_FRAME_11V_TIMING_MSR_REQ:
2645 {
2646 /* send 11v timing mearurement request */
2647 }
2648 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002649
Dake Zhao0a832172015-01-06 11:08:47 -08002650 case WFD_FRAME_RTSP:
2651 {
2652 /* send WFD RTSP messages*/
2653 // fetch the type of RTSP message and send it.
2654 switch(wfd->eRtspMsgType)
2655 {
2656 case WFD_RTSP_PAUSE:
2657 break;
2658 case WFD_RTSP_PLAY:
2659 //send RTSP PLAY
2660 break;
2661 case WFD_RTSP_TEARDOWN:
2662 //send RTSP TEARDOWN
2663 break;
2664 case WFD_RTSP_TRIG_PAUSE:
2665 //send RTSP TRIGGER PAUSE
2666 break;
2667 case WFD_RTSP_TRIG_PLAY:
2668 //send RTSP TRIGGER PLAY
2669 break;
2670 case WFD_RTSP_TRIG_TEARDOWN:
2671 //send RTSP TRIGGER TEARDOWN
2672 break;
2673 case WFD_RTSP_SET_PARAMETER:
2674 //send RTSP SET PARAMETER
2675 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2676 {
2677 //send RTSP SET PARAMETER message for UIBC keyboard
2678 }
2679 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2680 {
2681 //send RTSP SET PARAMETER message for UIBC Mouse
2682 }
2683 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2684 {
2685 //send RTSP SET PARAMETER message Capability re-negotiation
2686 }
2687 else if (wfd->eSetParams == WFD_STANDBY)
2688 {
2689 //send RTSP SET PARAMETER message for standby
2690 }
2691 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2692 {
2693 //send RTSP SET PARAMETER message for UIBC settings enable
2694 }
2695 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2696 {
2697 //send RTSP SET PARAMETER message for UIBC settings disable
2698 }
2699 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2700 {
2701 //send RTSP SET PARAMETER message for route audio
2702 }
2703 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2704 {
2705 //send RTSP SET PARAMETER message for 3D video parameters
2706 }
2707 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2708 {
2709 //send RTSP SET PARAMETER message for 2D video parameters
2710 }
2711 break;
Dake Zhao97708202014-11-26 13:59:04 -08002712 }
Dake Zhao0a832172015-01-06 11:08:47 -08002713 }
2714 break;
2715 }
2716 }
2717 break;
2718 /* not need to support HS2 release 1, due to very short time period */
2719 case PROG_TYPE_HS2_R2:
2720 {
2721 /* type of frames */
2722 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2723 switch(hs2->eframe)
2724 {
2725 case HS2_FRAME_ANQPQuery:
2726 {
Dake Zhao97708202014-11-26 13:59:04 -08002727
Dake Zhao0a832172015-01-06 11:08:47 -08002728 }
2729 break;
2730 case HS2_FRAME_DLSRequest:
2731 {
Dake Zhao97708202014-11-26 13:59:04 -08002732
Dake Zhao0a832172015-01-06 11:08:47 -08002733 }
2734 break;
2735 case HS2_FRAME_GARPReq:
2736 {
Dake Zhao97708202014-11-26 13:59:04 -08002737
Dake Zhao0a832172015-01-06 11:08:47 -08002738 }
2739 break;
2740 case HS2_FRAME_GARPRes:
2741 {
2742 }
2743 break;
2744 case HS2_FRAME_NeighAdv:
2745 {
2746 }
2747 case HS2_FRAME_ARPProbe:
2748 {
2749 }
2750 case HS2_FRAME_ARPAnnounce:
2751 {
Dake Zhao97708202014-11-26 13:59:04 -08002752
Dake Zhao0a832172015-01-06 11:08:47 -08002753 }
2754 break;
2755 case HS2_FRAME_NeighSolicitReq:
2756 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002757
Dake Zhao0a832172015-01-06 11:08:47 -08002758 }
2759 break;
2760 case HS2_FRAME_ARPReply:
2761 {
2762
2763 }
2764 break;
2765 }
2766
2767 }/* PROG_TYPE_HS2-R2 */
2768 case PROG_TYPE_GEN:
2769 {
2770 /* General frames */
2771 }
2772
2773
2774 }
2775 devSendResp->status = STATUS_COMPLETE;
2776 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2777 *respLen = WFA_TLV_HDR_LEN + 4;
2778
2779 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002780}
2781
2782/*
2783 * This is used to set a temporary MAC address of an interface
2784 */
2785int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2786{
Dake Zhao0a832172015-01-06 11:08:47 -08002787 // Uncomment it if needed
2788 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2789 // char *ifname = cmd->intf;
2790 dutCmdResponse_t *staCmdResp = &gGenericResp;
2791 // Uncomment it if needed
2792 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002793
Dake Zhao0a832172015-01-06 11:08:47 -08002794 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2795 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002796
Dake Zhao0a832172015-01-06 11:08:47 -08002797 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002798}
2799
2800
2801int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2802{
2803 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2804 //char *intf = disc->intf;
2805 dutCmdResponse_t *staDiscResp = &gGenericResp;
2806
2807 // stop the supplicant
2808
2809 staDiscResp->status = STATUS_COMPLETE;
2810
2811 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2812 *respLen = WFA_TLV_HDR_LEN + 4;
2813
2814 return WFA_SUCCESS;
2815}
2816
2817/* Execute CLI, read the status from Environment variable */
2818int wfaExecuteCLI(char *CLI)
2819{
Dake Zhao0a832172015-01-06 11:08:47 -08002820 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002821
Dake Zhao0a832172015-01-06 11:08:47 -08002822 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002823
Dake Zhao0a832172015-01-06 11:08:47 -08002824 retstr = getenv("WFA_CLI_STATUS");
2825 printf("cli status %s\n", retstr);
2826 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002827}
2828
2829/* Supporting Functions */
2830
2831void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2832{
Dake Zhao97708202014-11-26 13:59:04 -08002833 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002834 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002835// char *addr = staPing->dipaddr;
2836#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002837 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002838 char bflag[] = "-b";
2839 char *tmpstr;
2840 int inum=0;
2841#else
2842 char bflag[] = " ";
2843#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002844
Ray Wang9b47f362014-03-19 16:51:10 -07002845 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002846
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002847#ifdef WFA_PC_CONSOLE
2848
Dake Zhao353c55e2015-07-20 18:54:45 -07002849 printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d",streamid);
2850
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002851 strcpy(addr,staPing->dipaddr);
Dake Zhao353c55e2015-07-20 18:54:45 -07002852 printf("\nCS :the addr is %s ",addr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002853 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2854 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002855 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002856 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002857 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002858 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002859 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002860 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002861 tmpstr = strtok(addr, ".");
2862 inum = atoi(tmpstr);
2863
2864 printf("interval %f\n", *interval);
2865
2866 if(inum >= 224 && inum <= 239) // multicast
2867 {
2868 }
2869 else // if not MC, check if it is BC address
2870 {
2871 printf("\nCS :Inside the BC address BLOCK");
2872 printf("\nCS :the inum %d",inum);
2873 strtok(NULL, ".");
2874 //strtok(NULL, ".");
2875 tmpstr = strtok(NULL, ".");
2876 printf("tmpstr %s\n", tmpstr);
2877 inum = atoi(tmpstr);
2878 printf("\nCS : The string is %s",tmpstr);
2879 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002880 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002881 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002882 }
2883#endif
Dake Zhao97708202014-11-26 13:59:04 -08002884 if ( staPing->dscp >= 0)
2885 {
Dake Zhao0a832172015-01-06 11:08:47 -08002886 tos= convertDscpToTos(staPing->dscp);
2887 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002888 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2889 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002890 printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n",streamid, staPing->iptype);
Dake Zhao97708202014-11-26 13:59:04 -08002891 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002892
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002893 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002894 {
Dake Zhao97708202014-11-26 13:59:04 -08002895 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002896 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",
2897 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002898 else
Dake Zhao0a832172015-01-06 11:08:47 -08002899 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",
2900 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002901 sret = system(cmdStr);
2902 printf("\nCS : The command string is %s",cmdStr);
2903 }
2904 else
2905 {
Dake Zhao97708202014-11-26 13:59:04 -08002906 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002907 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",
2908 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002909 else
Dake Zhao0a832172015-01-06 11:08:47 -08002910 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",
2911 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002912 sret = system(cmdStr);
2913 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002914 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002915 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002916 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002917 printf("\nCS : The command string is %s",cmdStr);
2918
2919}
2920
2921int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2922{
2923 char strout[256];
2924 FILE *tmpfile = NULL;
2925 char cmdStr[128];
Dake Zhao353c55e2015-07-20 18:54:45 -07002926 printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002927 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002928 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002929
2930 printf("\nCS : The command string is %s",cmdStr);
2931
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002932 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002933
2934 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002935 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002936
2937 printf("\nCS : The command string is %s",cmdStr);
2938
2939 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2940
2941 if(tmpfile == NULL)
2942 {
2943 return WFA_FAILURE;
2944 }
2945
2946 if(fscanf(tmpfile, "%s", strout) != EOF)
2947 {
2948 if(*strout == '\0')
2949 {
2950 stpResp->cmdru.pingStp.sendCnt = 0;
2951 }
2952
2953 else
2954 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2955 }
2956
Dake Zhao353c55e2015-07-20 18:54:45 -07002957 printf("\nwfaStopPing after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002958
2959
2960 if(fscanf(tmpfile, "%s", strout) != EOF)
2961 {
2962 if(*strout == '\0')
2963 {
2964 stpResp->cmdru.pingStp.repliedCnt = 0;
2965 }
2966 else
2967 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2968 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002969 printf("wfaStopPing after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002970
2971 fclose(tmpfile);
2972
2973 return WFA_SUCCESS;
2974}
2975
Ankur Vachhanic485b712012-02-15 23:29:49 +00002976/*
Dake Zhao0a832172015-01-06 11:08:47 -08002977 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002978 */
2979int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2980{
Dake Zhao0a832172015-01-06 11:08:47 -08002981 dutCmdResponse_t infoResp;
2982 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002983
Dake Zhao0a832172015-01-06 11:08:47 -08002984 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002985
Dake Zhao0a832172015-01-06 11:08:47 -08002986 // Fetch the device ID and store into infoResp->cmdru.devid
2987 //strcpy(infoResp->cmdru.devid, str);
2988 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002989
Dake Zhao0a832172015-01-06 11:08:47 -08002990 infoResp.status = STATUS_COMPLETE;
2991 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2992 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2993
2994 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002995}
2996
2997
2998
2999/*
Dake Zhao0a832172015-01-06 11:08:47 -08003000 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003001 */
3002int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3003{
Dake Zhao0a832172015-01-06 11:08:47 -08003004 dutCmdResponse_t infoResp;
3005 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00003006
Dake Zhao0a832172015-01-06 11:08:47 -08003007 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003008
Dake Zhao0a832172015-01-06 11:08:47 -08003009 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003010
Dake Zhao0a832172015-01-06 11:08:47 -08003011 infoResp.status = STATUS_COMPLETE;
3012 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3013 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3014
3015 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003016}
3017/*
Dake Zhao0a832172015-01-06 11:08:47 -08003018 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003019 */
3020int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3021{
Dake Zhao0a832172015-01-06 11:08:47 -08003022 dutCmdResponse_t infoResp;
3023 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003024
Dake Zhao0a832172015-01-06 11:08:47 -08003025 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003026
Dake Zhao0a832172015-01-06 11:08:47 -08003027 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003028
Ankur Vachhanic485b712012-02-15 23:29:49 +00003029
Dake Zhao0a832172015-01-06 11:08:47 -08003030 infoResp.status = STATUS_COMPLETE;
3031 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3032 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3033
3034 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003035}
3036
3037/*
Dake Zhao0a832172015-01-06 11:08:47 -08003038 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003039 */
3040int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3041{
Dake Zhao0a832172015-01-06 11:08:47 -08003042 dutCmdResponse_t infoResp;
3043 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003044
Dake Zhao0a832172015-01-06 11:08:47 -08003045 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003046
Dake Zhao0a832172015-01-06 11:08:47 -08003047 // Fetch the group ID and store into infoResp->cmdru.grpid
3048 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003049
Dake Zhao0a832172015-01-06 11:08:47 -08003050 infoResp.status = STATUS_COMPLETE;
3051 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3052 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3053
3054 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003055}
3056
3057
3058
3059
3060/*
Dake Zhao0a832172015-01-06 11:08:47 -08003061 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003062 */
3063int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3064{
Dake Zhao0a832172015-01-06 11:08:47 -08003065 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003066
Dake Zhao0a832172015-01-06 11:08:47 -08003067 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003068
Dake Zhao0a832172015-01-06 11:08:47 -08003069 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3070 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003071
Ankur Vachhanic485b712012-02-15 23:29:49 +00003072
Dake Zhao0a832172015-01-06 11:08:47 -08003073 infoResp.status = STATUS_COMPLETE;
3074 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3075 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3076
3077 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003078}
3079
3080
3081/*
Dake Zhao0a832172015-01-06 11:08:47 -08003082 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003083 */
3084int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3085{
Dake Zhao0a832172015-01-06 11:08:47 -08003086 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003087
Dake Zhao0a832172015-01-06 11:08:47 -08003088 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003089
Dake Zhao0a832172015-01-06 11:08:47 -08003090 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003091
Dake Zhao0a832172015-01-06 11:08:47 -08003092 infoResp.status = STATUS_COMPLETE;
3093 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3094 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3095
3096 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003097}
3098
3099/*
Dake Zhao0a832172015-01-06 11:08:47 -08003100 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003101 */
3102int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3103{
Dake Zhao0a832172015-01-06 11:08:47 -08003104 dutCmdResponse_t infoResp;
3105 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003106
Dake Zhao0a832172015-01-06 11:08:47 -08003107 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003108
Dake Zhao0a832172015-01-06 11:08:47 -08003109 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003110
Dake Zhao0a832172015-01-06 11:08:47 -08003111 infoResp.status = STATUS_COMPLETE;
3112 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3113 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3114
3115 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003116}
3117
3118
3119/*
Dake Zhao0a832172015-01-06 11:08:47 -08003120 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003121 */
3122int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3123{
Dake Zhao0a832172015-01-06 11:08:47 -08003124 dutCmdResponse_t infoResp;
3125 /* uncomment and use it
3126 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3127 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003128
Dake Zhao0a832172015-01-06 11:08:47 -08003129 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003130
Dake Zhao0a832172015-01-06 11:08:47 -08003131 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003132
Dake Zhao0a832172015-01-06 11:08:47 -08003133 infoResp.status = STATUS_COMPLETE;
3134 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3135 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3136
3137 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003138}
3139
3140
3141/*
Dake Zhao0a832172015-01-06 11:08:47 -08003142 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003143 */
3144int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3145{
Dake Zhao0a832172015-01-06 11:08:47 -08003146 dutCmdResponse_t infoResp;
3147 /* uncomment and use it
3148 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3149 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003150
Dake Zhao0a832172015-01-06 11:08:47 -08003151 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003152
Dake Zhao0a832172015-01-06 11:08:47 -08003153 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003154
Dake Zhao0a832172015-01-06 11:08:47 -08003155 infoResp.status = STATUS_COMPLETE;
3156 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3157 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3158
3159 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003160}
3161
3162/*
Dake Zhao0a832172015-01-06 11:08:47 -08003163 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003164 */
3165int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3166{
Dake Zhao0a832172015-01-06 11:08:47 -08003167 dutCmdResponse_t infoResp;
3168 /* uncomment and use it
3169 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3170 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003171
Dake Zhao0a832172015-01-06 11:08:47 -08003172 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003173
Dake Zhao0a832172015-01-06 11:08:47 -08003174 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003175
Dake Zhao0a832172015-01-06 11:08:47 -08003176 infoResp.status = STATUS_COMPLETE;
3177 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3178 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3179
3180 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003181}
3182
3183/*
Dake Zhao0a832172015-01-06 11:08:47 -08003184 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003185 */
3186int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3187{
Dake Zhao0a832172015-01-06 11:08:47 -08003188 dutCmdResponse_t infoResp;
3189 /* uncomment and use it
3190 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3191 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003192
Dake Zhao0a832172015-01-06 11:08:47 -08003193 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003194
Dake Zhao0a832172015-01-06 11:08:47 -08003195 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3196 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3197 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003198
Ankur Vachhanic485b712012-02-15 23:29:49 +00003199
Dake Zhao0a832172015-01-06 11:08:47 -08003200 infoResp.status = STATUS_COMPLETE;
3201 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3202 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3203
3204 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003205}
3206
3207
3208
3209/*
Dake Zhao0a832172015-01-06 11:08:47 -08003210 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003211 */
3212int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3213{
Dake Zhao0a832172015-01-06 11:08:47 -08003214 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003215
Dake Zhao0a832172015-01-06 11:08:47 -08003216 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003217
Dake Zhao0a832172015-01-06 11:08:47 -08003218 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3219 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3220 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003221
Ankur Vachhanic485b712012-02-15 23:29:49 +00003222
Dake Zhao0a832172015-01-06 11:08:47 -08003223 infoResp.status = STATUS_COMPLETE;
3224 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3225 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3226
3227 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003228}
3229
3230
3231/*
Dake Zhao0a832172015-01-06 11:08:47 -08003232 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003233 */
3234int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3235{
Dake Zhao0a832172015-01-06 11:08:47 -08003236 dutCmdResponse_t infoResp;
3237 /* uncomment and use it
3238 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3239 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003240
Dake Zhao0a832172015-01-06 11:08:47 -08003241 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003242
Dake Zhao0a832172015-01-06 11:08:47 -08003243 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003244
Ankur Vachhanic485b712012-02-15 23:29:49 +00003245
Dake Zhao0a832172015-01-06 11:08:47 -08003246 infoResp.status = STATUS_COMPLETE;
3247 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3248 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3249
3250 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003251}
3252
3253
3254/*
Dake Zhao0a832172015-01-06 11:08:47 -08003255 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003256 */
3257int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3258{
Dake Zhao0a832172015-01-06 11:08:47 -08003259 dutCmdResponse_t infoResp;
3260 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003261
Dake Zhao0a832172015-01-06 11:08:47 -08003262 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003263
3264
Dake Zhao0a832172015-01-06 11:08:47 -08003265 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3266 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3267 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003268
Ankur Vachhanic485b712012-02-15 23:29:49 +00003269
Dake Zhao0a832172015-01-06 11:08:47 -08003270 infoResp.status = STATUS_COMPLETE;
3271 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3272 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3273
3274 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003275}
3276
3277/*
Dake Zhao0a832172015-01-06 11:08:47 -08003278 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003279 */
3280int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3281{
Dake Zhao0a832172015-01-06 11:08:47 -08003282 dutCmdResponse_t infoResp;
3283 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003284
Dake Zhao0a832172015-01-06 11:08:47 -08003285 printf("\n Entry wfaStaP2pReset... ");
3286 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003287
Dake Zhao0a832172015-01-06 11:08:47 -08003288 infoResp.status = STATUS_COMPLETE;
3289 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3290 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3291
3292 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003293}
3294
3295
3296
3297/*
Dake Zhao0a832172015-01-06 11:08:47 -08003298 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003299 */
3300int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3301{
Dake Zhao0a832172015-01-06 11:08:47 -08003302 dutCmdResponse_t infoResp;
3303 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003304
Dake Zhao0a832172015-01-06 11:08:47 -08003305 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003306
Dake Zhao0a832172015-01-06 11:08:47 -08003307 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003308
Dake Zhao0a832172015-01-06 11:08:47 -08003309 ifinfo->isDhcp =0;
3310 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3311 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3312 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3313 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3314
3315 infoResp.status = STATUS_COMPLETE;
3316 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3317 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3318
3319 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003320}
3321
3322
3323
3324
3325/*
Dake Zhao0a832172015-01-06 11:08:47 -08003326 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003327 */
3328int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3329{
Dake Zhao0a832172015-01-06 11:08:47 -08003330 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003331
Dake Zhao0a832172015-01-06 11:08:47 -08003332 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3333 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003334
Dake Zhao0a832172015-01-06 11:08:47 -08003335
3336 infoResp.status = STATUS_COMPLETE;
3337 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3338 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3339
3340 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003341}
3342
3343
3344
3345/*
Dake Zhao0a832172015-01-06 11:08:47 -08003346 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003347 */
3348int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3349{
Dake Zhao0a832172015-01-06 11:08:47 -08003350 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003351
Dake Zhao0a832172015-01-06 11:08:47 -08003352 infoResp.status = STATUS_COMPLETE;
3353 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3354 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003355
Dake Zhao0a832172015-01-06 11:08:47 -08003356 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003357}
3358
3359/*
Dake Zhao0a832172015-01-06 11:08:47 -08003360 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003361 */
3362int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3363{
Dake Zhao0a832172015-01-06 11:08:47 -08003364 dutCmdResponse_t infoResp;
3365 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003366
Dake Zhao0a832172015-01-06 11:08:47 -08003367 printf("\n Entry wfaStaSetSleepReq... ");
3368 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003369
Dake Zhao0a832172015-01-06 11:08:47 -08003370
3371 infoResp.status = STATUS_COMPLETE;
3372 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3373 *respLen = WFA_TLV_HDR_LEN +4;
3374
3375 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003376}
3377
3378/*
Dake Zhao0a832172015-01-06 11:08:47 -08003379 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003380 */
3381int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3382{
Dake Zhao0a832172015-01-06 11:08:47 -08003383 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003384
Dake Zhao0a832172015-01-06 11:08:47 -08003385 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3386 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003387
Dake Zhao0a832172015-01-06 11:08:47 -08003388
3389 infoResp.status = STATUS_COMPLETE;
3390 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3391 *respLen = WFA_TLV_HDR_LEN + 4;
3392
3393 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003394}
3395#ifndef WFA_STA_TB
3396/*
Dake Zhao0a832172015-01-06 11:08:47 -08003397 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003398 */
3399
3400int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3401{
Dake Zhao0a832172015-01-06 11:08:47 -08003402 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003403
Dake Zhao0a832172015-01-06 11:08:47 -08003404 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003405
Dake Zhao0a832172015-01-06 11:08:47 -08003406 // Implement the function and its sub commands
3407 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003408
Dake Zhao0a832172015-01-06 11:08:47 -08003409 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3410 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003411
Dake Zhao0a832172015-01-06 11:08:47 -08003412 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003413}
Dake Zhao0a832172015-01-06 11:08:47 -08003414int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003415{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003416
3417 dutCmdResponse_t infoResp;
3418 dutCmdResponse_t *v11nParamsResp = &infoResp;
3419
3420#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003421
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003422 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3423
3424 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003425
3426 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003427
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003428 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3429 {
Dake Zhao0a832172015-01-06 11:08:47 -08003430 // implement the funciton
3431 if(st != 0)
3432 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003433 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003434 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3435 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3436 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3437 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003438 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003439 }
Dake Zhao0a832172015-01-06 11:08:47 -08003440
Ankur Vachhanic485b712012-02-15 23:29:49 +00003441 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003442 {
Dake Zhao0a832172015-01-06 11:08:47 -08003443 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003444
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003445 if(st != 0)
3446 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003447 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003448 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3449 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3450 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3451 return FALSE;
3452 }
3453 }
3454
Ankur Vachhanic485b712012-02-15 23:29:49 +00003455 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003456 {
Dake Zhao0a832172015-01-06 11:08:47 -08003457 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003458 if(st != 0)
3459 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003460 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003461 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3462 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3463 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003464 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003465 }
3466 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003467
3468 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003469 {
3470 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003471 if(st != 0)
3472 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003473 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003474 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3475 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3476 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3477 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003478 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003479 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003480
3481 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003482 {
Dake Zhao0a832172015-01-06 11:08:47 -08003483 // implement the funciton
3484 //st = wfaExecuteCLI(gCmdStr);
3485 if(st != 0)
3486 {
3487 v11nParamsResp->status = STATUS_ERROR;
3488 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3489 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3490 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3491 return FALSE;
3492 }
3493 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003494 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3495 {
3496 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003497 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003498 if(st != 0)
3499 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003500 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003501 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003502 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3503 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003504 return FALSE;
3505 }
Dake Zhao0a832172015-01-06 11:08:47 -08003506 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003507 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3508 {
3509 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003510 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 if(st != 0)
3512 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003513 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003514 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003515 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3516 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003517 return FALSE;
3518 }
3519 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003520
3521 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003522 {
3523 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003524 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003525 if(st != 0)
3526 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003527 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003528 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003529 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3530 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003531 return FALSE;
3532 }
3533 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003534
3535 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003536 {
3537 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003538 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003539 if(st != 0)
3540 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003541 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003542 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3543 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3544 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3545 return FALSE;
3546 }
3547 }
3548
3549 if(v11nParams->smps != 0xFFFF)
3550 {
3551 if(v11nParams->smps == 0)
3552 {
Dake Zhao0a832172015-01-06 11:08:47 -08003553 // implement the funciton
3554 //st = wfaExecuteCLI(gCmdStr);
3555 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003556 else if(v11nParams->smps == 1)
3557 {
Dake Zhao0a832172015-01-06 11:08:47 -08003558 // implement the funciton
3559 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003560 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003561 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003562 else if(v11nParams->smps == 2)
3563 {
Dake Zhao0a832172015-01-06 11:08:47 -08003564 // implement the funciton
3565 //st = wfaExecuteCLI(gCmdStr);
3566 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003567 }
3568 if(st != 0)
3569 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003570 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003571 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3572 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3573 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3574 return FALSE;
3575 }
3576 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003577
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003578 if(v11nParams->stbc_rx != 0xFFFF)
3579 {
3580 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003581 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003582 if(st != 0)
3583 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003584 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003585 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003586 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3587 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003588 return FALSE;
3589 }
3590 }
Dake Zhao0a832172015-01-06 11:08:47 -08003591
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003592 if(v11nParams->width[0] != '\0')
3593 {
3594 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003595 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003596 if(st != 0)
3597 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003598 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003599 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3600 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3601 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3602 return FALSE;
3603 }
3604 }
Dake Zhao0a832172015-01-06 11:08:47 -08003605
Ankur Vachhanic485b712012-02-15 23:29:49 +00003606 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003607 {
3608 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003609 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003610 if(st != 0)
3611 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003612 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003613 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3614 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3615 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3616 return FALSE;
3617 }
3618 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003619
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003620 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3621 {
3622 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003623 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003624 if(st != 0)
3625 {
3626 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003627 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003628 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3629 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3630 return FALSE;
3631 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003632
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003633 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003634
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003635 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3636 {
3637 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003638 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003639 if(st != 0)
3640 {
3641 v11nParamsResp->status = STATUS_ERROR;
3642 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3643 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3644 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3645 return FALSE;
3646 }
3647 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003648
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003649#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003650
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003651 v11nParamsResp->status = STATUS_COMPLETE;
3652 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3653 *respLen = WFA_TLV_HDR_LEN + 4;
3654 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003655}
3656#endif
3657/*
Dake Zhao0a832172015-01-06 11:08:47 -08003658 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003659 */
3660int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3661{
Dake Zhao0a832172015-01-06 11:08:47 -08003662 dutCmdResponse_t infoResp;
3663 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003664
Dake Zhao0a832172015-01-06 11:08:47 -08003665 printf("\n Entry wfastaAddARPTableEntry... ");
3666 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003667
Dake Zhao0a832172015-01-06 11:08:47 -08003668 infoResp.status = STATUS_COMPLETE;
3669 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3670 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3671
3672 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003673}
3674
3675/*
Dake Zhao0a832172015-01-06 11:08:47 -08003676 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003677 */
3678int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3679{
Dake Zhao0a832172015-01-06 11:08:47 -08003680 dutCmdResponse_t infoResp;
3681 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003682
Dake Zhao0a832172015-01-06 11:08:47 -08003683 printf("\n Entry wfaStaBlockICMPResponse... ");
3684 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003685
Dake Zhao0a832172015-01-06 11:08:47 -08003686 infoResp.status = STATUS_COMPLETE;
3687 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3688 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3689
3690 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003691}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003692
3693/*
Dake Zhao0a832172015-01-06 11:08:47 -08003694 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003695 */
3696
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003697int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3698{
3699 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3700 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003701 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3702
3703 if(sr->mode == WFA_OFF)
3704 {
Dake Zhao0a832172015-01-06 11:08:47 -08003705 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003706 }
3707 else
3708 {
Dake Zhao0a832172015-01-06 11:08:47 -08003709 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003710 }
3711
3712 staCmdResp->status = STATUS_COMPLETE;
3713 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3714 *respLen = WFA_TLV_HDR_LEN + 4;
3715
3716 return WFA_SUCCESS;
3717}
3718
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003719/*
Dake Zhao0a832172015-01-06 11:08:47 -08003720 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003721 */
3722
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003723int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3724{
Dake Zhao0a832172015-01-06 11:08:47 -08003725 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3726 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3727 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003728
Dake Zhao0a832172015-01-06 11:08:47 -08003729 if(strcasecmp(rfeat->prog, "tdls") == 0)
3730 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003731
3732
Dake Zhao0a832172015-01-06 11:08:47 -08003733 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003734
Dake Zhao0a832172015-01-06 11:08:47 -08003735 caResp->status = STATUS_COMPLETE;
3736 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3737 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003738
Dake Zhao0a832172015-01-06 11:08:47 -08003739 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003740}
3741
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003742/*
Dake Zhao0a832172015-01-06 11:08:47 -08003743 * wfaStaStartWfdConnection():
3744 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003745int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3746{
Dake Zhao0a832172015-01-06 11:08:47 -08003747 dutCmdResponse_t infoResp;
3748 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003749
Dake Zhao0a832172015-01-06 11:08:47 -08003750 printf("\n Entry wfaStaStartWfdConnection... ");
3751
3752
3753 // Fetch the GrpId and WFD session and return
3754 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3755 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3756 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3757
3758 infoResp.status = STATUS_COMPLETE;
3759 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3760 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3761
3762 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003763}
3764/*
Dake Zhao0a832172015-01-06 11:08:47 -08003765 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003766 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003767
Ankur Vachhanic485b712012-02-15 23:29:49 +00003768int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3769{
Dake Zhao0a832172015-01-06 11:08:47 -08003770 char cmdName[32];
3771 char *pcmdStr=NULL, *str;
3772 int st = 1;
3773 char CmdStr[WFA_CMD_STR_SZ];
3774 FILE *wfaCliFd;
3775 char wfaCliBuff[64];
3776 char retstr[256];
3777 int CmdReturnFlag =0;
3778 char tmp[256];
Li Yincba7d352015-09-23 20:30:49 +08003779 FILE * sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003780 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003781
Dake Zhao0a832172015-01-06 11:08:47 -08003782 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3783 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3784 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003785
Dake Zhao0a832172015-01-06 11:08:47 -08003786 for(;;)
3787 {
3788 // construct CLI standard cmd string
3789 str = strtok_r(NULL, ",", &pcmdStr);
3790 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003791 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003792 else
3793 {
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003794 strcat(strcat(CmdStr, " /"), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003795 str = strtok_r(NULL, ",", &pcmdStr);
Shuo-Peng Liao806a2b52020-08-21 11:39:36 +08003796 strcat(strcat(CmdStr, " "), str);
Dake Zhao0a832172015-01-06 11:08:47 -08003797 }
3798 }
3799 // check the return process
3800 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3801 if(wfaCliFd!= NULL)
3802 {
3803 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3804 {
3805 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3806 if(ferror(wfaCliFd))
3807 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003808
Dake Zhao0a832172015-01-06 11:08:47 -08003809 str=strtok(wfaCliBuff,"-");
3810 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003811 {
Dake Zhao0a832172015-01-06 11:08:47 -08003812 str=strtok(NULL,",");
3813 if (str != NULL)
3814 {
3815 if(strcmp(str,"TRUE") == 0)
3816 CmdReturnFlag =1;
3817 }
3818 else
3819 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3820 break;
Dake Zhao97708202014-11-26 13:59:04 -08003821 }
Dake Zhao0a832172015-01-06 11:08:47 -08003822 }
3823 fclose(wfaCliFd);
3824 }
3825 else
3826 {
3827 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3828 goto cleanup;
3829 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003830
Dake Zhao0a832172015-01-06 11:08:47 -08003831 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3832 memset(&retstr[0],'\0',255);
3833 memset(&tmp[0],'\0',255);
3834 sprintf(gCmdStr, "%s", CmdStr);
3835 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003836
Dake Zhao0a832172015-01-06 11:08:47 -08003837 sh_pipe = popen(gCmdStr,"r");
3838 if(!sh_pipe)
3839 {
3840 printf ("Error in opening pipe\n");
3841 goto cleanup;
3842 }
Dake Zhao97708202014-11-26 13:59:04 -08003843
Dake Zhao0a832172015-01-06 11:08:47 -08003844 sleep(5);
3845 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3846 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3847 {
3848 printf("Getting NULL string in popen return\n");
3849 goto cleanup;
3850 }
3851 else
3852 printf("popen return str=%s\n",retstr);
3853
3854 sleep(2);
3855 if(pclose(sh_pipe) == -1)
3856 {
3857 printf("Error in closing shell cmd pipe\n");
3858 goto cleanup;
3859 }
Li Yincba7d352015-09-23 20:30:49 +08003860 sh_pipe = NULL;
Dake Zhao0a832172015-01-06 11:08:47 -08003861 sleep(2);
3862
3863 // find status first in output
3864 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3865 if (str != NULL)
3866 {
3867 memset(tmp, 0, 10);
3868 memcpy(tmp, str, 2);
3869 printf("cli status=%s\n",tmp);
3870 if(strlen(tmp) > 0)
3871 st = atoi(tmp);
3872 else printf("Missing status code\n");
3873 }
3874 else
3875 {
3876 printf("wfaStaCliCommand no return code found\n");
3877 }
3878 infoResp.resFlag=CmdReturnFlag;
3879
Dake Zhao97708202014-11-26 13:59:04 -08003880cleanup:
Li Yincba7d352015-09-23 20:30:49 +08003881 if (sh_pipe)
3882 pclose(sh_pipe);
Dake Zhao0a832172015-01-06 11:08:47 -08003883
3884 switch(st)
3885 {
3886 case 0:
3887 infoResp.status = STATUS_COMPLETE;
3888 if (CmdReturnFlag)
3889 {
3890 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3891 {
3892 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003893 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 -08003894 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3895 }
3896 else
3897 {
Dake Zhao97708202014-11-26 13:59:04 -08003898 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003899 }
3900 }
3901 break;
3902 case 1:
3903 infoResp.status = STATUS_ERROR;
3904 break;
3905 case 2:
3906 infoResp.status = STATUS_INVALID;
3907 break;
3908 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003909
Dake Zhao0a832172015-01-06 11:08:47 -08003910 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3911 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003912
Dake Zhao0a832172015-01-06 11:08:47 -08003913 printf("Exit from wfaStaCliCommand\n");
3914 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003915
Ankur Vachhanic485b712012-02-15 23:29:49 +00003916}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003917/*
Dake Zhao0a832172015-01-06 11:08:47 -08003918 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003919 */
3920
3921int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3922{
3923 dutCmdResponse_t infoResp;
3924// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003925
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003926 printf("\n Entry wfaStaConnectGoStartWfd... ");
3927
Dake Zhao0a832172015-01-06 11:08:47 -08003928 // connect the specified GO and then establish the wfd session
3929
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003930 // Fetch WFD session and return
3931 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3932
3933 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003934 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003935 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003936
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003937 return WFA_SUCCESS;
3938}
3939
3940/*
Dake Zhao0a832172015-01-06 11:08:47 -08003941 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003942 */
3943
3944int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3945{
3946 dutCmdResponse_t infoResp;
3947 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3948 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003949
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003950 printf("\n Entry wfaStaGenerateEvent... ");
3951
3952
3953 // Geneate the specified action and return with complete/error.
3954 if(staGenerateEvent->program == PROG_TYPE_WFD)
3955 {
3956 wfdGenEvent = &staGenerateEvent->wfdEvent;
3957 if(wfdGenEvent ->type == eUibcGen)
3958 {
Dake Zhao0a832172015-01-06 11:08:47 -08003959 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003960 else if(wfdGenEvent ->type == eUibcHid)
3961 {
Dake Zhao0a832172015-01-06 11:08:47 -08003962 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003963 else if(wfdGenEvent ->type == eFrameSkip)
3964 {
3965
3966 }
3967 else if(wfdGenEvent ->type == eI2cRead)
3968 {
3969 }
3970 else if(wfdGenEvent ->type == eI2cWrite)
3971 {
Dake Zhao0a832172015-01-06 11:08:47 -08003972 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003973 else if(wfdGenEvent ->type == eInputContent)
3974 {
Dake Zhao0a832172015-01-06 11:08:47 -08003975 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003976 else if(wfdGenEvent ->type == eIdrReq)
3977 {
Dake Zhao0a832172015-01-06 11:08:47 -08003978 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003979 }
Dake Zhao0a832172015-01-06 11:08:47 -08003980
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003981 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003982 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003983 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003984
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003985 return WFA_SUCCESS;
3986}
3987
Dake Zhao0a832172015-01-06 11:08:47 -08003988
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003989
3990
3991/*
Dake Zhao0a832172015-01-06 11:08:47 -08003992 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003993 */
3994
3995int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3996{
3997 dutCmdResponse_t infoResp;
3998// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003999
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004000 printf("\n Entry wfaStaReinvokeWfdSession... ");
4001
4002 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08004003
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004004
4005 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004006 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004007 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004008
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004009 return WFA_SUCCESS;
4010}
4011
4012
4013int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4014{
Dake Zhao0a832172015-01-06 11:08:47 -08004015 dutCmdResponse_t infoResp;
4016 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004017
4018
Dake Zhao0a832172015-01-06 11:08:47 -08004019 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004020
Dake Zhao0a832172015-01-06 11:08:47 -08004021 printf("\n Entry wfaStaGetParameter... ");
4022
4023 // Check the program type
4024 if(staGetParam->program == PROG_TYPE_WFD)
4025 {
4026 if(staGetParam->getParamValue == eDiscoveredDevList )
4027 {
4028 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4029 paramList->getParamType = eDiscoveredDevList;
4030 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4031 }
4032 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004033
Dake Zhao655efed2015-03-11 17:39:13 -07004034 if(staGetParam->program == PROG_TYPE_WFDS)
4035 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004036
Dake Zhao655efed2015-03-11 17:39:13 -07004037 if(staGetParam->getParamValue == eDiscoveredDevList )
4038 {
4039 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4040 paramList->getParamType = eDiscoveredDevList;
4041 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4042
4043 }
4044 if(staGetParam->getParamValue == eOpenPorts)
4045 {
4046 // Run the port checker tool
4047 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
4048 paramList->getParamType = eOpenPorts;
4049 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
4050
4051 }
4052
4053 }
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004054 if(staGetParam->program == PROG_TYPE_NAN)
4055 {
4056 if(staGetParam->getParamValue == eMasterPref )
4057 {
4058 // Get the master preference of the device and return the value
4059 paramList->getParamType = eMasterPref;
4060 strcpy((char *)&paramList->masterPref, "0xff");
4061 }
4062 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004063
Dake Zhao655efed2015-03-11 17:39:13 -07004064 infoResp.status = STATUS_COMPLETE;
4065 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4066 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4067
4068 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004069}
4070
Ankur Vachhanic485b712012-02-15 23:29:49 +00004071
Dake Zhao655efed2015-03-11 17:39:13 -07004072int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4073{
4074
4075 dutCmdResponse_t infoResp;
4076 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4077
4078 printf("\n Entry wfaStaNfcAction... ");
4079
4080 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4081 {
4082 printf("\n NfcAction - HandOver... ");
4083
4084 }
4085 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4086 {
4087 printf("\n NfcAction - Read Tag... ");
4088
4089 }
4090 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4091 {
4092 printf("\n NfcAction - Write Select... ");
4093
4094 }
4095 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4096 {
4097 printf("\n NfcAction - Write Config... ");
4098
4099 }
4100 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4101 {
4102 printf("\n NfcAction - Write Password... ");
4103
4104 }
4105 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4106 {
4107 printf("\n NfcAction - WPS Handover... ");
4108
4109 }
4110
4111 // Fetch the device mode and put in infoResp->cmdru.p2presult
4112 //strcpy(infoResp->cmdru.p2presult, "GO");
4113
4114 // Fetch the device grp id and put in infoResp->cmdru.grpid
4115 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4116
4117 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4118 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4119 infoResp.cmdru.staNfcAction.peerRole = 1;
4120
4121
4122
4123
4124 infoResp.status = STATUS_COMPLETE;
4125 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4126 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4127
4128 return WFA_SUCCESS;
4129}
4130
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004131int wfaStaExecAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4132{
4133
4134 dutCmdResponse_t infoResp;
4135 caStaExecAction_t *staExecAction = (caStaExecAction_t *)caCmdBuf; //comment if not used
4136
4137 printf("\n Entry wfaStaExecAction... ");
4138
4139 if(staExecAction->prog == PROG_TYPE_NAN)
4140 {
4141 // Perform necessary configurations and actions
4142 // return the MAC address conditionally as per CAPI specification
4143 }
4144
4145 infoResp.status = STATUS_COMPLETE;
4146 wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4147 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4148
4149 return WFA_SUCCESS;
4150}
4151
Dake Zhao655efed2015-03-11 17:39:13 -07004152int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4153{
4154
4155 dutCmdResponse_t infoResp;
4156 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4157
4158 printf("\n Entry wfaStaInvokeCommand... ");
4159
4160
4161 // based on the command type , invoke API or complete the required procedures
4162 // return the defined parameters based on the command that is received ( example response below)
4163
4164 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4165 {
4166 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4167 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4168 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4169 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4170 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4171 }
4172 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4173 {
4174 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4175 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4176 }
4177 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4178 {
4179 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4180 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4181 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4182 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4183
4184 }
4185 infoResp.status = STATUS_COMPLETE;
4186 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4187 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4188
4189 return WFA_SUCCESS;
4190}
4191
4192
4193int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4194{
4195
4196 dutCmdResponse_t infoResp;
4197 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4198
4199 printf("\n Entry wfaStaManageService... ");
4200
4201 // based on the manage service type , invoke API's or complete the required procedures
4202 // return the defined parameters based on the command that is received ( example response below)
4203 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4204 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4205 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4206
4207 infoResp.status = STATUS_COMPLETE;
4208 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4209 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4210
4211 return WFA_SUCCESS;
4212}
4213
4214
4215
4216int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4217{
4218
4219 dutCmdResponse_t infoResp;
Dake Zhao353c55e2015-07-20 18:54:45 -07004220 caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004221
4222 printf("\n Entry wfaStaGetEvents... ");
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004223
4224 if(staGetEvents->program == PROG_TYPE_NAN)
4225 {
4226 // Get all the events from the Log file or stored events
4227 // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac
4228 }
Dake Zhao655efed2015-03-11 17:39:13 -07004229
4230 // Get all the event from the Log file or stored events
4231 // return the received/recorded events as space seperated list ( example response below)
4232 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4233
4234 infoResp.status = STATUS_COMPLETE;
4235 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4236 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4237
4238 return WFA_SUCCESS;
4239}
4240
4241int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4242{
4243
4244 dutCmdResponse_t infoResp;
Li Yinf467b182015-09-23 21:21:30 +08004245 caStaGetEventDetails_t *getStaGetEventDetails = (caStaGetEventDetails_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004246
4247 printf("\n Entry wfaStaGetEventDetails... ");
4248
4249
4250 // based on the Requested Event type
4251 // return the latest corresponding evnet detailed parameters ( example response below)
4252
4253 if(getStaGetEventDetails->eventId== eSearchResult )
4254 {
4255 // fetch from log file or event history for the search result event and return the parameters
4256 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4257
4258 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4259 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4260 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4261 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4262
4263 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4264 }
4265 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4266 { // fetch from log file or event history for the search terminated event and return the parameters
4267 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4268 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4269 }
4270 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4271 {// fetch from log file or event history for the Advertise Status event and return the parameters
4272 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4273 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4274
4275 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4276 }
4277 else if (getStaGetEventDetails->eventId == eSessionRequest)
4278 {// fetch from log file or event history for the session request event and return the parameters
4279 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4280 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4281 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4282 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4283 }
4284 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4285 {// fetch from log file or event history for the session status event and return the parameters
4286 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4287 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4288 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4289 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4290 }
4291 else if (getStaGetEventDetails->eventId == eConnectStatus)
4292 {
4293 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4294 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4295 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4296 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4297
4298 }
4299 else if (getStaGetEventDetails->eventId == ePortStatus)
4300 {
4301 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4302 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4303 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4304 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4305 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4306 }
4307
4308
4309
4310 infoResp.status = STATUS_COMPLETE;
4311 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4312 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4313
4314 return WFA_SUCCESS;
4315}
4316
4317
4318
4319