blob: 4c019f13c60e7f2b4f1ec8c5697ba6367672e4f3 [file] [log] [blame]
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001/****************************************************************************
Dake Zhao97708202014-11-26 13:59:04 -08002(c) Copyright 2014 Wi-Fi Alliance. All Rights Reserved
3
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 */
259 sprintf(gCmdStr, "/sbin/wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
260 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);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000277
Dake Zhao0a832172015-01-06 11:08:47 -0800278 if(strncmp(result, "COMPLETED", 9) == 0)
279 staConnectResp->cmdru.connected = 1;
280 else
281 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000282#endif
283
Dake Zhao0a832172015-01-06 11:08:47 -0800284 /*
285 * Report back the status: Complete or Failed.
286 */
287 staConnectResp->status = STATUS_COMPLETE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000288
Dake Zhao0a832172015-01-06 11:08:47 -0800289 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
290 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
291
292 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000293}
294
295/*
296 * wfaStaGetIpConfig():
297 * This function is to retriev the ip info including
298 * 1. dhcp enable
299 * 2. ip address
Dake Zhao0a832172015-01-06 11:08:47 -0800300 * 3. mask
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000301 * 4. primary-dns
302 * 5. secondary-dns
303 *
304 * The current implementation is to use a script to find these information
Dake Zhao0a832172015-01-06 11:08:47 -0800305 * and store them in a file.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000306 */
307int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
308{
309 int slen, ret, i = 0;
310 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
Dake Zhao0a832172015-01-06 11:08:47 -0800311 dutCmdResponse_t *ipconfigResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000312 char *ifname = getIpConf->intf;
313 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
314
315 FILE *tmpfd;
316 char string[256];
317 char *str;
318
319 /*
320 * check a script file (the current implementation specific)
321 */
322 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
323 if(ret == -1)
324 {
Dake Zhao0a832172015-01-06 11:08:47 -0800325 ipconfigResp->status = STATUS_ERROR;
326 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
327 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000328
Dake Zhao0a832172015-01-06 11:08:47 -0800329 DPRINT_ERR(WFA_ERR, "file not exist\n");
330 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000331
332 }
333
334 strcpy(ifinfo->dns[0], "0");
335 strcpy(ifinfo->dns[1], "0");
Dake Zhao0a832172015-01-06 11:08:47 -0800336
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000337 /*
Dake Zhao0a832172015-01-06 11:08:47 -0800338 * Run the script file "getipconfig.sh" to check the ip status
339 * (current implementation specific).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000340 * note: "getipconfig.sh" is only defined for the current implementation
341 */
Dake Zhao0a832172015-01-06 11:08:47 -0800342 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000343
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800344 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000345
346 /* open the output result and scan/retrieve the info */
347 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
348
349 if(tmpfd == NULL)
350 {
Dake Zhao0a832172015-01-06 11:08:47 -0800351 ipconfigResp->status = STATUS_ERROR;
352 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
353 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000354
Dake Zhao0a832172015-01-06 11:08:47 -0800355 DPRINT_ERR(WFA_ERR, "file open failed\n");
356 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000357 }
358
359 for(;;)
360 {
361 if(fgets(string, 256, tmpfd) == NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800362 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000363
364 /* check dhcp enabled */
365 if(strncmp(string, "dhcpcli", 7) ==0)
366 {
367 str = strtok(string, "=");
368 str = strtok(NULL, "=");
369 if(str != NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800370 ifinfo->isDhcp = 1;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000371 else
Dake Zhao0a832172015-01-06 11:08:47 -0800372 ifinfo->isDhcp = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000373 }
374
375 /* find out the ip address */
376 if(strncmp(string, "ipaddr", 6) == 0)
377 {
378 str = strtok(string, "=");
379 str = strtok(NULL, " ");
380 if(str != NULL)
381 {
Dake Zhao0a832172015-01-06 11:08:47 -0800382 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800383
Dake Zhao0a832172015-01-06 11:08:47 -0800384 ifinfo->ipaddr[15]='\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000385 }
386 else
Dake Zhao0a832172015-01-06 11:08:47 -0800387 wSTRNCPY(ifinfo->ipaddr, "none", 15);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000388 }
389
390 /* check the mask */
391 if(strncmp(string, "mask", 4) == 0)
392 {
393 char ttstr[16];
394 char *ttp = ttstr;
395
396 str = strtok_r(string, "=", &ttp);
397 if(*ttp != '\0')
398 {
Dake Zhao0a832172015-01-06 11:08:47 -0800399 strcpy(ifinfo->mask, ttp);
400 slen = strlen(ifinfo->mask);
401 ifinfo->mask[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000402 }
403 else
Dake Zhao0a832172015-01-06 11:08:47 -0800404 strcpy(ifinfo->mask, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000405 }
406
407 /* find out the dns server ip address */
408 if(strncmp(string, "nameserv", 8) == 0)
409 {
410 char ttstr[16];
411 char *ttp = ttstr;
Dake Zhao0a832172015-01-06 11:08:47 -0800412
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000413 str = strtok_r(string, " ", &ttp);
414 if(str != NULL && i < 2)
415 {
Dake Zhao0a832172015-01-06 11:08:47 -0800416 strcpy(ifinfo->dns[i], ttp);
417 slen = strlen(ifinfo->dns[i]);
418 ifinfo->dns[i][slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000419 }
420 else
Dake Zhao0a832172015-01-06 11:08:47 -0800421 strcpy(ifinfo->dns[i], "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000422
423 i++;
424 }
Dake Zhao0a832172015-01-06 11:08:47 -0800425 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000426
Dake Zhao0a832172015-01-06 11:08:47 -0800427 /*
428 * Report back the results
429 */
430 ipconfigResp->status = STATUS_COMPLETE;
431 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000432
Dake Zhao0a832172015-01-06 11:08:47 -0800433 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000434
435#if 0
Dake Zhao0a832172015-01-06 11:08:47 -0800436 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
437 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
438 ifinfo->dns[0], ifinfo->dns[1], *respLen);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000439#endif
440
Dake Zhao0a832172015-01-06 11:08:47 -0800441 fclose(tmpfd);
442 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000443}
444
445/*
446 * wfaStaSetIpConfig():
447 * The function is to set the ip configuration to a wireless I/F.
448 * 1. IP address
449 * 2. Mac address
450 * 3. default gateway
Dake Zhao0a832172015-01-06 11:08:47 -0800451 * 4. dns nameserver (pri and sec).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000452 */
453int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
454{
Dake Zhao0a832172015-01-06 11:08:47 -0800455 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
456 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
457 dutCmdResponse_t *staSetIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000458
Dake Zhao0a832172015-01-06 11:08:47 -0800459 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000460
Dake Zhao0a832172015-01-06 11:08:47 -0800461 /*
462 * Use command 'ifconfig' to configure the interface ip address, mask.
463 * (Linux specific).
464 */
465 sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
466 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000467
Dake Zhao0a832172015-01-06 11:08:47 -0800468 /* use command 'route add' to set set gatewway (linux specific) */
469 if(ipconfig->defGateway[0] != '\0')
470 {
471 sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway);
472 sret = system(gCmdStr);
473 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000474
Dake Zhao0a832172015-01-06 11:08:47 -0800475 /* set dns (linux specific) */
476 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
477 sret = system(gCmdStr);
478 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
479 sret = system(gCmdStr);
480 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
481 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000482
Dake Zhao0a832172015-01-06 11:08:47 -0800483 /*
484 * report status
485 */
486 staSetIpResp->status = STATUS_COMPLETE;
487 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
488 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000489
Dake Zhao0a832172015-01-06 11:08:47 -0800490 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000491}
492
493/*
494 * wfaStaVerifyIpConnection():
495 * The function is to verify if the station has IP connection with an AP by
496 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800497 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000498int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
499{
Dake Zhao0a832172015-01-06 11:08:47 -0800500 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
501 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000502
503#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800504 char strout[64], *pcnt;
505 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000506
Dake Zhao0a832172015-01-06 11:08:47 -0800507 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
508
509 /* set timeout value in case not set */
510 if(verip->cmdsu.verifyIp.timeout <= 0)
511 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000512 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800513 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000514
Dake Zhao0a832172015-01-06 11:08:47 -0800515 /* execute the ping command and pipe the result to a tmp file */
516 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);
517 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000518
Dake Zhao0a832172015-01-06 11:08:47 -0800519 /* scan/check the output */
520 tmpfile = fopen("/tmp/pingout.txt", "r+");
521 if(tmpfile == NULL)
522 {
523 verifyIpResp->status = STATUS_ERROR;
524 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
525 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000526
Dake Zhao0a832172015-01-06 11:08:47 -0800527 DPRINT_ERR(WFA_ERR, "file open failed\n");
528 return WFA_FAILURE;
529 }
530
531 verifyIpResp->status = STATUS_COMPLETE;
532 if(fscanf(tmpfile, "%s", strout) == EOF)
533 verifyIpResp->cmdru.connected = 0;
534 else
535 {
536 pcnt = strtok(strout, "%");
537
538 /* if the loss rate is 100%, not able to connect */
539 if(atoi(pcnt) == 100)
540 verifyIpResp->cmdru.connected = 0;
541 else
542 verifyIpResp->cmdru.connected = 1;
543 }
544
545 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000546#else
Dake Zhao0a832172015-01-06 11:08:47 -0800547 int btSockfd;
548 struct pollfd fds[2];
549 int timeout = 2000;
550 char anyBuf[64];
551 struct sockaddr_in toAddr;
552 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000553
Dake Zhao0a832172015-01-06 11:08:47 -0800554 verifyIpResp->status = STATUS_COMPLETE;
555 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000556
Dake Zhao0a832172015-01-06 11:08:47 -0800557 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000558
Dake Zhao0a832172015-01-06 11:08:47 -0800559 if(btSockfd == -1)
560 {
561 verifyIpResp->status = STATUS_ERROR;
562 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
563 *respLen = WFA_TLV_HDR_LEN + 4;
564 return WFA_FAILURE;;
565 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000566
Dake Zhao0a832172015-01-06 11:08:47 -0800567 toAddr.sin_family = AF_INET;
568 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
569 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000570
Dake Zhao0a832172015-01-06 11:08:47 -0800571 while(done)
572 {
573 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
574 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000575
Dake Zhao0a832172015-01-06 11:08:47 -0800576 fds[0].fd = btSockfd;
577 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000578
Dake Zhao0a832172015-01-06 11:08:47 -0800579 ret = poll(fds, 1, timeout);
580 switch(ret)
581 {
582 case 0:
583 /* it is time out, count a packet lost*/
584 break;
585 case -1:
586 /* it is an error */
587 default:
588 {
589 switch(fds[0].revents)
590 {
591 case POLLIN:
592 case POLLPRI:
593 case POLLOUT:
594 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
595 if(nbytes != 0)
596 verifyIpResp->cmdru.connected = 1;
597 done = 0;
598 break;
599 default:
600 /* errors but not care */
601 ;
602 }
603 }
604 }
605 if(cnt == 3)
606 {
607 done = 0;
608 }
609 }
610
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000611#endif
612
Dake Zhao0a832172015-01-06 11:08:47 -0800613 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000614
Dake Zhao0a832172015-01-06 11:08:47 -0800615 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
616
617 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000618}
619
620/*
621 * wfaStaGetMacAddress()
622 * This function is to retrieve the MAC address of a wireless I/F.
623 */
624int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
625{
626 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
627 dutCmdResponse_t *getmacResp = &gGenericResp;
628 char *str;
629 char *ifname = getMac->intf;
630
631 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800632 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000633
634 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
635 /*
636 * run the script "getipconfig.sh" to find out the mac
637 */
Dake Zhao0a832172015-01-06 11:08:47 -0800638 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800639 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000640
641 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
642 if(tmpfd == NULL)
643 {
Dake Zhao0a832172015-01-06 11:08:47 -0800644 getmacResp->status = STATUS_ERROR;
645 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
646 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000647
Dake Zhao0a832172015-01-06 11:08:47 -0800648 DPRINT_ERR(WFA_ERR, "file open failed\n");
649 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000650 }
651
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800652 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
653 {
Dake Zhao0a832172015-01-06 11:08:47 -0800654 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000655 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800656
657 str = strtok(string, " ");
658 while(str && ((strcmp(str,"HWaddr")) != 0))
659 {
Dake Zhao0a832172015-01-06 11:08:47 -0800660 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800661 }
Dake Zhao0a832172015-01-06 11:08:47 -0800662
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800663 /* get mac */
664 if(str)
665 {
666 str = strtok(NULL, " ");
667 strcpy(getmacResp->cmdru.mac, str);
668 getmacResp->status = STATUS_COMPLETE;
669 }
Dake Zhao0a832172015-01-06 11:08:47 -0800670
671 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000672
673 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
674
675 fclose(tmpfd);
676 return WFA_SUCCESS;
677}
678
679/*
680 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800681 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000682 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800683 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000684 */
685int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
686{
Dake Zhao0a832172015-01-06 11:08:47 -0800687 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000688
Dake Zhao0a832172015-01-06 11:08:47 -0800689 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000690
Dake Zhao0a832172015-01-06 11:08:47 -0800691 statsResp->status = STATUS_ERROR;
692 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
693 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000694
695
Dake Zhao0a832172015-01-06 11:08:47 -0800696 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000697}
698
699/*
700 * wfaSetEncryption():
701 * The function is to set the wireless interface with WEP or none.
702 *
Dake Zhao0a832172015-01-06 11:08:47 -0800703 * Since WEP is optional test, current function is only used for
704 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000705 * this function should be replaced by the next one (wfaSetEncryption1())
706 *
Dake Zhao0a832172015-01-06 11:08:47 -0800707 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000708 * 1. I/F
709 * 2. ssid
710 * 3. encpType - wep or none
711 * Optional:
712 * 4. key1
713 * 5. key2
714 * 6. key3
715 * 7. key4
716 * 8. activeKey Index
717 */
718
719int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
720{
Dake Zhao0a832172015-01-06 11:08:47 -0800721 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
722 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000723
Dake Zhao0a832172015-01-06 11:08:47 -0800724 /*
725 * disable the network first
726 */
727 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
728 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000729
Dake Zhao0a832172015-01-06 11:08:47 -0800730 /*
731 * set SSID
732 */
733 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
734 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000735
Dake Zhao0a832172015-01-06 11:08:47 -0800736 /*
737 * Tell the supplicant for infrastructure mode (1)
738 */
739 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
740 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000741
Dake Zhao0a832172015-01-06 11:08:47 -0800742 /*
743 * set Key management to NONE (NO WPA) for plaintext or WEP
744 */
745 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
746 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000747
Dake Zhao0a832172015-01-06 11:08:47 -0800748 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
749 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000750
Dake Zhao0a832172015-01-06 11:08:47 -0800751 setEncrypResp->status = STATUS_COMPLETE;
752 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
753 *respLen = WFA_TLV_HDR_LEN + 4;
754
755 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000756}
757
758/*
759 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800760 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000761 */
762int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
763{
Dake Zhao0a832172015-01-06 11:08:47 -0800764 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
765 dutCmdResponse_t *setEncrypResp = &gGenericResp;
766 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000767
Dake Zhao0a832172015-01-06 11:08:47 -0800768 /*
769 * disable the network first
770 */
771 sprintf(gCmdStr, "wpa_cli -i %s disable_network 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 SSID
776 */
777 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
778 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000779
Dake Zhao0a832172015-01-06 11:08:47 -0800780 /*
781 * Tell the supplicant for infrastructure mode (1)
782 */
783 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
784 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000785
Dake Zhao0a832172015-01-06 11:08:47 -0800786 /*
787 * set Key management to NONE (NO WPA) for plaintext or WEP
788 */
789 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
790 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000791
Dake Zhao0a832172015-01-06 11:08:47 -0800792 /* set keys */
793 if(setEncryp->encpType == 1)
794 {
795 for(i=0; i<4; i++)
796 {
797 if(setEncryp->keys[i][0] != '\0')
798 {
799 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
800 setEncryp->intf, i, setEncryp->keys[i]);
801 sret = system(gCmdStr);
802 }
803 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000804
Dake Zhao0a832172015-01-06 11:08:47 -0800805 /* set active key */
806 i = setEncryp->activeKeyIdx;
807 if(setEncryp->keys[i][0] != '\0')
808 {
809 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
810 setEncryp->intf, setEncryp->activeKeyIdx);
811 sret = system(gCmdStr);
812 }
813 }
814 else /* clearly remove the keys -- reported by p.schwann */
815 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000816
Dake Zhao0a832172015-01-06 11:08:47 -0800817 for(i = 0; i < 4; i++)
818 {
819 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
820 sret = system(gCmdStr);
821 }
822 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000823
Dake Zhao0a832172015-01-06 11:08:47 -0800824 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
825 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000826
Dake Zhao0a832172015-01-06 11:08:47 -0800827 setEncrypResp->status = STATUS_COMPLETE;
828 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
829 *respLen = WFA_TLV_HDR_LEN + 4;
830
831 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000832}
833
834int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
835{
836 int ret = WFA_SUCCESS;
837
838 return ret;
839}
840
841/*
842 * wfaStaSetEapTLS():
843 * This is to set
844 * 1. ssid
845 * 2. encrypType - tkip or aes-ccmp
846 * 3. keyManagementType - wpa or wpa2
847 * 4. trustedRootCA
848 * 5. clientCertificate
849 */
850int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
851{
Dake Zhao0a832172015-01-06 11:08:47 -0800852 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
853 char *ifname = setTLS->intf;
854 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000855
Dake Zhao0a832172015-01-06 11:08:47 -0800856 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000857
Dake Zhao0a832172015-01-06 11:08:47 -0800858 /*
859 * need to store the trustedROOTCA and clientCertificate into a file first.
860 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000861#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800862 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
863 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000864#else
865
Dake Zhao0a832172015-01-06 11:08:47 -0800866 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
867 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000868
Dake Zhao0a832172015-01-06 11:08:47 -0800869 /* ssid */
870 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
871 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000872
Dake Zhao0a832172015-01-06 11:08:47 -0800873 /* key management */
874 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
875 {
876 }
877 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
878 {
879 }
880 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
881 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000882
Dake Zhao0a832172015-01-06 11:08:47 -0800883 }
884 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
885 {
886 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
887 }
888 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
889 {
890 // to take all and device to pick any one supported.
891 }
892 else
893 {
894 // ??
895 }
896 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000897
Dake Zhao0a832172015-01-06 11:08:47 -0800898 /* protocol WPA */
899 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
900 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000901
Dake Zhao0a832172015-01-06 11:08:47 -0800902 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
903 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000904
Dake Zhao0a832172015-01-06 11:08:47 -0800905 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
906 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000907
Dake Zhao0a832172015-01-06 11:08:47 -0800908 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
909 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000910
Dake Zhao0a832172015-01-06 11:08:47 -0800911 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
912 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000913
Dake Zhao0a832172015-01-06 11:08:47 -0800914 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
915 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000916
Dake Zhao0a832172015-01-06 11:08:47 -0800917 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
918 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000919#endif
920
Dake Zhao0a832172015-01-06 11:08:47 -0800921 setEapTlsResp->status = STATUS_COMPLETE;
922 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
923 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000924
Dake Zhao0a832172015-01-06 11:08:47 -0800925 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000926}
927
928/*
Dake Zhao0a832172015-01-06 11:08:47 -0800929 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000930 * 1. ssid
931 * 2. passPhrase
932 * 3. keyMangementType - wpa/wpa2
933 * 4. encrypType - tkip or aes-ccmp
934 */
935int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -0800936{
937 /*Incompleted function*/
938 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000939
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800940#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -0800941 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000942#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800943 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
944 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000945#else
Dake Zhao0a832172015-01-06 11:08:47 -0800946 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
947 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000948
Dake Zhao0a832172015-01-06 11:08:47 -0800949 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
950 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
951 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
952 {
953 // take all and device to pick it supported.
954 }
955 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
956 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000957
Dake Zhao0a832172015-01-06 11:08:47 -0800958 }
959 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
960 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000961
Dake Zhao0a832172015-01-06 11:08:47 -0800962 }
963 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
964 {
Ray Wang9c508692014-04-01 17:04:59 -0700965
Dake Zhao0a832172015-01-06 11:08:47 -0800966 }
967 else
968 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800969
Dake Zhao0a832172015-01-06 11:08:47 -0800970 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000971
Dake Zhao0a832172015-01-06 11:08:47 -0800972 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
973 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000974
Dake Zhao0a832172015-01-06 11:08:47 -0800975 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
976 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000977
Dake Zhao0a832172015-01-06 11:08:47 -0800978 /* if PMF enable */
979 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
980 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000981
Dake Zhao0a832172015-01-06 11:08:47 -0800982 }
983 else if(setPSK->pmf == WFA_REQUIRED)
984 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000985
Dake Zhao0a832172015-01-06 11:08:47 -0800986 }
987 else if(setPSK->pmf == WFA_F_REQUIRED)
988 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000989
Dake Zhao0a832172015-01-06 11:08:47 -0800990 }
991 else if(setPSK->pmf == WFA_F_DISABLED)
992 {
993
994 }
995 else
996 {
997 /* Disable PMF */
998
999 }
1000
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001001#endif
1002
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001003#endif
1004
Dake Zhao0a832172015-01-06 11:08:47 -08001005 setPskResp->status = STATUS_COMPLETE;
1006 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1007 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001008
Dake Zhao0a832172015-01-06 11:08:47 -08001009 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001010}
1011
1012/*
Dake Zhao0a832172015-01-06 11:08:47 -08001013 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001014 * Get vendor specific information in name/value pair by a wireless I/F.
1015 */
1016int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1017{
Dake Zhao0a832172015-01-06 11:08:47 -08001018 dutCmdResponse_t infoResp;
1019 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001020
Dake Zhao0a832172015-01-06 11:08:47 -08001021 /*
1022 * Normally this is called to retrieve the vendor information
1023 * from a interface, no implement yet
1024 */
1025 sprintf(infoResp.cmdru.info, "interface,%s,vendor,XXX,cardtype,802.11a/b/g", getInfo->intf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001026
Dake Zhao0a832172015-01-06 11:08:47 -08001027 infoResp.status = STATUS_COMPLETE;
1028 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
1029 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
1030
1031 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001032}
1033
1034/*
1035 * wfaStaSetEapTTLS():
1036 * This is to set
1037 * 1. ssid
1038 * 2. username
1039 * 3. passwd
1040 * 4. encrypType - tkip or aes-ccmp
1041 * 5. keyManagementType - wpa or wpa2
1042 * 6. trustedRootCA
1043 */
1044int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1045{
Dake Zhao0a832172015-01-06 11:08:47 -08001046 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1047 char *ifname = setTTLS->intf;
1048 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001049
1050#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001051 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
1052 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001053#else
1054
Dake Zhao0a832172015-01-06 11:08:47 -08001055 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1056 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001057
Dake Zhao0a832172015-01-06 11:08:47 -08001058 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
1059 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001060
Dake Zhao0a832172015-01-06 11:08:47 -08001061 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
1062 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001063
Dake Zhao0a832172015-01-06 11:08:47 -08001064 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
1065 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001066
Dake Zhao0a832172015-01-06 11:08:47 -08001067 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1068 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001069
Dake Zhao0a832172015-01-06 11:08:47 -08001070 /* This may not need to set. if it is not set, default to take all */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001071// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001072 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1073 {
1074 }
1075 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1076 {
1077 }
1078 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1079 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001080
Dake Zhao0a832172015-01-06 11:08:47 -08001081 }
1082 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1083 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001084
Dake Zhao0a832172015-01-06 11:08:47 -08001085 }
1086 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1087 {
1088 // to take all and device to pick one it supported
1089 }
1090 else
1091 {
1092 // ??
1093 }
1094 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001095
Dake Zhao0a832172015-01-06 11:08:47 -08001096 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
1097 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001098
Dake Zhao0a832172015-01-06 11:08:47 -08001099 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
1100 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001101
Dake Zhao0a832172015-01-06 11:08:47 -08001102 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1103 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001104
Dake Zhao0a832172015-01-06 11:08:47 -08001105 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
1106 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001107
Dake Zhao0a832172015-01-06 11:08:47 -08001108 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1109 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001110#endif
1111
Dake Zhao0a832172015-01-06 11:08:47 -08001112 setEapTtlsResp->status = STATUS_COMPLETE;
1113 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1114 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001115
Dake Zhao0a832172015-01-06 11:08:47 -08001116 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001117}
1118
1119/*
1120 * wfaStaSetEapSIM():
1121 * This is to set
1122 * 1. ssid
1123 * 2. user name
1124 * 3. passwd
1125 * 4. encrypType - tkip or aes-ccmp
1126 * 5. keyMangementType - wpa or wpa2
1127 */
1128int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1129{
Dake Zhao0a832172015-01-06 11:08:47 -08001130 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1131 char *ifname = setSIM->intf;
1132 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001133
1134#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001135 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
1136 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001137#else
1138
Dake Zhao0a832172015-01-06 11:08:47 -08001139 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1140 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001141
Dake Zhao0a832172015-01-06 11:08:47 -08001142 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
1143 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001144
1145
Dake Zhao0a832172015-01-06 11:08:47 -08001146 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
1147 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001148
Dake Zhao0a832172015-01-06 11:08:47 -08001149 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
1150 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001151
Dake Zhao0a832172015-01-06 11:08:47 -08001152 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
1153 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001154
Dake Zhao0a832172015-01-06 11:08:47 -08001155 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1156 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001157
Dake Zhao0a832172015-01-06 11:08:47 -08001158 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1159 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001160
Dake Zhao0a832172015-01-06 11:08:47 -08001161 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1162 {
1163 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1164 }
1165 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1166 {
1167 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1168 }
1169 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1170 {
1171 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1172 }
1173 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1174 {
1175 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1176 }
1177 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1178 {
1179 // take all and device to pick one which is supported.
1180 }
1181 else
1182 {
1183 // ??
1184 }
1185 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001186
1187#endif
1188
Dake Zhao0a832172015-01-06 11:08:47 -08001189 setEapSimResp->status = STATUS_COMPLETE;
1190 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1191 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001192
Dake Zhao0a832172015-01-06 11:08:47 -08001193 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001194}
1195
1196/*
1197 * wfaStaSetPEAP()
1198 * This is to set
1199 * 1. ssid
1200 * 2. user name
1201 * 3. passwd
1202 * 4. encryType - tkip or aes-ccmp
1203 * 5. keyMgmtType - wpa or wpa2
1204 * 6. trustedRootCA
1205 * 7. innerEAP
1206 * 8. peapVersion
1207 */
1208int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1209{
Dake Zhao0a832172015-01-06 11:08:47 -08001210 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1211 char *ifname = setPEAP->intf;
1212 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001213
1214#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001215 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1216 setPEAP->passwd, setPEAP->trustedRootCA,
1217 setPEAP->encrptype, setPEAP->peapVersion,
1218 setPEAP->innerEAP);
1219 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001220#else
1221
Dake Zhao0a832172015-01-06 11:08:47 -08001222 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", 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 set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
1226 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001227
Dake Zhao0a832172015-01-06 11:08:47 -08001228 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
1229 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001230
Dake Zhao0a832172015-01-06 11:08:47 -08001231 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
1232 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001233
Dake Zhao0a832172015-01-06 11:08:47 -08001234 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
1235 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001236
Dake Zhao0a832172015-01-06 11:08:47 -08001237 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
1238 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001239
Dake Zhao0a832172015-01-06 11:08:47 -08001240 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
1241 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001242
Dake Zhao0a832172015-01-06 11:08:47 -08001243 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1244 {
1245 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1246 }
1247 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1248 {
1249 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1250 }
1251 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1252 {
1253 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1254 }
1255 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1256 {
1257 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1258 }
1259 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1260 {
1261 // take all and device to pick one which is supported.
1262 }
1263 else
1264 {
1265 // ??
1266 }
1267 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001268
Dake Zhao0a832172015-01-06 11:08:47 -08001269 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
1270 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001271
Dake Zhao0a832172015-01-06 11:08:47 -08001272 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
1273 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001274
Dake Zhao0a832172015-01-06 11:08:47 -08001275 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1276 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001277#endif
1278
Dake Zhao0a832172015-01-06 11:08:47 -08001279 setPeapResp->status = STATUS_COMPLETE;
1280 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1281 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001282
Dake Zhao0a832172015-01-06 11:08:47 -08001283 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001284}
1285
1286/*
1287 * wfaStaSetUAPSD()
1288 * This is to set
1289 * 1. acBE
1290 * 2. acBK
1291 * 3. acVI
1292 * 4. acVO
1293 */
1294int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1295{
Dake Zhao0a832172015-01-06 11:08:47 -08001296 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001297#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001298 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1299 char *ifname = setUAPSD->intf;
1300 char tmpStr[10];
1301 char line[100];
1302 char *pathl="/etc/Wireless/RT61STA";
1303 BYTE acBE=1;
1304 BYTE acBK=1;
1305 BYTE acVO=1;
1306 BYTE acVI=1;
1307 BYTE APSDCapable;
1308 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001309
Dake Zhao0a832172015-01-06 11:08:47 -08001310 /*
1311 * A series of setting need to be done before doing WMM-PS
1312 * Additional steps of configuration may be needed.
1313 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001314
Dake Zhao0a832172015-01-06 11:08:47 -08001315 /*
1316 * bring down the interface
1317 */
1318 sprintf(gCmdStr, "ifconfig %s down",ifname);
1319 sret = system(gCmdStr);
1320 /*
1321 * Unload the Driver
1322 */
1323 sprintf(gCmdStr, "rmmod rt61");
1324 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001325#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001326 if(setUAPSD->acBE != 1)
1327 acBE=setUAPSD->acBE = 0;
1328 if(setUAPSD->acBK != 1)
1329 acBK=setUAPSD->acBK = 0;
1330 if(setUAPSD->acVO != 1)
1331 acVO=setUAPSD->acVO = 0;
1332 if(setUAPSD->acVI != 1)
1333 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001334#else
Dake Zhao0a832172015-01-06 11:08:47 -08001335 acBE=setUAPSD->acBE;
1336 acBK=setUAPSD->acBK;
1337 acVO=setUAPSD->acVO;
1338 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001339#endif
1340
Dake Zhao0a832172015-01-06 11:08:47 -08001341 APSDCapable = acBE||acBK||acVO||acVI;
1342 /*
1343 * set other AC parameters
1344 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001345
Dake Zhao0a832172015-01-06 11:08:47 -08001346 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1347 sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl);
1348 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001349
Dake Zhao0a832172015-01-06 11:08:47 -08001350 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
1351 sret = system(gCmdStr);
1352 pipe = popen("uname -r", "r");
1353 /* Read into line the output of uname*/
1354 fscanf(pipe,"%s",line);
1355 pclose(pipe);
1356
1357 /*
1358 * load the Driver
1359 */
1360 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
1361 sret = system(gCmdStr);
1362
1363 sprintf(gCmdStr, "ifconfig %s up",ifname);
1364 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001365#endif
1366
Dake Zhao0a832172015-01-06 11:08:47 -08001367 setUAPSDResp->status = STATUS_COMPLETE;
1368 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1369 *respLen = WFA_TLV_HDR_LEN + 4;
1370 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001371}
1372
1373int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1374{
Dake Zhao0a832172015-01-06 11:08:47 -08001375 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1376 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1377 dutCmdResponse_t *infoResp = &gGenericResp;
1378 /*a vendor can fill in the proper info or anything non-disclosure */
1379 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001380
Dake Zhao0a832172015-01-06 11:08:47 -08001381 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001382
Dake Zhao0a832172015-01-06 11:08:47 -08001383 if(devInfo->fw == 0)
1384 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1385 else
1386 {
1387 // Call internal API to pull the version ID */
1388 memcpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
1389 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001390
Dake Zhao0a832172015-01-06 11:08:47 -08001391 infoResp->status = STATUS_COMPLETE;
1392 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1393 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001394
Dake Zhao0a832172015-01-06 11:08:47 -08001395 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001396
1397}
1398
1399/*
1400 * This funciton is to retrieve a list of interfaces and return
1401 * the list back to Agent control.
1402 * ********************************************************************
1403 * Note: We intend to make this WLAN interface name as a hardcode name.
1404 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001405 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1406 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001407 * likely is hardcoded just for CAPI command responses.
1408 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001409 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001410 */
1411int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1412{
Dake Zhao0a832172015-01-06 11:08:47 -08001413 dutCmdResponse_t *infoResp = &gGenericResp;
1414 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1415 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001416
Dake Zhao0a832172015-01-06 11:08:47 -08001417 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001418
Dake Zhao0a832172015-01-06 11:08:47 -08001419 switch(ifList->cmdsu.iftype)
1420 {
1421 case IF_80211:
1422 infoResp->status = STATUS_COMPLETE;
1423 ifListResp->iftype = IF_80211;
1424 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1425 strcpy(ifListResp->ifs[1], "NULL");
1426 strcpy(ifListResp->ifs[2], "NULL");
1427 break;
1428 case IF_ETH:
1429 infoResp->status = STATUS_COMPLETE;
1430 ifListResp->iftype = IF_ETH;
1431 strcpy(ifListResp->ifs[0], "eth0");
1432 strcpy(ifListResp->ifs[1], "NULL");
1433 strcpy(ifListResp->ifs[2], "NULL");
1434 break;
1435 default:
1436 {
1437 infoResp->status = STATUS_ERROR;
1438 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1439 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001440
Dake Zhao0a832172015-01-06 11:08:47 -08001441 return WFA_SUCCESS;
1442 }
1443 }
1444
1445 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1446 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1447
1448 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001449}
1450
1451int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1452{
Dake Zhao0a832172015-01-06 11:08:47 -08001453 dutCmdResponse_t *debugResp = &gGenericResp;
1454 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001455
Dake Zhao0a832172015-01-06 11:08:47 -08001456 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001457
Dake Zhao0a832172015-01-06 11:08:47 -08001458 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1459 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1460 else
1461 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001462
Dake Zhao0a832172015-01-06 11:08:47 -08001463 debugResp->status = STATUS_COMPLETE;
1464 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1465 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001466
1467
Dake Zhao0a832172015-01-06 11:08:47 -08001468 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001469}
1470
1471
1472/*
1473 * wfaStaGetBSSID():
1474 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001475 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001476int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1477{
Dake Zhao0a832172015-01-06 11:08:47 -08001478 char string[64];
1479 char *str;
1480 FILE *tmpfd;
1481 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001482
Dake Zhao0a832172015-01-06 11:08:47 -08001483 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1484 /* retrieve the BSSID */
1485 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001486
Dake Zhao0a832172015-01-06 11:08:47 -08001487 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001488
Dake Zhao0a832172015-01-06 11:08:47 -08001489 tmpfd = fopen("/tmp/bssid.txt", "r+");
1490 if(tmpfd == NULL)
1491 {
1492 bssidResp->status = STATUS_ERROR;
1493 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1494 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001495
Dake Zhao0a832172015-01-06 11:08:47 -08001496 DPRINT_ERR(WFA_ERR, "file open failed\n");
1497 return WFA_FAILURE;
1498 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001499
Dake Zhao0a832172015-01-06 11:08:47 -08001500 for(;;)
1501 {
1502 if(fscanf(tmpfd, "%s", string) == EOF)
1503 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001504 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001505 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001506 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001507 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001508
Dake Zhao0a832172015-01-06 11:08:47 -08001509 if(strncmp(string, "bssid", 5) == 0)
1510 {
1511 str = strtok(string, "=");
1512 str = strtok(NULL, "=");
1513 if(str != NULL)
1514 {
1515 strcpy(bssidResp->cmdru.bssid, str);
1516 bssidResp->status = STATUS_COMPLETE;
1517 break;
1518 }
1519 }
1520 }
1521
1522 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1523 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1524
1525 fclose(tmpfd);
1526 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001527}
1528
1529/*
1530 * wfaStaSetIBSS()
1531 * This is to set
1532 * 1. ssid
1533 * 2. channel
1534 * 3. encrypType - none or wep
1535 * optional
1536 * 4. key1
1537 * 5. key2
1538 * 6. key3
1539 * 7. key4
1540 * 8. activeIndex - 1, 2, 3, or 4
1541 */
1542int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1543{
Dake Zhao0a832172015-01-06 11:08:47 -08001544 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1545 dutCmdResponse_t *setIbssResp = &gGenericResp;
1546 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001547
Dake Zhao0a832172015-01-06 11:08:47 -08001548 /*
1549 * disable the network first
1550 */
1551 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
1552 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001553
Dake Zhao0a832172015-01-06 11:08:47 -08001554 /*
1555 * set SSID
1556 */
1557 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
1558 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001559
Dake Zhao0a832172015-01-06 11:08:47 -08001560 /*
1561 * Set channel for IBSS
1562 */
1563 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
1564 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001565
Dake Zhao0a832172015-01-06 11:08:47 -08001566 /*
1567 * Tell the supplicant for IBSS mode (1)
1568 */
1569 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
1570 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001571
Dake Zhao0a832172015-01-06 11:08:47 -08001572 /*
1573 * set Key management to NONE (NO WPA) for plaintext or WEP
1574 */
1575 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
1576 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001577
Dake Zhao0a832172015-01-06 11:08:47 -08001578 if(setIBSS->encpType == 1)
1579 {
1580 for(i=0; i<4; i++)
1581 {
1582 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1583 {
1584 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1585 setIBSS->intf, i, setIBSS->keys[i]);
1586 sret = system(gCmdStr);
1587 }
1588 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001589
Dake Zhao0a832172015-01-06 11:08:47 -08001590 i = setIBSS->activeKeyIdx;
1591 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1592 {
1593 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1594 setIBSS->intf, setIBSS->activeKeyIdx);
1595 sret = system(gCmdStr);
1596 }
1597 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001598
Dake Zhao0a832172015-01-06 11:08:47 -08001599 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
1600 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001601
Dake Zhao0a832172015-01-06 11:08:47 -08001602 setIbssResp->status = STATUS_COMPLETE;
1603 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1604 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001605
Dake Zhao0a832172015-01-06 11:08:47 -08001606 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001607}
1608
1609/*
1610 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001611 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001612 * adhoc)
1613 * Input parameters:
1614 * 1. I/F
1615 * 2. ssid
1616 * 3. mode adhoc or managed
1617 * 4. encType
1618 * 5. channel
1619 * 6. key(s)
1620 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001621 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001622int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1623{
Dake Zhao0a832172015-01-06 11:08:47 -08001624 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1625 dutCmdResponse_t *SetModeResp = &gGenericResp;
1626 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001627
Dake Zhao0a832172015-01-06 11:08:47 -08001628 /*
1629 * bring down the interface
1630 */
1631 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
1632 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001633
Dake Zhao0a832172015-01-06 11:08:47 -08001634 /*
1635 * distroy the interface
1636 */
1637 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
1638 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001639
1640
Dake Zhao0a832172015-01-06 11:08:47 -08001641 /*
1642 * re-create the interface with the given mode
1643 */
1644 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001645 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001646 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001647 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1648
Dake Zhao0a832172015-01-06 11:08:47 -08001649 sret = system(gCmdStr);
1650 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001651 {
Dake Zhao0a832172015-01-06 11:08:47 -08001652 int j = setmode->activeKeyIdx;
1653 for(i=0; i<4; i++)
1654 {
1655 if(setmode->keys[i][0] != '\0')
1656 {
1657 sprintf(gCmdStr, "iwconfig %s key s:%s",
1658 setmode->intf, setmode->keys[i]);
1659 sret = system(gCmdStr);
1660 }
1661 /* set active key */
1662 if(setmode->keys[j][0] != '\0')
1663 sprintf(gCmdStr, "iwconfig %s key s:%s",
1664 setmode->intf, setmode->keys[j]);
1665 sret = system(gCmdStr);
1666 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001667
1668 }
Dake Zhao0a832172015-01-06 11:08:47 -08001669 /*
1670 * Set channel for IBSS
1671 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001672 if(setmode->channel)
1673 {
Dake Zhao0a832172015-01-06 11:08:47 -08001674 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
1675 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001676 }
1677
1678
Dake Zhao0a832172015-01-06 11:08:47 -08001679 /*
1680 * set SSID
1681 */
1682 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
1683 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001684
Dake Zhao0a832172015-01-06 11:08:47 -08001685 /*
1686 * bring up the interface
1687 */
1688 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
1689 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001690
Dake Zhao0a832172015-01-06 11:08:47 -08001691 SetModeResp->status = STATUS_COMPLETE;
1692 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1693 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001694
Dake Zhao0a832172015-01-06 11:08:47 -08001695 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001696}
1697
1698int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1699{
Dake Zhao0a832172015-01-06 11:08:47 -08001700 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1701 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001702
Dake Zhao0a832172015-01-06 11:08:47 -08001703 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
1704 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001705
1706
Dake Zhao0a832172015-01-06 11:08:47 -08001707 SetPSResp->status = STATUS_COMPLETE;
1708 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1709 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001710
Dake Zhao0a832172015-01-06 11:08:47 -08001711 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001712}
1713
1714int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1715{
Dake Zhao0a832172015-01-06 11:08:47 -08001716 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1717 dutCmdResponse_t *upLoadResp = &gGenericResp;
1718 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001719
Dake Zhao0a832172015-01-06 11:08:47 -08001720 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1721 {
1722 int rbytes;
1723 /*
1724 * if asked for the first packet, always to open the file
1725 */
1726 if(upload->next == 1)
1727 {
1728 if(e2efp != NULL)
1729 {
1730 fclose(e2efp);
1731 e2efp = NULL;
1732 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001733
Dake Zhao0a832172015-01-06 11:08:47 -08001734 e2efp = fopen(e2eResults, "r");
1735 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001736
Dake Zhao0a832172015-01-06 11:08:47 -08001737 if(e2efp == NULL)
1738 {
1739 upLoadResp->status = STATUS_ERROR;
1740 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1741 *respLen = WFA_TLV_HDR_LEN + 4;
1742 return WFA_FAILURE;
1743 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001744
Dake Zhao0a832172015-01-06 11:08:47 -08001745 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001746
Dake Zhao0a832172015-01-06 11:08:47 -08001747 if(rbytes < 256)
1748 {
1749 /*
1750 * this means no more bytes after this read
1751 */
1752 upld->seqnum = 0;
1753 fclose(e2efp);
1754 e2efp=NULL;
1755 }
1756 else
1757 {
1758 upld->seqnum = upload->next;
1759 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001760
Dake Zhao0a832172015-01-06 11:08:47 -08001761 upld->nbytes = rbytes;
1762
1763 upLoadResp->status = STATUS_COMPLETE;
1764 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1765 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1766 }
1767 else
1768 {
1769 upLoadResp->status = STATUS_ERROR;
1770 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1771 *respLen = WFA_TLV_HDR_LEN + 4;
1772 }
1773
1774 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001775}
1776/*
1777 * wfaStaSetWMM()
1778 * TO be ported on a specific plaform for the DUT
1779 * This is to set the WMM related parameters at the DUT.
1780 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1781 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1782 */
1783int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1784{
1785#ifdef WFA_WMM_AC
1786 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1787 char *ifname = setwmm->intf;
1788 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001789
1790 switch(setwmm->group)
1791 {
1792 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001793 if (setwmm->send_trig)
1794 {
1795 int Sockfd;
1796 struct sockaddr_in psToAddr;
1797 unsigned int TxMsg[512];
1798
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001799 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001800 memset(&psToAddr, 0, sizeof(psToAddr));
1801 psToAddr.sin_family = AF_INET;
1802 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1803 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001804
1805
Dake Zhao0a832172015-01-06 11:08:47 -08001806 switch (setwmm->trig_ac)
1807 {
1808 case WMMAC_AC_VO:
1809 wfaTGSetPrio(Sockfd, 7);
1810 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1811 printf("\r\nSending AC_VO trigger packet\n");
1812 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001813
Dake Zhao0a832172015-01-06 11:08:47 -08001814 case WMMAC_AC_VI:
1815 wfaTGSetPrio(Sockfd, 5);
1816 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1817 printf("\r\nSending AC_VI trigger packet\n");
1818 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001819
Dake Zhao0a832172015-01-06 11:08:47 -08001820 case WMMAC_AC_BK:
1821 wfaTGSetPrio(Sockfd, 2);
1822 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1823 printf("\r\nSending AC_BK trigger packet\n");
1824 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001825
Dake Zhao0a832172015-01-06 11:08:47 -08001826 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001827 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001828 wfaTGSetPrio(Sockfd, 0);
1829 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1830 printf("\r\nSending AC_BE trigger packet\n");
1831 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001832 }
1833
Dake Zhao0a832172015-01-06 11:08:47 -08001834 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1835 sizeof(struct sockaddr));
1836 close(Sockfd);
1837 usleep(1000000);
1838 }
1839 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001840 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001841 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001842 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1843 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1844 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1845 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1846 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1847 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1848 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1849 setwmm->actions.addts.dialog_token,
1850 setwmm->actions.addts.tspec.tsinfo.TID,
1851 setwmm->actions.addts.tspec.tsinfo.direction,
1852 setwmm->actions.addts.tspec.tsinfo.PSB,
1853 setwmm->actions.addts.tspec.tsinfo.UP,
1854 setwmm->actions.addts.tspec.tsinfo.infoAck,
1855 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1856 setwmm->actions.addts.tspec.Fixed,
1857 setwmm->actions.addts.tspec.size,
1858 setwmm->actions.addts.tspec.maxsize,
1859 setwmm->actions.addts.tspec.min_srvc,
1860 setwmm->actions.addts.tspec.max_srvc,
1861 setwmm->actions.addts.tspec.inactivity,
1862 setwmm->actions.addts.tspec.suspension,
1863 setwmm->actions.addts.tspec.srvc_strt_tim,
1864 setwmm->actions.addts.tspec.mindatarate,
1865 setwmm->actions.addts.tspec.meandatarate,
1866 setwmm->actions.addts.tspec.peakdatarate,
1867 setwmm->actions.addts.tspec.burstsize,
1868 setwmm->actions.addts.tspec.delaybound,
1869 setwmm->actions.addts.tspec.PHYrate,
1870 setwmm->actions.addts.tspec.sba,
1871 setwmm->actions.addts.tspec.medium_time,
1872 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001873
Dake Zhao862c94b2014-12-08 14:35:35 -08001874 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001875
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001876 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001877 }
1878 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08001879 {
1880 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001881 }
1882
1883 setwmmResp->status = STATUS_COMPLETE;
1884 break;
1885
1886 case GROUP_WMMCONF:
1887 sprintf(gCmdStr, "iwconfig %s rts %d",
1888 ifname,setwmm->actions.config.rts_thr);
1889
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001890 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001891 sprintf(gCmdStr, "iwconfig %s frag %d",
1892 ifname,setwmm->actions.config.frag_thr);
1893
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001894 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001895 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1896 ifname, setwmm->actions.config.wmm);
1897
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001898 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001899 setwmmResp->status = STATUS_COMPLETE;
1900 break;
1901
1902 default:
1903 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1904 setwmmResp->status = STATUS_ERROR;
1905 break;
1906
1907 }
1908
1909 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1910 *respLen = WFA_TLV_HDR_LEN + 4;
1911#endif
1912
1913 return WFA_SUCCESS;
1914}
1915
1916int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1917{
Dake Zhao0a832172015-01-06 11:08:47 -08001918 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001919
Dake Zhao0a832172015-01-06 11:08:47 -08001920 /*
1921 * run your device to send NEIGREQ
1922 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001923
Dake Zhao0a832172015-01-06 11:08:47 -08001924 sendNeigReqResp->status = STATUS_COMPLETE;
1925 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
1926 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001927
Dake Zhao0a832172015-01-06 11:08:47 -08001928 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001929}
1930
1931int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1932{
1933 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
1934 char *ifname = setFAST->intf;
1935 dutCmdResponse_t *setEapFastResp = &gGenericResp;
1936
1937#ifdef WFA_NEW_CLI_FORMAT
1938 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08001939 setFAST->passwd, setFAST->pacFileName,
1940 setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001941 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001942#else
1943
1944 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001945 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001946
1947 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001948 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001949
1950 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001951 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001952
1953 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001954 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001955
1956 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
1957 {
1958 }
1959 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
1960 {
1961 }
1962 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
1963 {
Dake Zhao0a832172015-01-06 11:08:47 -08001964
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001965 }
1966 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
1967 {
Dake Zhao0a832172015-01-06 11:08:47 -08001968 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001969 }
1970 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
1971 {
Dake Zhao0a832172015-01-06 11:08:47 -08001972 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001973 }
1974 else
1975 {
Dake Zhao0a832172015-01-06 11:08:47 -08001976 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001977 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001978 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001979
1980 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001981 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001982
1983 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001984 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001985
1986 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001987 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001988
1989 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001990 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001991
1992 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001993 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001994
1995 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001996 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001997#endif
1998
1999 setEapFastResp->status = STATUS_COMPLETE;
2000 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2001 *respLen = WFA_TLV_HDR_LEN + 4;
2002
2003 return WFA_SUCCESS;
2004}
2005
2006int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2007{
2008 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2009 char *ifname = setAKA->intf;
2010 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2011
2012#ifdef WFA_NEW_CLI_FORMAT
2013 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002014 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002015#else
2016
2017 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
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 ssid '\"%s\"'", ifname, setAKA->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002021 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002022
2023 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2024 {
2025 }
2026 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2027 {
2028 }
2029 else if(strcasecmp(setAKA->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(setAKA->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(setAKA->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 proto WPA2", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002048 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002049 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002050 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002051
2052 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002053 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002054
2055 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002056 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002057
2058 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002059 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002060
2061 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002062 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002063
2064 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002065 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002066#endif
2067
2068 setEapAkaResp->status = STATUS_COMPLETE;
2069 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2070 *respLen = WFA_TLV_HDR_LEN + 4;
2071
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002072 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002073}
2074
Ray Wangd11ca032015-05-29 18:25:46 -07002075/* EAP-AKA' */
2076int wfaStaSetEapAKAPrime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2077{
2078 caStaSetEapAKAPrime_t *setAKAPrime = (caStaSetEapAKAPrime_t *)caCmdBuf;
2079 char *ifname = setAKAPrime->intf;
2080 dutCmdResponse_t *setEapAkaPrimeResp = &gGenericResp;
2081
2082#ifdef WFA_NEW_CLI_FORMAT
2083 sprintf(gCmdStr, "wfa_set_eapakaprime %s %s %s %s", ifname, setAKAPrime->ssid, setAKAPrime->username, setAKAPrime->passwd);
2084 sret = system(gCmdStr);
2085#else
2086
2087 sprintf(gCmdStr, "wpa_cli -i%s remove_network 0", ifname);
2088 sret = system(gCmdStr);
2089
2090 sprintf(gCmdStr, "wpa_cli -i%s add_network", ifname);
2091 sret = system(gCmdStr);
2092
2093 if(strcasecmp(setAKAPrime->keyMgmtType, "wpa2-sha256") == 0)
2094 {
2095 }
2096 else if(strcasecmp(setAKAPrime->keyMgmtType, "wpa2-eap") == 0)
2097 {
2098 }
2099 else if(strcasecmp(setAKAPrime->keyMgmtType, "wpa2-ft") == 0)
2100 {
2101
2102 }
2103 else if(strcasecmp(setAKAPrime->keyMgmtType, "wpa") == 0)
2104 {
2105 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 key_mgmt WPA-EAP", ifname);
2106 }
2107 else if(strcasecmp(setAKAPrime->keyMgmtType, "wpa2") == 0)
2108 {
2109 // take all and device to pick one which is supported.
2110 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 key_mgmt WPA-EAP", ifname);
2111 }
2112 else
2113 {
2114 // ??
2115 setEapAkaPrimeResp->status = STATUS_INVALID;
2116 strcpy(setEapAkaPrimeResp->cmdru.info, "invalid key management parameter");
2117 wfaEncodeTLV(WFA_STA_SET_EAPAKAPRIME_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)setEapAkaPrimeResp, respBuf);
2118 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
2119 return WFA_FAILURE;
2120 }
2121 sret = system(gCmdStr);
2122
2123 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 pairwise CCMP", ifname);
2124 sret = system(gCmdStr);
2125
2126 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 proto WPA2", ifname);
2127 sret = system(gCmdStr);
2128
2129 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 eap AKA\\'", ifname);
2130 printf("eap command=%s\n", gCmdStr);
2131 sret = system(gCmdStr);
2132
2133 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 phase1 '\"result_ind=1\"'", ifname);
2134 sret = system(gCmdStr);
2135
2136 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 identity '\"%s\"'", ifname, setAKAPrime->username);
2137 printf("user name=%s\n", setAKAPrime->username);
2138 sret = system(gCmdStr);
2139
2140 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 password '\"%s\"'", ifname, setAKAPrime->passwd);
2141 printf("password=%s\n", setAKAPrime->passwd);
2142 sret = system(gCmdStr);
2143
2144 sprintf(gCmdStr, "wpa_cli -i%s set_network 0 ssid '\"%s\"'", ifname, setAKAPrime->ssid);
2145 sret = system(gCmdStr);
2146
2147 sprintf(gCmdStr, "wpa_cli -i%s enable_network 0", ifname);
2148 sret = system(gCmdStr);
2149#endif
2150
2151 setEapAkaPrimeResp->status = STATUS_COMPLETE;
2152 wfaEncodeTLV(WFA_STA_SET_EAPAKAPRIME_RESP_TLV, 4, (BYTE *)setEapAkaPrimeResp, respBuf);
2153 *respLen = WFA_TLV_HDR_LEN + 4;
2154
2155 return WFA_SUCCESS;
2156}
2157
2158
2159
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002160int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2161{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002162 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2163 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002164
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002165 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002166
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002167 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2168 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002169
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002170 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2171 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002172
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002173 setSystimeResp->status = STATUS_COMPLETE;
2174 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2175 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002176
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002177 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002178}
2179
2180#ifdef WFA_STA_TB
2181int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2182{
Dake Zhao0a832172015-01-06 11:08:47 -08002183 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2184 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2185 BYTE presetDone = 1;
2186 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002187 char cmdStr[128];
2188 char string[256];
2189 FILE *tmpfd = NULL;
2190 long val;
2191 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002192
Dake Zhao0a832172015-01-06 11:08:47 -08002193 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002194
Ray Wangd11ca032015-05-29 18:25:46 -07002195 if (presetParams->supplicant == eWpaSupplicant)
2196 {
2197 st = access("/tmp/processid.txt", F_OK);
2198 if (st != -1)
2199 {
2200 st = remove("/tmp/processid.txt");
2201 }
2202
2203 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
2204 st = system(cmdStr);
2205
2206 tmpfd = fopen("/tmp/processid.txt", "r+");
2207 if (tmpfd == NULL)
2208 {
2209 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2210 return WFA_FAILURE;
2211 }
2212
2213 for (;;)
2214 {
2215 if (fgets(string, 256, tmpfd) == NULL)
2216 break;
2217
2218 errno = 0;
2219 val = strtol(string, &endptr, 10);
2220 if (errno != 0 && val == 0)
2221 {
2222 DPRINT_ERR(WFA_ERR, "strtol error\n");
2223 return WFA_FAILURE;
2224 }
2225
2226 if (endptr == string)
2227 {
2228 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2229 }
2230
2231 presetDone = 1;
2232 }
2233 }
2234
Dake Zhao0a832172015-01-06 11:08:47 -08002235 if(presetParams->wmmFlag)
2236 {
2237 st = wfaExecuteCLI(gCmdStr);
2238 switch(st)
2239 {
2240 case 0:
2241 presetDone = 1;
2242 break;
2243 case 1:
2244 presetDone = 0;
2245 break;
2246 case 2:
2247 presetDone = 0;
2248 break;
2249 }
2250 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002251
Dake Zhao0a832172015-01-06 11:08:47 -08002252 if(presetParams->modeFlag != 0)
2253 {
2254 switch(presetParams->wirelessMode)
2255 {
2256 default:
2257 printf("other mode does not need to support\n");
2258 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002259
Dake Zhao0a832172015-01-06 11:08:47 -08002260 st = wfaExecuteCLI(gCmdStr);
2261 switch(st)
2262 {
2263 case 0:
2264 presetDone = 1;
2265 break;
2266 case 1:
2267 presetDone = 0;
2268 case 2:
2269 presetDone = 0;
2270 break;
2271 }
2272 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002273
2274
Dake Zhao0a832172015-01-06 11:08:47 -08002275 if(presetParams->psFlag)
2276 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002277
Dake Zhao0a832172015-01-06 11:08:47 -08002278 printf("%s\n", gCmdStr);
2279 sret = system(gCmdStr);
2280 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002281
Dake Zhao0a832172015-01-06 11:08:47 -08002282 /************the followings are used for Voice Enterprise **************/
2283 if(presetParams->program == PROG_TYPE_VENT)
2284 {
2285 if(presetParams->ftoa == eEnable)
2286 {
2287 // enable Fast BSS Transition Over the Air
2288 }
2289 else
2290 {
2291 // disable Fast BSS Transition Over the Air
2292 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002293
Dake Zhao0a832172015-01-06 11:08:47 -08002294 if(presetParams->ftds == eEnable)
2295 {
2296 // enable Fast BSS Transition Over the DS
2297 }
2298 else
2299 {
2300 // disable Fast BSS Transition Over the DS
2301 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002302
Dake Zhao0a832172015-01-06 11:08:47 -08002303 if(presetParams->activescan == eEnable)
2304 {
2305 // Enable Active Scan on STA
2306 }
2307 else
2308 {
2309 // disable Active Scan on STA
2310 }
2311 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002312
Dake Zhao0a832172015-01-06 11:08:47 -08002313 /************the followings are used for Wi-Fi Display *************/
2314 if(presetParams->program == PROG_TYPE_WFD)
2315 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002316
Dake Zhao0a832172015-01-06 11:08:47 -08002317 if(presetParams->tdlsFlag)
2318 {
2319 // enable / disable tdls based on tdls
2320 }
2321 if(presetParams->wfdDevTypeFlag)
2322 {
2323 // set WFD device type to source/sink/dual based on wfdDevType
2324 }
2325 if(presetParams->wfdUibcGenFlag)
2326 {
2327 // enable / disable the feature
2328 }
2329 if(presetParams->wfdUibcHidFlag)
2330 {
2331 // enable / disable feature
2332 }
2333 if(presetParams->wfdUiInputFlag)
2334 {
2335 // set the UI input as mentioned
2336 }
2337 if(presetParams->wfdHdcpFlag)
2338 {
2339 // enable / disable feature
2340 }
2341 if(presetParams->wfdFrameSkipFlag)
2342 {
2343 // enable / disable feature
2344 }
2345 if(presetParams->wfdAvChangeFlag)
2346 {
2347 // enable / disable feature
2348 }
2349 if(presetParams->wfdStandByFlag)
2350 {
2351 // enable / disable feature
2352 }
2353 if(presetParams->wfdInVideoFlag)
2354 {
2355 // select the input vide as protecteed or non-protetcted or protected audio
2356 // or unprotected audio etc.
2357 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002358
Dake Zhao0a832172015-01-06 11:08:47 -08002359 if(presetParams->wfdVideoFmatFlag)
2360 {
2361 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002362
Dake Zhao0a832172015-01-06 11:08:47 -08002363 //switch(presetParams->wfdVideoFmt )
2364 //{
2365 // case e640x480p60:
2366 // ;
2367 // default:
2368 // set the mandatory
2369 // }
2370 }
2371 if(presetParams->wfdAudioFmatFlag)
2372 {
2373 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002374
Dake Zhao0a832172015-01-06 11:08:47 -08002375 //switch(presetParams->wfdAudioFmt )
2376 //{
2377 // case eMandatoryAudioMode:
2378 // ;
2379 // case eDefaultAudioMode:
2380 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002381
Dake Zhao0a832172015-01-06 11:08:47 -08002382 // default:
2383 // set the mandatory
2384 // }
2385 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002386
Dake Zhao0a832172015-01-06 11:08:47 -08002387 if(presetParams->wfdI2cFlag)
2388 {
2389 // enable / disable feature
2390 }
2391 if(presetParams->wfdVideoRecoveryFlag)
2392 {
2393 // enable / disable feature
2394 }
2395 if(presetParams->wfdPrefDisplayFlag)
2396 {
2397 // enable / disable feature
2398 }
2399 if(presetParams->wfdServiceDiscoveryFlag)
2400 {
2401 // enable / disable feature
2402 }
2403 if(presetParams->wfd3dVideoFlag)
2404 {
2405 // enable / disable feature
2406 }
2407 if(presetParams->wfdMultiTxStreamFlag)
2408 {
2409 // enable / disable feature
2410 }
2411 if(presetParams->wfdTimeSyncFlag)
2412 {
2413 // enable / disable feature
2414 }
2415 if(presetParams->wfdEDIDFlag)
2416 {
2417 // enable / disable feature
2418 }
2419 if(presetParams->wfdUIBCPrepareFlag)
2420 {
2421 // Provdes information to start valid WFD session to check UIBC operation.
2422 }
2423 if(presetParams->wfdCoupledCapFlag)
2424 {
2425 // enable / disable feature
2426 }
2427 if(presetParams->wfdOptionalFeatureFlag)
2428 {
2429 // disable all program specific optional features
2430 }
2431 if(presetParams->wfdSessionAvailFlag)
2432 {
2433 // enable / disable session available bit
2434 }
2435 if(presetParams->wfdDeviceDiscoverabilityFlag)
2436 {
2437 // enable / disable feature
2438 }
2439 }
2440
Dake Zhao655efed2015-03-11 17:39:13 -07002441 if(presetParams->program == PROG_TYPE_WFDS)
2442 {
2443
2444 if(presetParams->wfdsType == eAcceptPD)
2445 {
2446 // preset to accept PD request
2447 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2448 {
2449 // use presetParams->wfdsConnectionCapability and set role accordingly
2450 }
2451
2452 }
2453 if(presetParams->wfdsType == eRejectPD)
2454 {
2455 // preset to Reject PD request
2456 }
2457 if(presetParams->wfdsType == eIgnorePD)
2458 {
2459 // preset to Ignore PD request
2460 }
2461 if(presetParams->wfdsType == eRejectSession)
2462 {
2463 // preset to reject Session request
2464 }
2465
2466 }
2467
2468 if (presetDone)
2469 {
2470 PresetParamsResp->status = STATUS_COMPLETE;
2471 }
2472 else
2473 {
2474 PresetParamsResp->status = STATUS_INVALID;
2475 }
Dake Zhao0a832172015-01-06 11:08:47 -08002476
2477 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2478 *respLen = WFA_TLV_HDR_LEN + 4;
2479
2480 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002481}
2482
2483int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2484{
2485 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2486
2487 v11nParamsResp->status = STATUS_COMPLETE;
2488 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2489 *respLen = WFA_TLV_HDR_LEN + 4;
2490 return WFA_SUCCESS;
2491}
2492int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2493{
2494 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2495
2496 staWirelessResp->status = STATUS_COMPLETE;
2497 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2498 *respLen = WFA_TLV_HDR_LEN + 4;
2499 return WFA_SUCCESS;
2500}
2501
2502int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2503{
2504 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2505
2506 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2507 *respLen = WFA_TLV_HDR_LEN + 4;
2508 return WFA_SUCCESS;
2509}
2510
2511int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2512{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002513 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002514
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002515 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2516 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002517
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002518 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002519}
2520
2521int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2522{
2523 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2524
2525 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2526 *respLen = WFA_TLV_HDR_LEN + 4;
2527
2528 return WFA_SUCCESS;
2529
2530}
2531
2532int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2533{
Dake Zhao0a832172015-01-06 11:08:47 -08002534 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2535 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002536
2537
Dake Zhao0a832172015-01-06 11:08:47 -08002538 // need to make your own command available for this, here is only an example
2539 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2540 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002541
Dake Zhao0a832172015-01-06 11:08:47 -08002542 ResetResp->status = STATUS_COMPLETE;
2543 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2544 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002545
Dake Zhao0a832172015-01-06 11:08:47 -08002546 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002547}
2548
2549#else
2550
2551int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2552{
2553 dutCmdResponse_t *staCmdResp = &gGenericResp;
2554
2555 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2556 *respLen = WFA_TLV_HDR_LEN + 4;
2557
2558 return WFA_SUCCESS;
2559}
2560#endif
2561
2562/*
2563 * This is used to send a frame or action frame
2564 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002565int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002566{
Dake Zhao0a832172015-01-06 11:08:47 -08002567 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2568 /* uncomment it if needed */
2569 // char *ifname = cmd->intf;
2570 dutCmdResponse_t *devSendResp = &gGenericResp;
2571 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002572
Dake Zhao0a832172015-01-06 11:08:47 -08002573 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2574 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002575
Dake Zhao0a832172015-01-06 11:08:47 -08002576 switch(sf->program)
2577 {
2578 case PROG_TYPE_PMF:
2579 {
2580 pmfFrame_t *pmf = &sf->frameType.pmf;
2581 switch(pmf->eFrameName)
2582 {
2583 case PMF_TYPE_DISASSOC:
2584 {
2585 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002586
Dake Zhao0a832172015-01-06 11:08:47 -08002587 }
2588 break;
2589 case PMF_TYPE_DEAUTH:
2590 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002591
Dake Zhao0a832172015-01-06 11:08:47 -08002592 }
2593 break;
2594 case PMF_TYPE_SAQUERY:
2595 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002596
Dake Zhao0a832172015-01-06 11:08:47 -08002597 }
2598 break;
2599 case PMF_TYPE_AUTH:
2600 {
2601 }
2602 break;
2603 case PMF_TYPE_ASSOCREQ:
2604 {
2605 }
2606 break;
2607 case PMF_TYPE_REASSOCREQ:
2608 {
2609 }
2610 break;
2611 }
2612 }
2613 break;
2614 case PROG_TYPE_TDLS:
2615 {
2616 tdlsFrame_t *tdls = &sf->frameType.tdls;
2617 switch(tdls->eFrameName)
2618 {
2619 case TDLS_TYPE_DISCOVERY:
2620 /* use the peer mac address to send the frame */
2621 break;
2622 case TDLS_TYPE_SETUP:
2623 break;
2624 case TDLS_TYPE_TEARDOWN:
2625 break;
2626 case TDLS_TYPE_CHANNELSWITCH:
2627 break;
2628 case TDLS_TYPE_NULLFRAME:
2629 break;
2630 }
2631 }
2632 break;
2633 case PROG_TYPE_VENT:
2634 {
2635 ventFrame_t *vent = &sf->frameType.vent;
2636 switch(vent->type)
2637 {
2638 case VENT_TYPE_NEIGREQ:
2639 break;
2640 case VENT_TYPE_TRANSMGMT:
2641 break;
2642 }
2643 }
2644 break;
2645 case PROG_TYPE_WFD:
2646 {
2647 wfdFrame_t *wfd = &sf->frameType.wfd;
2648 switch(wfd->eframe)
2649 {
2650 case WFD_FRAME_PRBREQ:
2651 {
2652 /* send probe req */
2653 }
2654 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002655
Dake Zhao0a832172015-01-06 11:08:47 -08002656 case WFD_FRAME_PRBREQ_TDLS_REQ:
2657 {
2658 /* send tunneled tdls probe req */
2659 }
2660 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002661
Dake Zhao0a832172015-01-06 11:08:47 -08002662 case WFD_FRAME_11V_TIMING_MSR_REQ:
2663 {
2664 /* send 11v timing mearurement request */
2665 }
2666 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002667
Dake Zhao0a832172015-01-06 11:08:47 -08002668 case WFD_FRAME_RTSP:
2669 {
2670 /* send WFD RTSP messages*/
2671 // fetch the type of RTSP message and send it.
2672 switch(wfd->eRtspMsgType)
2673 {
2674 case WFD_RTSP_PAUSE:
2675 break;
2676 case WFD_RTSP_PLAY:
2677 //send RTSP PLAY
2678 break;
2679 case WFD_RTSP_TEARDOWN:
2680 //send RTSP TEARDOWN
2681 break;
2682 case WFD_RTSP_TRIG_PAUSE:
2683 //send RTSP TRIGGER PAUSE
2684 break;
2685 case WFD_RTSP_TRIG_PLAY:
2686 //send RTSP TRIGGER PLAY
2687 break;
2688 case WFD_RTSP_TRIG_TEARDOWN:
2689 //send RTSP TRIGGER TEARDOWN
2690 break;
2691 case WFD_RTSP_SET_PARAMETER:
2692 //send RTSP SET PARAMETER
2693 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2694 {
2695 //send RTSP SET PARAMETER message for UIBC keyboard
2696 }
2697 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2698 {
2699 //send RTSP SET PARAMETER message for UIBC Mouse
2700 }
2701 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2702 {
2703 //send RTSP SET PARAMETER message Capability re-negotiation
2704 }
2705 else if (wfd->eSetParams == WFD_STANDBY)
2706 {
2707 //send RTSP SET PARAMETER message for standby
2708 }
2709 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2710 {
2711 //send RTSP SET PARAMETER message for UIBC settings enable
2712 }
2713 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2714 {
2715 //send RTSP SET PARAMETER message for UIBC settings disable
2716 }
2717 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2718 {
2719 //send RTSP SET PARAMETER message for route audio
2720 }
2721 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2722 {
2723 //send RTSP SET PARAMETER message for 3D video parameters
2724 }
2725 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2726 {
2727 //send RTSP SET PARAMETER message for 2D video parameters
2728 }
2729 break;
Dake Zhao97708202014-11-26 13:59:04 -08002730 }
Dake Zhao0a832172015-01-06 11:08:47 -08002731 }
2732 break;
2733 }
2734 }
2735 break;
2736 /* not need to support HS2 release 1, due to very short time period */
2737 case PROG_TYPE_HS2_R2:
2738 {
2739 /* type of frames */
2740 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2741 switch(hs2->eframe)
2742 {
2743 case HS2_FRAME_ANQPQuery:
2744 {
Dake Zhao97708202014-11-26 13:59:04 -08002745
Dake Zhao0a832172015-01-06 11:08:47 -08002746 }
2747 break;
2748 case HS2_FRAME_DLSRequest:
2749 {
Dake Zhao97708202014-11-26 13:59:04 -08002750
Dake Zhao0a832172015-01-06 11:08:47 -08002751 }
2752 break;
2753 case HS2_FRAME_GARPReq:
2754 {
Dake Zhao97708202014-11-26 13:59:04 -08002755
Dake Zhao0a832172015-01-06 11:08:47 -08002756 }
2757 break;
2758 case HS2_FRAME_GARPRes:
2759 {
2760 }
2761 break;
2762 case HS2_FRAME_NeighAdv:
2763 {
2764 }
2765 case HS2_FRAME_ARPProbe:
2766 {
2767 }
2768 case HS2_FRAME_ARPAnnounce:
2769 {
Dake Zhao97708202014-11-26 13:59:04 -08002770
Dake Zhao0a832172015-01-06 11:08:47 -08002771 }
2772 break;
2773 case HS2_FRAME_NeighSolicitReq:
2774 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002775
Dake Zhao0a832172015-01-06 11:08:47 -08002776 }
2777 break;
2778 case HS2_FRAME_ARPReply:
2779 {
2780
2781 }
2782 break;
2783 }
2784
2785 }/* PROG_TYPE_HS2-R2 */
2786 case PROG_TYPE_GEN:
2787 {
2788 /* General frames */
2789 }
2790
2791
2792 }
2793 devSendResp->status = STATUS_COMPLETE;
2794 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2795 *respLen = WFA_TLV_HDR_LEN + 4;
2796
2797 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002798}
2799
2800/*
2801 * This is used to set a temporary MAC address of an interface
2802 */
2803int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2804{
Dake Zhao0a832172015-01-06 11:08:47 -08002805 // Uncomment it if needed
2806 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2807 // char *ifname = cmd->intf;
2808 dutCmdResponse_t *staCmdResp = &gGenericResp;
2809 // Uncomment it if needed
2810 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002811
Dake Zhao0a832172015-01-06 11:08:47 -08002812 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2813 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002814
Dake Zhao0a832172015-01-06 11:08:47 -08002815 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002816}
2817
2818
2819int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2820{
2821 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2822 //char *intf = disc->intf;
2823 dutCmdResponse_t *staDiscResp = &gGenericResp;
2824
2825 // stop the supplicant
2826
2827 staDiscResp->status = STATUS_COMPLETE;
2828
2829 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2830 *respLen = WFA_TLV_HDR_LEN + 4;
2831
2832 return WFA_SUCCESS;
2833}
2834
2835/* Execute CLI, read the status from Environment variable */
2836int wfaExecuteCLI(char *CLI)
2837{
Dake Zhao0a832172015-01-06 11:08:47 -08002838 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002839
Dake Zhao0a832172015-01-06 11:08:47 -08002840 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002841
Dake Zhao0a832172015-01-06 11:08:47 -08002842 retstr = getenv("WFA_CLI_STATUS");
2843 printf("cli status %s\n", retstr);
2844 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002845}
2846
2847/* Supporting Functions */
2848
2849void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2850{
Dake Zhao97708202014-11-26 13:59:04 -08002851 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002852 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002853// char *addr = staPing->dipaddr;
2854#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002855 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002856 char bflag[] = "-b";
2857 char *tmpstr;
2858 int inum=0;
2859#else
2860 char bflag[] = " ";
2861#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002862
Ray Wang9b47f362014-03-19 16:51:10 -07002863 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002864
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002865#ifdef WFA_PC_CONSOLE
2866
2867 printf("\nCS : The Stream ID is %d",streamid);
2868 printf("\nCS :the addr is %s ",addr);
2869 strcpy(addr,staPing->dipaddr);
2870 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2871 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002872 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002873 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002874 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002875 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002876 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002877 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002878 tmpstr = strtok(addr, ".");
2879 inum = atoi(tmpstr);
2880
2881 printf("interval %f\n", *interval);
2882
2883 if(inum >= 224 && inum <= 239) // multicast
2884 {
2885 }
2886 else // if not MC, check if it is BC address
2887 {
2888 printf("\nCS :Inside the BC address BLOCK");
2889 printf("\nCS :the inum %d",inum);
2890 strtok(NULL, ".");
2891 //strtok(NULL, ".");
2892 tmpstr = strtok(NULL, ".");
2893 printf("tmpstr %s\n", tmpstr);
2894 inum = atoi(tmpstr);
2895 printf("\nCS : The string is %s",tmpstr);
2896 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002897 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002898 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002899 }
2900#endif
Dake Zhao97708202014-11-26 13:59:04 -08002901 if ( staPing->dscp >= 0)
2902 {
Dake Zhao0a832172015-01-06 11:08:47 -08002903 tos= convertDscpToTos(staPing->dscp);
2904 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002905 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2906 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002907 printf("\nCS : The Stream ID is %d",streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002908 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002909
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002910 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002911 {
Dake Zhao97708202014-11-26 13:59:04 -08002912 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002913 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",
2914 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002915 else
Dake Zhao0a832172015-01-06 11:08:47 -08002916 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",
2917 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002918 sret = system(cmdStr);
2919 printf("\nCS : The command string is %s",cmdStr);
2920 }
2921 else
2922 {
Dake Zhao97708202014-11-26 13:59:04 -08002923 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002924 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",
2925 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002926 else
Dake Zhao0a832172015-01-06 11:08:47 -08002927 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",
2928 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002929 sret = system(cmdStr);
2930 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002931 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002932 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002933 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002934 printf("\nCS : The command string is %s",cmdStr);
2935
2936}
2937
2938int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2939{
2940 char strout[256];
2941 FILE *tmpfile = NULL;
2942 char cmdStr[128];
2943 printf("Ping stop id %d\n", streamid);
2944 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002945 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002946
2947 printf("\nCS : The command string is %s",cmdStr);
2948
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002949 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002950
2951 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002952 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002953
2954 printf("\nCS : The command string is %s",cmdStr);
2955
2956 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2957
2958 if(tmpfile == NULL)
2959 {
2960 return WFA_FAILURE;
2961 }
2962
2963 if(fscanf(tmpfile, "%s", strout) != EOF)
2964 {
2965 if(*strout == '\0')
2966 {
2967 stpResp->cmdru.pingStp.sendCnt = 0;
2968 }
2969
2970 else
2971 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2972 }
2973
2974 printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
2975
2976
2977 if(fscanf(tmpfile, "%s", strout) != EOF)
2978 {
2979 if(*strout == '\0')
2980 {
2981 stpResp->cmdru.pingStp.repliedCnt = 0;
2982 }
2983 else
2984 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2985 }
2986 printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
2987
2988 fclose(tmpfile);
2989
2990 return WFA_SUCCESS;
2991}
2992
Ankur Vachhanic485b712012-02-15 23:29:49 +00002993/*
Dake Zhao0a832172015-01-06 11:08:47 -08002994 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002995 */
2996int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2997{
Dake Zhao0a832172015-01-06 11:08:47 -08002998 dutCmdResponse_t infoResp;
2999 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003000
Dake Zhao0a832172015-01-06 11:08:47 -08003001 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003002
Dake Zhao0a832172015-01-06 11:08:47 -08003003 // Fetch the device ID and store into infoResp->cmdru.devid
3004 //strcpy(infoResp->cmdru.devid, str);
3005 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003006
Dake Zhao0a832172015-01-06 11:08:47 -08003007 infoResp.status = STATUS_COMPLETE;
3008 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3009 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3010
3011 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003012}
3013
3014
3015
3016/*
Dake Zhao0a832172015-01-06 11:08:47 -08003017 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003018 */
3019int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3020{
Dake Zhao0a832172015-01-06 11:08:47 -08003021 dutCmdResponse_t infoResp;
3022 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00003023
Dake Zhao0a832172015-01-06 11:08:47 -08003024 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003025
Dake Zhao0a832172015-01-06 11:08:47 -08003026 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003027
Dake Zhao0a832172015-01-06 11:08:47 -08003028 infoResp.status = STATUS_COMPLETE;
3029 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3030 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3031
3032 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003033}
3034/*
Dake Zhao0a832172015-01-06 11:08:47 -08003035 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003036 */
3037int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3038{
Dake Zhao0a832172015-01-06 11:08:47 -08003039 dutCmdResponse_t infoResp;
3040 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003041
Dake Zhao0a832172015-01-06 11:08:47 -08003042 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003043
Dake Zhao0a832172015-01-06 11:08:47 -08003044 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003045
Ankur Vachhanic485b712012-02-15 23:29:49 +00003046
Dake Zhao0a832172015-01-06 11:08:47 -08003047 infoResp.status = STATUS_COMPLETE;
3048 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3049 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3050
3051 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003052}
3053
3054/*
Dake Zhao0a832172015-01-06 11:08:47 -08003055 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003056 */
3057int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3058{
Dake Zhao0a832172015-01-06 11:08:47 -08003059 dutCmdResponse_t infoResp;
3060 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003061
Dake Zhao0a832172015-01-06 11:08:47 -08003062 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003063
Dake Zhao0a832172015-01-06 11:08:47 -08003064 // Fetch the group ID and store into infoResp->cmdru.grpid
3065 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003066
Dake Zhao0a832172015-01-06 11:08:47 -08003067 infoResp.status = STATUS_COMPLETE;
3068 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3069 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3070
3071 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003072}
3073
3074
3075
3076
3077/*
Dake Zhao0a832172015-01-06 11:08:47 -08003078 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003079 */
3080int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3081{
Dake Zhao0a832172015-01-06 11:08:47 -08003082 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003083
Dake Zhao0a832172015-01-06 11:08:47 -08003084 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003085
Dake Zhao0a832172015-01-06 11:08:47 -08003086 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3087 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003088
Ankur Vachhanic485b712012-02-15 23:29:49 +00003089
Dake Zhao0a832172015-01-06 11:08:47 -08003090 infoResp.status = STATUS_COMPLETE;
3091 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3092 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3093
3094 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003095}
3096
3097
3098/*
Dake Zhao0a832172015-01-06 11:08:47 -08003099 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003100 */
3101int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3102{
Dake Zhao0a832172015-01-06 11:08:47 -08003103 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003104
Dake Zhao0a832172015-01-06 11:08:47 -08003105 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003106
Dake Zhao0a832172015-01-06 11:08:47 -08003107 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003108
Dake Zhao0a832172015-01-06 11:08:47 -08003109 infoResp.status = STATUS_COMPLETE;
3110 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3111 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3112
3113 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003114}
3115
3116/*
Dake Zhao0a832172015-01-06 11:08:47 -08003117 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003118 */
3119int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3120{
Dake Zhao0a832172015-01-06 11:08:47 -08003121 dutCmdResponse_t infoResp;
3122 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003123
Dake Zhao0a832172015-01-06 11:08:47 -08003124 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003125
Dake Zhao0a832172015-01-06 11:08:47 -08003126 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003127
Dake Zhao0a832172015-01-06 11:08:47 -08003128 infoResp.status = STATUS_COMPLETE;
3129 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3130 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3131
3132 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003133}
3134
3135
3136/*
Dake Zhao0a832172015-01-06 11:08:47 -08003137 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003138 */
3139int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3140{
Dake Zhao0a832172015-01-06 11:08:47 -08003141 dutCmdResponse_t infoResp;
3142 /* uncomment and use it
3143 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3144 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003145
Dake Zhao0a832172015-01-06 11:08:47 -08003146 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003147
Dake Zhao0a832172015-01-06 11:08:47 -08003148 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003149
Dake Zhao0a832172015-01-06 11:08:47 -08003150 infoResp.status = STATUS_COMPLETE;
3151 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3152 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3153
3154 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003155}
3156
3157
3158/*
Dake Zhao0a832172015-01-06 11:08:47 -08003159 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003160 */
3161int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3162{
Dake Zhao0a832172015-01-06 11:08:47 -08003163 dutCmdResponse_t infoResp;
3164 /* uncomment and use it
3165 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3166 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003167
Dake Zhao0a832172015-01-06 11:08:47 -08003168 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003169
Dake Zhao0a832172015-01-06 11:08:47 -08003170 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003171
Dake Zhao0a832172015-01-06 11:08:47 -08003172 infoResp.status = STATUS_COMPLETE;
3173 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3174 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3175
3176 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003177}
3178
3179/*
Dake Zhao0a832172015-01-06 11:08:47 -08003180 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003181 */
3182int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3183{
Dake Zhao0a832172015-01-06 11:08:47 -08003184 dutCmdResponse_t infoResp;
3185 /* uncomment and use it
3186 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3187 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003188
Dake Zhao0a832172015-01-06 11:08:47 -08003189 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003190
Dake Zhao0a832172015-01-06 11:08:47 -08003191 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003192
Dake Zhao0a832172015-01-06 11:08:47 -08003193 infoResp.status = STATUS_COMPLETE;
3194 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3195 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3196
3197 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003198}
3199
3200/*
Dake Zhao0a832172015-01-06 11:08:47 -08003201 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003202 */
3203int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3204{
Dake Zhao0a832172015-01-06 11:08:47 -08003205 dutCmdResponse_t infoResp;
3206 /* uncomment and use it
3207 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3208 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003209
Dake Zhao0a832172015-01-06 11:08:47 -08003210 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003211
Dake Zhao0a832172015-01-06 11:08:47 -08003212 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3213 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3214 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003215
Ankur Vachhanic485b712012-02-15 23:29:49 +00003216
Dake Zhao0a832172015-01-06 11:08:47 -08003217 infoResp.status = STATUS_COMPLETE;
3218 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3219 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3220
3221 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003222}
3223
3224
3225
3226/*
Dake Zhao0a832172015-01-06 11:08:47 -08003227 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003228 */
3229int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3230{
Dake Zhao0a832172015-01-06 11:08:47 -08003231 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003232
Dake Zhao0a832172015-01-06 11:08:47 -08003233 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003234
Dake Zhao0a832172015-01-06 11:08:47 -08003235 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3236 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3237 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003238
Ankur Vachhanic485b712012-02-15 23:29:49 +00003239
Dake Zhao0a832172015-01-06 11:08:47 -08003240 infoResp.status = STATUS_COMPLETE;
3241 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3242 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3243
3244 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003245}
3246
3247
3248/*
Dake Zhao0a832172015-01-06 11:08:47 -08003249 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003250 */
3251int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3252{
Dake Zhao0a832172015-01-06 11:08:47 -08003253 dutCmdResponse_t infoResp;
3254 /* uncomment and use it
3255 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3256 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003257
Dake Zhao0a832172015-01-06 11:08:47 -08003258 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003259
Dake Zhao0a832172015-01-06 11:08:47 -08003260 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003261
Ankur Vachhanic485b712012-02-15 23:29:49 +00003262
Dake Zhao0a832172015-01-06 11:08:47 -08003263 infoResp.status = STATUS_COMPLETE;
3264 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3265 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3266
3267 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003268}
3269
3270
3271/*
Dake Zhao0a832172015-01-06 11:08:47 -08003272 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003273 */
3274int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3275{
Dake Zhao0a832172015-01-06 11:08:47 -08003276 dutCmdResponse_t infoResp;
3277 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003278
Dake Zhao0a832172015-01-06 11:08:47 -08003279 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003280
3281
Dake Zhao0a832172015-01-06 11:08:47 -08003282 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3283 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3284 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003285
Ankur Vachhanic485b712012-02-15 23:29:49 +00003286
Dake Zhao0a832172015-01-06 11:08:47 -08003287 infoResp.status = STATUS_COMPLETE;
3288 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3289 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3290
3291 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003292}
3293
3294/*
Dake Zhao0a832172015-01-06 11:08:47 -08003295 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003296 */
3297int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3298{
Dake Zhao0a832172015-01-06 11:08:47 -08003299 dutCmdResponse_t infoResp;
3300 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003301
Dake Zhao0a832172015-01-06 11:08:47 -08003302 printf("\n Entry wfaStaP2pReset... ");
3303 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003304
Dake Zhao0a832172015-01-06 11:08:47 -08003305 infoResp.status = STATUS_COMPLETE;
3306 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3307 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3308
3309 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003310}
3311
3312
3313
3314/*
Dake Zhao0a832172015-01-06 11:08:47 -08003315 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003316 */
3317int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3318{
Dake Zhao0a832172015-01-06 11:08:47 -08003319 dutCmdResponse_t infoResp;
3320 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003321
Dake Zhao0a832172015-01-06 11:08:47 -08003322 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003323
Dake Zhao0a832172015-01-06 11:08:47 -08003324 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003325
Dake Zhao0a832172015-01-06 11:08:47 -08003326 ifinfo->isDhcp =0;
3327 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3328 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3329 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3330 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3331
3332 infoResp.status = STATUS_COMPLETE;
3333 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3334 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3335
3336 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003337}
3338
3339
3340
3341
3342/*
Dake Zhao0a832172015-01-06 11:08:47 -08003343 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003344 */
3345int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3346{
Dake Zhao0a832172015-01-06 11:08:47 -08003347 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003348
Dake Zhao0a832172015-01-06 11:08:47 -08003349 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3350 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003351
Dake Zhao0a832172015-01-06 11:08:47 -08003352
3353 infoResp.status = STATUS_COMPLETE;
3354 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3355 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3356
3357 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003358}
3359
3360
3361
3362/*
Dake Zhao0a832172015-01-06 11:08:47 -08003363 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003364 */
3365int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3366{
Dake Zhao0a832172015-01-06 11:08:47 -08003367 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003368
Dake Zhao0a832172015-01-06 11:08:47 -08003369 infoResp.status = STATUS_COMPLETE;
3370 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3371 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003372
Dake Zhao0a832172015-01-06 11:08:47 -08003373 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003374}
3375
3376/*
Dake Zhao0a832172015-01-06 11:08:47 -08003377 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003378 */
3379int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3380{
Dake Zhao0a832172015-01-06 11:08:47 -08003381 dutCmdResponse_t infoResp;
3382 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003383
Dake Zhao0a832172015-01-06 11:08:47 -08003384 printf("\n Entry wfaStaSetSleepReq... ");
3385 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003386
Dake Zhao0a832172015-01-06 11:08:47 -08003387
3388 infoResp.status = STATUS_COMPLETE;
3389 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3390 *respLen = WFA_TLV_HDR_LEN +4;
3391
3392 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003393}
3394
3395/*
Dake Zhao0a832172015-01-06 11:08:47 -08003396 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003397 */
3398int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3399{
Dake Zhao0a832172015-01-06 11:08:47 -08003400 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003401
Dake Zhao0a832172015-01-06 11:08:47 -08003402 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3403 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003404
Dake Zhao0a832172015-01-06 11:08:47 -08003405
3406 infoResp.status = STATUS_COMPLETE;
3407 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3408 *respLen = WFA_TLV_HDR_LEN + 4;
3409
3410 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003411}
3412#ifndef WFA_STA_TB
3413/*
Dake Zhao0a832172015-01-06 11:08:47 -08003414 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003415 */
3416
3417int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3418{
Dake Zhao0a832172015-01-06 11:08:47 -08003419 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003420
Dake Zhao0a832172015-01-06 11:08:47 -08003421 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003422
Dake Zhao0a832172015-01-06 11:08:47 -08003423 // Implement the function and its sub commands
3424 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003425
Dake Zhao0a832172015-01-06 11:08:47 -08003426 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3427 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003428
Dake Zhao0a832172015-01-06 11:08:47 -08003429 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003430}
Dake Zhao0a832172015-01-06 11:08:47 -08003431int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003432{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003433
3434 dutCmdResponse_t infoResp;
3435 dutCmdResponse_t *v11nParamsResp = &infoResp;
3436
3437#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003438
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003439 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3440
3441 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003442
3443 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003444
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003445 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3446 {
Dake Zhao0a832172015-01-06 11:08:47 -08003447 // implement the funciton
3448 if(st != 0)
3449 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003450 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003451 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3452 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3453 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3454 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003455 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003456 }
Dake Zhao0a832172015-01-06 11:08:47 -08003457
Ankur Vachhanic485b712012-02-15 23:29:49 +00003458 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003459 {
Dake Zhao0a832172015-01-06 11:08:47 -08003460 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003461
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003462 if(st != 0)
3463 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003464 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003465 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3466 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3467 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3468 return FALSE;
3469 }
3470 }
3471
Ankur Vachhanic485b712012-02-15 23:29:49 +00003472 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003473 {
Dake Zhao0a832172015-01-06 11:08:47 -08003474 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003475 if(st != 0)
3476 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003477 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003478 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3479 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3480 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003481 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003482 }
3483 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003484
3485 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003486 {
3487 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003488 if(st != 0)
3489 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003490 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003491 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3492 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3493 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3494 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003495 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003496 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003497
3498 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003499 {
Dake Zhao0a832172015-01-06 11:08:47 -08003500 // implement the funciton
3501 //st = wfaExecuteCLI(gCmdStr);
3502 if(st != 0)
3503 {
3504 v11nParamsResp->status = STATUS_ERROR;
3505 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3506 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3507 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3508 return FALSE;
3509 }
3510 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3512 {
3513 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003514 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003515 if(st != 0)
3516 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003517 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003518 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003519 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3520 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003521 return FALSE;
3522 }
Dake Zhao0a832172015-01-06 11:08:47 -08003523 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003524 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3525 {
3526 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003527 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003528 if(st != 0)
3529 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003530 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003531 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003532 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3533 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003534 return FALSE;
3535 }
3536 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003537
3538 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003539 {
3540 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003541 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003542 if(st != 0)
3543 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003544 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003545 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003546 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3547 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003548 return FALSE;
3549 }
3550 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003551
3552 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003553 {
3554 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003555 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003556 if(st != 0)
3557 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003558 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003559 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3560 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3561 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3562 return FALSE;
3563 }
3564 }
3565
3566 if(v11nParams->smps != 0xFFFF)
3567 {
3568 if(v11nParams->smps == 0)
3569 {
Dake Zhao0a832172015-01-06 11:08:47 -08003570 // implement the funciton
3571 //st = wfaExecuteCLI(gCmdStr);
3572 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003573 else if(v11nParams->smps == 1)
3574 {
Dake Zhao0a832172015-01-06 11:08:47 -08003575 // implement the funciton
3576 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003577 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003578 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003579 else if(v11nParams->smps == 2)
3580 {
Dake Zhao0a832172015-01-06 11:08:47 -08003581 // implement the funciton
3582 //st = wfaExecuteCLI(gCmdStr);
3583 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003584 }
3585 if(st != 0)
3586 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003587 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003588 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3589 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3590 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3591 return FALSE;
3592 }
3593 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003594
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003595 if(v11nParams->stbc_rx != 0xFFFF)
3596 {
3597 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003598 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003599 if(st != 0)
3600 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003601 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003602 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003603 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3604 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003605 return FALSE;
3606 }
3607 }
Dake Zhao0a832172015-01-06 11:08:47 -08003608
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003609 if(v11nParams->width[0] != '\0')
3610 {
3611 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003612 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003613 if(st != 0)
3614 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003615 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003616 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3617 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3618 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3619 return FALSE;
3620 }
3621 }
Dake Zhao0a832172015-01-06 11:08:47 -08003622
Ankur Vachhanic485b712012-02-15 23:29:49 +00003623 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003624 {
3625 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003626 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003627 if(st != 0)
3628 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003629 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003630 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3631 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3632 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3633 return FALSE;
3634 }
3635 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003636
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003637 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3638 {
3639 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003640 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003641 if(st != 0)
3642 {
3643 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003644 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003645 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3646 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3647 return FALSE;
3648 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003649
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003650 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003651
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003652 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3653 {
3654 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003655 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003656 if(st != 0)
3657 {
3658 v11nParamsResp->status = STATUS_ERROR;
3659 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3660 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3661 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3662 return FALSE;
3663 }
3664 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003665
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003666#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003667
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003668 v11nParamsResp->status = STATUS_COMPLETE;
3669 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3670 *respLen = WFA_TLV_HDR_LEN + 4;
3671 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003672}
3673#endif
3674/*
Dake Zhao0a832172015-01-06 11:08:47 -08003675 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003676 */
3677int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3678{
Dake Zhao0a832172015-01-06 11:08:47 -08003679 dutCmdResponse_t infoResp;
3680 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003681
Dake Zhao0a832172015-01-06 11:08:47 -08003682 printf("\n Entry wfastaAddARPTableEntry... ");
3683 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003684
Dake Zhao0a832172015-01-06 11:08:47 -08003685 infoResp.status = STATUS_COMPLETE;
3686 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3687 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3688
3689 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003690}
3691
3692/*
Dake Zhao0a832172015-01-06 11:08:47 -08003693 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003694 */
3695int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3696{
Dake Zhao0a832172015-01-06 11:08:47 -08003697 dutCmdResponse_t infoResp;
3698 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003699
Dake Zhao0a832172015-01-06 11:08:47 -08003700 printf("\n Entry wfaStaBlockICMPResponse... ");
3701 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003702
Dake Zhao0a832172015-01-06 11:08:47 -08003703 infoResp.status = STATUS_COMPLETE;
3704 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3705 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3706
3707 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003708}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003709
3710/*
Dake Zhao0a832172015-01-06 11:08:47 -08003711 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003712 */
3713
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003714int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3715{
3716 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3717 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003718 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3719
3720 if(sr->mode == WFA_OFF)
3721 {
Dake Zhao0a832172015-01-06 11:08:47 -08003722 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003723 }
3724 else
3725 {
Dake Zhao0a832172015-01-06 11:08:47 -08003726 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003727 }
3728
3729 staCmdResp->status = STATUS_COMPLETE;
3730 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3731 *respLen = WFA_TLV_HDR_LEN + 4;
3732
3733 return WFA_SUCCESS;
3734}
3735
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003736/*
Dake Zhao0a832172015-01-06 11:08:47 -08003737 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003738 */
3739
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003740int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3741{
Dake Zhao0a832172015-01-06 11:08:47 -08003742 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3743 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3744 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003745
Dake Zhao0a832172015-01-06 11:08:47 -08003746 if(strcasecmp(rfeat->prog, "tdls") == 0)
3747 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003748
3749
Dake Zhao0a832172015-01-06 11:08:47 -08003750 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003751
Dake Zhao0a832172015-01-06 11:08:47 -08003752 caResp->status = STATUS_COMPLETE;
3753 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3754 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003755
Dake Zhao0a832172015-01-06 11:08:47 -08003756 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003757}
3758
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003759/*
Dake Zhao0a832172015-01-06 11:08:47 -08003760 * wfaStaStartWfdConnection():
3761 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003762int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3763{
Dake Zhao0a832172015-01-06 11:08:47 -08003764 dutCmdResponse_t infoResp;
3765 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003766
Dake Zhao0a832172015-01-06 11:08:47 -08003767 printf("\n Entry wfaStaStartWfdConnection... ");
3768
3769
3770 // Fetch the GrpId and WFD session and return
3771 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3772 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3773 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3774
3775 infoResp.status = STATUS_COMPLETE;
3776 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3777 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3778
3779 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003780}
3781/*
Dake Zhao0a832172015-01-06 11:08:47 -08003782 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003783 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003784
Ankur Vachhanic485b712012-02-15 23:29:49 +00003785int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3786{
Dake Zhao0a832172015-01-06 11:08:47 -08003787 char cmdName[32];
3788 char *pcmdStr=NULL, *str;
3789 int st = 1;
3790 char CmdStr[WFA_CMD_STR_SZ];
3791 FILE *wfaCliFd;
3792 char wfaCliBuff[64];
3793 char retstr[256];
3794 int CmdReturnFlag =0;
3795 char tmp[256];
3796 FILE * sh_pipe;
3797 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003798
Dake Zhao0a832172015-01-06 11:08:47 -08003799 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3800 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3801 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003802
Dake Zhao0a832172015-01-06 11:08:47 -08003803 for(;;)
3804 {
3805 // construct CLI standard cmd string
3806 str = strtok_r(NULL, ",", &pcmdStr);
3807 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003808 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003809 else
3810 {
3811 sprintf(CmdStr, "%s /%s",CmdStr,str);
3812 str = strtok_r(NULL, ",", &pcmdStr);
3813 sprintf(CmdStr, "%s %s",CmdStr,str);
3814 }
3815 }
3816 // check the return process
3817 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3818 if(wfaCliFd!= NULL)
3819 {
3820 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3821 {
3822 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3823 if(ferror(wfaCliFd))
3824 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003825
Dake Zhao0a832172015-01-06 11:08:47 -08003826 str=strtok(wfaCliBuff,"-");
3827 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003828 {
Dake Zhao0a832172015-01-06 11:08:47 -08003829 str=strtok(NULL,",");
3830 if (str != NULL)
3831 {
3832 if(strcmp(str,"TRUE") == 0)
3833 CmdReturnFlag =1;
3834 }
3835 else
3836 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3837 break;
Dake Zhao97708202014-11-26 13:59:04 -08003838 }
Dake Zhao0a832172015-01-06 11:08:47 -08003839 }
3840 fclose(wfaCliFd);
3841 }
3842 else
3843 {
3844 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3845 goto cleanup;
3846 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003847
Dake Zhao0a832172015-01-06 11:08:47 -08003848 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3849 memset(&retstr[0],'\0',255);
3850 memset(&tmp[0],'\0',255);
3851 sprintf(gCmdStr, "%s", CmdStr);
3852 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003853
Dake Zhao0a832172015-01-06 11:08:47 -08003854 sh_pipe = popen(gCmdStr,"r");
3855 if(!sh_pipe)
3856 {
3857 printf ("Error in opening pipe\n");
3858 goto cleanup;
3859 }
Dake Zhao97708202014-11-26 13:59:04 -08003860
Dake Zhao0a832172015-01-06 11:08:47 -08003861 sleep(5);
3862 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3863 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3864 {
3865 printf("Getting NULL string in popen return\n");
3866 goto cleanup;
3867 }
3868 else
3869 printf("popen return str=%s\n",retstr);
3870
3871 sleep(2);
3872 if(pclose(sh_pipe) == -1)
3873 {
3874 printf("Error in closing shell cmd pipe\n");
3875 goto cleanup;
3876 }
3877 sleep(2);
3878
3879 // find status first in output
3880 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3881 if (str != NULL)
3882 {
3883 memset(tmp, 0, 10);
3884 memcpy(tmp, str, 2);
3885 printf("cli status=%s\n",tmp);
3886 if(strlen(tmp) > 0)
3887 st = atoi(tmp);
3888 else printf("Missing status code\n");
3889 }
3890 else
3891 {
3892 printf("wfaStaCliCommand no return code found\n");
3893 }
3894 infoResp.resFlag=CmdReturnFlag;
3895
Dake Zhao97708202014-11-26 13:59:04 -08003896cleanup:
Dake Zhao0a832172015-01-06 11:08:47 -08003897
3898 switch(st)
3899 {
3900 case 0:
3901 infoResp.status = STATUS_COMPLETE;
3902 if (CmdReturnFlag)
3903 {
3904 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3905 {
3906 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003907 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 -08003908 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3909 }
3910 else
3911 {
Dake Zhao97708202014-11-26 13:59:04 -08003912 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003913 }
3914 }
3915 break;
3916 case 1:
3917 infoResp.status = STATUS_ERROR;
3918 break;
3919 case 2:
3920 infoResp.status = STATUS_INVALID;
3921 break;
3922 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003923
Dake Zhao0a832172015-01-06 11:08:47 -08003924 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3925 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003926
Dake Zhao0a832172015-01-06 11:08:47 -08003927 printf("Exit from wfaStaCliCommand\n");
3928 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003929
Ankur Vachhanic485b712012-02-15 23:29:49 +00003930}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003931/*
Dake Zhao0a832172015-01-06 11:08:47 -08003932 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003933 */
3934
3935int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3936{
3937 dutCmdResponse_t infoResp;
3938// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003939
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003940 printf("\n Entry wfaStaConnectGoStartWfd... ");
3941
Dake Zhao0a832172015-01-06 11:08:47 -08003942 // connect the specified GO and then establish the wfd session
3943
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003944 // Fetch WFD session and return
3945 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3946
3947 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003948 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003949 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003950
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003951 return WFA_SUCCESS;
3952}
3953
3954/*
Dake Zhao0a832172015-01-06 11:08:47 -08003955 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003956 */
3957
3958int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3959{
3960 dutCmdResponse_t infoResp;
3961 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3962 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003963
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003964 printf("\n Entry wfaStaGenerateEvent... ");
3965
3966
3967 // Geneate the specified action and return with complete/error.
3968 if(staGenerateEvent->program == PROG_TYPE_WFD)
3969 {
3970 wfdGenEvent = &staGenerateEvent->wfdEvent;
3971 if(wfdGenEvent ->type == eUibcGen)
3972 {
Dake Zhao0a832172015-01-06 11:08:47 -08003973 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003974 else if(wfdGenEvent ->type == eUibcHid)
3975 {
Dake Zhao0a832172015-01-06 11:08:47 -08003976 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003977 else if(wfdGenEvent ->type == eFrameSkip)
3978 {
3979
3980 }
3981 else if(wfdGenEvent ->type == eI2cRead)
3982 {
3983 }
3984 else if(wfdGenEvent ->type == eI2cWrite)
3985 {
Dake Zhao0a832172015-01-06 11:08:47 -08003986 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003987 else if(wfdGenEvent ->type == eInputContent)
3988 {
Dake Zhao0a832172015-01-06 11:08:47 -08003989 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003990 else if(wfdGenEvent ->type == eIdrReq)
3991 {
Dake Zhao0a832172015-01-06 11:08:47 -08003992 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003993 }
Dake Zhao0a832172015-01-06 11:08:47 -08003994
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003995 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003996 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003997 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003998
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003999 return WFA_SUCCESS;
4000}
4001
Dake Zhao0a832172015-01-06 11:08:47 -08004002
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004003
4004
4005/*
Dake Zhao0a832172015-01-06 11:08:47 -08004006 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004007 */
4008
4009int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4010{
4011 dutCmdResponse_t infoResp;
4012// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08004013
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004014 printf("\n Entry wfaStaReinvokeWfdSession... ");
4015
4016 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08004017
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004018
4019 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08004020 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004021 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08004022
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004023 return WFA_SUCCESS;
4024}
4025
4026
4027int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4028{
Dake Zhao0a832172015-01-06 11:08:47 -08004029 dutCmdResponse_t infoResp;
4030 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004031
4032
Dake Zhao0a832172015-01-06 11:08:47 -08004033 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004034
Dake Zhao0a832172015-01-06 11:08:47 -08004035 printf("\n Entry wfaStaGetParameter... ");
4036
4037 // Check the program type
4038 if(staGetParam->program == PROG_TYPE_WFD)
4039 {
4040 if(staGetParam->getParamValue == eDiscoveredDevList )
4041 {
4042 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4043 paramList->getParamType = eDiscoveredDevList;
4044 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4045 }
4046 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004047
Dake Zhao655efed2015-03-11 17:39:13 -07004048 if(staGetParam->program == PROG_TYPE_WFDS)
4049 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004050
Dake Zhao655efed2015-03-11 17:39:13 -07004051 if(staGetParam->getParamValue == eDiscoveredDevList )
4052 {
4053 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
4054 paramList->getParamType = eDiscoveredDevList;
4055 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
4056
4057 }
4058 if(staGetParam->getParamValue == eOpenPorts)
4059 {
4060 // Run the port checker tool
4061 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
4062 paramList->getParamType = eOpenPorts;
4063 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
4064
4065 }
4066
4067 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004068
Dake Zhao655efed2015-03-11 17:39:13 -07004069 infoResp.status = STATUS_COMPLETE;
4070 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4071 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4072
4073 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08004074}
4075
Ankur Vachhanic485b712012-02-15 23:29:49 +00004076
Dake Zhao655efed2015-03-11 17:39:13 -07004077int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4078{
4079
4080 dutCmdResponse_t infoResp;
4081 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4082
4083 printf("\n Entry wfaStaNfcAction... ");
4084
4085 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4086 {
4087 printf("\n NfcAction - HandOver... ");
4088
4089 }
4090 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4091 {
4092 printf("\n NfcAction - Read Tag... ");
4093
4094 }
4095 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4096 {
4097 printf("\n NfcAction - Write Select... ");
4098
4099 }
4100 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4101 {
4102 printf("\n NfcAction - Write Config... ");
4103
4104 }
4105 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4106 {
4107 printf("\n NfcAction - Write Password... ");
4108
4109 }
4110 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4111 {
4112 printf("\n NfcAction - WPS Handover... ");
4113
4114 }
4115
4116 // Fetch the device mode and put in infoResp->cmdru.p2presult
4117 //strcpy(infoResp->cmdru.p2presult, "GO");
4118
4119 // Fetch the device grp id and put in infoResp->cmdru.grpid
4120 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4121
4122 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4123 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4124 infoResp.cmdru.staNfcAction.peerRole = 1;
4125
4126
4127
4128
4129 infoResp.status = STATUS_COMPLETE;
4130 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4131 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4132
4133 return WFA_SUCCESS;
4134}
4135
4136int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4137{
4138
4139 dutCmdResponse_t infoResp;
4140 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4141
4142 printf("\n Entry wfaStaInvokeCommand... ");
4143
4144
4145 // based on the command type , invoke API or complete the required procedures
4146 // return the defined parameters based on the command that is received ( example response below)
4147
4148 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4149 {
4150 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4151 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4152 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4153 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4154 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4155 }
4156 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4157 {
4158 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4159 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4160 }
4161 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4162 {
4163 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4164 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4165 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4166 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4167
4168 }
4169 infoResp.status = STATUS_COMPLETE;
4170 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4171 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4172
4173 return WFA_SUCCESS;
4174}
4175
4176
4177int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4178{
4179
4180 dutCmdResponse_t infoResp;
4181 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4182
4183 printf("\n Entry wfaStaManageService... ");
4184
4185 // based on the manage service type , invoke API's or complete the required procedures
4186 // return the defined parameters based on the command that is received ( example response below)
4187 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4188 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4189 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4190
4191 infoResp.status = STATUS_COMPLETE;
4192 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4193 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4194
4195 return WFA_SUCCESS;
4196}
4197
4198
4199
4200int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4201{
4202
4203 dutCmdResponse_t infoResp;
4204 //caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
4205
4206 printf("\n Entry wfaStaGetEvents... ");
4207
4208 // Get all the event from the Log file or stored events
4209 // return the received/recorded events as space seperated list ( example response below)
4210 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4211
4212 infoResp.status = STATUS_COMPLETE;
4213 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4214 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4215
4216 return WFA_SUCCESS;
4217}
4218
4219int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4220{
4221
4222 dutCmdResponse_t infoResp;
4223 caStaGetEventDetails_t *getStaGetEventDetails = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4224
4225 printf("\n Entry wfaStaGetEventDetails... ");
4226
4227
4228 // based on the Requested Event type
4229 // return the latest corresponding evnet detailed parameters ( example response below)
4230
4231 if(getStaGetEventDetails->eventId== eSearchResult )
4232 {
4233 // fetch from log file or event history for the search result event and return the parameters
4234 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4235
4236 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4237 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4238 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4239 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4240
4241 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4242 }
4243 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4244 { // fetch from log file or event history for the search terminated event and return the parameters
4245 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4246 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4247 }
4248 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4249 {// fetch from log file or event history for the Advertise Status event and return the parameters
4250 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4251 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4252
4253 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4254 }
4255 else if (getStaGetEventDetails->eventId == eSessionRequest)
4256 {// fetch from log file or event history for the session request event and return the parameters
4257 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4258 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4259 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4260 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4261 }
4262 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4263 {// fetch from log file or event history for the session status event and return the parameters
4264 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4265 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4266 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4267 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4268 }
4269 else if (getStaGetEventDetails->eventId == eConnectStatus)
4270 {
4271 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4272 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4273 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4274 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4275
4276 }
4277 else if (getStaGetEventDetails->eventId == ePortStatus)
4278 {
4279 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4280 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4281 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4282 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4283 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4284 }
4285
4286
4287
4288 infoResp.status = STATUS_COMPLETE;
4289 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4290 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4291
4292 return WFA_SUCCESS;
4293}
4294
4295
4296
4297