blob: e94901373822e01fa4b3185fa83196a11286a797 [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 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000034 *
35 */
36#include <stdio.h>
37#include <unistd.h>
38#include <string.h>
39#include <stdlib.h>
40#include <sys/socket.h>
41#include <arpa/inet.h>
42#include <linux/types.h>
43#include <linux/socket.h>
44#include <poll.h>
45
46#include "wfa_portall.h"
47#include "wfa_debug.h"
48#include "wfa_ver.h"
49#include "wfa_main.h"
50#include "wfa_types.h"
51#include "wfa_ca.h"
52#include "wfa_tlv.h"
53#include "wfa_sock.h"
54#include "wfa_tg.h"
55#include "wfa_cmds.h"
56#include "wfa_rsp.h"
57#include "wfa_utils.h"
58#ifdef WFA_WMM_PS_EXT
59#include "wfa_wmmps.h"
60#endif
61
62#define CERTIFICATES_PATH "/etc/wpa_supplicant"
63
64/* Some device may only support UDP ECHO, activate this line */
65//#define WFA_PING_UDP_ECHO_ONLY 1
66
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080067#define WFA_ENABLED 1
68
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000069extern unsigned short wfa_defined_debug;
70int wfaExecuteCLI(char *CLI);
71
72/* Since the two definitions are used all over the CA function */
73char gCmdStr[WFA_CMD_STR_SZ];
74dutCmdResponse_t gGenericResp;
75int wfaTGSetPrio(int sockfd, int tgClass);
76void create_apts_msg(int msg, unsigned int txbuf[],int id);
77
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080078int sret = 0;
79
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000080extern char e2eResults[];
81//extern char *e2eResults;
82FILE *e2efp = NULL;
83int chk_ret_status()
84{
85 char *ret = getenv(WFA_RET_ENV);
86
87 if(*ret == '1')
88 return WFA_SUCCESS;
89 else
90 return WFA_FAILURE;
91}
92
93/*
94 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
95 * input: cmd --- not used
96 * valLen -- not used
97 * output: parms -- a buffer to store the version info response.
98 */
99int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
100{
101 dutCmdResponse_t *getverResp = &gGenericResp;
102
103 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
104
105 getverResp->status = STATUS_COMPLETE;
106 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
107
108 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
109
110 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
111
112 return WFA_SUCCESS;
113}
114
115/*
116 * wfaStaAssociate():
117 * The function is to force the station wireless I/F to re/associate
118 * with the AP.
119 */
120int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
121{
122 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
123 char *ifname = assoc->intf;
124 dutCmdResponse_t *staAssocResp = &gGenericResp;
125
126 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
127 /*
128 * if bssid appears, station should associate with the specific
129 * BSSID AP at its initial association.
130 * If it is different to the current associating AP, it will be forced to
131 * roam the new AP
132 */
133 if(assoc->cmdsu.assoc.bssid[0] != '\0')
134 {
135 /* if (the first association) */
136 /* just do initial association to the BSSID */
137
138
139 /* else (station already associate to an AP) */
140 /* Do forced roaming */
141
142 }
143 else
144 {
145 /* use 'ifconfig' command to bring down the interface (linux specific) */
146 sprintf(gCmdStr, "ifconfig %s down", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800147 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000148
149 /* use 'ifconfig' command to bring up the interface (linux specific) */
150 sprintf(gCmdStr, "ifconfig %s up", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800151 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000152
153 /*
154 * use 'wpa_cli' command to force a 802.11 re/associate
155 * (wpa_supplicant specific)
156 */
157 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800158 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000159 }
160
161 /*
162 * Then report back to control PC for completion.
163 * This does not have failed/error status. The result only tells
164 * a completion.
165 */
166 staAssocResp->status = STATUS_COMPLETE;
167 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
168 *respLen = WFA_TLV_HDR_LEN + 4;
169
170 return WFA_SUCCESS;
171}
172
173/*
174 * wfaStaReAssociate():
175 * The function is to force the station wireless I/F to re/associate
176 * with the AP.
177 */
178int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
179{
180 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
181 char *ifname = assoc->intf;
182 dutCmdResponse_t *staAssocResp = &gGenericResp;
183
184 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
185 /*
186 * if bssid appears, station should associate with the specific
187 * BSSID AP at its initial association.
188 * If it is different to the current associating AP, it will be forced to
189 * roam the new AP
190 */
191 if(assoc->cmdsu.assoc.bssid[0] != '\0')
192 {
193 /* if (the first association) */
194 /* just do initial association to the BSSID */
195
196
197 /* else (station already associate to an AP) */
198 /* Do forced roaming */
199
200 }
201 else
202 {
203 /* use 'ifconfig' command to bring down the interface (linux specific) */
204 sprintf(gCmdStr, "ifconfig %s down", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800205 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000206
207 /* use 'ifconfig' command to bring up the interface (linux specific) */
208 sprintf(gCmdStr, "ifconfig %s up", ifname);
209
210 /*
211 * use 'wpa_cli' command to force a 802.11 re/associate
212 * (wpa_supplicant specific)
213 */
214 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800215 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000216 }
217
218 /*
219 * Then report back to control PC for completion.
220 * This does not have failed/error status. The result only tells
221 * a completion.
222 */
223 staAssocResp->status = STATUS_COMPLETE;
224 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
225 *respLen = WFA_TLV_HDR_LEN + 4;
226
227 return WFA_SUCCESS;
228}
229
230/*
231 * wfaStaIsConnected():
232 * The function is to check whether the station's wireless I/F has
233 * already connected to an AP.
234 */
235int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
236{
237 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
238 dutCmdResponse_t *staConnectResp = &gGenericResp;
239 char *ifname = connStat->intf;
240 FILE *tmpfile = NULL;
241 char result[32];
242
243
244 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
245
246#ifdef WFA_NEW_CLI_FORMAT
247 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800248 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000249
250 if(chk_ret_status() == WFA_SUCCESS)
251 staConnectResp->cmdru.connected = 1;
252 else
253 staConnectResp->cmdru.connected = 0;
254#else
255 /*
256 * use 'wpa_cli' command to check the interface status
257 * none, scanning or complete (wpa_supplicant specific)
258 */
259 sprintf(gCmdStr, "/sbin/wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800260 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000261
262 /*
263 * the status is saved in a file. Open the file and check it.
264 */
265 tmpfile = fopen("/tmp/.isConnected", "r+");
266 if(tmpfile == NULL)
267 {
268 staConnectResp->status = STATUS_ERROR;
269 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
270 *respLen = WFA_TLV_HDR_LEN + 4;
271
272 DPRINT_ERR(WFA_ERR, "file open failed\n");
273 return WFA_FAILURE;
274 }
275
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800276 sret = fscanf(tmpfile, "%s", (char *)result);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000277
278 if(strncmp(result, "COMPLETED", 9) == 0)
279 staConnectResp->cmdru.connected = 1;
280 else
281 staConnectResp->cmdru.connected = 0;
282#endif
283
284 /*
285 * Report back the status: Complete or Failed.
286 */
287 staConnectResp->status = STATUS_COMPLETE;
288
289 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
290 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
291
292 return WFA_SUCCESS;
293}
294
295/*
296 * wfaStaGetIpConfig():
297 * This function is to retriev the ip info including
298 * 1. dhcp enable
299 * 2. ip address
300 * 3. mask
301 * 4. primary-dns
302 * 5. secondary-dns
303 *
304 * The current implementation is to use a script to find these information
305 * and store them in a file.
306 */
307int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
308{
309 int slen, ret, i = 0;
310 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
311 dutCmdResponse_t *ipconfigResp = &gGenericResp;
312 char *ifname = getIpConf->intf;
313 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
314
315 FILE *tmpfd;
316 char string[256];
317 char *str;
318
319 /*
320 * check a script file (the current implementation specific)
321 */
322 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
323 if(ret == -1)
324 {
325 ipconfigResp->status = STATUS_ERROR;
326 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
327 *respLen = WFA_TLV_HDR_LEN + 4;
328
329 DPRINT_ERR(WFA_ERR, "file not exist\n");
330 return WFA_FAILURE;
331
332 }
333
334 strcpy(ifinfo->dns[0], "0");
335 strcpy(ifinfo->dns[1], "0");
336
337 /*
338 * Run the script file "getipconfig.sh" to check the ip status
339 * (current implementation specific).
340 * note: "getipconfig.sh" is only defined for the current implementation
341 */
342 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
343
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800344 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000345
346 /* open the output result and scan/retrieve the info */
347 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
348
349 if(tmpfd == NULL)
350 {
351 ipconfigResp->status = STATUS_ERROR;
352 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
353 *respLen = WFA_TLV_HDR_LEN + 4;
354
355 DPRINT_ERR(WFA_ERR, "file open failed\n");
356 return WFA_FAILURE;
357 }
358
359 for(;;)
360 {
361 if(fgets(string, 256, tmpfd) == NULL)
362 break;
363
364 /* check dhcp enabled */
365 if(strncmp(string, "dhcpcli", 7) ==0)
366 {
367 str = strtok(string, "=");
368 str = strtok(NULL, "=");
369 if(str != NULL)
370 ifinfo->isDhcp = 1;
371 else
372 ifinfo->isDhcp = 0;
373 }
374
375 /* find out the ip address */
376 if(strncmp(string, "ipaddr", 6) == 0)
377 {
378 str = strtok(string, "=");
379 str = strtok(NULL, " ");
380 if(str != NULL)
381 {
382 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800383
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000384 ifinfo->ipaddr[15]='\0';
385 }
386 else
387 wSTRNCPY(ifinfo->ipaddr, "none", 15);
388 }
389
390 /* check the mask */
391 if(strncmp(string, "mask", 4) == 0)
392 {
393 char ttstr[16];
394 char *ttp = ttstr;
395
396 str = strtok_r(string, "=", &ttp);
397 if(*ttp != '\0')
398 {
399 strcpy(ifinfo->mask, ttp);
400 slen = strlen(ifinfo->mask);
401 ifinfo->mask[slen-1] = '\0';
402 }
403 else
404 strcpy(ifinfo->mask, "none");
405 }
406
407 /* find out the dns server ip address */
408 if(strncmp(string, "nameserv", 8) == 0)
409 {
410 char ttstr[16];
411 char *ttp = ttstr;
412
413 str = strtok_r(string, " ", &ttp);
414 if(str != NULL && i < 2)
415 {
416 strcpy(ifinfo->dns[i], ttp);
417 slen = strlen(ifinfo->dns[i]);
418 ifinfo->dns[i][slen-1] = '\0';
419 }
420 else
421 strcpy(ifinfo->dns[i], "none");
422
423 i++;
424 }
425 }
426
427 /*
428 * Report back the results
429 */
430 ipconfigResp->status = STATUS_COMPLETE;
431 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
432
433 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
434
435#if 0
436 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
437 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
438 ifinfo->dns[0], ifinfo->dns[1], *respLen);
439#endif
440
441 fclose(tmpfd);
442 return WFA_SUCCESS;
443}
444
445/*
446 * wfaStaSetIpConfig():
447 * The function is to set the ip configuration to a wireless I/F.
448 * 1. IP address
449 * 2. Mac address
450 * 3. default gateway
451 * 4. dns nameserver (pri and sec).
452 */
453int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
454{
455 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
456 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
457 dutCmdResponse_t *staSetIpResp = &gGenericResp;
458
459 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
460
461 /*
462 * Use command 'ifconfig' to configure the interface ip address, mask.
463 * (Linux specific).
464 */
465 sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800466 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000467
468 /* use command 'route add' to set set gatewway (linux specific) */
469 if(ipconfig->defGateway[0] != '\0')
470 {
471 sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800472 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000473 }
474
475 /* set dns (linux specific) */
476 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800477 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000478 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800479 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000480 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800481 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000482
483 /*
484 * report status
485 */
486 staSetIpResp->status = STATUS_COMPLETE;
487 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
488 *respLen = WFA_TLV_HDR_LEN + 4;
489
490 return WFA_SUCCESS;
491}
492
493/*
494 * wfaStaVerifyIpConnection():
495 * The function is to verify if the station has IP connection with an AP by
496 * send ICMP/pings to the AP.
497 */
498int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
499{
500 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
501 dutCmdResponse_t *verifyIpResp = &gGenericResp;
502
503#ifndef WFA_PING_UDP_ECHO_ONLY
504 char strout[64], *pcnt;
505 FILE *tmpfile;
506
507 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
508
509 /* set timeout value in case not set */
510 if(verip->cmdsu.verifyIp.timeout <= 0)
511 {
512 verip->cmdsu.verifyIp.timeout = 10;
513 }
514
515 /* execute the ping command and pipe the result to a tmp file */
516 sprintf(gCmdStr, "ping %s -c 3 -W %u | grep loss | cut -f3 -d, 1>& /tmp/pingout.txt", verip->cmdsu.verifyIp.dipaddr, verip->cmdsu.verifyIp.timeout);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800517 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000518
519 /* scan/check the output */
520 tmpfile = fopen("/tmp/pingout.txt", "r+");
521 if(tmpfile == NULL)
522 {
523 verifyIpResp->status = STATUS_ERROR;
524 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
525 *respLen = WFA_TLV_HDR_LEN + 4;
526
527 DPRINT_ERR(WFA_ERR, "file open failed\n");
528 return WFA_FAILURE;
529 }
530
531 verifyIpResp->status = STATUS_COMPLETE;
532 if(fscanf(tmpfile, "%s", strout) == EOF)
533 verifyIpResp->cmdru.connected = 0;
534 else
535 {
536 pcnt = strtok(strout, "%");
537
538 /* if the loss rate is 100%, not able to connect */
539 if(atoi(pcnt) == 100)
540 verifyIpResp->cmdru.connected = 0;
541 else
542 verifyIpResp->cmdru.connected = 1;
543 }
544
545 fclose(tmpfile);
546#else
547 int btSockfd;
548 struct pollfd fds[2];
549 int timeout = 2000;
550 char anyBuf[64];
551 struct sockaddr_in toAddr;
552 int done = 1, cnt = 0, ret, nbytes;
553
554 verifyIpResp->status = STATUS_COMPLETE;
555 verifyIpResp->cmdru.connected = 0;
556
557 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
558
559 if(btSockfd == -1)
560 {
561 verifyIpResp->status = STATUS_ERROR;
562 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
563 *respLen = WFA_TLV_HDR_LEN + 4;
564 return WFA_FAILURE;;
565 }
566
567 toAddr.sin_family = AF_INET;
568 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
569 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
570
571 while(done)
572 {
573 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
574 cnt++;
575
576 fds[0].fd = btSockfd;
577 fds[0].events = POLLIN | POLLOUT;
578
579 ret = poll(fds, 1, timeout);
580 switch(ret)
581 {
582 case 0:
583 /* it is time out, count a packet lost*/
584 break;
585 case -1:
586 /* it is an error */
587 default:
588 {
589 switch(fds[0].revents)
590 {
591 case POLLIN:
592 case POLLPRI:
593 case POLLOUT:
594 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
595 if(nbytes != 0)
596 verifyIpResp->cmdru.connected = 1;
597 done = 0;
598 break;
599 default:
600 /* errors but not care */
601 ;
602 }
603 }
604 }
605 if(cnt == 3)
606 {
607 done = 0;
608 }
609 }
610
611#endif
612
613 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
614
615 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
616
617 return WFA_SUCCESS;
618}
619
620/*
621 * wfaStaGetMacAddress()
622 * This function is to retrieve the MAC address of a wireless I/F.
623 */
624int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
625{
626 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
627 dutCmdResponse_t *getmacResp = &gGenericResp;
628 char *str;
629 char *ifname = getMac->intf;
630
631 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800632 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000633
634 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
635 /*
636 * run the script "getipconfig.sh" to find out the mac
637 */
638 //sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s", ifname);
639 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800640 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000641
642 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
643 if(tmpfd == NULL)
644 {
645 getmacResp->status = STATUS_ERROR;
646 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
647 *respLen = WFA_TLV_HDR_LEN + 4;
648
649 DPRINT_ERR(WFA_ERR, "file open failed\n");
650 return WFA_FAILURE;
651 }
652
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800653 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
654 {
655 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000656 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800657
658 str = strtok(string, " ");
659 while(str && ((strcmp(str,"HWaddr")) != 0))
660 {
661 str = strtok(NULL, " ");
662 }
663
664 /* get mac */
665 if(str)
666 {
667 str = strtok(NULL, " ");
668 strcpy(getmacResp->cmdru.mac, str);
669 getmacResp->status = STATUS_COMPLETE;
670 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000671
672 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
673
674 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
675
676 fclose(tmpfd);
677 return WFA_SUCCESS;
678}
679
680/*
681 * wfaStaGetStats():
682 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
683 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
684 * Currently there is not definition how to use these info.
685 */
686int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
687{
688 dutCmdResponse_t *statsResp = &gGenericResp;
689
690 /* this is never used, you can skip this call */
691
692 statsResp->status = STATUS_ERROR;
693 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
694 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
695
696
697 return WFA_SUCCESS;
698}
699
700/*
701 * wfaSetEncryption():
702 * The function is to set the wireless interface with WEP or none.
703 *
704 * Since WEP is optional test, current function is only used for
705 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
706 * this function should be replaced by the next one (wfaSetEncryption1())
707 *
708 * Input parameters:
709 * 1. I/F
710 * 2. ssid
711 * 3. encpType - wep or none
712 * Optional:
713 * 4. key1
714 * 5. key2
715 * 6. key3
716 * 7. key4
717 * 8. activeKey Index
718 */
719
720int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
721{
722 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
723 dutCmdResponse_t *setEncrypResp = &gGenericResp;
724
725 /*
726 * disable the network first
727 */
728 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800729 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000730
731 /*
732 * set SSID
733 */
734 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800735 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000736
737 /*
738 * Tell the supplicant for infrastructure mode (1)
739 */
740 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800741 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000742
743 /*
744 * set Key management to NONE (NO WPA) for plaintext or WEP
745 */
746 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800747 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000748
749 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800750 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000751
752 setEncrypResp->status = STATUS_COMPLETE;
753 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
754 *respLen = WFA_TLV_HDR_LEN + 4;
755
756 return WFA_SUCCESS;
757}
758
759/*
760 * Since WEP is optional, this function could be used to replace
761 * wfaSetEncryption() if necessary.
762 */
763int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
764{
765 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
766 dutCmdResponse_t *setEncrypResp = &gGenericResp;
767 int i;
768
769 /*
770 * disable the network first
771 */
772 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800773 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000774
775 /*
776 * set SSID
777 */
778 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800779 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000780
781 /*
782 * Tell the supplicant for infrastructure mode (1)
783 */
784 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800785 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000786
787 /*
788 * set Key management to NONE (NO WPA) for plaintext or WEP
789 */
790 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800791 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000792
793 /* set keys */
794 if(setEncryp->encpType == 1)
795 {
796 for(i=0; i<4; i++)
797 {
798 if(setEncryp->keys[i][0] != '\0')
799 {
800 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
801 setEncryp->intf, i, setEncryp->keys[i]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800802 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000803 }
804 }
805
806 /* set active key */
807 i = setEncryp->activeKeyIdx;
808 if(setEncryp->keys[i][0] != '\0')
809 {
810 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
811 setEncryp->intf, setEncryp->activeKeyIdx);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800812 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000813 }
814 }
815 else /* clearly remove the keys -- reported by p.schwann */
816 {
817
818 for(i = 0; i < 4; i++)
819 {
820 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800821 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000822 }
823 }
824
825 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800826 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000827
828 setEncrypResp->status = STATUS_COMPLETE;
829 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
830 *respLen = WFA_TLV_HDR_LEN + 4;
831
832 return WFA_SUCCESS;
833}
834
835int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
836{
837 int ret = WFA_SUCCESS;
838
839 return ret;
840}
841
842/*
843 * wfaStaSetEapTLS():
844 * This is to set
845 * 1. ssid
846 * 2. encrypType - tkip or aes-ccmp
847 * 3. keyManagementType - wpa or wpa2
848 * 4. trustedRootCA
849 * 5. clientCertificate
850 */
851int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
852{
853 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
854 char *ifname = setTLS->intf;
855 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
856
857 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
858
859 /*
860 * need to store the trustedROOTCA and clientCertificate into a file first.
861 */
862#ifdef WFA_NEW_CLI_FORMAT
863 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800864 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000865#else
866
867 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800868 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000869
870 /* ssid */
871 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800872 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000873
874 /* key management */
875 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
876 {
877 }
878 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
879 {
880 }
881 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
882 {
883
884 }
885 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
886 {
887 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
888 }
889 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
890 {
891 // to take all and device to pick any one supported.
892 }
893 else
894 {
895 // ??
896 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800897 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000898
899 /* protocol WPA */
900 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800901 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000902
903 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800904 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000905
906 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800907 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000908
909 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800910 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000911
912 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 -0800913 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000914
915 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800916 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000917
918 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800919 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000920#endif
921
922 setEapTlsResp->status = STATUS_COMPLETE;
923 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
924 *respLen = WFA_TLV_HDR_LEN + 4;
925
926 return WFA_SUCCESS;
927}
928
929/*
930 * The function is to set
931 * 1. ssid
932 * 2. passPhrase
933 * 3. keyMangementType - wpa/wpa2
934 * 4. encrypType - tkip or aes-ccmp
935 */
936int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800937{ /*Incompleted function*/
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000938 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
939 dutCmdResponse_t *setPskResp = &gGenericResp;
940
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800941#ifndef WFA_PC_CONSOLE
942
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000943#ifdef WFA_NEW_CLI_FORMAT
944 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800945 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000946#else
947 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800948 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000949
950 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
951 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
952 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
953 {
954 // take all and device to pick it supported.
955 }
956 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
957 {
958
959 }
960 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
961 {
962
963 }
Ray Wang9c508692014-04-01 17:04:59 -0700964 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
965 {
966
967 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000968 else
969 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800970
971 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000972
973 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800974 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000975
976 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800977 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000978
979 /* if PMF enable */
980 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
981 {
982
983 }
984 else if(setPSK->pmf == WFA_REQUIRED)
985 {
986
987 }
988 else if(setPSK->pmf == WFA_F_REQUIRED)
989 {
990
991 }
992 else if(setPSK->pmf == WFA_F_DISABLED)
993 {
994
995 }
996 else
997 { /* Disable PMF */
998
999 }
1000
1001#endif
1002
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001003#endif
1004
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001005 setPskResp->status = STATUS_COMPLETE;
1006 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1007 *respLen = WFA_TLV_HDR_LEN + 4;
1008
1009 return WFA_SUCCESS;
1010}
1011
1012/*
1013 * wfaStaGetInfo():
1014 * Get vendor specific information in name/value pair by a wireless I/F.
1015 */
1016int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1017{
1018 dutCmdResponse_t infoResp;
1019 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
1020
1021 /*
1022 * Normally this is called to retrieve the vendor information
1023 * from a interface, no implement yet
1024 */
1025 sprintf(infoResp.cmdru.info, "interface,%s,vendor,XXX,cardtype,802.11a/b/g", getInfo->intf);
1026
1027 infoResp.status = STATUS_COMPLETE;
1028 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
1029 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
1030
1031 return WFA_SUCCESS;
1032}
1033
1034/*
1035 * wfaStaSetEapTTLS():
1036 * This is to set
1037 * 1. ssid
1038 * 2. username
1039 * 3. passwd
1040 * 4. encrypType - tkip or aes-ccmp
1041 * 5. keyManagementType - wpa or wpa2
1042 * 6. trustedRootCA
1043 */
1044int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1045{
1046 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1047 char *ifname = setTTLS->intf;
1048 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
1049
1050#ifdef WFA_NEW_CLI_FORMAT
1051 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 -08001052 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001053#else
1054
1055 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001056 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001057
1058 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001059 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001060
1061 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001062 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001063
1064 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001065 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001066
1067 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001068 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001069
1070/* This may not need to set. if it is not set, default to take all */
1071// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
1072 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1073 {
1074 }
1075 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1076 {
1077 }
1078 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1079 {
1080
1081 }
1082 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1083 {
1084
1085 }
1086 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1087 {
1088 // to take all and device to pick one it supported
1089 }
1090 else
1091 {
1092 // ??
1093 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001094 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001095
1096 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001097 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001098
1099 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 -08001100 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001101
1102 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001103 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001104
1105// sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001106// sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001107
1108 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001109 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001110
1111 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001112 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001113#endif
1114
1115 setEapTtlsResp->status = STATUS_COMPLETE;
1116 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1117 *respLen = WFA_TLV_HDR_LEN + 4;
1118
1119 return WFA_SUCCESS;
1120}
1121
1122/*
1123 * wfaStaSetEapSIM():
1124 * This is to set
1125 * 1. ssid
1126 * 2. user name
1127 * 3. passwd
1128 * 4. encrypType - tkip or aes-ccmp
1129 * 5. keyMangementType - wpa or wpa2
1130 */
1131int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1132{
1133 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1134 char *ifname = setSIM->intf;
1135 dutCmdResponse_t *setEapSimResp = &gGenericResp;
1136
1137#ifdef WFA_NEW_CLI_FORMAT
1138 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001139 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001140#else
1141
1142 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001143 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001144
1145 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001146 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001147
1148
1149 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001150 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001151
1152 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001153 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001154
1155 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001156 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001157
1158 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001159 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001160
1161 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001162 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001163
1164 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1165 {
1166 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1167 }
1168 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1169 {
1170 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1171 }
1172 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1173 {
1174 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1175 }
1176 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1177 {
1178 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1179 }
1180 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1181 {
1182 // take all and device to pick one which is supported.
1183 }
1184 else
1185 {
1186 // ??
1187 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001188 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001189
1190#endif
1191
1192 setEapSimResp->status = STATUS_COMPLETE;
1193 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1194 *respLen = WFA_TLV_HDR_LEN + 4;
1195
1196 return WFA_SUCCESS;
1197}
1198
1199/*
1200 * wfaStaSetPEAP()
1201 * This is to set
1202 * 1. ssid
1203 * 2. user name
1204 * 3. passwd
1205 * 4. encryType - tkip or aes-ccmp
1206 * 5. keyMgmtType - wpa or wpa2
1207 * 6. trustedRootCA
1208 * 7. innerEAP
1209 * 8. peapVersion
1210 */
1211int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1212{
1213 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1214 char *ifname = setPEAP->intf;
1215 dutCmdResponse_t *setPeapResp = &gGenericResp;
1216
1217#ifdef WFA_NEW_CLI_FORMAT
1218 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1219 setPEAP->passwd, setPEAP->trustedRootCA,
1220 setPEAP->encrptype, setPEAP->peapVersion,
1221 setPEAP->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001222 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001223#else
1224
1225 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001226 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001227
1228 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001229 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001230
1231 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001232 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001233
1234 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001235 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001236
1237 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001238 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001239
1240 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001241 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001242
1243 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 -08001244 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001245
1246 /* if this not set, default to set support all */
1247 //sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setPEAP->encrptype);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001248 //sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001249
1250 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1251 {
1252 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1253 }
1254 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1255 {
1256 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1257 }
1258 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1259 {
1260 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1261 }
1262 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1263 {
1264 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1265 }
1266 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1267 {
1268 // take all and device to pick one which is supported.
1269 }
1270 else
1271 {
1272 // ??
1273 }
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 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001277 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001278
1279 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001280 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001281
1282 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001283 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001284#endif
1285
1286 setPeapResp->status = STATUS_COMPLETE;
1287 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1288 *respLen = WFA_TLV_HDR_LEN + 4;
1289
1290 return WFA_SUCCESS;
1291}
1292
1293/*
1294 * wfaStaSetUAPSD()
1295 * This is to set
1296 * 1. acBE
1297 * 2. acBK
1298 * 3. acVI
1299 * 4. acVO
1300 */
1301int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1302{
1303 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
1304#if 0 /* used for only one specific device, need to update to reflect yours */
1305 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1306 char *ifname = setUAPSD->intf;
1307 char tmpStr[10];
1308 char line[100];
1309 char *pathl="/etc/Wireless/RT61STA";
1310 BYTE acBE=1;
1311 BYTE acBK=1;
1312 BYTE acVO=1;
1313 BYTE acVI=1;
1314 BYTE APSDCapable;
1315 FILE *pipe;
1316
1317 /*
1318 * A series of setting need to be done before doing WMM-PS
1319 * Additional steps of configuration may be needed.
1320 */
1321
1322 /*
1323 * bring down the interface
1324 */
1325 sprintf(gCmdStr, "ifconfig %s down",ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001326 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001327 /*
1328 * Unload the Driver
1329 */
1330 sprintf(gCmdStr, "rmmod rt61");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001331 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001332#ifndef WFA_WMM_AC
1333 if(setUAPSD->acBE != 1)
1334 acBE=setUAPSD->acBE = 0;
1335 if(setUAPSD->acBK != 1)
1336 acBK=setUAPSD->acBK = 0;
1337 if(setUAPSD->acVO != 1)
1338 acVO=setUAPSD->acVO = 0;
1339 if(setUAPSD->acVI != 1)
1340 acVI=setUAPSD->acVI = 0;
1341#else
1342 acBE=setUAPSD->acBE;
1343 acBK=setUAPSD->acBK;
1344 acVO=setUAPSD->acVO;
1345 acVI=setUAPSD->acVI;
1346#endif
1347
1348 APSDCapable = acBE||acBK||acVO||acVI;
1349 /*
1350 * set other AC parameters
1351 */
1352
1353 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1354 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 -08001355 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001356
1357 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001358 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001359 pipe = popen("uname -r", "r");
1360 /* Read into line the output of uname*/
1361 fscanf(pipe,"%s",line);
1362 pclose(pipe);
1363
1364 /*
1365 * load the Driver
1366 */
1367 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001368 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001369
1370 sprintf(gCmdStr, "ifconfig %s up",ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001371 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001372#endif
1373
1374 setUAPSDResp->status = STATUS_COMPLETE;
1375 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1376 *respLen = WFA_TLV_HDR_LEN + 4;
1377 return WFA_SUCCESS;
1378}
1379
1380int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1381{
1382 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1383 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1384 dutCmdResponse_t *infoResp = &gGenericResp;
1385 /*a vendor can fill in the proper info or anything non-disclosure */
1386 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
1387
1388 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
1389
1390 if(devInfo->fw == 0)
1391 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1392 else
1393 {
1394 // Call internal API to pull the version ID */
1395 memcpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
1396 }
1397
1398 infoResp->status = STATUS_COMPLETE;
1399 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1400 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1401
1402 return WFA_SUCCESS;
1403
1404}
1405
1406/*
1407 * This funciton is to retrieve a list of interfaces and return
1408 * the list back to Agent control.
1409 * ********************************************************************
1410 * Note: We intend to make this WLAN interface name as a hardcode name.
1411 * Therefore, for a particular device, you should know and change the name
1412 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1413 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
1414 * likely is hardcoded just for CAPI command responses.
1415 * *******************************************************************
1416 *
1417 */
1418int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1419{
1420 dutCmdResponse_t *infoResp = &gGenericResp;
1421 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1422 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
1423
1424 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
1425
1426 switch(ifList->cmdsu.iftype)
1427 {
1428 case IF_80211:
1429 infoResp->status = STATUS_COMPLETE;
1430 ifListResp->iftype = IF_80211;
1431 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1432 strcpy(ifListResp->ifs[1], "NULL");
1433 strcpy(ifListResp->ifs[2], "NULL");
1434 break;
1435 case IF_ETH:
1436 infoResp->status = STATUS_COMPLETE;
1437 ifListResp->iftype = IF_ETH;
1438 strcpy(ifListResp->ifs[0], "eth0");
1439 strcpy(ifListResp->ifs[1], "NULL");
1440 strcpy(ifListResp->ifs[2], "NULL");
1441 break;
1442 default:
1443 {
1444 infoResp->status = STATUS_ERROR;
1445 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1446 *respLen = WFA_TLV_HDR_LEN + 4;
1447
1448 return WFA_SUCCESS;
1449 }
1450 }
1451
1452 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1453 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1454
1455 return WFA_SUCCESS;
1456}
1457
1458int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1459{
1460 dutCmdResponse_t *debugResp = &gGenericResp;
1461 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
1462
1463 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
1464
1465 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1466 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1467 else
1468 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
1469
1470 debugResp->status = STATUS_COMPLETE;
1471 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1472 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1473
1474
1475 return WFA_SUCCESS;
1476}
1477
1478
1479/*
1480 * wfaStaGetBSSID():
1481 * This function is to retrieve BSSID of a specific wireless I/F.
1482 */
1483int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1484{
1485 char string[64];
1486 char *str;
1487 FILE *tmpfd;
1488 dutCmdResponse_t *bssidResp = &gGenericResp;
1489
1490 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1491 /* retrieve the BSSID */
1492 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
1493
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001494 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001495
1496 tmpfd = fopen("/tmp/bssid.txt", "r+");
1497 if(tmpfd == NULL)
1498 {
1499 bssidResp->status = STATUS_ERROR;
1500 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1501 *respLen = WFA_TLV_HDR_LEN + 4;
1502
1503 DPRINT_ERR(WFA_ERR, "file open failed\n");
1504 return WFA_FAILURE;
1505 }
1506
1507 for(;;)
1508 {
1509 if(fscanf(tmpfd, "%s", string) == EOF)
1510 {
1511 bssidResp->status = STATUS_COMPLETE;
1512 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
1513 break;
1514 }
1515
1516 if(strncmp(string, "bssid", 5) == 0)
1517 {
1518 str = strtok(string, "=");
1519 str = strtok(NULL, "=");
1520 if(str != NULL)
1521 {
1522 strcpy(bssidResp->cmdru.bssid, str);
1523 bssidResp->status = STATUS_COMPLETE;
1524 break;
1525 }
1526 }
1527 }
1528
1529 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1530 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1531
1532 fclose(tmpfd);
1533 return WFA_SUCCESS;
1534}
1535
1536/*
1537 * wfaStaSetIBSS()
1538 * This is to set
1539 * 1. ssid
1540 * 2. channel
1541 * 3. encrypType - none or wep
1542 * optional
1543 * 4. key1
1544 * 5. key2
1545 * 6. key3
1546 * 7. key4
1547 * 8. activeIndex - 1, 2, 3, or 4
1548 */
1549int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1550{
1551 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1552 dutCmdResponse_t *setIbssResp = &gGenericResp;
1553 int i;
1554
1555 /*
1556 * disable the network first
1557 */
1558 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001559 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001560
1561 /*
1562 * set SSID
1563 */
1564 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001565 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001566
1567 /*
1568 * Set channel for IBSS
1569 */
1570 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001571 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001572
1573 /*
1574 * Tell the supplicant for IBSS mode (1)
1575 */
1576 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001577 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001578
1579 /*
1580 * set Key management to NONE (NO WPA) for plaintext or WEP
1581 */
1582 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001583 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001584
1585 if(setIBSS->encpType == 1)
1586 {
1587 for(i=0; i<4; i++)
1588 {
1589 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1590 {
1591 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1592 setIBSS->intf, i, setIBSS->keys[i]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001593 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001594 }
1595 }
1596
1597 i = setIBSS->activeKeyIdx;
1598 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1599 {
1600 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1601 setIBSS->intf, setIBSS->activeKeyIdx);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001602 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001603 }
1604 }
1605
1606 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001607 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001608
1609 setIbssResp->status = STATUS_COMPLETE;
1610 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1611 *respLen = WFA_TLV_HDR_LEN + 4;
1612
1613 return WFA_SUCCESS;
1614}
1615
1616/*
1617 * wfaSetMode():
1618 * The function is to set the wireless interface with a given mode (possible
1619 * adhoc)
1620 * Input parameters:
1621 * 1. I/F
1622 * 2. ssid
1623 * 3. mode adhoc or managed
1624 * 4. encType
1625 * 5. channel
1626 * 6. key(s)
1627 * 7. active key
1628 */
1629int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1630{
1631 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1632 dutCmdResponse_t *SetModeResp = &gGenericResp;
1633 int i;
1634
1635 /*
1636 * bring down the interface
1637 */
1638 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001639 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001640
1641 /*
1642 * distroy the interface
1643 */
1644 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001645 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001646
1647
1648 /*
1649 * re-create the interface with the given mode
1650 */
1651 if(setmode->mode == 1)
1652 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
1653 else
1654 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1655
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001656 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001657 if(setmode->encpType == ENCRYPT_WEP)
1658 {
1659 int j = setmode->activeKeyIdx;
1660 for(i=0; i<4; i++)
1661 {
1662 if(setmode->keys[i][0] != '\0')
1663 {
1664 sprintf(gCmdStr, "iwconfig %s key s:%s",
1665 setmode->intf, setmode->keys[i]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001666 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001667 }
1668 /* set active key */
1669 if(setmode->keys[j][0] != '\0')
1670 sprintf(gCmdStr, "iwconfig %s key s:%s",
1671 setmode->intf, setmode->keys[j]);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001672 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001673 }
1674
1675 }
1676 /*
1677 * Set channel for IBSS
1678 */
1679 if(setmode->channel)
1680 {
1681 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001682 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001683 }
1684
1685
1686 /*
1687 * set SSID
1688 */
1689 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001690 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001691
1692 /*
1693 * bring up the interface
1694 */
1695 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001696 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001697
1698 SetModeResp->status = STATUS_COMPLETE;
1699 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1700 *respLen = WFA_TLV_HDR_LEN + 4;
1701
1702 return WFA_SUCCESS;
1703}
1704
1705int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1706{
1707 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1708 dutCmdResponse_t *SetPSResp = &gGenericResp;
1709
1710 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001711 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001712
1713
1714 SetPSResp->status = STATUS_COMPLETE;
1715 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1716 *respLen = WFA_TLV_HDR_LEN + 4;
1717
1718 return WFA_SUCCESS;
1719}
1720
1721int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1722{
1723 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1724 dutCmdResponse_t *upLoadResp = &gGenericResp;
1725 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
1726
1727 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1728 {
1729 int rbytes;
1730 /*
1731 * if asked for the first packet, always to open the file
1732 */
1733 if(upload->next == 1)
1734 {
1735 if(e2efp != NULL)
1736 {
1737 fclose(e2efp);
1738 e2efp = NULL;
1739 }
1740
1741 e2efp = fopen(e2eResults, "r");
1742 }
1743
1744 if(e2efp == NULL)
1745 {
1746 upLoadResp->status = STATUS_ERROR;
1747 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1748 *respLen = WFA_TLV_HDR_LEN + 4;
1749 return WFA_FAILURE;
1750 }
1751
1752 rbytes = fread(upld->bytes, 1, 256, e2efp);
1753
1754 if(rbytes < 256)
1755 {
1756 /*
1757 * this means no more bytes after this read
1758 */
1759 upld->seqnum = 0;
1760 fclose(e2efp);
1761 e2efp=NULL;
1762 }
1763 else
1764 {
1765 upld->seqnum = upload->next;
1766 }
1767
1768 upld->nbytes = rbytes;
1769
1770 upLoadResp->status = STATUS_COMPLETE;
1771 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1772 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1773 }
1774 else
1775 {
1776 upLoadResp->status = STATUS_ERROR;
1777 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1778 *respLen = WFA_TLV_HDR_LEN + 4;
1779 }
1780
1781 return WFA_SUCCESS;
1782}
1783/*
1784 * wfaStaSetWMM()
1785 * TO be ported on a specific plaform for the DUT
1786 * This is to set the WMM related parameters at the DUT.
1787 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1788 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1789 */
1790int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1791{
1792#ifdef WFA_WMM_AC
1793 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1794 char *ifname = setwmm->intf;
1795 dutCmdResponse_t *setwmmResp = &gGenericResp;
1796 //IEEEtypes_WMM_TSPEC_t tspec;
1797
1798 switch(setwmm->group)
1799 {
1800 case GROUP_WMMAC:
1801 if (setwmm->send_trig)
1802 {
1803 int Sockfd;
1804 struct sockaddr_in psToAddr;
1805 unsigned int TxMsg[512];
1806
1807 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
1808 memset(&psToAddr, 0, sizeof(psToAddr));
1809 psToAddr.sin_family = AF_INET;
1810 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1811 psToAddr.sin_port = htons(12346);
1812
1813
1814 switch (setwmm->trig_ac)
1815 {
1816 case WMMAC_AC_VO:
1817 wfaTGSetPrio(Sockfd, 7);
1818 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1819 printf("\r\nSending AC_VO trigger packet\n");
1820 break;
1821
1822 case WMMAC_AC_VI:
1823 wfaTGSetPrio(Sockfd, 5);
1824 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1825 printf("\r\nSending AC_VI trigger packet\n");
1826 break;
1827
1828 case WMMAC_AC_BK:
1829 wfaTGSetPrio(Sockfd, 2);
1830 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1831 printf("\r\nSending AC_BK trigger packet\n");
1832 break;
1833
1834 default:
1835 case WMMAC_AC_BE:
1836 wfaTGSetPrio(Sockfd, 0);
1837 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1838 printf("\r\nSending AC_BE trigger packet\n");
1839 break;
1840 }
1841
1842 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1843 sizeof(struct sockaddr));
1844 close(Sockfd);
1845 usleep(1000000);
1846 }
1847 else if (setwmm->action == WMMAC_ADDTS)
1848 {
1849 //wmmtspec_t* pCmdTspec = &(setwmm->actions.addts.tspec);
1850 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
1851 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1852 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1853 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1854 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1855 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1856 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1857 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1858 setwmm->actions.addts.dialog_token,
1859 setwmm->actions.addts.tspec.tsinfo.TID,
1860 setwmm->actions.addts.tspec.tsinfo.direction,
1861 setwmm->actions.addts.tspec.tsinfo.PSB,
1862 setwmm->actions.addts.tspec.tsinfo.UP,
1863 setwmm->actions.addts.tspec.tsinfo.infoAck,
1864 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1865 setwmm->actions.addts.tspec.Fixed,
1866 setwmm->actions.addts.tspec.size,
1867 setwmm->actions.addts.tspec.maxsize,
1868 setwmm->actions.addts.tspec.min_srvc,
1869 setwmm->actions.addts.tspec.max_srvc,
1870 setwmm->actions.addts.tspec.inactivity,
1871 setwmm->actions.addts.tspec.suspension,
1872 setwmm->actions.addts.tspec.srvc_strt_tim,
1873 setwmm->actions.addts.tspec.mindatarate,
1874 setwmm->actions.addts.tspec.meandatarate,
1875 setwmm->actions.addts.tspec.peakdatarate,
1876 setwmm->actions.addts.tspec.burstsize,
1877 setwmm->actions.addts.tspec.delaybound,
1878 setwmm->actions.addts.tspec.PHYrate,
1879 setwmm->actions.addts.tspec.sba,
1880 setwmm->actions.addts.tspec.medium_time,
1881 setwmm->actions.addts.accesscat);
1882
1883 // you should set your tspec here.
1884
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001885 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001886 }
1887 else if (setwmm->action == WMMAC_DELTS)
1888 {
1889 // send del tspec
1890 }
1891
1892 setwmmResp->status = STATUS_COMPLETE;
1893 break;
1894
1895 case GROUP_WMMCONF:
1896 sprintf(gCmdStr, "iwconfig %s rts %d",
1897 ifname,setwmm->actions.config.rts_thr);
1898
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001899 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001900 sprintf(gCmdStr, "iwconfig %s frag %d",
1901 ifname,setwmm->actions.config.frag_thr);
1902
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001903 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001904 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1905 ifname, setwmm->actions.config.wmm);
1906
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001907 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001908 setwmmResp->status = STATUS_COMPLETE;
1909 break;
1910
1911 default:
1912 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1913 setwmmResp->status = STATUS_ERROR;
1914 break;
1915
1916 }
1917
1918 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1919 *respLen = WFA_TLV_HDR_LEN + 4;
1920#endif
1921
1922 return WFA_SUCCESS;
1923}
1924
1925int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1926{
1927 //dutCommand_t *sendNeigReq = (dutCommand_t *)caCmdBuf;
1928 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
1929
1930 /*
1931 * run your device to send NEIGREQ
1932 */
1933
1934 sendNeigReqResp->status = STATUS_COMPLETE;
1935 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
1936 *respLen = WFA_TLV_HDR_LEN + 4;
1937
1938 return WFA_SUCCESS;
1939}
1940
1941int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1942{
1943 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
1944 char *ifname = setFAST->intf;
1945 dutCmdResponse_t *setEapFastResp = &gGenericResp;
1946
1947#ifdef WFA_NEW_CLI_FORMAT
1948 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
1949 setFAST->passwd, setFAST->pacFileName,
1950 setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001951 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001952#else
1953
1954 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001955 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001956
1957 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001958 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001959
1960 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001961 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001962
1963 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001964 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001965
1966 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
1967 {
1968 }
1969 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
1970 {
1971 }
1972 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
1973 {
1974
1975 }
1976 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
1977 {
1978 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1979 }
1980 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
1981 {
1982 // take all and device to pick one which is supported.
1983 }
1984 else
1985 {
1986 // ??
1987 }
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 eap FAST", ifname);
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 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName);
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 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001997 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001998
1999 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002000 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002001
2002 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002003 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002004
2005 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002006 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002007#endif
2008
2009 setEapFastResp->status = STATUS_COMPLETE;
2010 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2011 *respLen = WFA_TLV_HDR_LEN + 4;
2012
2013 return WFA_SUCCESS;
2014}
2015
2016int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2017{
2018 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2019 char *ifname = setAKA->intf;
2020 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2021
2022#ifdef WFA_NEW_CLI_FORMAT
2023 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002024 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002025#else
2026
2027 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002028 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002029
2030 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002031 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002032
2033 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2034 {
2035 }
2036 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2037 {
2038 }
2039 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2040 {
2041
2042 }
2043 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2044 {
2045 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
2046 }
2047 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2048 {
2049 // take all and device to pick one which is supported.
2050 }
2051 else
2052 {
2053 // ??
2054 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002055 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002056
2057 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002058 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002059 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002060 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002061
2062 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002063 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002064
2065 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002066 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002067
2068 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002069 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002070
2071 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002072 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002073
2074 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002075 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002076#endif
2077
2078 setEapAkaResp->status = STATUS_COMPLETE;
2079 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2080 *respLen = WFA_TLV_HDR_LEN + 4;
2081
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002082 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002083}
2084
2085int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2086{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002087 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2088 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002089
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002090 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002091
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002092 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2093 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002094
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002095 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2096 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002097
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002098 setSystimeResp->status = STATUS_COMPLETE;
2099 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2100 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002101
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002102 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002103}
2104
2105#ifdef WFA_STA_TB
2106int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2107{
2108 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2109 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2110 //int ret;
2111 //char *intfname = presetParams->intf;
2112 BYTE presetDone = 1;
2113 int st = 0;
2114
2115 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
2116
2117 if(presetParams->wmmFlag)
2118 {
2119 st = wfaExecuteCLI(gCmdStr);
2120 switch(st)
2121 {
2122 case 0:
2123 presetDone = 1;
2124 break;
2125 case 1:
2126 presetDone = 0;
2127 break;
2128 case 2:
2129 presetDone = 0;
2130 break;
2131 }
2132 }
2133
2134 if(presetParams->modeFlag != 0)
2135 {
2136 switch(presetParams->wirelessMode)
2137 {
2138 default:
2139 printf("other mode does not need to support\n");
2140 }
2141
2142 st = wfaExecuteCLI(gCmdStr);
2143 switch(st)
2144 {
2145 case 0:
2146 presetDone = 1;
2147 break;
2148 case 1:
2149 presetDone = 0;
2150 case 2:
2151 presetDone = 0;
2152 break;
2153 }
2154 }
2155
2156
2157 if(presetParams->psFlag)
2158 {
2159
2160 printf("%s\n", gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002161 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002162 }
2163
2164 /************the followings are used for Voice Enterprise **************/
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002165 if(presetParams->program == PROG_TYPE_VENT)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002166 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002167 if(presetParams->ftoa == eEnable)
2168 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002169 // enable Fast BSS Transition Over the Air
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002170 }
2171 else
2172 {
2173 // disable Fast BSS Transition Over the Air
2174 }
2175
2176 if(presetParams->ftds == eEnable)
2177 {
2178 // enable Fast BSS Transition Over the DS
2179 }
2180 else
2181 {
2182 // disable Fast BSS Transition Over the DS
2183 }
2184
2185 if(presetParams->activescan == eEnable)
2186 {
2187 // Enable Active Scan on STA
2188 }
2189 else
2190 {
2191 // disable Active Scan on STA
2192 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002193 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002194
2195 /************the followings are used for Wi-Fi Display *************/
2196 if(presetParams->program == PROG_TYPE_WFD)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002197 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002198
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002199 if(presetParams->tdlsFlag)
2200 {
2201 // enable / disable tdls based on tdls
2202 }
2203 if(presetParams->wfdDevTypeFlag)
2204 {
2205 // set WFD device type to source/sink/dual based on wfdDevType
2206 }
2207 if(presetParams->wfdUibcGenFlag)
2208 {
2209 // enable / disable the feature
2210 }
2211 if(presetParams->wfdUibcHidFlag)
2212 {
2213 // enable / disable feature
2214 }
2215 if(presetParams->wfdUiInputFlag)
2216 {
2217 // set the UI input as mentioned
2218 }
2219 if(presetParams->wfdHdcpFlag)
2220 {
2221 // enable / disable feature
2222 }
2223 if(presetParams->wfdFrameSkipFlag)
2224 {
2225 // enable / disable feature
2226 }
2227 if(presetParams->wfdAvChangeFlag)
2228 {
2229 // enable / disable feature
2230 }
2231 if(presetParams->wfdStandByFlag)
2232 {
2233 // enable / disable feature
2234 }
2235 if(presetParams->wfdInVideoFlag)
2236 {
2237 // select the input vide as protecteed or non-protetcted or protected audio
2238 // or unprotected audio etc.
2239 }
2240
2241 if(presetParams->wfdVideoFmatFlag)
2242 {
2243 // set the video format as requested
2244
2245 //switch(presetParams->wfdVideoFmt )
2246 //{
2247 // case e640x480p60:
2248 // ;
2249 // default:
2250 // set the mandatory
2251 // }
2252 }
2253 if(presetParams->wfdAudioFmatFlag)
2254 {
2255 // set the Audio format as requested
2256
2257 //switch(presetParams->wfdAudioFmt )
2258 //{
2259 // case eMandatoryAudioMode:
2260 // ;
2261 // case eDefaultAudioMode:
2262 // ;
2263
2264 // default:
2265 // set the mandatory
2266 // }
2267 }
2268
2269 if(presetParams->wfdI2cFlag)
2270 {
2271 // enable / disable feature
2272 }
2273 if(presetParams->wfdVideoRecoveryFlag)
2274 {
2275 // enable / disable feature
2276 }
2277 if(presetParams->wfdPrefDisplayFlag)
2278 {
2279 // enable / disable feature
2280 }
2281 if(presetParams->wfdServiceDiscoveryFlag)
2282 {
2283 // enable / disable feature
2284 }
2285 if(presetParams->wfd3dVideoFlag)
2286 {
2287 // enable / disable feature
2288 }
2289 if(presetParams->wfdMultiTxStreamFlag)
2290 {
2291 // enable / disable feature
2292 }
2293 if(presetParams->wfdTimeSyncFlag)
2294 {
2295 // enable / disable feature
2296 }
2297 if(presetParams->wfdEDIDFlag)
2298 {
2299 // enable / disable feature
2300 }
2301 if(presetParams->wfdUIBCPrepareFlag)
2302 {
2303 // Provdes information to start valid WFD session to check UIBC operation.
2304 }
2305 if(presetParams->wfdCoupledCapFlag)
2306 {
2307 // enable / disable feature
2308 }
2309 if(presetParams->wfdOptionalFeatureFlag)
2310 {
2311 // disable all program specific optional features
2312 }
2313 if(presetParams->wfdSessionAvailFlag)
2314 {
2315 // enable / disable session available bit
2316 }
2317 if(presetParams->wfdDeviceDiscoverabilityFlag)
2318 {
2319 // enable / disable feature
2320 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002321 }
2322
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002323 if (presetDone)
2324 {
2325 PresetParamsResp->status = STATUS_COMPLETE;
2326 }
2327 else
2328 {
2329 PresetParamsResp->status = STATUS_INVALID;
2330 }
2331
2332 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2333 *respLen = WFA_TLV_HDR_LEN + 4;
2334
2335 return WFA_SUCCESS;
2336}
2337
2338int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2339{
2340 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2341
2342 v11nParamsResp->status = STATUS_COMPLETE;
2343 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2344 *respLen = WFA_TLV_HDR_LEN + 4;
2345 return WFA_SUCCESS;
2346}
2347int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2348{
2349 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2350
2351 staWirelessResp->status = STATUS_COMPLETE;
2352 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2353 *respLen = WFA_TLV_HDR_LEN + 4;
2354 return WFA_SUCCESS;
2355}
2356
2357int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2358{
2359 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2360
2361 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2362 *respLen = WFA_TLV_HDR_LEN + 4;
2363 return WFA_SUCCESS;
2364}
2365
2366int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2367{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002368 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002369
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002370 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2371 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002372
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002373 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002374}
2375
2376int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2377{
2378 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2379
2380 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2381 *respLen = WFA_TLV_HDR_LEN + 4;
2382
2383 return WFA_SUCCESS;
2384
2385}
2386
2387int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2388{
2389 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2390 dutCmdResponse_t *ResetResp = &gGenericResp;
2391
2392
2393 // need to make your own command available for this, here is only an example
2394 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002395 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002396
2397 ResetResp->status = STATUS_COMPLETE;
2398 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2399 *respLen = WFA_TLV_HDR_LEN + 4;
2400
2401 return WFA_SUCCESS;
2402}
2403
2404#else
2405
2406int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2407{
2408 dutCmdResponse_t *staCmdResp = &gGenericResp;
2409
2410 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2411 *respLen = WFA_TLV_HDR_LEN + 4;
2412
2413 return WFA_SUCCESS;
2414}
2415#endif
2416
2417/*
2418 * This is used to send a frame or action frame
2419 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002420int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002421{
2422 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2423 /* uncomment it if needed */
2424 // char *ifname = cmd->intf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002425 dutCmdResponse_t *devSendResp = &gGenericResp;
2426 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002427
Ankur Vachhanic485b712012-02-15 23:29:49 +00002428 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002429 /* processing the frame */
2430
Ankur Vachhanic485b712012-02-15 23:29:49 +00002431 switch(sf->program)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002432 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00002433 case PROG_TYPE_PMF:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002434 {
2435 pmfFrame_t *pmf = &sf->frameType.pmf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002436 switch(pmf->eFrameName)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002437 {
2438 case PMF_TYPE_DISASSOC:
2439 {
2440 /* use the protected to set what type of key to send */
2441
2442 }
2443 break;
2444 case PMF_TYPE_DEAUTH:
2445 {
2446
2447 }
2448 break;
2449 case PMF_TYPE_SAQUERY:
2450 {
2451
2452 }
2453 break;
2454 case PMF_TYPE_AUTH:
2455 {
2456 }
2457 break;
2458 case PMF_TYPE_ASSOCREQ:
2459 {
2460 }
2461 break;
2462 case PMF_TYPE_REASSOCREQ:
2463 {
2464 }
2465 break;
2466 }
2467 }
2468 break;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002469 case PROG_TYPE_TDLS:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002470 {
2471 tdlsFrame_t *tdls = &sf->frameType.tdls;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002472 switch(tdls->eFrameName)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002473 {
2474 case TDLS_TYPE_DISCOVERY:
2475 /* use the peer mac address to send the frame */
2476 break;
2477 case TDLS_TYPE_SETUP:
2478 break;
2479 case TDLS_TYPE_TEARDOWN:
2480 break;
2481 case TDLS_TYPE_CHANNELSWITCH:
2482 break;
2483 case TDLS_TYPE_NULLFRAME:
2484 break;
2485 }
2486 }
2487 break;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002488 case PROG_TYPE_VENT:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002489 {
2490 ventFrame_t *vent = &sf->frameType.vent;
2491 switch(vent->type)
2492 {
2493 case VENT_TYPE_NEIGREQ:
2494 break;
2495 case VENT_TYPE_TRANSMGMT:
2496 break;
2497 }
2498 }
Dake Zhao97708202014-11-26 13:59:04 -08002499 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002500 case PROG_TYPE_WFD:
2501 {
2502 wfdFrame_t *wfd = &sf->frameType.wfd;
2503 switch(wfd->eframe)
2504 {
2505 case WFD_FRAME_PRBREQ:
2506 {
2507 /* send probe req */
2508 }
2509 break;
2510
2511 case WFD_FRAME_PRBREQ_TDLS_REQ:
2512 {
2513 /* send tunneled tdls probe req */
2514 }
2515 break;
2516
2517 case WFD_FRAME_11V_TIMING_MSR_REQ:
2518 {
2519 /* send 11v timing mearurement request */
2520 }
2521 break;
2522
2523 case WFD_FRAME_RTSP:
2524 {
2525 /* send WFD RTSP messages*/
2526 // fetch the type of RTSP message and send it.
2527 switch(wfd->eRtspMsgType)
2528 {
2529 case WFD_RTSP_PAUSE:
2530 break;
2531 case WFD_RTSP_PLAY:
2532 //send RTSP PLAY
2533 break;
Dake Zhao97708202014-11-26 13:59:04 -08002534 case WFD_RTSP_TEARDOWN:
2535 //send RTSP TEARDOWN
2536 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002537 case WFD_RTSP_TRIG_PAUSE:
2538 //send RTSP TRIGGER PAUSE
2539 break;
2540 case WFD_RTSP_TRIG_PLAY:
2541 //send RTSP TRIGGER PLAY
2542 break;
2543 case WFD_RTSP_TRIG_TEARDOWN:
2544 //send RTSP TRIGGER TEARDOWN
2545 break;
2546 case WFD_RTSP_SET_PARAMETER:
2547 //send RTSP SET PARAMETER
2548 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2549 {
2550 //send RTSP SET PARAMETER message for UIBC keyboard
2551 }
2552 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2553 {
2554 //send RTSP SET PARAMETER message for UIBC Mouse
2555 }
2556 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2557 {
2558 //send RTSP SET PARAMETER message Capability re-negotiation
2559 }
2560 else if (wfd->eSetParams == WFD_STANDBY)
2561 {
2562 //send RTSP SET PARAMETER message for standby
2563 }
2564 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2565 {
2566 //send RTSP SET PARAMETER message for UIBC settings enable
2567 }
2568 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2569 {
2570 //send RTSP SET PARAMETER message for UIBC settings disable
2571 }
2572 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2573 {
2574 //send RTSP SET PARAMETER message for route audio
2575 }
2576 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2577 {
2578 //send RTSP SET PARAMETER message for 3D video parameters
2579 }
2580 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2581 {
2582 //send RTSP SET PARAMETER message for 2D video parameters
2583 }
2584 break;
2585 }
2586 }
2587 break;
2588 }
2589 }
Dake Zhao97708202014-11-26 13:59:04 -08002590 break;
2591 /* not need to support HS2 release 1, due to very short time period */
2592 case PROG_TYPE_HS2_R2:
2593 {
2594 /* type of frames */
2595 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2596 switch(hs2->eframe)
2597 {
2598 case HS2_FRAME_ANQPQuery:
2599 {
2600
2601 }
2602 break;
2603 case HS2_FRAME_DLSRequest:
2604 {
2605
2606 }
2607 break;
2608 case HS2_FRAME_GARPReq:
2609 {
2610
2611 }
2612 break;
2613 case HS2_FRAME_GARPRes:
2614 {
2615 }
2616 break;
2617 case HS2_FRAME_NeighAdv:
2618 {
2619 }
2620 case HS2_FRAME_ARPProbe:
2621 {
2622 }
2623 case HS2_FRAME_ARPAnnounce:
2624 {
2625
2626 }
2627 break;
2628 case HS2_FRAME_NeighSolicitReq:
2629 {
2630
2631 }
2632 break;
2633 case HS2_FRAME_ARPReply:
2634 {
2635
2636 }
2637 break;
2638 }
2639
2640 }/* PROG_TYPE_HS2-R2 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002641 case PROG_TYPE_GEN:
2642 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002643 /* General frames */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002644 }
2645
2646
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002647 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00002648 devSendResp->status = STATUS_COMPLETE;
2649 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002650 *respLen = WFA_TLV_HDR_LEN + 4;
2651
2652 return WFA_SUCCESS;
2653}
2654
2655/*
2656 * This is used to set a temporary MAC address of an interface
2657 */
2658int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2659{
2660 // Uncomment it if needed
2661 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2662 // char *ifname = cmd->intf;
2663 dutCmdResponse_t *staCmdResp = &gGenericResp;
2664 // Uncomment it if needed
2665 //char *macaddr = &cmd->cmdsu.macaddr[0];
2666
2667 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2668 *respLen = WFA_TLV_HDR_LEN + 4;
2669
2670 return WFA_SUCCESS;
2671}
2672
2673
2674int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2675{
2676 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2677 //char *intf = disc->intf;
2678 dutCmdResponse_t *staDiscResp = &gGenericResp;
2679
2680 // stop the supplicant
2681
2682 staDiscResp->status = STATUS_COMPLETE;
2683
2684 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2685 *respLen = WFA_TLV_HDR_LEN + 4;
2686
2687 return WFA_SUCCESS;
2688}
2689
2690/* Execute CLI, read the status from Environment variable */
2691int wfaExecuteCLI(char *CLI)
2692{
2693 char *retstr;
2694
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002695 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002696
2697 retstr = getenv("WFA_CLI_STATUS");
2698 printf("cli status %s\n", retstr);
2699 return atoi(retstr);
2700}
2701
2702/* Supporting Functions */
2703
2704void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2705{
Dake Zhao97708202014-11-26 13:59:04 -08002706 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002707 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002708// char *addr = staPing->dipaddr;
2709#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002710 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002711 char bflag[] = "-b";
2712 char *tmpstr;
2713 int inum=0;
2714#else
2715 char bflag[] = " ";
2716#endif
Ray Wang2b24ffc2014-03-27 12:33:22 -07002717
Ray Wang9b47f362014-03-19 16:51:10 -07002718 totalpkts = (int)(staPing->duration * staPing->frameRate);
Ray Wang2b24ffc2014-03-27 12:33:22 -07002719
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002720#ifdef WFA_PC_CONSOLE
2721
2722 printf("\nCS : The Stream ID is %d",streamid);
2723 printf("\nCS :the addr is %s ",addr);
2724 strcpy(addr,staPing->dipaddr);
2725 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2726 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002727 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002728 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002729 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002730 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002731 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002732 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002733 tmpstr = strtok(addr, ".");
2734 inum = atoi(tmpstr);
2735
2736 printf("interval %f\n", *interval);
2737
2738 if(inum >= 224 && inum <= 239) // multicast
2739 {
2740 }
2741 else // if not MC, check if it is BC address
2742 {
2743 printf("\nCS :Inside the BC address BLOCK");
2744 printf("\nCS :the inum %d",inum);
2745 strtok(NULL, ".");
2746 //strtok(NULL, ".");
2747 tmpstr = strtok(NULL, ".");
2748 printf("tmpstr %s\n", tmpstr);
2749 inum = atoi(tmpstr);
2750 printf("\nCS : The string is %s",tmpstr);
2751 if(inum != 255)
2752 memset(bflag, 0, strlen(bflag));
2753 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002754 }
2755#endif
Dake Zhao97708202014-11-26 13:59:04 -08002756 if ( staPing->dscp >= 0)
2757 {
2758 tos= convertDscpToTos(staPing->dscp);
2759 if (tos < 0)
2760 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2761 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002762 printf("\nCS : The Stream ID is %d",streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002763 printf("IPtype : %i tos=%d",staPing->iptype, tos);
2764
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002765 if (staPing->iptype == 2)
2766 {
Dake Zhao97708202014-11-26 13:59:04 -08002767 if ( tos>0)
2768 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",
2769 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
2770 else
2771 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",
2772 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002773 sret = system(cmdStr);
2774 printf("\nCS : The command string is %s",cmdStr);
2775 }
2776 else
2777 {
Dake Zhao97708202014-11-26 13:59:04 -08002778 if (tos > 0)
2779 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",
2780 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
2781 else
2782 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 -08002783 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
2784 sret = system(cmdStr);
2785 printf("\nCS : The command string is %s",cmdStr);
2786 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002787 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002788 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002789 printf("\nCS : The command string is %s",cmdStr);
2790
2791}
2792
2793int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2794{
2795 char strout[256];
2796 FILE *tmpfile = NULL;
2797 char cmdStr[128];
2798 printf("Ping stop id %d\n", streamid);
2799 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002800 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002801
2802 printf("\nCS : The command string is %s",cmdStr);
2803
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002804 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002805
2806 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002807 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002808
2809 printf("\nCS : The command string is %s",cmdStr);
2810
2811 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2812
2813 if(tmpfile == NULL)
2814 {
2815 return WFA_FAILURE;
2816 }
2817
2818 if(fscanf(tmpfile, "%s", strout) != EOF)
2819 {
2820 if(*strout == '\0')
2821 {
2822 stpResp->cmdru.pingStp.sendCnt = 0;
2823 }
2824
2825 else
2826 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2827 }
2828
2829 printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
2830
2831
2832 if(fscanf(tmpfile, "%s", strout) != EOF)
2833 {
2834 if(*strout == '\0')
2835 {
2836 stpResp->cmdru.pingStp.repliedCnt = 0;
2837 }
2838 else
2839 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2840 }
2841 printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
2842
2843 fclose(tmpfile);
2844
2845 return WFA_SUCCESS;
2846}
2847
Ankur Vachhanic485b712012-02-15 23:29:49 +00002848/*
2849 * wfaStaGetP2pDevAddress():
2850 */
2851int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2852{
2853 dutCmdResponse_t infoResp;
2854 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
2855
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002856 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002857
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002858 // Fetch the device ID and store into infoResp->cmdru.devid
2859 //strcpy(infoResp->cmdru.devid, str);
2860 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002861
2862 infoResp.status = STATUS_COMPLETE;
2863 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2864 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2865
2866 return WFA_SUCCESS;
2867}
2868
2869
2870
2871/*
2872 * wfaStaSetP2p():
2873 */
2874int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2875{
2876 dutCmdResponse_t infoResp;
2877 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
2878
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002879 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002880
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002881 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002882
2883 infoResp.status = STATUS_COMPLETE;
2884 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2885 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2886
2887 return WFA_SUCCESS;
2888}
2889/*
2890 * wfaStaP2pConnect():
2891 */
2892int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2893{
2894 dutCmdResponse_t infoResp;
2895 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
2896
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002897 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002898
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002899 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002900
2901
2902 infoResp.status = STATUS_COMPLETE;
2903 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2904 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2905
2906 return WFA_SUCCESS;
2907}
2908
2909/*
2910 * wfaStaStartAutoGo():
2911 */
2912int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2913{
2914 dutCmdResponse_t infoResp;
2915 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
2916
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002917 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002918
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002919 // Fetch the group ID and store into infoResp->cmdru.grpid
2920 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002921
2922 infoResp.status = STATUS_COMPLETE;
2923 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2924 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2925
2926 return WFA_SUCCESS;
2927}
2928
2929
2930
2931
2932/*
2933 * wfaStaP2pStartGrpFormation():
2934 */
2935int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2936{
2937 dutCmdResponse_t infoResp;
2938 //caStaP2pStartGrpForm_t *getStaP2pStartGrpForm = (caStaP2pStartGrpForm_t *)caCmdBuf;
2939
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002940 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002941
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002942 // Fetch the device mode and put in infoResp->cmdru.p2presult
2943 //strcpy(infoResp->cmdru.p2presult, "GO");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002944
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002945 // Fetch the device grp id and put in infoResp->cmdru.grpid
2946 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
2947
2948 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
2949 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002950
2951
2952 infoResp.status = STATUS_COMPLETE;
2953 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2954 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2955
2956 return WFA_SUCCESS;
2957}
2958
2959
2960/*
2961 * wfaStaP2pDissolve():
2962 */
2963int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2964{
2965 dutCmdResponse_t infoResp;
2966 //caStaP2pDissolve_t *getStap2pDissolve= (caStaP2pDissolve_t *)caCmdBuf;
2967
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002968 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002969
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002970 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002971
2972 infoResp.status = STATUS_COMPLETE;
2973 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2974 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2975
2976 return WFA_SUCCESS;
2977}
2978
2979/*
2980 * wfaStaSendP2pInvReq():
2981 */
2982int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2983{
2984 dutCmdResponse_t infoResp;
2985 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
2986
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002987 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002988
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002989 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002990
2991 infoResp.status = STATUS_COMPLETE;
2992 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2993 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2994
2995 return WFA_SUCCESS;
2996}
2997
2998
2999/*
3000 * wfaStaAcceptP2pInvReq():
3001 */
3002int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3003{
3004 dutCmdResponse_t infoResp;
3005 /* uncomment and use it
3006 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3007 */
3008
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003009 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003010
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003011 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003012
3013 infoResp.status = STATUS_COMPLETE;
3014 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3015 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3016
3017 return WFA_SUCCESS;
3018}
3019
3020
3021/*
3022 * wfaStaSendP2pProvDisReq():
3023 */
3024int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3025{
3026 dutCmdResponse_t infoResp;
3027 /* uncomment and use it
3028 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3029 */
3030
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003031 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003032
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003033 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003034
3035 infoResp.status = STATUS_COMPLETE;
3036 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3037 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3038
3039 return WFA_SUCCESS;
3040}
3041
3042/*
3043 * wfaStaSetWpsPbc():
3044 */
3045int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3046{
3047 dutCmdResponse_t infoResp;
3048 /* uncomment and use it
3049 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3050 */
3051
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003052 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003053
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003054 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003055
3056 infoResp.status = STATUS_COMPLETE;
3057 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3058 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3059
3060 return WFA_SUCCESS;
3061}
3062
3063/*
3064 * wfaStaWpsReadPin():
3065 */
3066int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3067{
3068 dutCmdResponse_t infoResp;
3069 /* uncomment and use it
3070 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3071 */
3072
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003073 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003074
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003075 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3076 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3077 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003078
3079
3080 infoResp.status = STATUS_COMPLETE;
3081 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3082 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3083
3084 return WFA_SUCCESS;
3085}
3086
3087
3088
3089/*
3090 * wfaStaWpsReadLabel():
3091 */
3092int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3093{
3094 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003095
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003096 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003097
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003098 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3099 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3100 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003101
3102
3103 infoResp.status = STATUS_COMPLETE;
3104 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3105 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3106
3107 return WFA_SUCCESS;
3108}
3109
3110
3111/*
3112 * wfaStaWpsEnterPin():
3113 */
3114int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3115{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003116 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003117 /* uncomment and use it
3118 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3119 */
3120
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003121 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003122
3123 // Implement the function and this does not return any thing back.
3124
3125
3126 infoResp.status = STATUS_COMPLETE;
3127 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3128 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3129
3130 return WFA_SUCCESS;
3131}
3132
3133
3134/*
3135 * wfaStaGetPsk():
3136 */
3137int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3138{
3139 dutCmdResponse_t infoResp;
3140 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
3141
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003142 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003143
3144
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003145 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3146 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3147 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3148 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003149
3150
3151 infoResp.status = STATUS_COMPLETE;
3152 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3153 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3154
3155 return WFA_SUCCESS;
3156}
3157
3158/*
3159 * wfaStaP2pReset():
3160 */
3161int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3162{
3163 dutCmdResponse_t infoResp;
3164 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
3165
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003166 printf("\n Entry wfaStaP2pReset... ");
3167 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003168
3169 infoResp.status = STATUS_COMPLETE;
3170 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3171 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3172
3173 return WFA_SUCCESS;
3174}
3175
3176
3177
3178/*
3179 * wfaStaGetP2pIpConfig():
3180 */
3181int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3182{
3183 dutCmdResponse_t infoResp;
3184 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
3185
3186 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
3187
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003188 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003189
3190
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003191 // Fetch the device IP config and put in infoResp->cmdru
3192 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3193 ifinfo->isDhcp =0;
3194 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3195 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3196 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3197 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003198
3199 infoResp.status = STATUS_COMPLETE;
3200 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3201 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3202
3203 return WFA_SUCCESS;
3204}
3205
3206
3207
3208
3209/*
3210 * wfaStaSendServiceDiscoveryReq():
3211 */
3212int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3213{
3214 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003215
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003216 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3217 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003218
3219
3220 infoResp.status = STATUS_COMPLETE;
3221 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3222 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3223
3224 return WFA_SUCCESS;
3225}
3226
3227
3228
3229/*
3230 * wfaStaSendP2pPresenceReq():
3231 */
3232int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3233{
3234 dutCmdResponse_t infoResp;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003235 //caStaSendP2pPresenceReq_t *staSendP2pPresenceReq= (caStaSendP2pPresenceReq_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003236
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003237 //printf("\n Entry wfaStaSendP2pPresenceReq... ");
3238 //printf("\n The long long Duration: %lld... ",staSendP2pPresenceReq->duration);
3239 //printf("\n The long long interval : %lld.. ",staSendP2pPresenceReq->interval);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003240
Ankur Vachhanic485b712012-02-15 23:29:49 +00003241 infoResp.status = STATUS_COMPLETE;
3242 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3243 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3244
3245 return WFA_SUCCESS;
3246}
3247
3248/*
3249 * wfaStaSetSleepReq():
3250 */
3251int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3252{
3253 dutCmdResponse_t infoResp;
3254 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
3255
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003256 printf("\n Entry wfaStaSetSleepReq... ");
3257 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003258
3259
3260 infoResp.status = STATUS_COMPLETE;
3261 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3262 *respLen = WFA_TLV_HDR_LEN +4;
3263
3264 return WFA_SUCCESS;
3265}
3266
3267/*
3268 * wfaStaSetOpportunisticPsReq():
3269 */
3270int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3271{
3272 dutCmdResponse_t infoResp;
3273 /* caStaSetOpprPs_t *staSetOpperPsReq= (caStaSetOpprPs_t *)caCmdBuf; uncomment and use it */
3274
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003275 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3276 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003277
3278
3279 infoResp.status = STATUS_COMPLETE;
3280 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3281 *respLen = WFA_TLV_HDR_LEN + 4;
3282
3283 return WFA_SUCCESS;
3284}
3285#ifndef WFA_STA_TB
3286/*
3287 * wfaStaPresetParams():
3288 */
3289
3290int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3291{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003292 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003293
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003294 //caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003295
3296
3297 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
3298
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003299 // Implement the function and its sub commands
3300 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003301
3302 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3303 *respLen = WFA_TLV_HDR_LEN + 4;
3304
3305 return WFA_SUCCESS;
3306}
3307int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3308{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003309
3310 dutCmdResponse_t infoResp;
3311 dutCmdResponse_t *v11nParamsResp = &infoResp;
3312
3313#ifdef WFA_11N_SUPPORT_ONLY
Ankur Vachhanic485b712012-02-15 23:29:49 +00003314
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003315 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3316
3317 int st =0; // SUCCESS
Ankur Vachhanic485b712012-02-15 23:29:49 +00003318
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003319 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003320
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003321 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3322 {
3323 // implement the funciton
3324 //st = wfaExecuteCLI(gCmdStr);
3325 if(st != 0)
3326 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003327 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003328 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3329 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3330 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3331 return FALSE;
3332 }
3333 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003334
3335 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003336 {
3337 // implement the funciton
3338 //st = wfaExecuteCLI(gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003339
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003340 if(st != 0)
3341 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003342 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003343 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3344 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3345 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3346 return FALSE;
3347 }
3348 }
3349
Ankur Vachhanic485b712012-02-15 23:29:49 +00003350 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003351 {
3352 // implement the funciton
3353 //st = wfaExecuteCLI(gCmdStr);
3354 if(st != 0)
3355 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003356 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003357 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3358 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3359 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3360 return FALSE;
3361 }
3362 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003363
3364 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003365 {
3366 // implement the funciton
3367 //st = wfaExecuteCLI(gCmdStr);
3368 if(st != 0)
3369 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003370 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003371 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3372 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3373 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3374 return FALSE;
3375 }
3376 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003377
3378 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003379 {
3380 // implement the funciton
3381 //st = wfaExecuteCLI(gCmdStr);
3382 if(st != 0)
3383 {
3384 v11nParamsResp->status = STATUS_ERROR;
3385 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3386 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3387 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3388 return FALSE;
3389 }
3390 }
3391 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3392 {
3393 // implement the funciton
3394 //st = wfaExecuteCLI(gCmdStr);
3395 if(st != 0)
3396 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003397 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003398 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
3399 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3400 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3401 return FALSE;
3402 }
3403 }
3404 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3405 {
3406 // implement the funciton
3407 //st = wfaExecuteCLI(gCmdStr);
3408 if(st != 0)
3409 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003410 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003411 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
3412 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3413 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3414 return FALSE;
3415 }
3416 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003417
3418 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003419 {
3420 // implement the funciton
3421 //st = wfaExecuteCLI(gCmdStr);
3422 if(st != 0)
3423 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003424 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003425 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
3426 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3427 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3428 return FALSE;
3429 }
3430 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003431
3432 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003433 {
3434 // implement the funciton
3435 //st = wfaExecuteCLI(gCmdStr);
3436 if(st != 0)
3437 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003438 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003439 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3440 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3441 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3442 return FALSE;
3443 }
3444 }
3445
3446 if(v11nParams->smps != 0xFFFF)
3447 {
3448 if(v11nParams->smps == 0)
3449 {
3450 // implement the funciton
3451 //st = wfaExecuteCLI(gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003452 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003453 else if(v11nParams->smps == 1)
3454 {
3455 // implement the funciton
3456 //st = wfaExecuteCLI(gCmdStr);
3457 ;
3458 }
3459 else if(v11nParams->smps == 2)
3460 {
3461 // implement the funciton
3462 //st = wfaExecuteCLI(gCmdStr);
3463 ;
3464 }
3465 if(st != 0)
3466 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003467 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003468 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3469 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3470 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3471 return FALSE;
3472 }
3473 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003474
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003475 if(v11nParams->stbc_rx != 0xFFFF)
3476 {
3477 // implement the funciton
3478 //st = wfaExecuteCLI(gCmdStr);
3479 if(st != 0)
3480 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003481 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003482 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
3483 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3484 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3485 return FALSE;
3486 }
3487 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003488
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003489 if(v11nParams->width[0] != '\0')
3490 {
3491 // implement the funciton
3492 //st = wfaExecuteCLI(gCmdStr);
3493 if(st != 0)
3494 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003495 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003496 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3497 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3498 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3499 return FALSE;
3500 }
3501 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003502
3503 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003504 {
3505 // implement the funciton
3506 //st = wfaExecuteCLI(gCmdStr);
3507 if(st != 0)
3508 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003509 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003510 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3511 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3512 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3513 return FALSE;
3514 }
3515 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003516
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003517 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3518 {
3519 // implement the funciton
3520 //st = wfaExecuteCLI(gCmdStr);
3521 if(st != 0)
3522 {
3523 v11nParamsResp->status = STATUS_ERROR;
3524 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
3525 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3526 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3527 return FALSE;
3528 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003529
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003530 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003531
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003532 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3533 {
3534 // implement the funciton
3535 //st = wfaExecuteCLI(gCmdStr);
3536 if(st != 0)
3537 {
3538 v11nParamsResp->status = STATUS_ERROR;
3539 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3540 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3541 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3542 return FALSE;
3543 }
3544 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003545
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003546#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003547
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003548 v11nParamsResp->status = STATUS_COMPLETE;
3549 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3550 *respLen = WFA_TLV_HDR_LEN + 4;
3551 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003552}
3553#endif
3554/*
3555 * wfaStaAddArpTableEntry():
3556 */
3557int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3558{
3559 dutCmdResponse_t infoResp;
3560 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
3561
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003562 printf("\n Entry wfastaAddARPTableEntry... ");
3563 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003564
3565 infoResp.status = STATUS_COMPLETE;
3566 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3567 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3568
3569 return WFA_SUCCESS;
3570}
3571
3572/*
3573 * wfaStaBlockICMPResponse():
3574 */
3575int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3576{
3577 dutCmdResponse_t infoResp;
3578 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
3579
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003580 printf("\n Entry wfaStaBlockICMPResponse... ");
3581 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003582
3583 infoResp.status = STATUS_COMPLETE;
3584 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3585 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3586
3587 return WFA_SUCCESS;
3588}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003589
3590/*
3591 * wfaStaSetRadio():
3592 */
3593
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003594int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3595{
3596 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3597 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003598 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3599
3600 if(sr->mode == WFA_OFF)
3601 {
3602 // turn radio off
3603 }
3604 else
3605 {
3606 // always turn the radio on
3607 }
3608
3609 staCmdResp->status = STATUS_COMPLETE;
3610 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3611 *respLen = WFA_TLV_HDR_LEN + 4;
3612
3613 return WFA_SUCCESS;
3614}
3615
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003616/*
3617 * wfaStaSetRFeature():
3618 */
3619
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003620int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3621{
3622 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3623 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3624 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003625
3626 if(strcasecmp(rfeat->prog, "tdls") == 0)
3627 {
3628
3629
3630 }
3631
3632 caResp->status = STATUS_COMPLETE;
3633 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3634 *respLen = WFA_TLV_HDR_LEN + 4;
3635
3636 return WFA_SUCCESS;
3637}
3638
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003639/*
3640 * wfaStaStartWfdConnection():
3641 */
3642int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3643{
3644 dutCmdResponse_t infoResp;
3645 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
3646
3647 printf("\n Entry wfaStaStartWfdConnection... ");
3648
3649
3650 // Fetch the GrpId and WFD session and return
3651 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3652 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3653 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3654
3655 infoResp.status = STATUS_COMPLETE;
3656 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3657 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3658
3659 return WFA_SUCCESS;
3660}
3661/*
3662 * wfaStaCliCommand():
3663 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003664
Ankur Vachhanic485b712012-02-15 23:29:49 +00003665int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3666{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003667 char cmdName[32];
3668 char *pcmdStr=NULL, *str;
Dake Zhao97708202014-11-26 13:59:04 -08003669 int st = 1;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003670 char CmdStr[WFA_CMD_STR_SZ];
3671 FILE *wfaCliFd;
3672 char wfaCliBuff[64];
3673 char retstr[256];
Dake Zhao97708202014-11-26 13:59:04 -08003674 int CmdReturnFlag =0;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003675 char tmp[256];
3676 FILE * sh_pipe;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003677 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003678
Dake Zhao97708202014-11-26 13:59:04 -08003679 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003680 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003681 sprintf(CmdStr, "%s",cmdName);
3682
3683 for(;;)
Dake Zhao97708202014-11-26 13:59:04 -08003684 {// construct CLI standard cmd string
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003685 str = strtok_r(NULL, ",", &pcmdStr);
3686 if(str == NULL || str[0] == '\0')
3687 break;
3688 else
3689 {
3690 sprintf(CmdStr, "%s /%s",CmdStr,str);
3691 str = strtok_r(NULL, ",", &pcmdStr);
3692 sprintf(CmdStr, "%s %s",CmdStr,str);
3693 }
3694 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003695 // check the return process
3696 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3697 if(wfaCliFd!= NULL)
3698 {
3699 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3700 {
3701 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3702 if(ferror(wfaCliFd))
3703 break;
3704
3705 str=strtok(wfaCliBuff,"-");
3706 if(strcmp(str,cmdName) == 0)
3707 {
3708 str=strtok(NULL,",");
Dake Zhao97708202014-11-26 13:59:04 -08003709 if (str != NULL)
3710 {
3711 if(strcmp(str,"TRUE") == 0)
3712 CmdReturnFlag =1;
3713 }
3714 else
3715 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003716 break;
3717 }
3718 }
3719 fclose(wfaCliFd);
3720 }
Dake Zhao97708202014-11-26 13:59:04 -08003721 else
3722 {
3723 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3724 goto cleanup;
3725 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003726
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003727 //printf("\n Command Return Flag : %d",CmdReturnFlag);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003728 memset(&retstr[0],'\0',255);
3729 memset(&tmp[0],'\0',255);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003730 sprintf(gCmdStr, "%s", CmdStr);
3731 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003732
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003733 sh_pipe = popen(gCmdStr,"r");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003734 if(!sh_pipe)
3735 {
Dake Zhao97708202014-11-26 13:59:04 -08003736 printf ("Error in opening pipe\n");
3737 goto cleanup;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003738 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003739
Dake Zhao97708202014-11-26 13:59:04 -08003740 sleep(5);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003741 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3742 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3743 {
Dake Zhao97708202014-11-26 13:59:04 -08003744 printf("Getting NULL string in popen return\n");
3745 goto cleanup;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003746 }
Dake Zhao97708202014-11-26 13:59:04 -08003747 else
3748 printf("popen return str=%s\n",retstr);
3749
3750 sleep(2);
3751 if(pclose(sh_pipe) == -1)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003752 {
Dake Zhao97708202014-11-26 13:59:04 -08003753 printf("Error in closing shell cmd pipe\n");
3754 goto cleanup;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003755 }
3756 sleep(2);
Dake Zhao97708202014-11-26 13:59:04 -08003757
3758 // find status first in output
3759 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3760 if (str != NULL)
3761 {
3762 memset(tmp, 0, 10);
3763 memcpy(tmp, str, 2);
3764 printf("cli status=%s\n",tmp);
3765 if(strlen(tmp) > 0)
3766 st = atoi(tmp);
3767 else printf("Missing status code\n");
3768 }
3769 else
3770 {
3771 printf("wfaStaCliCommand no return code found\n");
3772 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003773 infoResp.resFlag=CmdReturnFlag;
Dake Zhao97708202014-11-26 13:59:04 -08003774
3775cleanup:
3776
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003777 switch(st)
3778 {
3779 case 0:
3780 infoResp.status = STATUS_COMPLETE;
3781 if (CmdReturnFlag)
3782 {
Dake Zhao97708202014-11-26 13:59:04 -08003783 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003784 {
Dake Zhao97708202014-11-26 13:59:04 -08003785 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
3786 strncpy(&infoResp.result[0], pcmdStr ,(strlen(pcmdStr) < WFA_CLI_CMD_RESP_LEN ) ? strlen(pcmdStr) : (WFA_CLI_CMD_RESP_LEN-2) );
3787 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003788 }
3789 else
Dake Zhao97708202014-11-26 13:59:04 -08003790 {
3791 strcpy(&infoResp.result[0], "No return string found\n");
3792 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003793 }
3794 break;
3795 case 1:
3796 infoResp.status = STATUS_ERROR;
3797 break;
3798 case 2:
3799 infoResp.status = STATUS_INVALID;
3800 break;
3801 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003802
3803 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3804 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3805
Dake Zhao97708202014-11-26 13:59:04 -08003806 printf("Exit from wfaStaCliCommand\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003807 return TRUE;
3808
Ankur Vachhanic485b712012-02-15 23:29:49 +00003809}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003810/*
3811 * wfaStaConnectGoStartWfd():
3812 */
3813
3814int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3815{
3816 dutCmdResponse_t infoResp;
3817// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
3818
3819 printf("\n Entry wfaStaConnectGoStartWfd... ");
3820
3821 // connect the specified GO and then establish the wfd session
3822
3823 // Fetch WFD session and return
3824 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3825
3826 infoResp.status = STATUS_COMPLETE;
3827 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3828 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3829
3830 return WFA_SUCCESS;
3831}
3832
3833/*
3834 * wfaStaGenerateEvent():
3835 */
3836
3837int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3838{
3839 dutCmdResponse_t infoResp;
3840 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3841 caWfdStaGenEvent_t *wfdGenEvent;
3842
3843 printf("\n Entry wfaStaGenerateEvent... ");
3844
3845
3846 // Geneate the specified action and return with complete/error.
3847 if(staGenerateEvent->program == PROG_TYPE_WFD)
3848 {
3849 wfdGenEvent = &staGenerateEvent->wfdEvent;
3850 if(wfdGenEvent ->type == eUibcGen)
3851 {
3852 }
3853 else if(wfdGenEvent ->type == eUibcHid)
3854 {
3855 }
3856 else if(wfdGenEvent ->type == eFrameSkip)
3857 {
3858
3859 }
3860 else if(wfdGenEvent ->type == eI2cRead)
3861 {
3862 }
3863 else if(wfdGenEvent ->type == eI2cWrite)
3864 {
3865 }
3866 else if(wfdGenEvent ->type == eInputContent)
3867 {
3868 }
3869 else if(wfdGenEvent ->type == eIdrReq)
3870 {
3871 }
3872 }
3873
3874 infoResp.status = STATUS_COMPLETE;
3875 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3876 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3877
3878 return WFA_SUCCESS;
3879}
3880
3881
3882
3883
3884/*
3885 * wfaStaReinvokeWfdSession():
3886 */
3887
3888int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3889{
3890 dutCmdResponse_t infoResp;
3891// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
3892
3893 printf("\n Entry wfaStaReinvokeWfdSession... ");
3894
3895 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
3896
3897
3898 infoResp.status = STATUS_COMPLETE;
3899 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3900 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3901
3902 return WFA_SUCCESS;
3903}
3904
3905
3906int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3907{
3908 dutCmdResponse_t infoResp;
3909 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
3910
3911
3912 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
3913
3914 printf("\n Entry wfaStaGetParameter... ");
3915
3916 // Check the program type
3917 if(staGetParam->program == PROG_TYPE_WFD)
3918 {
3919 if(staGetParam->getParamValue == eDiscoveredDevList )
3920 {
3921 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3922 paramList->getParamType = eDiscoveredDevList;
3923 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3924 }
3925 }
3926
3927
3928 infoResp.status = STATUS_COMPLETE;
3929 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3930 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3931
3932 return WFA_SUCCESS;
3933}
3934
Ankur Vachhanic485b712012-02-15 23:29:49 +00003935