blob: d9ad9069e2ebd9c16fb4c4796bf6fb17b24601ed [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
4Permission 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
6notice appear in all copies.
7
8THE 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
14THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16******************************************************************************/
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000017
18/*
19 * File: wfa_cs.c -- configuration and setup
20 * This file contains all implementation for the dut setup and control
21 * 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
25 * should be defined in order to support the Agent Control/Test Manager
26 * control commands. To simplify the current work and avoid any GPL licenses,
27 * the functions mostly invoke shell commands by calling linux system call,
28 * system("<commands>").
29 *
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 *
34 * Revision History:
35 * 2006/03/10 -- initially created by qhu
36 * 2006/06/01 -- BETA Release by qhu
37 * 2006/06/13 -- 00.02 Release by qhu
38 * 2006/06/30 -- 00.10 Release by qhu
39 * 2006/07/10 -- 01.00 Release by qhu
40 * 2006/09/01 -- 01.05 Release by qhu
41 * 2006/10/26 -- 01.06 Released by qhu
42 * replace hardcoded buf size with macro
43 * 2006/12/02 -- bugs: 1. fixes incorrect order of getipconfig.sh
44 * input parameters reported by p.schwann
45 * 2. will add a new network for wap_cli command
46 * in case the network id 0 not present,
47 * recommended by c.benson
48 * the solution is to reimplement with calling
49 * native C API
50 * 2007/01/11 -- 01.10 released by qhu
51 * 2007/02/15 -- WMM Extension Beta released by qhu, mkaroshi
52 * 2007/03/18 -- add file close statements
53 * 2007/03/21 -- rename the file to avoid the confusion.
54 * 2007/03/30 -- 01.40 WPA2 and Official WMM Beta Release by qhu
55 * 2007/04/20 -- 02.00 WPA2 and Official WMM Release by qhu
56 * 2007/08/15 -- 02.10 WMM-Power Save release by qhu
57 * 2007/10/10 -- 02.20 Voice SOHO beta -- qhu
58 * 2007/11/07 -- 02.30 Voice HSO -- qhu
59 * 2007/12/10 -- 02.32 Add a function to upload test results.
60 * 2008/01/03 -- 02.34 Support the result upload command.
61 * 2008/03/12 -- 02.41 Bug #16, incorrect file descriptor used. Change
62 * the "tmpfile" to "tmpfd" and a few places. Make a macro
63 * WFA_STAUT_IF in file "inc/wfa_cs.h" for WLAN interface
64 * name in the function "wfaDeviceListIF()
65 *
66 * Not A Bug. Put back to the function from
67 * wfaSetEncryption1() to wfaSetEncryption() for
68 * supporting WEP. Porting could select which should be
69 * used according to WEP support or not.
70 *
71 *
72 */
73#include <stdio.h>
74#include <unistd.h>
75#include <string.h>
76#include <stdlib.h>
77#include <sys/socket.h>
78#include <arpa/inet.h>
79#include <linux/types.h>
80#include <linux/socket.h>
81#include <poll.h>
82
83#include "wfa_portall.h"
84#include "wfa_debug.h"
85#include "wfa_ver.h"
86#include "wfa_main.h"
87#include "wfa_types.h"
88#include "wfa_ca.h"
89#include "wfa_tlv.h"
90#include "wfa_sock.h"
91#include "wfa_tg.h"
92#include "wfa_cmds.h"
93#include "wfa_rsp.h"
94#include "wfa_utils.h"
95#ifdef WFA_WMM_PS_EXT
96#include "wfa_wmmps.h"
97#endif
98
99#define CERTIFICATES_PATH "/etc/wpa_supplicant"
100
101/* Some device may only support UDP ECHO, activate this line */
102//#define WFA_PING_UDP_ECHO_ONLY 1
103
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800104#define WFA_ENABLED 1
105
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000106extern unsigned short wfa_defined_debug;
107int wfaExecuteCLI(char *CLI);
108
109/* Since the two definitions are used all over the CA function */
110char gCmdStr[WFA_CMD_STR_SZ];
111dutCmdResponse_t gGenericResp;
112int wfaTGSetPrio(int sockfd, int tgClass);
113void create_apts_msg(int msg, unsigned int txbuf[],int id);
114
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800115int sret = 0;
116
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000117extern char e2eResults[];
118//extern char *e2eResults;
119FILE *e2efp = NULL;
120int chk_ret_status()
121{
122 char *ret = getenv(WFA_RET_ENV);
123
124 if(*ret == '1')
125 return WFA_SUCCESS;
126 else
127 return WFA_FAILURE;
128}
129
130/*
131 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
132 * input: cmd --- not used
133 * valLen -- not used
134 * output: parms -- a buffer to store the version info response.
135 */
136int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
137{
138 dutCmdResponse_t *getverResp = &gGenericResp;
139
140 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
141
142 getverResp->status = STATUS_COMPLETE;
143 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
144
145 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
146
147 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
148
149 return WFA_SUCCESS;
150}
151
152/*
153 * wfaStaAssociate():
154 * The function is to force the station wireless I/F to re/associate
155 * with the AP.
156 */
157int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
158{
159 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
160 char *ifname = assoc->intf;
161 dutCmdResponse_t *staAssocResp = &gGenericResp;
162
163 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
164 /*
165 * if bssid appears, station should associate with the specific
166 * BSSID AP at its initial association.
167 * If it is different to the current associating AP, it will be forced to
168 * roam the new AP
169 */
170 if(assoc->cmdsu.assoc.bssid[0] != '\0')
171 {
172 /* if (the first association) */
173 /* just do initial association to the BSSID */
174
175
176 /* else (station already associate to an AP) */
177 /* Do forced roaming */
178
179 }
180 else
181 {
182 /* use 'ifconfig' command to bring down the interface (linux specific) */
183 sprintf(gCmdStr, "ifconfig %s down", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800184 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000185
186 /* use 'ifconfig' command to bring up the interface (linux specific) */
187 sprintf(gCmdStr, "ifconfig %s up", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800188 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000189
190 /*
191 * use 'wpa_cli' command to force a 802.11 re/associate
192 * (wpa_supplicant specific)
193 */
194 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800195 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000196 }
197
198 /*
199 * Then report back to control PC for completion.
200 * This does not have failed/error status. The result only tells
201 * a completion.
202 */
203 staAssocResp->status = STATUS_COMPLETE;
204 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
205 *respLen = WFA_TLV_HDR_LEN + 4;
206
207 return WFA_SUCCESS;
208}
209
210/*
211 * wfaStaReAssociate():
212 * The function is to force the station wireless I/F to re/associate
213 * with the AP.
214 */
215int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
216{
217 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
218 char *ifname = assoc->intf;
219 dutCmdResponse_t *staAssocResp = &gGenericResp;
220
221 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
222 /*
223 * if bssid appears, station should associate with the specific
224 * BSSID AP at its initial association.
225 * If it is different to the current associating AP, it will be forced to
226 * roam the new AP
227 */
228 if(assoc->cmdsu.assoc.bssid[0] != '\0')
229 {
230 /* if (the first association) */
231 /* just do initial association to the BSSID */
232
233
234 /* else (station already associate to an AP) */
235 /* Do forced roaming */
236
237 }
238 else
239 {
240 /* use 'ifconfig' command to bring down the interface (linux specific) */
241 sprintf(gCmdStr, "ifconfig %s down", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800242 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000243
244 /* use 'ifconfig' command to bring up the interface (linux specific) */
245 sprintf(gCmdStr, "ifconfig %s up", ifname);
246
247 /*
248 * use 'wpa_cli' command to force a 802.11 re/associate
249 * (wpa_supplicant specific)
250 */
251 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800252 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000253 }
254
255 /*
256 * Then report back to control PC for completion.
257 * This does not have failed/error status. The result only tells
258 * a completion.
259 */
260 staAssocResp->status = STATUS_COMPLETE;
261 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
262 *respLen = WFA_TLV_HDR_LEN + 4;
263
264 return WFA_SUCCESS;
265}
266
267/*
268 * wfaStaIsConnected():
269 * The function is to check whether the station's wireless I/F has
270 * already connected to an AP.
271 */
272int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
273{
274 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
275 dutCmdResponse_t *staConnectResp = &gGenericResp;
276 char *ifname = connStat->intf;
277 FILE *tmpfile = NULL;
278 char result[32];
279
280
281 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
282
283#ifdef WFA_NEW_CLI_FORMAT
284 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800285 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000286
287 if(chk_ret_status() == WFA_SUCCESS)
288 staConnectResp->cmdru.connected = 1;
289 else
290 staConnectResp->cmdru.connected = 0;
291#else
292 /*
293 * use 'wpa_cli' command to check the interface status
294 * none, scanning or complete (wpa_supplicant specific)
295 */
296 sprintf(gCmdStr, "/sbin/wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800297 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000298
299 /*
300 * the status is saved in a file. Open the file and check it.
301 */
302 tmpfile = fopen("/tmp/.isConnected", "r+");
303 if(tmpfile == NULL)
304 {
305 staConnectResp->status = STATUS_ERROR;
306 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
307 *respLen = WFA_TLV_HDR_LEN + 4;
308
309 DPRINT_ERR(WFA_ERR, "file open failed\n");
310 return WFA_FAILURE;
311 }
312
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800313 sret = fscanf(tmpfile, "%s", (char *)result);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000314
315 if(strncmp(result, "COMPLETED", 9) == 0)
316 staConnectResp->cmdru.connected = 1;
317 else
318 staConnectResp->cmdru.connected = 0;
319#endif
320
321 /*
322 * Report back the status: Complete or Failed.
323 */
324 staConnectResp->status = STATUS_COMPLETE;
325
326 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
327 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
328
329 return WFA_SUCCESS;
330}
331
332/*
333 * wfaStaGetIpConfig():
334 * This function is to retriev the ip info including
335 * 1. dhcp enable
336 * 2. ip address
337 * 3. mask
338 * 4. primary-dns
339 * 5. secondary-dns
340 *
341 * The current implementation is to use a script to find these information
342 * and store them in a file.
343 */
344int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
345{
346 int slen, ret, i = 0;
347 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
348 dutCmdResponse_t *ipconfigResp = &gGenericResp;
349 char *ifname = getIpConf->intf;
350 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
351
352 FILE *tmpfd;
353 char string[256];
354 char *str;
355
356 /*
357 * check a script file (the current implementation specific)
358 */
359 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
360 if(ret == -1)
361 {
362 ipconfigResp->status = STATUS_ERROR;
363 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
364 *respLen = WFA_TLV_HDR_LEN + 4;
365
366 DPRINT_ERR(WFA_ERR, "file not exist\n");
367 return WFA_FAILURE;
368
369 }
370
371 strcpy(ifinfo->dns[0], "0");
372 strcpy(ifinfo->dns[1], "0");
373
374 /*
375 * Run the script file "getipconfig.sh" to check the ip status
376 * (current implementation specific).
377 * note: "getipconfig.sh" is only defined for the current implementation
378 */
379 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
380
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800381 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000382
383 /* open the output result and scan/retrieve the info */
384 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
385
386 if(tmpfd == NULL)
387 {
388 ipconfigResp->status = STATUS_ERROR;
389 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
390 *respLen = WFA_TLV_HDR_LEN + 4;
391
392 DPRINT_ERR(WFA_ERR, "file open failed\n");
393 return WFA_FAILURE;
394 }
395
396 for(;;)
397 {
398 if(fgets(string, 256, tmpfd) == NULL)
399 break;
400
401 /* check dhcp enabled */
402 if(strncmp(string, "dhcpcli", 7) ==0)
403 {
404 str = strtok(string, "=");
405 str = strtok(NULL, "=");
406 if(str != NULL)
407 ifinfo->isDhcp = 1;
408 else
409 ifinfo->isDhcp = 0;
410 }
411
412 /* find out the ip address */
413 if(strncmp(string, "ipaddr", 6) == 0)
414 {
415 str = strtok(string, "=");
416 str = strtok(NULL, " ");
417 if(str != NULL)
418 {
419 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800420
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000421 ifinfo->ipaddr[15]='\0';
422 }
423 else
424 wSTRNCPY(ifinfo->ipaddr, "none", 15);
425 }
426
427 /* check the mask */
428 if(strncmp(string, "mask", 4) == 0)
429 {
430 char ttstr[16];
431 char *ttp = ttstr;
432
433 str = strtok_r(string, "=", &ttp);
434 if(*ttp != '\0')
435 {
436 strcpy(ifinfo->mask, ttp);
437 slen = strlen(ifinfo->mask);
438 ifinfo->mask[slen-1] = '\0';
439 }
440 else
441 strcpy(ifinfo->mask, "none");
442 }
443
444 /* find out the dns server ip address */
445 if(strncmp(string, "nameserv", 8) == 0)
446 {
447 char ttstr[16];
448 char *ttp = ttstr;
449
450 str = strtok_r(string, " ", &ttp);
451 if(str != NULL && i < 2)
452 {
453 strcpy(ifinfo->dns[i], ttp);
454 slen = strlen(ifinfo->dns[i]);
455 ifinfo->dns[i][slen-1] = '\0';
456 }
457 else
458 strcpy(ifinfo->dns[i], "none");
459
460 i++;
461 }
462 }
463
464 /*
465 * Report back the results
466 */
467 ipconfigResp->status = STATUS_COMPLETE;
468 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
469
470 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
471
472#if 0
473 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
474 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
475 ifinfo->dns[0], ifinfo->dns[1], *respLen);
476#endif
477
478 fclose(tmpfd);
479 return WFA_SUCCESS;
480}
481
482/*
483 * wfaStaSetIpConfig():
484 * The function is to set the ip configuration to a wireless I/F.
485 * 1. IP address
486 * 2. Mac address
487 * 3. default gateway
488 * 4. dns nameserver (pri and sec).
489 */
490int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
491{
492 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
493 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
494 dutCmdResponse_t *staSetIpResp = &gGenericResp;
495
496 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
497
498 /*
499 * Use command 'ifconfig' to configure the interface ip address, mask.
500 * (Linux specific).
501 */
502 sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800503 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000504
505 /* use command 'route add' to set set gatewway (linux specific) */
506 if(ipconfig->defGateway[0] != '\0')
507 {
508 sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800509 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000510 }
511
512 /* set dns (linux specific) */
513 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800514 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000515 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800516 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000517 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800518 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000519
520 /*
521 * report status
522 */
523 staSetIpResp->status = STATUS_COMPLETE;
524 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
525 *respLen = WFA_TLV_HDR_LEN + 4;
526
527 return WFA_SUCCESS;
528}
529
530/*
531 * wfaStaVerifyIpConnection():
532 * The function is to verify if the station has IP connection with an AP by
533 * send ICMP/pings to the AP.
534 */
535int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
536{
537 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
538 dutCmdResponse_t *verifyIpResp = &gGenericResp;
539
540#ifndef WFA_PING_UDP_ECHO_ONLY
541 char strout[64], *pcnt;
542 FILE *tmpfile;
543
544 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
545
546 /* set timeout value in case not set */
547 if(verip->cmdsu.verifyIp.timeout <= 0)
548 {
549 verip->cmdsu.verifyIp.timeout = 10;
550 }
551
552 /* execute the ping command and pipe the result to a tmp file */
553 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);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800554 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000555
556 /* scan/check the output */
557 tmpfile = fopen("/tmp/pingout.txt", "r+");
558 if(tmpfile == NULL)
559 {
560 verifyIpResp->status = STATUS_ERROR;
561 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
562 *respLen = WFA_TLV_HDR_LEN + 4;
563
564 DPRINT_ERR(WFA_ERR, "file open failed\n");
565 return WFA_FAILURE;
566 }
567
568 verifyIpResp->status = STATUS_COMPLETE;
569 if(fscanf(tmpfile, "%s", strout) == EOF)
570 verifyIpResp->cmdru.connected = 0;
571 else
572 {
573 pcnt = strtok(strout, "%");
574
575 /* if the loss rate is 100%, not able to connect */
576 if(atoi(pcnt) == 100)
577 verifyIpResp->cmdru.connected = 0;
578 else
579 verifyIpResp->cmdru.connected = 1;
580 }
581
582 fclose(tmpfile);
583#else
584 int btSockfd;
585 struct pollfd fds[2];
586 int timeout = 2000;
587 char anyBuf[64];
588 struct sockaddr_in toAddr;
589 int done = 1, cnt = 0, ret, nbytes;
590
591 verifyIpResp->status = STATUS_COMPLETE;
592 verifyIpResp->cmdru.connected = 0;
593
594 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
595
596 if(btSockfd == -1)
597 {
598 verifyIpResp->status = STATUS_ERROR;
599 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
600 *respLen = WFA_TLV_HDR_LEN + 4;
601 return WFA_FAILURE;;
602 }
603
604 toAddr.sin_family = AF_INET;
605 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
606 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
607
608 while(done)
609 {
610 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
611 cnt++;
612
613 fds[0].fd = btSockfd;
614 fds[0].events = POLLIN | POLLOUT;
615
616 ret = poll(fds, 1, timeout);
617 switch(ret)
618 {
619 case 0:
620 /* it is time out, count a packet lost*/
621 break;
622 case -1:
623 /* it is an error */
624 default:
625 {
626 switch(fds[0].revents)
627 {
628 case POLLIN:
629 case POLLPRI:
630 case POLLOUT:
631 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
632 if(nbytes != 0)
633 verifyIpResp->cmdru.connected = 1;
634 done = 0;
635 break;
636 default:
637 /* errors but not care */
638 ;
639 }
640 }
641 }
642 if(cnt == 3)
643 {
644 done = 0;
645 }
646 }
647
648#endif
649
650 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
651
652 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
653
654 return WFA_SUCCESS;
655}
656
657/*
658 * wfaStaGetMacAddress()
659 * This function is to retrieve the MAC address of a wireless I/F.
660 */
661int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
662{
663 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
664 dutCmdResponse_t *getmacResp = &gGenericResp;
665 char *str;
666 char *ifname = getMac->intf;
667
668 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800669 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000670
671 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
672 /*
673 * run the script "getipconfig.sh" to find out the mac
674 */
675 //sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s", ifname);
676 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800677 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000678
679 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
680 if(tmpfd == NULL)
681 {
682 getmacResp->status = STATUS_ERROR;
683 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
684 *respLen = WFA_TLV_HDR_LEN + 4;
685
686 DPRINT_ERR(WFA_ERR, "file open failed\n");
687 return WFA_FAILURE;
688 }
689
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800690 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
691 {
692 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000693 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800694
695 str = strtok(string, " ");
696 while(str && ((strcmp(str,"HWaddr")) != 0))
697 {
698 str = strtok(NULL, " ");
699 }
700
701 /* get mac */
702 if(str)
703 {
704 str = strtok(NULL, " ");
705 strcpy(getmacResp->cmdru.mac, str);
706 getmacResp->status = STATUS_COMPLETE;
707 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000708
709 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
710
711 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
712
713 fclose(tmpfd);
714 return WFA_SUCCESS;
715}
716
717/*
718 * wfaStaGetStats():
719 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
720 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
721 * Currently there is not definition how to use these info.
722 */
723int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
724{
725 dutCmdResponse_t *statsResp = &gGenericResp;
726
727 /* this is never used, you can skip this call */
728
729 statsResp->status = STATUS_ERROR;
730 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
731 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
732
733
734 return WFA_SUCCESS;
735}
736
737/*
738 * wfaSetEncryption():
739 * The function is to set the wireless interface with WEP or none.
740 *
741 * Since WEP is optional test, current function is only used for
742 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
743 * this function should be replaced by the next one (wfaSetEncryption1())
744 *
745 * Input parameters:
746 * 1. I/F
747 * 2. ssid
748 * 3. encpType - wep or none
749 * Optional:
750 * 4. key1
751 * 5. key2
752 * 6. key3
753 * 7. key4
754 * 8. activeKey Index
755 */
756
757int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
758{
759 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
760 dutCmdResponse_t *setEncrypResp = &gGenericResp;
761
762 /*
763 * disable the network first
764 */
765 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800766 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000767
768 /*
769 * set SSID
770 */
771 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800772 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000773
774 /*
775 * Tell the supplicant for infrastructure mode (1)
776 */
777 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800778 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000779
780 /*
781 * set Key management to NONE (NO WPA) for plaintext or WEP
782 */
783 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800784 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000785
786 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800787 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000788
789 setEncrypResp->status = STATUS_COMPLETE;
790 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
791 *respLen = WFA_TLV_HDR_LEN + 4;
792
793 return WFA_SUCCESS;
794}
795
796/*
797 * Since WEP is optional, this function could be used to replace
798 * wfaSetEncryption() if necessary.
799 */
800int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
801{
802 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
803 dutCmdResponse_t *setEncrypResp = &gGenericResp;
804 int i;
805
806 /*
807 * disable the network first
808 */
809 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800810 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000811
812 /*
813 * set SSID
814 */
815 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800816 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000817
818 /*
819 * Tell the supplicant for infrastructure mode (1)
820 */
821 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800822 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000823
824 /*
825 * set Key management to NONE (NO WPA) for plaintext or WEP
826 */
827 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800828 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000829
830 /* set keys */
831 if(setEncryp->encpType == 1)
832 {
833 for(i=0; i<4; i++)
834 {
835 if(setEncryp->keys[i][0] != '\0')
836 {
837 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
838 setEncryp->intf, i, setEncryp->keys[i]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800839 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000840 }
841 }
842
843 /* set active key */
844 i = setEncryp->activeKeyIdx;
845 if(setEncryp->keys[i][0] != '\0')
846 {
847 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
848 setEncryp->intf, setEncryp->activeKeyIdx);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800849 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000850 }
851 }
852 else /* clearly remove the keys -- reported by p.schwann */
853 {
854
855 for(i = 0; i < 4; i++)
856 {
857 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800858 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000859 }
860 }
861
862 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800863 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000864
865 setEncrypResp->status = STATUS_COMPLETE;
866 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
867 *respLen = WFA_TLV_HDR_LEN + 4;
868
869 return WFA_SUCCESS;
870}
871
872int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
873{
874 int ret = WFA_SUCCESS;
875
876 return ret;
877}
878
879/*
880 * wfaStaSetEapTLS():
881 * This is to set
882 * 1. ssid
883 * 2. encrypType - tkip or aes-ccmp
884 * 3. keyManagementType - wpa or wpa2
885 * 4. trustedRootCA
886 * 5. clientCertificate
887 */
888int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
889{
890 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
891 char *ifname = setTLS->intf;
892 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
893
894 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
895
896 /*
897 * need to store the trustedROOTCA and clientCertificate into a file first.
898 */
899#ifdef WFA_NEW_CLI_FORMAT
900 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800901 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000902#else
903
904 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800905 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000906
907 /* ssid */
908 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800909 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000910
911 /* key management */
912 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
913 {
914 }
915 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
916 {
917 }
918 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
919 {
920
921 }
922 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
923 {
924 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
925 }
926 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
927 {
928 // to take all and device to pick any one supported.
929 }
930 else
931 {
932 // ??
933 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800934 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000935
936 /* protocol WPA */
937 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800938 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000939
940 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800941 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000942
943 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800944 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000945
946 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800947 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000948
949 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800950 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000951
952 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800953 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000954
955 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800956 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000957#endif
958
959 setEapTlsResp->status = STATUS_COMPLETE;
960 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
961 *respLen = WFA_TLV_HDR_LEN + 4;
962
963 return WFA_SUCCESS;
964}
965
966/*
967 * The function is to set
968 * 1. ssid
969 * 2. passPhrase
970 * 3. keyMangementType - wpa/wpa2
971 * 4. encrypType - tkip or aes-ccmp
972 */
973int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
974{
975 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
976 dutCmdResponse_t *setPskResp = &gGenericResp;
977
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000978#ifdef WFA_NEW_CLI_FORMAT
979 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800980 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000981#else
982 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800983 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000984
985 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
986 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
987 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
988 {
989 // take all and device to pick it supported.
990 }
991 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
992 {
993
994 }
995 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
996 {
997
998 }
Ray Wang9c508692014-04-01 17:04:59 -0700999 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
1000 {
1001
1002 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001003 else
1004 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001005
1006 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001007
1008 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001009 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001010
1011 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001012 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001013
1014 /* if PMF enable */
1015 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
1016 {
1017
1018 }
1019 else if(setPSK->pmf == WFA_REQUIRED)
1020 {
1021
1022 }
1023 else if(setPSK->pmf == WFA_F_REQUIRED)
1024 {
1025
1026 }
1027 else if(setPSK->pmf == WFA_F_DISABLED)
1028 {
1029
1030 }
1031 else
1032 { /* Disable PMF */
1033
1034 }
1035
1036#endif
1037
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001038 setPskResp->status = STATUS_COMPLETE;
1039 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1040 *respLen = WFA_TLV_HDR_LEN + 4;
1041
1042 return WFA_SUCCESS;
1043}
1044
1045/*
1046 * wfaStaGetInfo():
1047 * Get vendor specific information in name/value pair by a wireless I/F.
1048 */
1049int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1050{
1051 dutCmdResponse_t infoResp;
1052 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
1053
1054 /*
1055 * Normally this is called to retrieve the vendor information
1056 * from a interface, no implement yet
1057 */
1058 sprintf(infoResp.cmdru.info, "interface,%s,vendor,XXX,cardtype,802.11a/b/g", getInfo->intf);
1059
1060 infoResp.status = STATUS_COMPLETE;
1061 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
1062 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
1063
1064 return WFA_SUCCESS;
1065}
1066
1067/*
1068 * wfaStaSetEapTTLS():
1069 * This is to set
1070 * 1. ssid
1071 * 2. username
1072 * 3. passwd
1073 * 4. encrypType - tkip or aes-ccmp
1074 * 5. keyManagementType - wpa or wpa2
1075 * 6. trustedRootCA
1076 */
1077int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1078{
1079 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1080 char *ifname = setTTLS->intf;
1081 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
1082
1083#ifdef WFA_NEW_CLI_FORMAT
1084 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001085 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001086#else
1087
1088 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001089 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001090
1091 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001092 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001093
1094 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001095 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001096
1097 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001098 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001099
1100 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001101 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001102
1103/* This may not need to set. if it is not set, default to take all */
1104// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
1105 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1106 {
1107 }
1108 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1109 {
1110 }
1111 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1112 {
1113
1114 }
1115 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1116 {
1117
1118 }
1119 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1120 {
1121 // to take all and device to pick one it supported
1122 }
1123 else
1124 {
1125 // ??
1126 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001127 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001128
1129 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001130 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001131
1132 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001133 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001134
1135 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001136 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001137
1138// sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001139// sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001140
1141 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001142 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001143
1144 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001145 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001146#endif
1147
1148 setEapTtlsResp->status = STATUS_COMPLETE;
1149 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1150 *respLen = WFA_TLV_HDR_LEN + 4;
1151
1152 return WFA_SUCCESS;
1153}
1154
1155/*
1156 * wfaStaSetEapSIM():
1157 * This is to set
1158 * 1. ssid
1159 * 2. user name
1160 * 3. passwd
1161 * 4. encrypType - tkip or aes-ccmp
1162 * 5. keyMangementType - wpa or wpa2
1163 */
1164int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1165{
1166 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1167 char *ifname = setSIM->intf;
1168 dutCmdResponse_t *setEapSimResp = &gGenericResp;
1169
1170#ifdef WFA_NEW_CLI_FORMAT
1171 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001172 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001173#else
1174
1175 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001176 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001177
1178 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001179 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001180
1181
1182 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001183 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001184
1185 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001186 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001187
1188 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001189 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001190
1191 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001192 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001193
1194 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001195 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001196
1197 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1198 {
1199 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1200 }
1201 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1202 {
1203 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1204 }
1205 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1206 {
1207 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1208 }
1209 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1210 {
1211 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1212 }
1213 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1214 {
1215 // take all and device to pick one which is supported.
1216 }
1217 else
1218 {
1219 // ??
1220 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001221 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001222
1223#endif
1224
1225 setEapSimResp->status = STATUS_COMPLETE;
1226 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1227 *respLen = WFA_TLV_HDR_LEN + 4;
1228
1229 return WFA_SUCCESS;
1230}
1231
1232/*
1233 * wfaStaSetPEAP()
1234 * This is to set
1235 * 1. ssid
1236 * 2. user name
1237 * 3. passwd
1238 * 4. encryType - tkip or aes-ccmp
1239 * 5. keyMgmtType - wpa or wpa2
1240 * 6. trustedRootCA
1241 * 7. innerEAP
1242 * 8. peapVersion
1243 */
1244int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1245{
1246 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1247 char *ifname = setPEAP->intf;
1248 dutCmdResponse_t *setPeapResp = &gGenericResp;
1249
1250#ifdef WFA_NEW_CLI_FORMAT
1251 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1252 setPEAP->passwd, setPEAP->trustedRootCA,
1253 setPEAP->encrptype, setPEAP->peapVersion,
1254 setPEAP->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001255 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001256#else
1257
1258 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001259 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001260
1261 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001262 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001263
1264 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001265 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001266
1267 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001268 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001269
1270 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001271 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001272
1273 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001274 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001275
1276 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001277 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001278
1279 /* if this not set, default to set support all */
1280 //sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setPEAP->encrptype);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001281 //sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001282
1283 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1284 {
1285 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1286 }
1287 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1288 {
1289 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1290 }
1291 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1292 {
1293 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1294 }
1295 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1296 {
1297 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1298 }
1299 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1300 {
1301 // take all and device to pick one which is supported.
1302 }
1303 else
1304 {
1305 // ??
1306 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001307 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001308
1309 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001310 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001311
1312 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001313 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001314
1315 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001316 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001317#endif
1318
1319 setPeapResp->status = STATUS_COMPLETE;
1320 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1321 *respLen = WFA_TLV_HDR_LEN + 4;
1322
1323 return WFA_SUCCESS;
1324}
1325
1326/*
1327 * wfaStaSetUAPSD()
1328 * This is to set
1329 * 1. acBE
1330 * 2. acBK
1331 * 3. acVI
1332 * 4. acVO
1333 */
1334int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1335{
1336 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
1337#if 0 /* used for only one specific device, need to update to reflect yours */
1338 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1339 char *ifname = setUAPSD->intf;
1340 char tmpStr[10];
1341 char line[100];
1342 char *pathl="/etc/Wireless/RT61STA";
1343 BYTE acBE=1;
1344 BYTE acBK=1;
1345 BYTE acVO=1;
1346 BYTE acVI=1;
1347 BYTE APSDCapable;
1348 FILE *pipe;
1349
1350 /*
1351 * A series of setting need to be done before doing WMM-PS
1352 * Additional steps of configuration may be needed.
1353 */
1354
1355 /*
1356 * bring down the interface
1357 */
1358 sprintf(gCmdStr, "ifconfig %s down",ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001359 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001360 /*
1361 * Unload the Driver
1362 */
1363 sprintf(gCmdStr, "rmmod rt61");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001364 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001365#ifndef WFA_WMM_AC
1366 if(setUAPSD->acBE != 1)
1367 acBE=setUAPSD->acBE = 0;
1368 if(setUAPSD->acBK != 1)
1369 acBK=setUAPSD->acBK = 0;
1370 if(setUAPSD->acVO != 1)
1371 acVO=setUAPSD->acVO = 0;
1372 if(setUAPSD->acVI != 1)
1373 acVI=setUAPSD->acVI = 0;
1374#else
1375 acBE=setUAPSD->acBE;
1376 acBK=setUAPSD->acBK;
1377 acVO=setUAPSD->acVO;
1378 acVI=setUAPSD->acVI;
1379#endif
1380
1381 APSDCapable = acBE||acBK||acVO||acVI;
1382 /*
1383 * set other AC parameters
1384 */
1385
1386 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1387 sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001388 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001389
1390 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001391 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001392 pipe = popen("uname -r", "r");
1393 /* Read into line the output of uname*/
1394 fscanf(pipe,"%s",line);
1395 pclose(pipe);
1396
1397 /*
1398 * load the Driver
1399 */
1400 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001401 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001402
1403 sprintf(gCmdStr, "ifconfig %s up",ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001404 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001405#endif
1406
1407 setUAPSDResp->status = STATUS_COMPLETE;
1408 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1409 *respLen = WFA_TLV_HDR_LEN + 4;
1410 return WFA_SUCCESS;
1411}
1412
1413int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1414{
1415 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1416 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1417 dutCmdResponse_t *infoResp = &gGenericResp;
1418 /*a vendor can fill in the proper info or anything non-disclosure */
1419 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
1420
1421 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
1422
1423 if(devInfo->fw == 0)
1424 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1425 else
1426 {
1427 // Call internal API to pull the version ID */
1428 memcpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
1429 }
1430
1431 infoResp->status = STATUS_COMPLETE;
1432 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1433 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1434
1435 return WFA_SUCCESS;
1436
1437}
1438
1439/*
1440 * This funciton is to retrieve a list of interfaces and return
1441 * the list back to Agent control.
1442 * ********************************************************************
1443 * Note: We intend to make this WLAN interface name as a hardcode name.
1444 * Therefore, for a particular device, you should know and change the name
1445 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1446 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
1447 * likely is hardcoded just for CAPI command responses.
1448 * *******************************************************************
1449 *
1450 */
1451int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1452{
1453 dutCmdResponse_t *infoResp = &gGenericResp;
1454 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1455 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
1456
1457 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
1458
1459 switch(ifList->cmdsu.iftype)
1460 {
1461 case IF_80211:
1462 infoResp->status = STATUS_COMPLETE;
1463 ifListResp->iftype = IF_80211;
1464 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1465 strcpy(ifListResp->ifs[1], "NULL");
1466 strcpy(ifListResp->ifs[2], "NULL");
1467 break;
1468 case IF_ETH:
1469 infoResp->status = STATUS_COMPLETE;
1470 ifListResp->iftype = IF_ETH;
1471 strcpy(ifListResp->ifs[0], "eth0");
1472 strcpy(ifListResp->ifs[1], "NULL");
1473 strcpy(ifListResp->ifs[2], "NULL");
1474 break;
1475 default:
1476 {
1477 infoResp->status = STATUS_ERROR;
1478 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1479 *respLen = WFA_TLV_HDR_LEN + 4;
1480
1481 return WFA_SUCCESS;
1482 }
1483 }
1484
1485 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1486 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1487
1488 return WFA_SUCCESS;
1489}
1490
1491int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1492{
1493 dutCmdResponse_t *debugResp = &gGenericResp;
1494 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
1495
1496 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
1497
1498 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1499 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1500 else
1501 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
1502
1503 debugResp->status = STATUS_COMPLETE;
1504 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1505 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1506
1507
1508 return WFA_SUCCESS;
1509}
1510
1511
1512/*
1513 * wfaStaGetBSSID():
1514 * This function is to retrieve BSSID of a specific wireless I/F.
1515 */
1516int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1517{
1518 char string[64];
1519 char *str;
1520 FILE *tmpfd;
1521 dutCmdResponse_t *bssidResp = &gGenericResp;
1522
1523 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1524 /* retrieve the BSSID */
1525 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
1526
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001527 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001528
1529 tmpfd = fopen("/tmp/bssid.txt", "r+");
1530 if(tmpfd == NULL)
1531 {
1532 bssidResp->status = STATUS_ERROR;
1533 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1534 *respLen = WFA_TLV_HDR_LEN + 4;
1535
1536 DPRINT_ERR(WFA_ERR, "file open failed\n");
1537 return WFA_FAILURE;
1538 }
1539
1540 for(;;)
1541 {
1542 if(fscanf(tmpfd, "%s", string) == EOF)
1543 {
1544 bssidResp->status = STATUS_COMPLETE;
1545 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
1546 break;
1547 }
1548
1549 if(strncmp(string, "bssid", 5) == 0)
1550 {
1551 str = strtok(string, "=");
1552 str = strtok(NULL, "=");
1553 if(str != NULL)
1554 {
1555 strcpy(bssidResp->cmdru.bssid, str);
1556 bssidResp->status = STATUS_COMPLETE;
1557 break;
1558 }
1559 }
1560 }
1561
1562 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1563 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1564
1565 fclose(tmpfd);
1566 return WFA_SUCCESS;
1567}
1568
1569/*
1570 * wfaStaSetIBSS()
1571 * This is to set
1572 * 1. ssid
1573 * 2. channel
1574 * 3. encrypType - none or wep
1575 * optional
1576 * 4. key1
1577 * 5. key2
1578 * 6. key3
1579 * 7. key4
1580 * 8. activeIndex - 1, 2, 3, or 4
1581 */
1582int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1583{
1584 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1585 dutCmdResponse_t *setIbssResp = &gGenericResp;
1586 int i;
1587
1588 /*
1589 * disable the network first
1590 */
1591 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001592 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001593
1594 /*
1595 * set SSID
1596 */
1597 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001598 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001599
1600 /*
1601 * Set channel for IBSS
1602 */
1603 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001604 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001605
1606 /*
1607 * Tell the supplicant for IBSS mode (1)
1608 */
1609 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001610 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001611
1612 /*
1613 * set Key management to NONE (NO WPA) for plaintext or WEP
1614 */
1615 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001616 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001617
1618 if(setIBSS->encpType == 1)
1619 {
1620 for(i=0; i<4; i++)
1621 {
1622 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1623 {
1624 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1625 setIBSS->intf, i, setIBSS->keys[i]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001626 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001627 }
1628 }
1629
1630 i = setIBSS->activeKeyIdx;
1631 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1632 {
1633 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1634 setIBSS->intf, setIBSS->activeKeyIdx);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001635 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001636 }
1637 }
1638
1639 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001640 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001641
1642 setIbssResp->status = STATUS_COMPLETE;
1643 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1644 *respLen = WFA_TLV_HDR_LEN + 4;
1645
1646 return WFA_SUCCESS;
1647}
1648
1649/*
1650 * wfaSetMode():
1651 * The function is to set the wireless interface with a given mode (possible
1652 * adhoc)
1653 * Input parameters:
1654 * 1. I/F
1655 * 2. ssid
1656 * 3. mode adhoc or managed
1657 * 4. encType
1658 * 5. channel
1659 * 6. key(s)
1660 * 7. active key
1661 */
1662int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1663{
1664 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1665 dutCmdResponse_t *SetModeResp = &gGenericResp;
1666 int i;
1667
1668 /*
1669 * bring down the interface
1670 */
1671 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001672 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001673
1674 /*
1675 * distroy the interface
1676 */
1677 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001678 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001679
1680
1681 /*
1682 * re-create the interface with the given mode
1683 */
1684 if(setmode->mode == 1)
1685 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
1686 else
1687 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1688
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001689 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001690 if(setmode->encpType == ENCRYPT_WEP)
1691 {
1692 int j = setmode->activeKeyIdx;
1693 for(i=0; i<4; i++)
1694 {
1695 if(setmode->keys[i][0] != '\0')
1696 {
1697 sprintf(gCmdStr, "iwconfig %s key s:%s",
1698 setmode->intf, setmode->keys[i]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001699 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001700 }
1701 /* set active key */
1702 if(setmode->keys[j][0] != '\0')
1703 sprintf(gCmdStr, "iwconfig %s key s:%s",
1704 setmode->intf, setmode->keys[j]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001705 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001706 }
1707
1708 }
1709 /*
1710 * Set channel for IBSS
1711 */
1712 if(setmode->channel)
1713 {
1714 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001715 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001716 }
1717
1718
1719 /*
1720 * set SSID
1721 */
1722 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001723 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001724
1725 /*
1726 * bring up the interface
1727 */
1728 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001729 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001730
1731 SetModeResp->status = STATUS_COMPLETE;
1732 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1733 *respLen = WFA_TLV_HDR_LEN + 4;
1734
1735 return WFA_SUCCESS;
1736}
1737
1738int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1739{
1740 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1741 dutCmdResponse_t *SetPSResp = &gGenericResp;
1742
1743 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001744 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001745
1746
1747 SetPSResp->status = STATUS_COMPLETE;
1748 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1749 *respLen = WFA_TLV_HDR_LEN + 4;
1750
1751 return WFA_SUCCESS;
1752}
1753
1754int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1755{
1756 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1757 dutCmdResponse_t *upLoadResp = &gGenericResp;
1758 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
1759
1760 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1761 {
1762 int rbytes;
1763 /*
1764 * if asked for the first packet, always to open the file
1765 */
1766 if(upload->next == 1)
1767 {
1768 if(e2efp != NULL)
1769 {
1770 fclose(e2efp);
1771 e2efp = NULL;
1772 }
1773
1774 e2efp = fopen(e2eResults, "r");
1775 }
1776
1777 if(e2efp == NULL)
1778 {
1779 upLoadResp->status = STATUS_ERROR;
1780 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1781 *respLen = WFA_TLV_HDR_LEN + 4;
1782 return WFA_FAILURE;
1783 }
1784
1785 rbytes = fread(upld->bytes, 1, 256, e2efp);
1786
1787 if(rbytes < 256)
1788 {
1789 /*
1790 * this means no more bytes after this read
1791 */
1792 upld->seqnum = 0;
1793 fclose(e2efp);
1794 e2efp=NULL;
1795 }
1796 else
1797 {
1798 upld->seqnum = upload->next;
1799 }
1800
1801 upld->nbytes = rbytes;
1802
1803 upLoadResp->status = STATUS_COMPLETE;
1804 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1805 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1806 }
1807 else
1808 {
1809 upLoadResp->status = STATUS_ERROR;
1810 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1811 *respLen = WFA_TLV_HDR_LEN + 4;
1812 }
1813
1814 return WFA_SUCCESS;
1815}
1816/*
1817 * wfaStaSetWMM()
1818 * TO be ported on a specific plaform for the DUT
1819 * This is to set the WMM related parameters at the DUT.
1820 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1821 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1822 */
1823int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1824{
1825#ifdef WFA_WMM_AC
1826 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1827 char *ifname = setwmm->intf;
1828 dutCmdResponse_t *setwmmResp = &gGenericResp;
1829 //IEEEtypes_WMM_TSPEC_t tspec;
1830
1831 switch(setwmm->group)
1832 {
1833 case GROUP_WMMAC:
1834 if (setwmm->send_trig)
1835 {
1836 int Sockfd;
1837 struct sockaddr_in psToAddr;
1838 unsigned int TxMsg[512];
1839
1840 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
1841 memset(&psToAddr, 0, sizeof(psToAddr));
1842 psToAddr.sin_family = AF_INET;
1843 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1844 psToAddr.sin_port = htons(12346);
1845
1846
1847 switch (setwmm->trig_ac)
1848 {
1849 case WMMAC_AC_VO:
1850 wfaTGSetPrio(Sockfd, 7);
1851 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1852 printf("\r\nSending AC_VO trigger packet\n");
1853 break;
1854
1855 case WMMAC_AC_VI:
1856 wfaTGSetPrio(Sockfd, 5);
1857 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1858 printf("\r\nSending AC_VI trigger packet\n");
1859 break;
1860
1861 case WMMAC_AC_BK:
1862 wfaTGSetPrio(Sockfd, 2);
1863 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1864 printf("\r\nSending AC_BK trigger packet\n");
1865 break;
1866
1867 default:
1868 case WMMAC_AC_BE:
1869 wfaTGSetPrio(Sockfd, 0);
1870 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1871 printf("\r\nSending AC_BE trigger packet\n");
1872 break;
1873 }
1874
1875 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1876 sizeof(struct sockaddr));
1877 close(Sockfd);
1878 usleep(1000000);
1879 }
1880 else if (setwmm->action == WMMAC_ADDTS)
1881 {
1882 //wmmtspec_t* pCmdTspec = &(setwmm->actions.addts.tspec);
1883 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
1884 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1885 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1886 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1887 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1888 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1889 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1890 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1891 setwmm->actions.addts.dialog_token,
1892 setwmm->actions.addts.tspec.tsinfo.TID,
1893 setwmm->actions.addts.tspec.tsinfo.direction,
1894 setwmm->actions.addts.tspec.tsinfo.PSB,
1895 setwmm->actions.addts.tspec.tsinfo.UP,
1896 setwmm->actions.addts.tspec.tsinfo.infoAck,
1897 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1898 setwmm->actions.addts.tspec.Fixed,
1899 setwmm->actions.addts.tspec.size,
1900 setwmm->actions.addts.tspec.maxsize,
1901 setwmm->actions.addts.tspec.min_srvc,
1902 setwmm->actions.addts.tspec.max_srvc,
1903 setwmm->actions.addts.tspec.inactivity,
1904 setwmm->actions.addts.tspec.suspension,
1905 setwmm->actions.addts.tspec.srvc_strt_tim,
1906 setwmm->actions.addts.tspec.mindatarate,
1907 setwmm->actions.addts.tspec.meandatarate,
1908 setwmm->actions.addts.tspec.peakdatarate,
1909 setwmm->actions.addts.tspec.burstsize,
1910 setwmm->actions.addts.tspec.delaybound,
1911 setwmm->actions.addts.tspec.PHYrate,
1912 setwmm->actions.addts.tspec.sba,
1913 setwmm->actions.addts.tspec.medium_time,
1914 setwmm->actions.addts.accesscat);
1915
1916 // you should set your tspec here.
1917
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001918 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001919 }
1920 else if (setwmm->action == WMMAC_DELTS)
1921 {
1922 // send del tspec
1923 }
1924
1925 setwmmResp->status = STATUS_COMPLETE;
1926 break;
1927
1928 case GROUP_WMMCONF:
1929 sprintf(gCmdStr, "iwconfig %s rts %d",
1930 ifname,setwmm->actions.config.rts_thr);
1931
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001932 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001933 sprintf(gCmdStr, "iwconfig %s frag %d",
1934 ifname,setwmm->actions.config.frag_thr);
1935
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001936 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001937 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1938 ifname, setwmm->actions.config.wmm);
1939
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001940 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001941 setwmmResp->status = STATUS_COMPLETE;
1942 break;
1943
1944 default:
1945 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1946 setwmmResp->status = STATUS_ERROR;
1947 break;
1948
1949 }
1950
1951 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1952 *respLen = WFA_TLV_HDR_LEN + 4;
1953#endif
1954
1955 return WFA_SUCCESS;
1956}
1957
1958int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1959{
1960 //dutCommand_t *sendNeigReq = (dutCommand_t *)caCmdBuf;
1961 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
1962
1963 /*
1964 * run your device to send NEIGREQ
1965 */
1966
1967 sendNeigReqResp->status = STATUS_COMPLETE;
1968 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
1969 *respLen = WFA_TLV_HDR_LEN + 4;
1970
1971 return WFA_SUCCESS;
1972}
1973
1974int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1975{
1976 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
1977 char *ifname = setFAST->intf;
1978 dutCmdResponse_t *setEapFastResp = &gGenericResp;
1979
1980#ifdef WFA_NEW_CLI_FORMAT
1981 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
1982 setFAST->passwd, setFAST->pacFileName,
1983 setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001984 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001985#else
1986
1987 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001988 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001989
1990 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001991 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001992
1993 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001994 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001995
1996 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001997 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001998
1999 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
2000 {
2001 }
2002 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
2003 {
2004 }
2005 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
2006 {
2007
2008 }
2009 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2010 {
2011 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
2012 }
2013 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2014 {
2015 // take all and device to pick one which is supported.
2016 }
2017 else
2018 {
2019 // ??
2020 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002021 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002022
2023 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002024 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002025
2026 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 -08002027 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002028
2029 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002030 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002031
2032 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002033 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002034
2035 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002036 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002037
2038 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002039 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002040#endif
2041
2042 setEapFastResp->status = STATUS_COMPLETE;
2043 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2044 *respLen = WFA_TLV_HDR_LEN + 4;
2045
2046 return WFA_SUCCESS;
2047}
2048
2049int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2050{
2051 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2052 char *ifname = setAKA->intf;
2053 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2054
2055#ifdef WFA_NEW_CLI_FORMAT
2056 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002057 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002058#else
2059
2060 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002061 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002062
2063 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002064 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002065
2066 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2067 {
2068 }
2069 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2070 {
2071 }
2072 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2073 {
2074
2075 }
2076 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2077 {
2078 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
2079 }
2080 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2081 {
2082 // take all and device to pick one which is supported.
2083 }
2084 else
2085 {
2086 // ??
2087 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002088 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002089
2090 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002091 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002092 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002093 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002094
2095 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002096 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002097
2098 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002099 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002100
2101 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002102 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002103
2104 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002105 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002106
2107 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002108 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002109#endif
2110
2111 setEapAkaResp->status = STATUS_COMPLETE;
2112 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2113 *respLen = WFA_TLV_HDR_LEN + 4;
2114
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002115 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002116}
2117
2118int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2119{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002120 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2121 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002122
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002123 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002124
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002125 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2126 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002127
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002128 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2129 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002130
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002131 setSystimeResp->status = STATUS_COMPLETE;
2132 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2133 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002134
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002135 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002136}
2137
2138#ifdef WFA_STA_TB
2139int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2140{
2141 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2142 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2143 //int ret;
2144 //char *intfname = presetParams->intf;
2145 BYTE presetDone = 1;
2146 int st = 0;
2147
2148 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
2149
2150 if(presetParams->wmmFlag)
2151 {
2152 st = wfaExecuteCLI(gCmdStr);
2153 switch(st)
2154 {
2155 case 0:
2156 presetDone = 1;
2157 break;
2158 case 1:
2159 presetDone = 0;
2160 break;
2161 case 2:
2162 presetDone = 0;
2163 break;
2164 }
2165 }
2166
2167 if(presetParams->modeFlag != 0)
2168 {
2169 switch(presetParams->wirelessMode)
2170 {
2171 default:
2172 printf("other mode does not need to support\n");
2173 }
2174
2175 st = wfaExecuteCLI(gCmdStr);
2176 switch(st)
2177 {
2178 case 0:
2179 presetDone = 1;
2180 break;
2181 case 1:
2182 presetDone = 0;
2183 case 2:
2184 presetDone = 0;
2185 break;
2186 }
2187 }
2188
2189
2190 if(presetParams->psFlag)
2191 {
2192
2193 printf("%s\n", gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002194 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002195 }
2196
2197 /************the followings are used for Voice Enterprise **************/
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002198 if(presetParams->program == PROG_TYPE_VENT)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002199 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002200 if(presetParams->ftoa == eEnable)
2201 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002202 // enable Fast BSS Transition Over the Air
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002203 }
2204 else
2205 {
2206 // disable Fast BSS Transition Over the Air
2207 }
2208
2209 if(presetParams->ftds == eEnable)
2210 {
2211 // enable Fast BSS Transition Over the DS
2212 }
2213 else
2214 {
2215 // disable Fast BSS Transition Over the DS
2216 }
2217
2218 if(presetParams->activescan == eEnable)
2219 {
2220 // Enable Active Scan on STA
2221 }
2222 else
2223 {
2224 // disable Active Scan on STA
2225 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002226 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002227
2228 /************the followings are used for Wi-Fi Display *************/
2229 if(presetParams->program == PROG_TYPE_WFD)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002230 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002231
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002232 if(presetParams->tdlsFlag)
2233 {
2234 // enable / disable tdls based on tdls
2235 }
2236 if(presetParams->wfdDevTypeFlag)
2237 {
2238 // set WFD device type to source/sink/dual based on wfdDevType
2239 }
2240 if(presetParams->wfdUibcGenFlag)
2241 {
2242 // enable / disable the feature
2243 }
2244 if(presetParams->wfdUibcHidFlag)
2245 {
2246 // enable / disable feature
2247 }
2248 if(presetParams->wfdUiInputFlag)
2249 {
2250 // set the UI input as mentioned
2251 }
2252 if(presetParams->wfdHdcpFlag)
2253 {
2254 // enable / disable feature
2255 }
2256 if(presetParams->wfdFrameSkipFlag)
2257 {
2258 // enable / disable feature
2259 }
2260 if(presetParams->wfdAvChangeFlag)
2261 {
2262 // enable / disable feature
2263 }
2264 if(presetParams->wfdStandByFlag)
2265 {
2266 // enable / disable feature
2267 }
2268 if(presetParams->wfdInVideoFlag)
2269 {
2270 // select the input vide as protecteed or non-protetcted or protected audio
2271 // or unprotected audio etc.
2272 }
2273
2274 if(presetParams->wfdVideoFmatFlag)
2275 {
2276 // set the video format as requested
2277
2278 //switch(presetParams->wfdVideoFmt )
2279 //{
2280 // case e640x480p60:
2281 // ;
2282 // default:
2283 // set the mandatory
2284 // }
2285 }
2286 if(presetParams->wfdAudioFmatFlag)
2287 {
2288 // set the Audio format as requested
2289
2290 //switch(presetParams->wfdAudioFmt )
2291 //{
2292 // case eMandatoryAudioMode:
2293 // ;
2294 // case eDefaultAudioMode:
2295 // ;
2296
2297 // default:
2298 // set the mandatory
2299 // }
2300 }
2301
2302 if(presetParams->wfdI2cFlag)
2303 {
2304 // enable / disable feature
2305 }
2306 if(presetParams->wfdVideoRecoveryFlag)
2307 {
2308 // enable / disable feature
2309 }
2310 if(presetParams->wfdPrefDisplayFlag)
2311 {
2312 // enable / disable feature
2313 }
2314 if(presetParams->wfdServiceDiscoveryFlag)
2315 {
2316 // enable / disable feature
2317 }
2318 if(presetParams->wfd3dVideoFlag)
2319 {
2320 // enable / disable feature
2321 }
2322 if(presetParams->wfdMultiTxStreamFlag)
2323 {
2324 // enable / disable feature
2325 }
2326 if(presetParams->wfdTimeSyncFlag)
2327 {
2328 // enable / disable feature
2329 }
2330 if(presetParams->wfdEDIDFlag)
2331 {
2332 // enable / disable feature
2333 }
2334 if(presetParams->wfdUIBCPrepareFlag)
2335 {
2336 // Provdes information to start valid WFD session to check UIBC operation.
2337 }
2338 if(presetParams->wfdCoupledCapFlag)
2339 {
2340 // enable / disable feature
2341 }
2342 if(presetParams->wfdOptionalFeatureFlag)
2343 {
2344 // disable all program specific optional features
2345 }
2346 if(presetParams->wfdSessionAvailFlag)
2347 {
2348 // enable / disable session available bit
2349 }
2350 if(presetParams->wfdDeviceDiscoverabilityFlag)
2351 {
2352 // enable / disable feature
2353 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002354 }
2355
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002356 if (presetDone)
2357 {
2358 PresetParamsResp->status = STATUS_COMPLETE;
2359 }
2360 else
2361 {
2362 PresetParamsResp->status = STATUS_INVALID;
2363 }
2364
2365 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2366 *respLen = WFA_TLV_HDR_LEN + 4;
2367
2368 return WFA_SUCCESS;
2369}
2370
2371int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2372{
2373 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2374
2375 v11nParamsResp->status = STATUS_COMPLETE;
2376 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2377 *respLen = WFA_TLV_HDR_LEN + 4;
2378 return WFA_SUCCESS;
2379}
2380int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2381{
2382 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2383
2384 staWirelessResp->status = STATUS_COMPLETE;
2385 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2386 *respLen = WFA_TLV_HDR_LEN + 4;
2387 return WFA_SUCCESS;
2388}
2389
2390int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2391{
2392 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2393
2394 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2395 *respLen = WFA_TLV_HDR_LEN + 4;
2396 return WFA_SUCCESS;
2397}
2398
2399int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2400{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002401 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002402
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002403 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2404 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002405
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002406 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002407}
2408
2409int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2410{
2411 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2412
2413 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2414 *respLen = WFA_TLV_HDR_LEN + 4;
2415
2416 return WFA_SUCCESS;
2417
2418}
2419
2420int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2421{
2422 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2423 dutCmdResponse_t *ResetResp = &gGenericResp;
2424
2425
2426 // need to make your own command available for this, here is only an example
2427 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002428 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002429
2430 ResetResp->status = STATUS_COMPLETE;
2431 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2432 *respLen = WFA_TLV_HDR_LEN + 4;
2433
2434 return WFA_SUCCESS;
2435}
2436
2437#else
2438
2439int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2440{
2441 dutCmdResponse_t *staCmdResp = &gGenericResp;
2442
2443 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2444 *respLen = WFA_TLV_HDR_LEN + 4;
2445
2446 return WFA_SUCCESS;
2447}
2448#endif
2449
2450/*
2451 * This is used to send a frame or action frame
2452 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002453int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002454{
2455 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2456 /* uncomment it if needed */
2457 // char *ifname = cmd->intf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002458 dutCmdResponse_t *devSendResp = &gGenericResp;
2459 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002460
Ankur Vachhanic485b712012-02-15 23:29:49 +00002461 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002462 /* processing the frame */
2463
Ankur Vachhanic485b712012-02-15 23:29:49 +00002464 switch(sf->program)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002465 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00002466 case PROG_TYPE_PMF:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002467 {
2468 pmfFrame_t *pmf = &sf->frameType.pmf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002469 switch(pmf->eFrameName)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002470 {
2471 case PMF_TYPE_DISASSOC:
2472 {
2473 /* use the protected to set what type of key to send */
2474
2475 }
2476 break;
2477 case PMF_TYPE_DEAUTH:
2478 {
2479
2480 }
2481 break;
2482 case PMF_TYPE_SAQUERY:
2483 {
2484
2485 }
2486 break;
2487 case PMF_TYPE_AUTH:
2488 {
2489 }
2490 break;
2491 case PMF_TYPE_ASSOCREQ:
2492 {
2493 }
2494 break;
2495 case PMF_TYPE_REASSOCREQ:
2496 {
2497 }
2498 break;
2499 }
2500 }
2501 break;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002502 case PROG_TYPE_TDLS:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002503 {
2504 tdlsFrame_t *tdls = &sf->frameType.tdls;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002505 switch(tdls->eFrameName)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002506 {
2507 case TDLS_TYPE_DISCOVERY:
2508 /* use the peer mac address to send the frame */
2509 break;
2510 case TDLS_TYPE_SETUP:
2511 break;
2512 case TDLS_TYPE_TEARDOWN:
2513 break;
2514 case TDLS_TYPE_CHANNELSWITCH:
2515 break;
2516 case TDLS_TYPE_NULLFRAME:
2517 break;
2518 }
2519 }
2520 break;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002521 case PROG_TYPE_VENT:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002522 {
2523 ventFrame_t *vent = &sf->frameType.vent;
2524 switch(vent->type)
2525 {
2526 case VENT_TYPE_NEIGREQ:
2527 break;
2528 case VENT_TYPE_TRANSMGMT:
2529 break;
2530 }
2531 }
Dake Zhao97708202014-11-26 13:59:04 -08002532 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002533 case PROG_TYPE_WFD:
2534 {
2535 wfdFrame_t *wfd = &sf->frameType.wfd;
2536 switch(wfd->eframe)
2537 {
2538 case WFD_FRAME_PRBREQ:
2539 {
2540 /* send probe req */
2541 }
2542 break;
2543
2544 case WFD_FRAME_PRBREQ_TDLS_REQ:
2545 {
2546 /* send tunneled tdls probe req */
2547 }
2548 break;
2549
2550 case WFD_FRAME_11V_TIMING_MSR_REQ:
2551 {
2552 /* send 11v timing mearurement request */
2553 }
2554 break;
2555
2556 case WFD_FRAME_RTSP:
2557 {
2558 /* send WFD RTSP messages*/
2559 // fetch the type of RTSP message and send it.
2560 switch(wfd->eRtspMsgType)
2561 {
2562 case WFD_RTSP_PAUSE:
2563 break;
2564 case WFD_RTSP_PLAY:
2565 //send RTSP PLAY
2566 break;
Dake Zhao97708202014-11-26 13:59:04 -08002567 case WFD_RTSP_TEARDOWN:
2568 //send RTSP TEARDOWN
2569 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002570 case WFD_RTSP_TRIG_PAUSE:
2571 //send RTSP TRIGGER PAUSE
2572 break;
2573 case WFD_RTSP_TRIG_PLAY:
2574 //send RTSP TRIGGER PLAY
2575 break;
2576 case WFD_RTSP_TRIG_TEARDOWN:
2577 //send RTSP TRIGGER TEARDOWN
2578 break;
2579 case WFD_RTSP_SET_PARAMETER:
2580 //send RTSP SET PARAMETER
2581 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2582 {
2583 //send RTSP SET PARAMETER message for UIBC keyboard
2584 }
2585 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2586 {
2587 //send RTSP SET PARAMETER message for UIBC Mouse
2588 }
2589 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2590 {
2591 //send RTSP SET PARAMETER message Capability re-negotiation
2592 }
2593 else if (wfd->eSetParams == WFD_STANDBY)
2594 {
2595 //send RTSP SET PARAMETER message for standby
2596 }
2597 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2598 {
2599 //send RTSP SET PARAMETER message for UIBC settings enable
2600 }
2601 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2602 {
2603 //send RTSP SET PARAMETER message for UIBC settings disable
2604 }
2605 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2606 {
2607 //send RTSP SET PARAMETER message for route audio
2608 }
2609 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2610 {
2611 //send RTSP SET PARAMETER message for 3D video parameters
2612 }
2613 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2614 {
2615 //send RTSP SET PARAMETER message for 2D video parameters
2616 }
2617 break;
2618 }
2619 }
2620 break;
2621 }
2622 }
Dake Zhao97708202014-11-26 13:59:04 -08002623 break;
2624 /* not need to support HS2 release 1, due to very short time period */
2625 case PROG_TYPE_HS2_R2:
2626 {
2627 /* type of frames */
2628 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2629 switch(hs2->eframe)
2630 {
2631 case HS2_FRAME_ANQPQuery:
2632 {
2633
2634 }
2635 break;
2636 case HS2_FRAME_DLSRequest:
2637 {
2638
2639 }
2640 break;
2641 case HS2_FRAME_GARPReq:
2642 {
2643
2644 }
2645 break;
2646 case HS2_FRAME_GARPRes:
2647 {
2648 }
2649 break;
2650 case HS2_FRAME_NeighAdv:
2651 {
2652 }
2653 case HS2_FRAME_ARPProbe:
2654 {
2655 }
2656 case HS2_FRAME_ARPAnnounce:
2657 {
2658
2659 }
2660 break;
2661 case HS2_FRAME_NeighSolicitReq:
2662 {
2663
2664 }
2665 break;
2666 case HS2_FRAME_ARPReply:
2667 {
2668
2669 }
2670 break;
2671 }
2672
2673 }/* PROG_TYPE_HS2-R2 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002674 case PROG_TYPE_GEN:
2675 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002676 /* General frames */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002677 }
2678
2679
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002680 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00002681 devSendResp->status = STATUS_COMPLETE;
2682 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002683 *respLen = WFA_TLV_HDR_LEN + 4;
2684
2685 return WFA_SUCCESS;
2686}
2687
2688/*
2689 * This is used to set a temporary MAC address of an interface
2690 */
2691int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2692{
2693 // Uncomment it if needed
2694 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2695 // char *ifname = cmd->intf;
2696 dutCmdResponse_t *staCmdResp = &gGenericResp;
2697 // Uncomment it if needed
2698 //char *macaddr = &cmd->cmdsu.macaddr[0];
2699
2700 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2701 *respLen = WFA_TLV_HDR_LEN + 4;
2702
2703 return WFA_SUCCESS;
2704}
2705
2706
2707int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2708{
2709 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2710 //char *intf = disc->intf;
2711 dutCmdResponse_t *staDiscResp = &gGenericResp;
2712
2713 // stop the supplicant
2714
2715 staDiscResp->status = STATUS_COMPLETE;
2716
2717 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2718 *respLen = WFA_TLV_HDR_LEN + 4;
2719
2720 return WFA_SUCCESS;
2721}
2722
2723/* Execute CLI, read the status from Environment variable */
2724int wfaExecuteCLI(char *CLI)
2725{
2726 char *retstr;
2727
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002728 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002729
2730 retstr = getenv("WFA_CLI_STATUS");
2731 printf("cli status %s\n", retstr);
2732 return atoi(retstr);
2733}
2734
2735/* Supporting Functions */
2736
2737void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2738{
Dake Zhao97708202014-11-26 13:59:04 -08002739 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002740 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002741// char *addr = staPing->dipaddr;
2742#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002743 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002744 char bflag[] = "-b";
2745 char *tmpstr;
2746 int inum=0;
2747#else
2748 char bflag[] = " ";
2749#endif
Ray Wang2b24ffc2014-03-27 12:33:22 -07002750
Ray Wang9b47f362014-03-19 16:51:10 -07002751 totalpkts = (int)(staPing->duration * staPing->frameRate);
Ray Wang2b24ffc2014-03-27 12:33:22 -07002752
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002753#ifdef WFA_PC_CONSOLE
2754
2755 printf("\nCS : The Stream ID is %d",streamid);
2756 printf("\nCS :the addr is %s ",addr);
2757 strcpy(addr,staPing->dipaddr);
2758 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2759 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002760 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002761 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002762 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002763 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002764 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002765 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002766 tmpstr = strtok(addr, ".");
2767 inum = atoi(tmpstr);
2768
2769 printf("interval %f\n", *interval);
2770
2771 if(inum >= 224 && inum <= 239) // multicast
2772 {
2773 }
2774 else // if not MC, check if it is BC address
2775 {
2776 printf("\nCS :Inside the BC address BLOCK");
2777 printf("\nCS :the inum %d",inum);
2778 strtok(NULL, ".");
2779 //strtok(NULL, ".");
2780 tmpstr = strtok(NULL, ".");
2781 printf("tmpstr %s\n", tmpstr);
2782 inum = atoi(tmpstr);
2783 printf("\nCS : The string is %s",tmpstr);
2784 if(inum != 255)
2785 memset(bflag, 0, strlen(bflag));
2786 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002787 }
2788#endif
Dake Zhao97708202014-11-26 13:59:04 -08002789 if ( staPing->dscp >= 0)
2790 {
2791 tos= convertDscpToTos(staPing->dscp);
2792 if (tos < 0)
2793 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2794 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002795 printf("\nCS : The Stream ID is %d",streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002796 printf("IPtype : %i tos=%d",staPing->iptype, tos);
2797
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002798 if (staPing->iptype == 2)
2799 {
Dake Zhao97708202014-11-26 13:59:04 -08002800 if ( tos>0)
2801 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",
2802 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
2803 else
2804 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",
2805 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002806 sret = system(cmdStr);
2807 printf("\nCS : The command string is %s",cmdStr);
2808 }
2809 else
2810 {
Dake Zhao97708202014-11-26 13:59:04 -08002811 if (tos > 0)
2812 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",
2813 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
2814 else
2815 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",
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002816 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
2817 sret = system(cmdStr);
2818 printf("\nCS : The command string is %s",cmdStr);
2819 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002820 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002821 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002822 printf("\nCS : The command string is %s",cmdStr);
2823
2824}
2825
2826int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2827{
2828 char strout[256];
2829 FILE *tmpfile = NULL;
2830 char cmdStr[128];
2831 printf("Ping stop id %d\n", streamid);
2832 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002833 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002834
2835 printf("\nCS : The command string is %s",cmdStr);
2836
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002837 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002838
2839 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002840 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002841
2842 printf("\nCS : The command string is %s",cmdStr);
2843
2844 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2845
2846 if(tmpfile == NULL)
2847 {
2848 return WFA_FAILURE;
2849 }
2850
2851 if(fscanf(tmpfile, "%s", strout) != EOF)
2852 {
2853 if(*strout == '\0')
2854 {
2855 stpResp->cmdru.pingStp.sendCnt = 0;
2856 }
2857
2858 else
2859 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2860 }
2861
2862 printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
2863
2864
2865 if(fscanf(tmpfile, "%s", strout) != EOF)
2866 {
2867 if(*strout == '\0')
2868 {
2869 stpResp->cmdru.pingStp.repliedCnt = 0;
2870 }
2871 else
2872 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2873 }
2874 printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
2875
2876 fclose(tmpfile);
2877
2878 return WFA_SUCCESS;
2879}
2880
Ankur Vachhanic485b712012-02-15 23:29:49 +00002881/*
2882 * wfaStaGetP2pDevAddress():
2883 */
2884int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2885{
2886 dutCmdResponse_t infoResp;
2887 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
2888
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002889 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002890
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002891 // Fetch the device ID and store into infoResp->cmdru.devid
2892 //strcpy(infoResp->cmdru.devid, str);
2893 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002894
2895 infoResp.status = STATUS_COMPLETE;
2896 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2897 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2898
2899 return WFA_SUCCESS;
2900}
2901
2902
2903
2904/*
2905 * wfaStaSetP2p():
2906 */
2907int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2908{
2909 dutCmdResponse_t infoResp;
2910 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
2911
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002912 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002913
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002914 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002915
2916 infoResp.status = STATUS_COMPLETE;
2917 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2918 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2919
2920 return WFA_SUCCESS;
2921}
2922/*
2923 * wfaStaP2pConnect():
2924 */
2925int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2926{
2927 dutCmdResponse_t infoResp;
2928 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
2929
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002930 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002931
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002932 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002933
2934
2935 infoResp.status = STATUS_COMPLETE;
2936 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2937 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2938
2939 return WFA_SUCCESS;
2940}
2941
2942/*
2943 * wfaStaStartAutoGo():
2944 */
2945int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2946{
2947 dutCmdResponse_t infoResp;
2948 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
2949
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002950 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002951
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002952 // Fetch the group ID and store into infoResp->cmdru.grpid
2953 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002954
2955 infoResp.status = STATUS_COMPLETE;
2956 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2957 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2958
2959 return WFA_SUCCESS;
2960}
2961
2962
2963
2964
2965/*
2966 * wfaStaP2pStartGrpFormation():
2967 */
2968int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2969{
2970 dutCmdResponse_t infoResp;
2971 //caStaP2pStartGrpForm_t *getStaP2pStartGrpForm = (caStaP2pStartGrpForm_t *)caCmdBuf;
2972
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002973 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002974
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002975 // Fetch the device mode and put in infoResp->cmdru.p2presult
2976 //strcpy(infoResp->cmdru.p2presult, "GO");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002977
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002978 // Fetch the device grp id and put in infoResp->cmdru.grpid
2979 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
2980
2981 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
2982 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002983
2984
2985 infoResp.status = STATUS_COMPLETE;
2986 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2987 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2988
2989 return WFA_SUCCESS;
2990}
2991
2992
2993/*
2994 * wfaStaP2pDissolve():
2995 */
2996int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2997{
2998 dutCmdResponse_t infoResp;
2999 //caStaP2pDissolve_t *getStap2pDissolve= (caStaP2pDissolve_t *)caCmdBuf;
3000
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003001 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003002
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003003 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003004
3005 infoResp.status = STATUS_COMPLETE;
3006 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3007 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3008
3009 return WFA_SUCCESS;
3010}
3011
3012/*
3013 * wfaStaSendP2pInvReq():
3014 */
3015int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3016{
3017 dutCmdResponse_t infoResp;
3018 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
3019
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003020 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003021
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003022 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003023
3024 infoResp.status = STATUS_COMPLETE;
3025 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3026 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3027
3028 return WFA_SUCCESS;
3029}
3030
3031
3032/*
3033 * wfaStaAcceptP2pInvReq():
3034 */
3035int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3036{
3037 dutCmdResponse_t infoResp;
3038 /* uncomment and use it
3039 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3040 */
3041
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003042 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003043
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003044 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003045
3046 infoResp.status = STATUS_COMPLETE;
3047 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3048 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3049
3050 return WFA_SUCCESS;
3051}
3052
3053
3054/*
3055 * wfaStaSendP2pProvDisReq():
3056 */
3057int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3058{
3059 dutCmdResponse_t infoResp;
3060 /* uncomment and use it
3061 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3062 */
3063
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003064 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003065
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003066 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003067
3068 infoResp.status = STATUS_COMPLETE;
3069 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3070 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3071
3072 return WFA_SUCCESS;
3073}
3074
3075/*
3076 * wfaStaSetWpsPbc():
3077 */
3078int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3079{
3080 dutCmdResponse_t infoResp;
3081 /* uncomment and use it
3082 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3083 */
3084
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003085 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003086
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003087 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003088
3089 infoResp.status = STATUS_COMPLETE;
3090 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3091 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3092
3093 return WFA_SUCCESS;
3094}
3095
3096/*
3097 * wfaStaWpsReadPin():
3098 */
3099int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3100{
3101 dutCmdResponse_t infoResp;
3102 /* uncomment and use it
3103 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3104 */
3105
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003106 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003107
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003108 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3109 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3110 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003111
3112
3113 infoResp.status = STATUS_COMPLETE;
3114 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3115 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3116
3117 return WFA_SUCCESS;
3118}
3119
3120
3121
3122/*
3123 * wfaStaWpsReadLabel():
3124 */
3125int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3126{
3127 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003128
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003129 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003130
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003131 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3132 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3133 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003134
3135
3136 infoResp.status = STATUS_COMPLETE;
3137 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3138 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3139
3140 return WFA_SUCCESS;
3141}
3142
3143
3144/*
3145 * wfaStaWpsEnterPin():
3146 */
3147int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3148{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003149 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003150 /* uncomment and use it
3151 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3152 */
3153
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003154 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003155
3156 // Implement the function and this does not return any thing back.
3157
3158
3159 infoResp.status = STATUS_COMPLETE;
3160 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3161 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3162
3163 return WFA_SUCCESS;
3164}
3165
3166
3167/*
3168 * wfaStaGetPsk():
3169 */
3170int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3171{
3172 dutCmdResponse_t infoResp;
3173 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
3174
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003175 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003176
3177
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003178 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3179 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3180 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3181 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003182
3183
3184 infoResp.status = STATUS_COMPLETE;
3185 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3186 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3187
3188 return WFA_SUCCESS;
3189}
3190
3191/*
3192 * wfaStaP2pReset():
3193 */
3194int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3195{
3196 dutCmdResponse_t infoResp;
3197 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
3198
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003199 printf("\n Entry wfaStaP2pReset... ");
3200 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003201
3202 infoResp.status = STATUS_COMPLETE;
3203 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3204 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3205
3206 return WFA_SUCCESS;
3207}
3208
3209
3210
3211/*
3212 * wfaStaGetP2pIpConfig():
3213 */
3214int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3215{
3216 dutCmdResponse_t infoResp;
3217 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
3218
3219 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
3220
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003221 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003222
3223
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003224 // Fetch the device IP config and put in infoResp->cmdru
3225 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3226 ifinfo->isDhcp =0;
3227 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3228 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3229 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3230 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003231
3232 infoResp.status = STATUS_COMPLETE;
3233 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3234 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3235
3236 return WFA_SUCCESS;
3237}
3238
3239
3240
3241
3242/*
3243 * wfaStaSendServiceDiscoveryReq():
3244 */
3245int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3246{
3247 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003248
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003249 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3250 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003251
3252
3253 infoResp.status = STATUS_COMPLETE;
3254 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3255 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3256
3257 return WFA_SUCCESS;
3258}
3259
3260
3261
3262/*
3263 * wfaStaSendP2pPresenceReq():
3264 */
3265int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3266{
3267 dutCmdResponse_t infoResp;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003268 //caStaSendP2pPresenceReq_t *staSendP2pPresenceReq= (caStaSendP2pPresenceReq_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003269
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003270 //printf("\n Entry wfaStaSendP2pPresenceReq... ");
3271 //printf("\n The long long Duration: %lld... ",staSendP2pPresenceReq->duration);
3272 //printf("\n The long long interval : %lld.. ",staSendP2pPresenceReq->interval);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003273
Ankur Vachhanic485b712012-02-15 23:29:49 +00003274 infoResp.status = STATUS_COMPLETE;
3275 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3276 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3277
3278 return WFA_SUCCESS;
3279}
3280
3281/*
3282 * wfaStaSetSleepReq():
3283 */
3284int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3285{
3286 dutCmdResponse_t infoResp;
3287 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
3288
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003289 printf("\n Entry wfaStaSetSleepReq... ");
3290 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003291
3292
3293 infoResp.status = STATUS_COMPLETE;
3294 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3295 *respLen = WFA_TLV_HDR_LEN +4;
3296
3297 return WFA_SUCCESS;
3298}
3299
3300/*
3301 * wfaStaSetOpportunisticPsReq():
3302 */
3303int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3304{
3305 dutCmdResponse_t infoResp;
3306 /* caStaSetOpprPs_t *staSetOpperPsReq= (caStaSetOpprPs_t *)caCmdBuf; uncomment and use it */
3307
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003308 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3309 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003310
3311
3312 infoResp.status = STATUS_COMPLETE;
3313 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3314 *respLen = WFA_TLV_HDR_LEN + 4;
3315
3316 return WFA_SUCCESS;
3317}
3318#ifndef WFA_STA_TB
3319/*
3320 * wfaStaPresetParams():
3321 */
3322
3323int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3324{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003325 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003326
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003327 //caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003328
3329
3330 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
3331
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003332 // Implement the function and its sub commands
3333 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003334
3335 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3336 *respLen = WFA_TLV_HDR_LEN + 4;
3337
3338 return WFA_SUCCESS;
3339}
3340int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3341{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003342
3343 dutCmdResponse_t infoResp;
3344 dutCmdResponse_t *v11nParamsResp = &infoResp;
3345
3346#ifdef WFA_11N_SUPPORT_ONLY
Ankur Vachhanic485b712012-02-15 23:29:49 +00003347
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003348 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3349
3350 int st =0; // SUCCESS
Ankur Vachhanic485b712012-02-15 23:29:49 +00003351
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003352 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003353
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003354 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3355 {
3356 // implement the funciton
3357 //st = wfaExecuteCLI(gCmdStr);
3358 if(st != 0)
3359 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003360 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003361 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3362 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3363 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3364 return FALSE;
3365 }
3366 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003367
3368 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003369 {
3370 // implement the funciton
3371 //st = wfaExecuteCLI(gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003372
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003373 if(st != 0)
3374 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003375 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003376 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3377 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3378 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3379 return FALSE;
3380 }
3381 }
3382
Ankur Vachhanic485b712012-02-15 23:29:49 +00003383 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003384 {
3385 // implement the funciton
3386 //st = wfaExecuteCLI(gCmdStr);
3387 if(st != 0)
3388 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003389 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003390 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3391 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3392 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3393 return FALSE;
3394 }
3395 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003396
3397 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003398 {
3399 // implement the funciton
3400 //st = wfaExecuteCLI(gCmdStr);
3401 if(st != 0)
3402 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003403 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003404 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3405 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3406 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3407 return FALSE;
3408 }
3409 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003410
3411 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003412 {
3413 // implement the funciton
3414 //st = wfaExecuteCLI(gCmdStr);
3415 if(st != 0)
3416 {
3417 v11nParamsResp->status = STATUS_ERROR;
3418 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3419 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3420 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3421 return FALSE;
3422 }
3423 }
3424 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3425 {
3426 // implement the funciton
3427 //st = wfaExecuteCLI(gCmdStr);
3428 if(st != 0)
3429 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003430 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003431 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
3432 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3433 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3434 return FALSE;
3435 }
3436 }
3437 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3438 {
3439 // implement the funciton
3440 //st = wfaExecuteCLI(gCmdStr);
3441 if(st != 0)
3442 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003443 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003444 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
3445 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3446 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3447 return FALSE;
3448 }
3449 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003450
3451 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003452 {
3453 // implement the funciton
3454 //st = wfaExecuteCLI(gCmdStr);
3455 if(st != 0)
3456 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003457 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003458 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
3459 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3460 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3461 return FALSE;
3462 }
3463 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003464
3465 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003466 {
3467 // implement the funciton
3468 //st = wfaExecuteCLI(gCmdStr);
3469 if(st != 0)
3470 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003471 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003472 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3473 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3474 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3475 return FALSE;
3476 }
3477 }
3478
3479 if(v11nParams->smps != 0xFFFF)
3480 {
3481 if(v11nParams->smps == 0)
3482 {
3483 // implement the funciton
3484 //st = wfaExecuteCLI(gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003485 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003486 else if(v11nParams->smps == 1)
3487 {
3488 // implement the funciton
3489 //st = wfaExecuteCLI(gCmdStr);
3490 ;
3491 }
3492 else if(v11nParams->smps == 2)
3493 {
3494 // implement the funciton
3495 //st = wfaExecuteCLI(gCmdStr);
3496 ;
3497 }
3498 if(st != 0)
3499 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003500 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003501 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3502 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3503 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3504 return FALSE;
3505 }
3506 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003507
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003508 if(v11nParams->stbc_rx != 0xFFFF)
3509 {
3510 // implement the funciton
3511 //st = wfaExecuteCLI(gCmdStr);
3512 if(st != 0)
3513 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003514 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003515 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
3516 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3517 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3518 return FALSE;
3519 }
3520 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003521
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003522 if(v11nParams->width[0] != '\0')
3523 {
3524 // implement the funciton
3525 //st = wfaExecuteCLI(gCmdStr);
3526 if(st != 0)
3527 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003528 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003529 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3530 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3531 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3532 return FALSE;
3533 }
3534 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003535
3536 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003537 {
3538 // implement the funciton
3539 //st = wfaExecuteCLI(gCmdStr);
3540 if(st != 0)
3541 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003542 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003543 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3544 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3545 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3546 return FALSE;
3547 }
3548 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003549
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003550 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3551 {
3552 // implement the funciton
3553 //st = wfaExecuteCLI(gCmdStr);
3554 if(st != 0)
3555 {
3556 v11nParamsResp->status = STATUS_ERROR;
3557 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
3558 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3559 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3560 return FALSE;
3561 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003562
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003563 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003564
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003565 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3566 {
3567 // implement the funciton
3568 //st = wfaExecuteCLI(gCmdStr);
3569 if(st != 0)
3570 {
3571 v11nParamsResp->status = STATUS_ERROR;
3572 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3573 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3574 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3575 return FALSE;
3576 }
3577 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003578
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003579#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003580
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003581 v11nParamsResp->status = STATUS_COMPLETE;
3582 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3583 *respLen = WFA_TLV_HDR_LEN + 4;
3584 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003585}
3586#endif
3587/*
3588 * wfaStaAddArpTableEntry():
3589 */
3590int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3591{
3592 dutCmdResponse_t infoResp;
3593 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
3594
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003595 printf("\n Entry wfastaAddARPTableEntry... ");
3596 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003597
3598 infoResp.status = STATUS_COMPLETE;
3599 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3600 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3601
3602 return WFA_SUCCESS;
3603}
3604
3605/*
3606 * wfaStaBlockICMPResponse():
3607 */
3608int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3609{
3610 dutCmdResponse_t infoResp;
3611 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
3612
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003613 printf("\n Entry wfaStaBlockICMPResponse... ");
3614 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003615
3616 infoResp.status = STATUS_COMPLETE;
3617 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3618 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3619
3620 return WFA_SUCCESS;
3621}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003622
3623/*
3624 * wfaStaSetRadio():
3625 */
3626
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003627int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3628{
3629 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3630 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003631 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3632
3633 if(sr->mode == WFA_OFF)
3634 {
3635 // turn radio off
3636 }
3637 else
3638 {
3639 // always turn the radio on
3640 }
3641
3642 staCmdResp->status = STATUS_COMPLETE;
3643 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3644 *respLen = WFA_TLV_HDR_LEN + 4;
3645
3646 return WFA_SUCCESS;
3647}
3648
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003649/*
3650 * wfaStaSetRFeature():
3651 */
3652
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003653int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3654{
3655 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3656 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3657 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003658
3659 if(strcasecmp(rfeat->prog, "tdls") == 0)
3660 {
3661
3662
3663 }
3664
3665 caResp->status = STATUS_COMPLETE;
3666 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3667 *respLen = WFA_TLV_HDR_LEN + 4;
3668
3669 return WFA_SUCCESS;
3670}
3671
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003672/*
3673 * wfaStaStartWfdConnection():
3674 */
3675int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3676{
3677 dutCmdResponse_t infoResp;
3678 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
3679
3680 printf("\n Entry wfaStaStartWfdConnection... ");
3681
3682
3683 // Fetch the GrpId and WFD session and return
3684 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3685 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3686 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3687
3688 infoResp.status = STATUS_COMPLETE;
3689 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3690 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3691
3692 return WFA_SUCCESS;
3693}
3694/*
3695 * wfaStaCliCommand():
3696 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003697
Ankur Vachhanic485b712012-02-15 23:29:49 +00003698int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3699{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003700 char cmdName[32];
3701 char *pcmdStr=NULL, *str;
Dake Zhao97708202014-11-26 13:59:04 -08003702 int st = 1;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003703 char CmdStr[WFA_CMD_STR_SZ];
3704 FILE *wfaCliFd;
3705 char wfaCliBuff[64];
3706 char retstr[256];
Dake Zhao97708202014-11-26 13:59:04 -08003707 int CmdReturnFlag =0;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003708 char tmp[256];
3709 FILE * sh_pipe;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003710 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003711
Dake Zhao97708202014-11-26 13:59:04 -08003712 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003713 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003714 sprintf(CmdStr, "%s",cmdName);
3715
3716 for(;;)
Dake Zhao97708202014-11-26 13:59:04 -08003717 {// construct CLI standard cmd string
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003718 str = strtok_r(NULL, ",", &pcmdStr);
3719 if(str == NULL || str[0] == '\0')
3720 break;
3721 else
3722 {
3723 sprintf(CmdStr, "%s /%s",CmdStr,str);
3724 str = strtok_r(NULL, ",", &pcmdStr);
3725 sprintf(CmdStr, "%s %s",CmdStr,str);
3726 }
3727 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003728 // check the return process
3729 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3730 if(wfaCliFd!= NULL)
3731 {
3732 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3733 {
3734 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3735 if(ferror(wfaCliFd))
3736 break;
3737
3738 str=strtok(wfaCliBuff,"-");
3739 if(strcmp(str,cmdName) == 0)
3740 {
3741 str=strtok(NULL,",");
Dake Zhao97708202014-11-26 13:59:04 -08003742 if (str != NULL)
3743 {
3744 if(strcmp(str,"TRUE") == 0)
3745 CmdReturnFlag =1;
3746 }
3747 else
3748 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003749 break;
3750 }
3751 }
3752 fclose(wfaCliFd);
3753 }
Dake Zhao97708202014-11-26 13:59:04 -08003754 else
3755 {
3756 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3757 goto cleanup;
3758 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003759
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003760 //printf("\n Command Return Flag : %d",CmdReturnFlag);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003761 memset(&retstr[0],'\0',255);
3762 memset(&tmp[0],'\0',255);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003763 sprintf(gCmdStr, "%s", CmdStr);
3764 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003765
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003766 sh_pipe = popen(gCmdStr,"r");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003767 if(!sh_pipe)
3768 {
Dake Zhao97708202014-11-26 13:59:04 -08003769 printf ("Error in opening pipe\n");
3770 goto cleanup;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003771 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003772
Dake Zhao97708202014-11-26 13:59:04 -08003773 sleep(5);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003774 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3775 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3776 {
Dake Zhao97708202014-11-26 13:59:04 -08003777 printf("Getting NULL string in popen return\n");
3778 goto cleanup;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003779 }
Dake Zhao97708202014-11-26 13:59:04 -08003780 else
3781 printf("popen return str=%s\n",retstr);
3782
3783 sleep(2);
3784 if(pclose(sh_pipe) == -1)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003785 {
Dake Zhao97708202014-11-26 13:59:04 -08003786 printf("Error in closing shell cmd pipe\n");
3787 goto cleanup;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003788 }
3789 sleep(2);
Dake Zhao97708202014-11-26 13:59:04 -08003790
3791 // find status first in output
3792 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3793 if (str != NULL)
3794 {
3795 memset(tmp, 0, 10);
3796 memcpy(tmp, str, 2);
3797 printf("cli status=%s\n",tmp);
3798 if(strlen(tmp) > 0)
3799 st = atoi(tmp);
3800 else printf("Missing status code\n");
3801 }
3802 else
3803 {
3804 printf("wfaStaCliCommand no return code found\n");
3805 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003806 infoResp.resFlag=CmdReturnFlag;
Dake Zhao97708202014-11-26 13:59:04 -08003807
3808cleanup:
3809
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003810 switch(st)
3811 {
3812 case 0:
3813 infoResp.status = STATUS_COMPLETE;
3814 if (CmdReturnFlag)
3815 {
Dake Zhao97708202014-11-26 13:59:04 -08003816 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003817 {
Dake Zhao97708202014-11-26 13:59:04 -08003818 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
3819 strncpy(&infoResp.result[0], pcmdStr ,(strlen(pcmdStr) < WFA_CLI_CMD_RESP_LEN ) ? strlen(pcmdStr) : (WFA_CLI_CMD_RESP_LEN-2) );
3820 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003821 }
3822 else
Dake Zhao97708202014-11-26 13:59:04 -08003823 {
3824 strcpy(&infoResp.result[0], "No return string found\n");
3825 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003826 }
3827 break;
3828 case 1:
3829 infoResp.status = STATUS_ERROR;
3830 break;
3831 case 2:
3832 infoResp.status = STATUS_INVALID;
3833 break;
3834 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003835
3836 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3837 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3838
Dake Zhao97708202014-11-26 13:59:04 -08003839 printf("Exit from wfaStaCliCommand\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003840 return TRUE;
3841
Ankur Vachhanic485b712012-02-15 23:29:49 +00003842}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003843/*
3844 * wfaStaConnectGoStartWfd():
3845 */
3846
3847int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3848{
3849 dutCmdResponse_t infoResp;
3850// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
3851
3852 printf("\n Entry wfaStaConnectGoStartWfd... ");
3853
3854 // connect the specified GO and then establish the wfd session
3855
3856 // Fetch WFD session and return
3857 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3858
3859 infoResp.status = STATUS_COMPLETE;
3860 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3861 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3862
3863 return WFA_SUCCESS;
3864}
3865
3866/*
3867 * wfaStaGenerateEvent():
3868 */
3869
3870int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3871{
3872 dutCmdResponse_t infoResp;
3873 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3874 caWfdStaGenEvent_t *wfdGenEvent;
3875
3876 printf("\n Entry wfaStaGenerateEvent... ");
3877
3878
3879 // Geneate the specified action and return with complete/error.
3880 if(staGenerateEvent->program == PROG_TYPE_WFD)
3881 {
3882 wfdGenEvent = &staGenerateEvent->wfdEvent;
3883 if(wfdGenEvent ->type == eUibcGen)
3884 {
3885 }
3886 else if(wfdGenEvent ->type == eUibcHid)
3887 {
3888 }
3889 else if(wfdGenEvent ->type == eFrameSkip)
3890 {
3891
3892 }
3893 else if(wfdGenEvent ->type == eI2cRead)
3894 {
3895 }
3896 else if(wfdGenEvent ->type == eI2cWrite)
3897 {
3898 }
3899 else if(wfdGenEvent ->type == eInputContent)
3900 {
3901 }
3902 else if(wfdGenEvent ->type == eIdrReq)
3903 {
3904 }
3905 }
3906
3907 infoResp.status = STATUS_COMPLETE;
3908 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3909 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3910
3911 return WFA_SUCCESS;
3912}
3913
3914
3915
3916
3917/*
3918 * wfaStaReinvokeWfdSession():
3919 */
3920
3921int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3922{
3923 dutCmdResponse_t infoResp;
3924// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
3925
3926 printf("\n Entry wfaStaReinvokeWfdSession... ");
3927
3928 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
3929
3930
3931 infoResp.status = STATUS_COMPLETE;
3932 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3933 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3934
3935 return WFA_SUCCESS;
3936}
3937
3938
3939int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3940{
3941 dutCmdResponse_t infoResp;
3942 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
3943
3944
3945 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
3946
3947 printf("\n Entry wfaStaGetParameter... ");
3948
3949 // Check the program type
3950 if(staGetParam->program == PROG_TYPE_WFD)
3951 {
3952 if(staGetParam->getParamValue == eDiscoveredDevList )
3953 {
3954 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3955 paramList->getParamType = eDiscoveredDevList;
3956 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3957 }
3958 }
3959
3960
3961 infoResp.status = STATUS_COMPLETE;
3962 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3963 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3964
3965 return WFA_SUCCESS;
3966}
3967
Ankur Vachhanic485b712012-02-15 23:29:49 +00003968