blob: cdf84790d6b2696533eab97c949860d4d3737e79 [file] [log] [blame]
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001
2/****************************************************************************
3 * (c) Copyright 2007 Wi-Fi Alliance. All Rights Reserved
4 *
5 *
6 * LICENSE
7 *
8 * License is granted only to Wi-Fi Alliance members and designated
9 * contractors ($B!H(BAuthorized Licensees$B!I(B)..AN Authorized Licensees are granted
10 * the non-exclusive, worldwide, limited right to use, copy, import, export
11 * and distribute this software:
12 * (i) solely for noncommercial applications and solely for testing Wi-Fi
13 * equipment; and
14 * (ii) solely for the purpose of embedding the software into Authorized
15 * Licensee$B!G(Bs proprietary equipment and software products for distribution to
16 * its customers under a license with at least the same restrictions as
17 * contained in this License, including, without limitation, the disclaimer of
18 * warranty and limitation of liability, below..AN The distribution rights
19 * granted in clause
20 * (ii), above, include distribution to third party companies who will
21 * redistribute the Authorized Licensee$B!G(Bs product to their customers with or
22 * without such third party$B!G(Bs private label. Other than expressly granted
23 * herein, this License is not transferable or sublicensable, and it does not
24 * extend to and may not be used with non-Wi-Fi applications..AN Wi-Fi Alliance
25 * reserves all rights not expressly granted herein..AN
26 *.AN
27 * Except as specifically set forth above, commercial derivative works of
28 * this software or applications that use the Wi-Fi scripts generated by this
29 * software are NOT AUTHORIZED without specific prior written permission from
30 * Wi-Fi Alliance.
31 *.AN
32 * Non-Commercial derivative works of this software for internal use are
33 * authorized and are limited by the same restrictions; provided, however,
34 * that the Authorized Licensee shall provide Wi-Fi Alliance with a copy of
35 * such derivative works under a perpetual, payment-free license to use,
36 * modify, and distribute such derivative works for purposes of testing Wi-Fi
37 * equipment.
38 *.AN
39 * Neither the name of the author nor "Wi-Fi Alliance" may be used to endorse
40 * or promote products that are derived from or that use this software without
41 * specific prior written permission from Wi-Fi Alliance.
42 *
43 * THIS SOFTWARE IS PROVIDED BY WI-FI ALLIANCE "AS IS" AND ANY EXPRESS OR
44 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45 * OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A.AN PARTICULAR PURPOSE,
46 * ARE DISCLAIMED. IN NO EVENT SHALL WI-FI ALLIANCE BE LIABLE FOR ANY DIRECT,
47 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
48 * (INCLUDING, BUT NOT LIMITED TO, THE COST OF PROCUREMENT OF SUBSTITUTE
49 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE) ARISING IN ANY WAY OUT OF
52 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************
53 */
54
55/*
56 * File: wfa_cs.c -- configuration and setup
57 * This file contains all implementation for the dut setup and control
58 * functions, such as network interfaces, ip address and wireless specific
59 * setup with its supplicant.
60 *
61 * The current implementation is to show how these functions
62 * should be defined in order to support the Agent Control/Test Manager
63 * control commands. To simplify the current work and avoid any GPL licenses,
64 * the functions mostly invoke shell commands by calling linux system call,
65 * system("<commands>").
66 *
67 * It depends on the differnt device and platform, vendors can choice their
68 * own ways to interact its systems, supplicants and process these commands
69 * such as using the native APIs.
70 *
71 * Revision History:
72 * 2006/03/10 -- initially created by qhu
73 * 2006/06/01 -- BETA Release by qhu
74 * 2006/06/13 -- 00.02 Release by qhu
75 * 2006/06/30 -- 00.10 Release by qhu
76 * 2006/07/10 -- 01.00 Release by qhu
77 * 2006/09/01 -- 01.05 Release by qhu
78 * 2006/10/26 -- 01.06 Released by qhu
79 * replace hardcoded buf size with macro
80 * 2006/12/02 -- bugs: 1. fixes incorrect order of getipconfig.sh
81 * input parameters reported by p.schwann
82 * 2. will add a new network for wap_cli command
83 * in case the network id 0 not present,
84 * recommended by c.benson
85 * the solution is to reimplement with calling
86 * native C API
87 * 2007/01/11 -- 01.10 released by qhu
88 * 2007/02/15 -- WMM Extension Beta released by qhu, mkaroshi
89 * 2007/03/18 -- add file close statements
90 * 2007/03/21 -- rename the file to avoid the confusion.
91 * 2007/03/30 -- 01.40 WPA2 and Official WMM Beta Release by qhu
92 * 2007/04/20 -- 02.00 WPA2 and Official WMM Release by qhu
93 * 2007/08/15 -- 02.10 WMM-Power Save release by qhu
94 * 2007/10/10 -- 02.20 Voice SOHO beta -- qhu
95 * 2007/11/07 -- 02.30 Voice HSO -- qhu
96 * 2007/12/10 -- 02.32 Add a function to upload test results.
97 * 2008/01/03 -- 02.34 Support the result upload command.
98 * 2008/03/12 -- 02.41 Bug #16, incorrect file descriptor used. Change
99 * the "tmpfile" to "tmpfd" and a few places. Make a macro
100 * WFA_STAUT_IF in file "inc/wfa_cs.h" for WLAN interface
101 * name in the function "wfaDeviceListIF()
102 *
103 * Not A Bug. Put back to the function from
104 * wfaSetEncryption1() to wfaSetEncryption() for
105 * supporting WEP. Porting could select which should be
106 * used according to WEP support or not.
107 *
108 *
109 */
110#include <stdio.h>
111#include <unistd.h>
112#include <string.h>
113#include <stdlib.h>
114#include <sys/socket.h>
115#include <arpa/inet.h>
116#include <linux/types.h>
117#include <linux/socket.h>
118#include <poll.h>
119
120#include "wfa_portall.h"
121#include "wfa_debug.h"
122#include "wfa_ver.h"
123#include "wfa_main.h"
124#include "wfa_types.h"
125#include "wfa_ca.h"
126#include "wfa_tlv.h"
127#include "wfa_sock.h"
128#include "wfa_tg.h"
129#include "wfa_cmds.h"
130#include "wfa_rsp.h"
131#include "wfa_utils.h"
132#ifdef WFA_WMM_PS_EXT
133#include "wfa_wmmps.h"
134#endif
135
136#define CERTIFICATES_PATH "/etc/wpa_supplicant"
137
138/* Some device may only support UDP ECHO, activate this line */
139//#define WFA_PING_UDP_ECHO_ONLY 1
140
141extern unsigned short wfa_defined_debug;
142int wfaExecuteCLI(char *CLI);
143
144/* Since the two definitions are used all over the CA function */
145char gCmdStr[WFA_CMD_STR_SZ];
146dutCmdResponse_t gGenericResp;
147int wfaTGSetPrio(int sockfd, int tgClass);
148void create_apts_msg(int msg, unsigned int txbuf[],int id);
149
150extern char e2eResults[];
151//extern char *e2eResults;
152FILE *e2efp = NULL;
153int chk_ret_status()
154{
155 char *ret = getenv(WFA_RET_ENV);
156
157 if(*ret == '1')
158 return WFA_SUCCESS;
159 else
160 return WFA_FAILURE;
161}
162
163/*
164 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
165 * input: cmd --- not used
166 * valLen -- not used
167 * output: parms -- a buffer to store the version info response.
168 */
169int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
170{
171 dutCmdResponse_t *getverResp = &gGenericResp;
172
173 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
174
175 getverResp->status = STATUS_COMPLETE;
176 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
177
178 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
179
180 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
181
182 return WFA_SUCCESS;
183}
184
185/*
186 * wfaStaAssociate():
187 * The function is to force the station wireless I/F to re/associate
188 * with the AP.
189 */
190int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
191{
192 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
193 char *ifname = assoc->intf;
194 dutCmdResponse_t *staAssocResp = &gGenericResp;
195
196 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
197 /*
198 * if bssid appears, station should associate with the specific
199 * BSSID AP at its initial association.
200 * If it is different to the current associating AP, it will be forced to
201 * roam the new AP
202 */
203 if(assoc->cmdsu.assoc.bssid[0] != '\0')
204 {
205 /* if (the first association) */
206 /* just do initial association to the BSSID */
207
208
209 /* else (station already associate to an AP) */
210 /* Do forced roaming */
211
212 }
213 else
214 {
215 /* use 'ifconfig' command to bring down the interface (linux specific) */
216 sprintf(gCmdStr, "ifconfig %s down", ifname);
217 system(gCmdStr);
218
219 /* use 'ifconfig' command to bring up the interface (linux specific) */
220 sprintf(gCmdStr, "ifconfig %s up", ifname);
221 system(gCmdStr);
222
223 /*
224 * use 'wpa_cli' command to force a 802.11 re/associate
225 * (wpa_supplicant specific)
226 */
227 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
228 system(gCmdStr);
229 }
230
231 /*
232 * Then report back to control PC for completion.
233 * This does not have failed/error status. The result only tells
234 * a completion.
235 */
236 staAssocResp->status = STATUS_COMPLETE;
237 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
238 *respLen = WFA_TLV_HDR_LEN + 4;
239
240 return WFA_SUCCESS;
241}
242
243/*
244 * wfaStaReAssociate():
245 * The function is to force the station wireless I/F to re/associate
246 * with the AP.
247 */
248int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
249{
250 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
251 char *ifname = assoc->intf;
252 dutCmdResponse_t *staAssocResp = &gGenericResp;
253
254 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
255 /*
256 * if bssid appears, station should associate with the specific
257 * BSSID AP at its initial association.
258 * If it is different to the current associating AP, it will be forced to
259 * roam the new AP
260 */
261 if(assoc->cmdsu.assoc.bssid[0] != '\0')
262 {
263 /* if (the first association) */
264 /* just do initial association to the BSSID */
265
266
267 /* else (station already associate to an AP) */
268 /* Do forced roaming */
269
270 }
271 else
272 {
273 /* use 'ifconfig' command to bring down the interface (linux specific) */
274 sprintf(gCmdStr, "ifconfig %s down", ifname);
275 system(gCmdStr);
276
277 /* use 'ifconfig' command to bring up the interface (linux specific) */
278 sprintf(gCmdStr, "ifconfig %s up", ifname);
279
280 /*
281 * use 'wpa_cli' command to force a 802.11 re/associate
282 * (wpa_supplicant specific)
283 */
284 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
285 system(gCmdStr);
286 }
287
288 /*
289 * Then report back to control PC for completion.
290 * This does not have failed/error status. The result only tells
291 * a completion.
292 */
293 staAssocResp->status = STATUS_COMPLETE;
294 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
295 *respLen = WFA_TLV_HDR_LEN + 4;
296
297 return WFA_SUCCESS;
298}
299
300/*
301 * wfaStaIsConnected():
302 * The function is to check whether the station's wireless I/F has
303 * already connected to an AP.
304 */
305int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
306{
307 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
308 dutCmdResponse_t *staConnectResp = &gGenericResp;
309 char *ifname = connStat->intf;
310 FILE *tmpfile = NULL;
311 char result[32];
312
313
314 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
315
316#ifdef WFA_NEW_CLI_FORMAT
317 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
318 system(gCmdStr);
319
320 if(chk_ret_status() == WFA_SUCCESS)
321 staConnectResp->cmdru.connected = 1;
322 else
323 staConnectResp->cmdru.connected = 0;
324#else
325 /*
326 * use 'wpa_cli' command to check the interface status
327 * none, scanning or complete (wpa_supplicant specific)
328 */
329 sprintf(gCmdStr, "/sbin/wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
330 system(gCmdStr);
331
332 /*
333 * the status is saved in a file. Open the file and check it.
334 */
335 tmpfile = fopen("/tmp/.isConnected", "r+");
336 if(tmpfile == NULL)
337 {
338 staConnectResp->status = STATUS_ERROR;
339 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
340 *respLen = WFA_TLV_HDR_LEN + 4;
341
342 DPRINT_ERR(WFA_ERR, "file open failed\n");
343 return WFA_FAILURE;
344 }
345
346 fscanf(tmpfile, "%s", result);
347
348 if(strncmp(result, "COMPLETED", 9) == 0)
349 staConnectResp->cmdru.connected = 1;
350 else
351 staConnectResp->cmdru.connected = 0;
352#endif
353
354 /*
355 * Report back the status: Complete or Failed.
356 */
357 staConnectResp->status = STATUS_COMPLETE;
358
359 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
360 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
361
362 return WFA_SUCCESS;
363}
364
365/*
366 * wfaStaGetIpConfig():
367 * This function is to retriev the ip info including
368 * 1. dhcp enable
369 * 2. ip address
370 * 3. mask
371 * 4. primary-dns
372 * 5. secondary-dns
373 *
374 * The current implementation is to use a script to find these information
375 * and store them in a file.
376 */
377int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
378{
379 int slen, ret, i = 0;
380 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
381 dutCmdResponse_t *ipconfigResp = &gGenericResp;
382 char *ifname = getIpConf->intf;
383 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
384
385 FILE *tmpfd;
386 char string[256];
387 char *str;
388
389 /*
390 * check a script file (the current implementation specific)
391 */
392 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
393 if(ret == -1)
394 {
395 ipconfigResp->status = STATUS_ERROR;
396 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
397 *respLen = WFA_TLV_HDR_LEN + 4;
398
399 DPRINT_ERR(WFA_ERR, "file not exist\n");
400 return WFA_FAILURE;
401
402 }
403
404 strcpy(ifinfo->dns[0], "0");
405 strcpy(ifinfo->dns[1], "0");
406
407 /*
408 * Run the script file "getipconfig.sh" to check the ip status
409 * (current implementation specific).
410 * note: "getipconfig.sh" is only defined for the current implementation
411 */
412 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
413
414 system(gCmdStr);
415
416 /* open the output result and scan/retrieve the info */
417 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
418
419 if(tmpfd == NULL)
420 {
421 ipconfigResp->status = STATUS_ERROR;
422 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
423 *respLen = WFA_TLV_HDR_LEN + 4;
424
425 DPRINT_ERR(WFA_ERR, "file open failed\n");
426 return WFA_FAILURE;
427 }
428
429 for(;;)
430 {
431 if(fgets(string, 256, tmpfd) == NULL)
432 break;
433
434 /* check dhcp enabled */
435 if(strncmp(string, "dhcpcli", 7) ==0)
436 {
437 str = strtok(string, "=");
438 str = strtok(NULL, "=");
439 if(str != NULL)
440 ifinfo->isDhcp = 1;
441 else
442 ifinfo->isDhcp = 0;
443 }
444
445 /* find out the ip address */
446 if(strncmp(string, "ipaddr", 6) == 0)
447 {
448 str = strtok(string, "=");
449 str = strtok(NULL, " ");
450 if(str != NULL)
451 {
452 wSTRNCPY(ifinfo->ipaddr, str, 15);
453 ifinfo->ipaddr[15]='\0';
454 }
455 else
456 wSTRNCPY(ifinfo->ipaddr, "none", 15);
457 }
458
459 /* check the mask */
460 if(strncmp(string, "mask", 4) == 0)
461 {
462 char ttstr[16];
463 char *ttp = ttstr;
464
465 str = strtok_r(string, "=", &ttp);
466 if(*ttp != '\0')
467 {
468 strcpy(ifinfo->mask, ttp);
469 slen = strlen(ifinfo->mask);
470 ifinfo->mask[slen-1] = '\0';
471 }
472 else
473 strcpy(ifinfo->mask, "none");
474 }
475
476 /* find out the dns server ip address */
477 if(strncmp(string, "nameserv", 8) == 0)
478 {
479 char ttstr[16];
480 char *ttp = ttstr;
481
482 str = strtok_r(string, " ", &ttp);
483 if(str != NULL && i < 2)
484 {
485 strcpy(ifinfo->dns[i], ttp);
486 slen = strlen(ifinfo->dns[i]);
487 ifinfo->dns[i][slen-1] = '\0';
488 }
489 else
490 strcpy(ifinfo->dns[i], "none");
491
492 i++;
493 }
494 }
495
496 /*
497 * Report back the results
498 */
499 ipconfigResp->status = STATUS_COMPLETE;
500 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
501
502 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
503
504#if 0
505 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
506 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
507 ifinfo->dns[0], ifinfo->dns[1], *respLen);
508#endif
509
510 fclose(tmpfd);
511 return WFA_SUCCESS;
512}
513
514/*
515 * wfaStaSetIpConfig():
516 * The function is to set the ip configuration to a wireless I/F.
517 * 1. IP address
518 * 2. Mac address
519 * 3. default gateway
520 * 4. dns nameserver (pri and sec).
521 */
522int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
523{
524 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
525 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
526 dutCmdResponse_t *staSetIpResp = &gGenericResp;
527
528 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
529
530 /*
531 * Use command 'ifconfig' to configure the interface ip address, mask.
532 * (Linux specific).
533 */
534 sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
535 system(gCmdStr);
536
537 /* use command 'route add' to set set gatewway (linux specific) */
538 if(ipconfig->defGateway[0] != '\0')
539 {
540 sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway);
541 system(gCmdStr);
542 }
543
544 /* set dns (linux specific) */
545 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
546 system(gCmdStr);
547 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
548 system(gCmdStr);
549 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
550 system(gCmdStr);
551
552 /*
553 * report status
554 */
555 staSetIpResp->status = STATUS_COMPLETE;
556 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
557 *respLen = WFA_TLV_HDR_LEN + 4;
558
559 return WFA_SUCCESS;
560}
561
562/*
563 * wfaStaVerifyIpConnection():
564 * The function is to verify if the station has IP connection with an AP by
565 * send ICMP/pings to the AP.
566 */
567int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
568{
569 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
570 dutCmdResponse_t *verifyIpResp = &gGenericResp;
571
572#ifndef WFA_PING_UDP_ECHO_ONLY
573 char strout[64], *pcnt;
574 FILE *tmpfile;
575
576 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
577
578 /* set timeout value in case not set */
579 if(verip->cmdsu.verifyIp.timeout <= 0)
580 {
581 verip->cmdsu.verifyIp.timeout = 10;
582 }
583
584 /* execute the ping command and pipe the result to a tmp file */
585 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);
586 system(gCmdStr);
587
588 /* scan/check the output */
589 tmpfile = fopen("/tmp/pingout.txt", "r+");
590 if(tmpfile == NULL)
591 {
592 verifyIpResp->status = STATUS_ERROR;
593 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
594 *respLen = WFA_TLV_HDR_LEN + 4;
595
596 DPRINT_ERR(WFA_ERR, "file open failed\n");
597 return WFA_FAILURE;
598 }
599
600 verifyIpResp->status = STATUS_COMPLETE;
601 if(fscanf(tmpfile, "%s", strout) == EOF)
602 verifyIpResp->cmdru.connected = 0;
603 else
604 {
605 pcnt = strtok(strout, "%");
606
607 /* if the loss rate is 100%, not able to connect */
608 if(atoi(pcnt) == 100)
609 verifyIpResp->cmdru.connected = 0;
610 else
611 verifyIpResp->cmdru.connected = 1;
612 }
613
614 fclose(tmpfile);
615#else
616 int btSockfd;
617 struct pollfd fds[2];
618 int timeout = 2000;
619 char anyBuf[64];
620 struct sockaddr_in toAddr;
621 int done = 1, cnt = 0, ret, nbytes;
622
623 verifyIpResp->status = STATUS_COMPLETE;
624 verifyIpResp->cmdru.connected = 0;
625
626 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
627
628 if(btSockfd == -1)
629 {
630 verifyIpResp->status = STATUS_ERROR;
631 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
632 *respLen = WFA_TLV_HDR_LEN + 4;
633 return WFA_FAILURE;;
634 }
635
636 toAddr.sin_family = AF_INET;
637 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
638 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
639
640 while(done)
641 {
642 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
643 cnt++;
644
645 fds[0].fd = btSockfd;
646 fds[0].events = POLLIN | POLLOUT;
647
648 ret = poll(fds, 1, timeout);
649 switch(ret)
650 {
651 case 0:
652 /* it is time out, count a packet lost*/
653 break;
654 case -1:
655 /* it is an error */
656 default:
657 {
658 switch(fds[0].revents)
659 {
660 case POLLIN:
661 case POLLPRI:
662 case POLLOUT:
663 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
664 if(nbytes != 0)
665 verifyIpResp->cmdru.connected = 1;
666 done = 0;
667 break;
668 default:
669 /* errors but not care */
670 ;
671 }
672 }
673 }
674 if(cnt == 3)
675 {
676 done = 0;
677 }
678 }
679
680#endif
681
682 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
683
684 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
685
686 return WFA_SUCCESS;
687}
688
689/*
690 * wfaStaGetMacAddress()
691 * This function is to retrieve the MAC address of a wireless I/F.
692 */
693int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
694{
695 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
696 dutCmdResponse_t *getmacResp = &gGenericResp;
697 char *str;
698 char *ifname = getMac->intf;
699
700 FILE *tmpfd;
701 char string[128];
702
703 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
704 /*
705 * run the script "getipconfig.sh" to find out the mac
706 */
707 //sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s", ifname);
708 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
709 system(gCmdStr);
710
711 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
712 if(tmpfd == NULL)
713 {
714 getmacResp->status = STATUS_ERROR;
715 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
716 *respLen = WFA_TLV_HDR_LEN + 4;
717
718 DPRINT_ERR(WFA_ERR, "file open failed\n");
719 return WFA_FAILURE;
720 }
721
722 if(fgets(string, 256, tmpfd) == NULL)
723 {
724 getmacResp->status = STATUS_ERROR;
725 }
726
727 str = strtok(string, " ");
728 while(str && ((strcmp(str,"HWaddr")) != 0))
729 {
730 str = strtok(NULL, " ");
731 }
732
733 /* get mac */
734 if(str)
735 {
736 str = strtok(NULL, " ");
737 strcpy(getmacResp->cmdru.mac, str);
738 getmacResp->status = STATUS_COMPLETE;
739 }
740
741
742 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
743
744 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
745
746 fclose(tmpfd);
747 return WFA_SUCCESS;
748}
749
750/*
751 * wfaStaGetStats():
752 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
753 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
754 * Currently there is not definition how to use these info.
755 */
756int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
757{
758 dutCmdResponse_t *statsResp = &gGenericResp;
759
760 /* this is never used, you can skip this call */
761
762 statsResp->status = STATUS_ERROR;
763 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
764 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
765
766
767 return WFA_SUCCESS;
768}
769
770/*
771 * wfaSetEncryption():
772 * The function is to set the wireless interface with WEP or none.
773 *
774 * Since WEP is optional test, current function is only used for
775 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
776 * this function should be replaced by the next one (wfaSetEncryption1())
777 *
778 * Input parameters:
779 * 1. I/F
780 * 2. ssid
781 * 3. encpType - wep or none
782 * Optional:
783 * 4. key1
784 * 5. key2
785 * 6. key3
786 * 7. key4
787 * 8. activeKey Index
788 */
789
790int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
791{
792 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
793 dutCmdResponse_t *setEncrypResp = &gGenericResp;
794
795 /*
796 * disable the network first
797 */
798 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
799 system(gCmdStr);
800
801 /*
802 * set SSID
803 */
804 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
805 system(gCmdStr);
806
807 /*
808 * Tell the supplicant for infrastructure mode (1)
809 */
810 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
811 system(gCmdStr);
812
813 /*
814 * set Key management to NONE (NO WPA) for plaintext or WEP
815 */
816 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
817 system(gCmdStr);
818
819 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
820 system(gCmdStr);
821
822 setEncrypResp->status = STATUS_COMPLETE;
823 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
824 *respLen = WFA_TLV_HDR_LEN + 4;
825
826 return WFA_SUCCESS;
827}
828
829/*
830 * Since WEP is optional, this function could be used to replace
831 * wfaSetEncryption() if necessary.
832 */
833int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
834{
835 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
836 dutCmdResponse_t *setEncrypResp = &gGenericResp;
837 int i;
838
839 /*
840 * disable the network first
841 */
842 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
843 system(gCmdStr);
844
845 /*
846 * set SSID
847 */
848 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
849 system(gCmdStr);
850
851 /*
852 * Tell the supplicant for infrastructure mode (1)
853 */
854 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
855 system(gCmdStr);
856
857 /*
858 * set Key management to NONE (NO WPA) for plaintext or WEP
859 */
860 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
861 system(gCmdStr);
862
863 /* set keys */
864 if(setEncryp->encpType == 1)
865 {
866 for(i=0; i<4; i++)
867 {
868 if(setEncryp->keys[i][0] != '\0')
869 {
870 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
871 setEncryp->intf, i, setEncryp->keys[i]);
872 system(gCmdStr);
873 }
874 }
875
876 /* set active key */
877 i = setEncryp->activeKeyIdx;
878 if(setEncryp->keys[i][0] != '\0')
879 {
880 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
881 setEncryp->intf, setEncryp->activeKeyIdx);
882 system(gCmdStr);
883 }
884 }
885 else /* clearly remove the keys -- reported by p.schwann */
886 {
887
888 for(i = 0; i < 4; i++)
889 {
890 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
891 system(gCmdStr);
892 }
893 }
894
895 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
896 system(gCmdStr);
897
898 setEncrypResp->status = STATUS_COMPLETE;
899 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
900 *respLen = WFA_TLV_HDR_LEN + 4;
901
902 return WFA_SUCCESS;
903}
904
905int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
906{
907 int ret = WFA_SUCCESS;
908
909 return ret;
910}
911
912/*
913 * wfaStaSetEapTLS():
914 * This is to set
915 * 1. ssid
916 * 2. encrypType - tkip or aes-ccmp
917 * 3. keyManagementType - wpa or wpa2
918 * 4. trustedRootCA
919 * 5. clientCertificate
920 */
921int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
922{
923 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
924 char *ifname = setTLS->intf;
925 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
926
927 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
928
929 /*
930 * need to store the trustedROOTCA and clientCertificate into a file first.
931 */
932#ifdef WFA_NEW_CLI_FORMAT
933 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
934 system(gCmdStr);
935#else
936
937 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
938 system(gCmdStr);
939
940 /* ssid */
941 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
942 system(gCmdStr);
943
944 /* key management */
945 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
946 {
947 }
948 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
949 {
950 }
951 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
952 {
953
954 }
955 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
956 {
957 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
958 }
959 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
960 {
961 // to take all and device to pick any one supported.
962 }
963 else
964 {
965 // ??
966 }
967 system(gCmdStr);
968
969 /* protocol WPA */
970 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
971 system(gCmdStr);
972
973 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
974 system(gCmdStr);
975
976 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
977 system(gCmdStr);
978
979 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
980 system(gCmdStr);
981
982 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
983 system(gCmdStr);
984
985 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
986 system(gCmdStr);
987
988 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
989 system(gCmdStr);
990#endif
991
992 setEapTlsResp->status = STATUS_COMPLETE;
993 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
994 *respLen = WFA_TLV_HDR_LEN + 4;
995
996 return WFA_SUCCESS;
997}
998
999/*
1000 * The function is to set
1001 * 1. ssid
1002 * 2. passPhrase
1003 * 3. keyMangementType - wpa/wpa2
1004 * 4. encrypType - tkip or aes-ccmp
1005 */
1006int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1007{
1008 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
1009 dutCmdResponse_t *setPskResp = &gGenericResp;
1010
1011#ifndef WFA_PC_CONSOLE
1012
1013#ifdef WFA_NEW_CLI_FORMAT
1014 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
1015 system(gCmdStr);
1016#else
1017 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
1018 system(gCmdStr);
1019
1020 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
1021 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
1022 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
1023 {
1024 // take all and device to pick it supported.
1025 }
1026 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
1027 {
1028
1029 }
1030 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
1031 {
1032
1033 }
1034 else
1035 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
1036 system(gCmdStr);
1037
1038 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
1039 system(gCmdStr);
1040
1041 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
1042 system(gCmdStr);
1043
1044 /* if PMF enable */
1045 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
1046 {
1047
1048 }
1049 else if(setPSK->pmf == WFA_REQUIRED)
1050 {
1051
1052 }
1053 else if(setPSK->pmf == WFA_F_REQUIRED)
1054 {
1055
1056 }
1057 else if(setPSK->pmf == WFA_F_DISABLED)
1058 {
1059
1060 }
1061 else
1062 { /* Disable PMF */
1063
1064 }
1065
1066#endif
1067
1068#endif
1069
1070 setPskResp->status = STATUS_COMPLETE;
1071 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1072 *respLen = WFA_TLV_HDR_LEN + 4;
1073
1074 return WFA_SUCCESS;
1075}
1076
1077/*
1078 * wfaStaGetInfo():
1079 * Get vendor specific information in name/value pair by a wireless I/F.
1080 */
1081int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1082{
1083 dutCmdResponse_t infoResp;
1084 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
1085
1086 /*
1087 * Normally this is called to retrieve the vendor information
1088 * from a interface, no implement yet
1089 */
1090 sprintf(infoResp.cmdru.info, "interface,%s,vendor,XXX,cardtype,802.11a/b/g", getInfo->intf);
1091
1092 infoResp.status = STATUS_COMPLETE;
1093 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
1094 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
1095
1096 return WFA_SUCCESS;
1097}
1098
1099/*
1100 * wfaStaSetEapTTLS():
1101 * This is to set
1102 * 1. ssid
1103 * 2. username
1104 * 3. passwd
1105 * 4. encrypType - tkip or aes-ccmp
1106 * 5. keyManagementType - wpa or wpa2
1107 * 6. trustedRootCA
1108 */
1109int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1110{
1111 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1112 char *ifname = setTTLS->intf;
1113 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
1114
1115#ifdef WFA_NEW_CLI_FORMAT
1116 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
1117 system(gCmdStr);
1118#else
1119
1120 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1121 system(gCmdStr);
1122
1123 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
1124 system(gCmdStr);
1125
1126 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
1127 system(gCmdStr);
1128
1129 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
1130 system(gCmdStr);
1131
1132 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1133 system(gCmdStr);
1134
1135/* This may not need to set. if it is not set, default to take all */
1136// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
1137 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1138 {
1139 }
1140 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1141 {
1142 }
1143 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1144 {
1145
1146 }
1147 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1148 {
1149
1150 }
1151 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1152 {
1153 // to take all and device to pick one it supported
1154 }
1155 else
1156 {
1157 // ??
1158 }
1159 system(gCmdStr);
1160
1161 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
1162 system(gCmdStr);
1163
1164 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
1165 system(gCmdStr);
1166
1167 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1168 system(gCmdStr);
1169
1170// sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
1171// system(gCmdStr);
1172
1173 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
1174 system(gCmdStr);
1175
1176 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1177 system(gCmdStr);
1178#endif
1179
1180 setEapTtlsResp->status = STATUS_COMPLETE;
1181 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1182 *respLen = WFA_TLV_HDR_LEN + 4;
1183
1184 return WFA_SUCCESS;
1185}
1186
1187/*
1188 * wfaStaSetEapSIM():
1189 * This is to set
1190 * 1. ssid
1191 * 2. user name
1192 * 3. passwd
1193 * 4. encrypType - tkip or aes-ccmp
1194 * 5. keyMangementType - wpa or wpa2
1195 */
1196int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1197{
1198 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1199 char *ifname = setSIM->intf;
1200 dutCmdResponse_t *setEapSimResp = &gGenericResp;
1201
1202#ifdef WFA_NEW_CLI_FORMAT
1203 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
1204 system(gCmdStr);
1205#else
1206
1207 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1208 system(gCmdStr);
1209
1210 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
1211 system(gCmdStr);
1212
1213
1214 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
1215 system(gCmdStr);
1216
1217 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
1218 system(gCmdStr);
1219
1220 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
1221 system(gCmdStr);
1222
1223 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1224 system(gCmdStr);
1225
1226 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1227 system(gCmdStr);
1228
1229 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1230 {
1231 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1232 }
1233 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1234 {
1235 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1236 }
1237 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1238 {
1239 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1240 }
1241 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1242 {
1243 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1244 }
1245 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1246 {
1247 // take all and device to pick one which is supported.
1248 }
1249 else
1250 {
1251 // ??
1252 }
1253 system(gCmdStr);
1254
1255#endif
1256
1257 setEapSimResp->status = STATUS_COMPLETE;
1258 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1259 *respLen = WFA_TLV_HDR_LEN + 4;
1260
1261 return WFA_SUCCESS;
1262}
1263
1264/*
1265 * wfaStaSetPEAP()
1266 * This is to set
1267 * 1. ssid
1268 * 2. user name
1269 * 3. passwd
1270 * 4. encryType - tkip or aes-ccmp
1271 * 5. keyMgmtType - wpa or wpa2
1272 * 6. trustedRootCA
1273 * 7. innerEAP
1274 * 8. peapVersion
1275 */
1276int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1277{
1278 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1279 char *ifname = setPEAP->intf;
1280 dutCmdResponse_t *setPeapResp = &gGenericResp;
1281
1282#ifdef WFA_NEW_CLI_FORMAT
1283 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1284 setPEAP->passwd, setPEAP->trustedRootCA,
1285 setPEAP->encrptype, setPEAP->peapVersion,
1286 setPEAP->innerEAP);
1287 system(gCmdStr);
1288#else
1289
1290 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1291 system(gCmdStr);
1292
1293 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
1294 system(gCmdStr);
1295
1296 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
1297 system(gCmdStr);
1298
1299 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
1300 system(gCmdStr);
1301
1302 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
1303 system(gCmdStr);
1304
1305 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
1306 system(gCmdStr);
1307
1308 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
1309 system(gCmdStr);
1310
1311 /* if this not set, default to set support all */
1312 //sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setPEAP->encrptype);
1313 //system(gCmdStr);
1314
1315 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1316 {
1317 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1318 }
1319 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1320 {
1321 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1322 }
1323 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1324 {
1325 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1326 }
1327 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1328 {
1329 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1330 }
1331 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1332 {
1333 // take all and device to pick one which is supported.
1334 }
1335 else
1336 {
1337 // ??
1338 }
1339 system(gCmdStr);
1340
1341 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
1342 system(gCmdStr);
1343
1344 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
1345 system(gCmdStr);
1346
1347 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1348 system(gCmdStr);
1349#endif
1350
1351 setPeapResp->status = STATUS_COMPLETE;
1352 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1353 *respLen = WFA_TLV_HDR_LEN + 4;
1354
1355 return WFA_SUCCESS;
1356}
1357
1358/*
1359 * wfaStaSetUAPSD()
1360 * This is to set
1361 * 1. acBE
1362 * 2. acBK
1363 * 3. acVI
1364 * 4. acVO
1365 */
1366int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1367{
1368 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
1369#if 0 /* used for only one specific device, need to update to reflect yours */
1370 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1371 char *ifname = setUAPSD->intf;
1372 char tmpStr[10];
1373 char line[100];
1374 char *pathl="/etc/Wireless/RT61STA";
1375 BYTE acBE=1;
1376 BYTE acBK=1;
1377 BYTE acVO=1;
1378 BYTE acVI=1;
1379 BYTE APSDCapable;
1380 FILE *pipe;
1381
1382 /*
1383 * A series of setting need to be done before doing WMM-PS
1384 * Additional steps of configuration may be needed.
1385 */
1386
1387 /*
1388 * bring down the interface
1389 */
1390 sprintf(gCmdStr, "ifconfig %s down",ifname);
1391 system(gCmdStr);
1392 /*
1393 * Unload the Driver
1394 */
1395 sprintf(gCmdStr, "rmmod rt61");
1396 system(gCmdStr);
1397#ifndef WFA_WMM_AC
1398 if(setUAPSD->acBE != 1)
1399 acBE=setUAPSD->acBE = 0;
1400 if(setUAPSD->acBK != 1)
1401 acBK=setUAPSD->acBK = 0;
1402 if(setUAPSD->acVO != 1)
1403 acVO=setUAPSD->acVO = 0;
1404 if(setUAPSD->acVI != 1)
1405 acVI=setUAPSD->acVI = 0;
1406#else
1407 acBE=setUAPSD->acBE;
1408 acBK=setUAPSD->acBK;
1409 acVO=setUAPSD->acVO;
1410 acVI=setUAPSD->acVI;
1411#endif
1412
1413 APSDCapable = acBE||acBK||acVO||acVI;
1414 /*
1415 * set other AC parameters
1416 */
1417
1418 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1419 sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl);
1420 system(gCmdStr);
1421
1422 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
1423 system(gCmdStr);
1424 pipe = popen("uname -r", "r");
1425 /* Read into line the output of uname*/
1426 fscanf(pipe,"%s",line);
1427 pclose(pipe);
1428
1429 /*
1430 * load the Driver
1431 */
1432 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
1433 system(gCmdStr);
1434
1435 sprintf(gCmdStr, "ifconfig %s up",ifname);
1436 system(gCmdStr);
1437#endif
1438
1439 setUAPSDResp->status = STATUS_COMPLETE;
1440 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1441 *respLen = WFA_TLV_HDR_LEN + 4;
1442 return WFA_SUCCESS;
1443}
1444
1445int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1446{
1447 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1448 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1449 dutCmdResponse_t *infoResp = &gGenericResp;
1450 /*a vendor can fill in the proper info or anything non-disclosure */
1451 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
1452
1453 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
1454
1455 if(devInfo->fw == 0)
1456 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1457 else
1458 {
1459 // Call internal API to pull the version ID */
1460 memcpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
1461 }
1462
1463 infoResp->status = STATUS_COMPLETE;
1464 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1465 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1466
1467 return WFA_SUCCESS;
1468
1469}
1470
1471/*
1472 * This funciton is to retrieve a list of interfaces and return
1473 * the list back to Agent control.
1474 * ********************************************************************
1475 * Note: We intend to make this WLAN interface name as a hardcode name.
1476 * Therefore, for a particular device, you should know and change the name
1477 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1478 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
1479 * likely is hardcoded just for CAPI command responses.
1480 * *******************************************************************
1481 *
1482 */
1483int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1484{
1485 dutCmdResponse_t *infoResp = &gGenericResp;
1486 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1487 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
1488
1489 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
1490
1491 switch(ifList->cmdsu.iftype)
1492 {
1493 case IF_80211:
1494 infoResp->status = STATUS_COMPLETE;
1495 ifListResp->iftype = IF_80211;
1496 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1497 strcpy(ifListResp->ifs[1], "NULL");
1498 strcpy(ifListResp->ifs[2], "NULL");
1499 break;
1500 case IF_ETH:
1501 infoResp->status = STATUS_COMPLETE;
1502 ifListResp->iftype = IF_ETH;
1503 strcpy(ifListResp->ifs[0], "eth0");
1504 strcpy(ifListResp->ifs[1], "NULL");
1505 strcpy(ifListResp->ifs[2], "NULL");
1506 break;
1507 default:
1508 {
1509 infoResp->status = STATUS_ERROR;
1510 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1511 *respLen = WFA_TLV_HDR_LEN + 4;
1512
1513 return WFA_SUCCESS;
1514 }
1515 }
1516
1517 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1518 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1519
1520 return WFA_SUCCESS;
1521}
1522
1523int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1524{
1525 dutCmdResponse_t *debugResp = &gGenericResp;
1526 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
1527
1528 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
1529
1530 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1531 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1532 else
1533 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
1534
1535 debugResp->status = STATUS_COMPLETE;
1536 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1537 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1538
1539
1540 return WFA_SUCCESS;
1541}
1542
1543
1544/*
1545 * wfaStaGetBSSID():
1546 * This function is to retrieve BSSID of a specific wireless I/F.
1547 */
1548int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1549{
1550 char string[64];
1551 char *str;
1552 FILE *tmpfd;
1553 dutCmdResponse_t *bssidResp = &gGenericResp;
1554
1555 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1556 /* retrieve the BSSID */
1557 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
1558
1559 system(gCmdStr);
1560
1561 tmpfd = fopen("/tmp/bssid.txt", "r+");
1562 if(tmpfd == NULL)
1563 {
1564 bssidResp->status = STATUS_ERROR;
1565 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1566 *respLen = WFA_TLV_HDR_LEN + 4;
1567
1568 DPRINT_ERR(WFA_ERR, "file open failed\n");
1569 return WFA_FAILURE;
1570 }
1571
1572 for(;;)
1573 {
1574 if(fscanf(tmpfd, "%s", string) == EOF)
1575 {
1576 bssidResp->status = STATUS_COMPLETE;
1577 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
1578 break;
1579 }
1580
1581 if(strncmp(string, "bssid", 5) == 0)
1582 {
1583 str = strtok(string, "=");
1584 str = strtok(NULL, "=");
1585 if(str != NULL)
1586 {
1587 strcpy(bssidResp->cmdru.bssid, str);
1588 bssidResp->status = STATUS_COMPLETE;
1589 break;
1590 }
1591 }
1592 }
1593
1594 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1595 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1596
1597 fclose(tmpfd);
1598 return WFA_SUCCESS;
1599}
1600
1601/*
1602 * wfaStaSetIBSS()
1603 * This is to set
1604 * 1. ssid
1605 * 2. channel
1606 * 3. encrypType - none or wep
1607 * optional
1608 * 4. key1
1609 * 5. key2
1610 * 6. key3
1611 * 7. key4
1612 * 8. activeIndex - 1, 2, 3, or 4
1613 */
1614int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1615{
1616 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1617 dutCmdResponse_t *setIbssResp = &gGenericResp;
1618 int i;
1619
1620 /*
1621 * disable the network first
1622 */
1623 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
1624 system(gCmdStr);
1625
1626 /*
1627 * set SSID
1628 */
1629 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
1630 system(gCmdStr);
1631
1632 /*
1633 * Set channel for IBSS
1634 */
1635 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
1636 system(gCmdStr);
1637
1638 /*
1639 * Tell the supplicant for IBSS mode (1)
1640 */
1641 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
1642 system(gCmdStr);
1643
1644 /*
1645 * set Key management to NONE (NO WPA) for plaintext or WEP
1646 */
1647 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
1648 system(gCmdStr);
1649
1650 if(setIBSS->encpType == 1)
1651 {
1652 for(i=0; i<4; i++)
1653 {
1654 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1655 {
1656 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1657 setIBSS->intf, i, setIBSS->keys[i]);
1658 system(gCmdStr);
1659 }
1660 }
1661
1662 i = setIBSS->activeKeyIdx;
1663 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1664 {
1665 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1666 setIBSS->intf, setIBSS->activeKeyIdx);
1667 system(gCmdStr);
1668 }
1669 }
1670
1671 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
1672 system(gCmdStr);
1673
1674 setIbssResp->status = STATUS_COMPLETE;
1675 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1676 *respLen = WFA_TLV_HDR_LEN + 4;
1677
1678 return WFA_SUCCESS;
1679}
1680
1681/*
1682 * wfaSetMode():
1683 * The function is to set the wireless interface with a given mode (possible
1684 * adhoc)
1685 * Input parameters:
1686 * 1. I/F
1687 * 2. ssid
1688 * 3. mode adhoc or managed
1689 * 4. encType
1690 * 5. channel
1691 * 6. key(s)
1692 * 7. active key
1693 */
1694int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1695{
1696 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1697 dutCmdResponse_t *SetModeResp = &gGenericResp;
1698 int i;
1699
1700 /*
1701 * bring down the interface
1702 */
1703 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
1704 system(gCmdStr);
1705
1706 /*
1707 * distroy the interface
1708 */
1709 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
1710 system(gCmdStr);
1711
1712
1713 /*
1714 * re-create the interface with the given mode
1715 */
1716 if(setmode->mode == 1)
1717 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
1718 else
1719 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1720
1721 system(gCmdStr);
1722 if(setmode->encpType == ENCRYPT_WEP)
1723 {
1724 int j = setmode->activeKeyIdx;
1725 for(i=0; i<4; i++)
1726 {
1727 if(setmode->keys[i][0] != '\0')
1728 {
1729 sprintf(gCmdStr, "iwconfig %s key s:%s",
1730 setmode->intf, setmode->keys[i]);
1731 system(gCmdStr);
1732 }
1733 /* set active key */
1734 if(setmode->keys[j][0] != '\0')
1735 sprintf(gCmdStr, "iwconfig %s key s:%s",
1736 setmode->intf, setmode->keys[j]);
1737 system(gCmdStr);
1738 }
1739
1740 }
1741 /*
1742 * Set channel for IBSS
1743 */
1744 if(setmode->channel)
1745 {
1746 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
1747 system(gCmdStr);
1748 }
1749
1750
1751 /*
1752 * set SSID
1753 */
1754 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
1755 system(gCmdStr);
1756
1757 /*
1758 * bring up the interface
1759 */
1760 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
1761 system(gCmdStr);
1762
1763 SetModeResp->status = STATUS_COMPLETE;
1764 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1765 *respLen = WFA_TLV_HDR_LEN + 4;
1766
1767 return WFA_SUCCESS;
1768}
1769
1770int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1771{
1772 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1773 dutCmdResponse_t *SetPSResp = &gGenericResp;
1774
1775 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
1776 system(gCmdStr);
1777
1778
1779 SetPSResp->status = STATUS_COMPLETE;
1780 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1781 *respLen = WFA_TLV_HDR_LEN + 4;
1782
1783 return WFA_SUCCESS;
1784}
1785
1786int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1787{
1788 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1789 dutCmdResponse_t *upLoadResp = &gGenericResp;
1790 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
1791
1792 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1793 {
1794 int rbytes;
1795 /*
1796 * if asked for the first packet, always to open the file
1797 */
1798 if(upload->next == 1)
1799 {
1800 if(e2efp != NULL)
1801 {
1802 fclose(e2efp);
1803 e2efp = NULL;
1804 }
1805
1806 e2efp = fopen(e2eResults, "r");
1807 }
1808
1809 if(e2efp == NULL)
1810 {
1811 upLoadResp->status = STATUS_ERROR;
1812 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1813 *respLen = WFA_TLV_HDR_LEN + 4;
1814 return WFA_FAILURE;
1815 }
1816
1817 rbytes = fread(upld->bytes, 1, 256, e2efp);
1818
1819 if(rbytes < 256)
1820 {
1821 /*
1822 * this means no more bytes after this read
1823 */
1824 upld->seqnum = 0;
1825 fclose(e2efp);
1826 e2efp=NULL;
1827 }
1828 else
1829 {
1830 upld->seqnum = upload->next;
1831 }
1832
1833 upld->nbytes = rbytes;
1834
1835 upLoadResp->status = STATUS_COMPLETE;
1836 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1837 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1838 }
1839 else
1840 {
1841 upLoadResp->status = STATUS_ERROR;
1842 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1843 *respLen = WFA_TLV_HDR_LEN + 4;
1844 }
1845
1846 return WFA_SUCCESS;
1847}
1848/*
1849 * wfaStaSetWMM()
1850 * TO be ported on a specific plaform for the DUT
1851 * This is to set the WMM related parameters at the DUT.
1852 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1853 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1854 */
1855int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1856{
1857#ifdef WFA_WMM_AC
1858 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1859 char *ifname = setwmm->intf;
1860 dutCmdResponse_t *setwmmResp = &gGenericResp;
1861 //IEEEtypes_WMM_TSPEC_t tspec;
1862
1863 switch(setwmm->group)
1864 {
1865 case GROUP_WMMAC:
1866 if (setwmm->send_trig)
1867 {
1868 int Sockfd;
1869 struct sockaddr_in psToAddr;
1870 unsigned int TxMsg[512];
1871
1872 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
1873 memset(&psToAddr, 0, sizeof(psToAddr));
1874 psToAddr.sin_family = AF_INET;
1875 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1876 psToAddr.sin_port = htons(12346);
1877
1878
1879 switch (setwmm->trig_ac)
1880 {
1881 case WMMAC_AC_VO:
1882 wfaTGSetPrio(Sockfd, 7);
1883 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1884 printf("\r\nSending AC_VO trigger packet\n");
1885 break;
1886
1887 case WMMAC_AC_VI:
1888 wfaTGSetPrio(Sockfd, 5);
1889 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1890 printf("\r\nSending AC_VI trigger packet\n");
1891 break;
1892
1893 case WMMAC_AC_BK:
1894 wfaTGSetPrio(Sockfd, 2);
1895 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1896 printf("\r\nSending AC_BK trigger packet\n");
1897 break;
1898
1899 default:
1900 case WMMAC_AC_BE:
1901 wfaTGSetPrio(Sockfd, 0);
1902 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1903 printf("\r\nSending AC_BE trigger packet\n");
1904 break;
1905 }
1906
1907 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1908 sizeof(struct sockaddr));
1909 close(Sockfd);
1910 usleep(1000000);
1911 }
1912 else if (setwmm->action == WMMAC_ADDTS)
1913 {
1914 //wmmtspec_t* pCmdTspec = &(setwmm->actions.addts.tspec);
1915 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
1916 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1917 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1918 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1919 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1920 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1921 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1922 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1923 setwmm->actions.addts.dialog_token,
1924 setwmm->actions.addts.tspec.tsinfo.TID,
1925 setwmm->actions.addts.tspec.tsinfo.direction,
1926 setwmm->actions.addts.tspec.tsinfo.PSB,
1927 setwmm->actions.addts.tspec.tsinfo.UP,
1928 setwmm->actions.addts.tspec.tsinfo.infoAck,
1929 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1930 setwmm->actions.addts.tspec.Fixed,
1931 setwmm->actions.addts.tspec.size,
1932 setwmm->actions.addts.tspec.maxsize,
1933 setwmm->actions.addts.tspec.min_srvc,
1934 setwmm->actions.addts.tspec.max_srvc,
1935 setwmm->actions.addts.tspec.inactivity,
1936 setwmm->actions.addts.tspec.suspension,
1937 setwmm->actions.addts.tspec.srvc_strt_tim,
1938 setwmm->actions.addts.tspec.mindatarate,
1939 setwmm->actions.addts.tspec.meandatarate,
1940 setwmm->actions.addts.tspec.peakdatarate,
1941 setwmm->actions.addts.tspec.burstsize,
1942 setwmm->actions.addts.tspec.delaybound,
1943 setwmm->actions.addts.tspec.PHYrate,
1944 setwmm->actions.addts.tspec.sba,
1945 setwmm->actions.addts.tspec.medium_time,
1946 setwmm->actions.addts.accesscat);
1947
1948 // you should set your tspec here.
1949
1950 system(gCmdStr);
1951 }
1952 else if (setwmm->action == WMMAC_DELTS)
1953 {
1954 // send del tspec
1955 }
1956
1957 setwmmResp->status = STATUS_COMPLETE;
1958 break;
1959
1960 case GROUP_WMMCONF:
1961 sprintf(gCmdStr, "iwconfig %s rts %d",
1962 ifname,setwmm->actions.config.rts_thr);
1963
1964 system(gCmdStr);
1965 sprintf(gCmdStr, "iwconfig %s frag %d",
1966 ifname,setwmm->actions.config.frag_thr);
1967
1968 system(gCmdStr);
1969 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1970 ifname, setwmm->actions.config.wmm);
1971
1972 system(gCmdStr);
1973 setwmmResp->status = STATUS_COMPLETE;
1974 break;
1975
1976 default:
1977 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1978 setwmmResp->status = STATUS_ERROR;
1979 break;
1980
1981 }
1982
1983 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1984 *respLen = WFA_TLV_HDR_LEN + 4;
1985#endif
1986
1987 return WFA_SUCCESS;
1988}
1989
1990int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1991{
1992 //dutCommand_t *sendNeigReq = (dutCommand_t *)caCmdBuf;
1993 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
1994
1995 /*
1996 * run your device to send NEIGREQ
1997 */
1998
1999 sendNeigReqResp->status = STATUS_COMPLETE;
2000 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
2001 *respLen = WFA_TLV_HDR_LEN + 4;
2002
2003 return WFA_SUCCESS;
2004}
2005
2006int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2007{
2008 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
2009 char *ifname = setFAST->intf;
2010 dutCmdResponse_t *setEapFastResp = &gGenericResp;
2011
2012#ifdef WFA_NEW_CLI_FORMAT
2013 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
2014 setFAST->passwd, setFAST->pacFileName,
2015 setFAST->innerEAP);
2016 system(gCmdStr);
2017#else
2018
2019 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
2020 system(gCmdStr);
2021
2022 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
2023 system(gCmdStr);
2024
2025 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
2026 system(gCmdStr);
2027
2028 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
2029 system(gCmdStr);
2030
2031 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
2032 {
2033 }
2034 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
2035 {
2036 }
2037 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
2038 {
2039
2040 }
2041 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
2042 {
2043 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
2044 }
2045 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
2046 {
2047 // take all and device to pick one which is supported.
2048 }
2049 else
2050 {
2051 // ??
2052 }
2053 system(gCmdStr);
2054
2055 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname);
2056 system(gCmdStr);
2057
2058 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName);
2059 system(gCmdStr);
2060
2061 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
2062 system(gCmdStr);
2063
2064 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
2065 system(gCmdStr);
2066
2067 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
2068 system(gCmdStr);
2069
2070 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
2071 system(gCmdStr);
2072#endif
2073
2074 setEapFastResp->status = STATUS_COMPLETE;
2075 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2076 *respLen = WFA_TLV_HDR_LEN + 4;
2077
2078 return WFA_SUCCESS;
2079}
2080
2081int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2082{
2083 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2084 char *ifname = setAKA->intf;
2085 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2086
2087#ifdef WFA_NEW_CLI_FORMAT
2088 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
2089 system(gCmdStr);
2090#else
2091
2092 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
2093 system(gCmdStr);
2094
2095 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
2096 system(gCmdStr);
2097
2098 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2099 {
2100 }
2101 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2102 {
2103 }
2104 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2105 {
2106
2107 }
2108 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2109 {
2110 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
2111 }
2112 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2113 {
2114 // take all and device to pick one which is supported.
2115 }
2116 else
2117 {
2118 // ??
2119 }
2120 system(gCmdStr);
2121
2122 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname);
2123 system(gCmdStr);
2124 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
2125 system(gCmdStr);
2126
2127 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
2128 system(gCmdStr);
2129
2130 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
2131 system(gCmdStr);
2132
2133 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
2134 system(gCmdStr);
2135
2136 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
2137 system(gCmdStr);
2138
2139 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
2140 system(gCmdStr);
2141#endif
2142
2143 setEapAkaResp->status = STATUS_COMPLETE;
2144 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2145 *respLen = WFA_TLV_HDR_LEN + 4;
2146
2147 return WFA_SUCCESS;
2148}
2149
2150int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2151{
2152 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2153 dutCmdResponse_t *setSystimeResp = &gGenericResp;
2154
2155 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
2156
2157 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2158 system(gCmdStr);
2159
2160 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2161 system(gCmdStr);
2162
2163 setSystimeResp->status = STATUS_COMPLETE;
2164 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2165 *respLen = WFA_TLV_HDR_LEN + 4;
2166
2167 return WFA_SUCCESS;
2168}
2169
2170#ifdef WFA_STA_TB
2171int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2172{
2173 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2174 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2175 //int ret;
2176 //char *intfname = presetParams->intf;
2177 BYTE presetDone = 1;
2178 int st = 0;
2179
2180 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
2181
2182 if(presetParams->wmmFlag)
2183 {
2184 st = wfaExecuteCLI(gCmdStr);
2185 switch(st)
2186 {
2187 case 0:
2188 presetDone = 1;
2189 break;
2190 case 1:
2191 presetDone = 0;
2192 break;
2193 case 2:
2194 presetDone = 0;
2195 break;
2196 }
2197 }
2198
2199 if(presetParams->modeFlag != 0)
2200 {
2201 switch(presetParams->wirelessMode)
2202 {
2203 default:
2204 printf("other mode does not need to support\n");
2205 }
2206
2207 st = wfaExecuteCLI(gCmdStr);
2208 switch(st)
2209 {
2210 case 0:
2211 presetDone = 1;
2212 break;
2213 case 1:
2214 presetDone = 0;
2215 case 2:
2216 presetDone = 0;
2217 break;
2218 }
2219 }
2220
2221
2222 if(presetParams->psFlag)
2223 {
2224
2225 printf("%s\n", gCmdStr);
2226 system(gCmdStr);
2227 }
2228
2229 /************the followings are used for Voice Enterprise **************/
2230 if(presetParams->ftoa == eEnable)
2231 {
2232 // enable Fast BSS Transition Over the Air
2233 }
2234 else
2235 {
2236 // disable Fast BSS Transition Over the Air
2237
2238 }
2239
2240 if(presetParams->ftds == eEnable)
2241 {
2242 // enable Fast BSS Transition Over the DS
2243
2244 }
2245 else
2246 {
2247 // disable Fast BSS Transition Over the DS
2248
2249 }
2250
2251 if(presetParams->activescan == eEnable)
2252 {
2253 // Enable Active Scan on STA
2254
2255 }
2256 else
2257 {
2258 // disable Active Scan on STA
2259
2260 }
2261
2262
2263 if (presetDone)
2264 {
2265 PresetParamsResp->status = STATUS_COMPLETE;
2266 }
2267 else
2268 {
2269 PresetParamsResp->status = STATUS_INVALID;
2270 }
2271
2272 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2273 *respLen = WFA_TLV_HDR_LEN + 4;
2274
2275 return WFA_SUCCESS;
2276}
2277
2278int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2279{
2280 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2281
2282 v11nParamsResp->status = STATUS_COMPLETE;
2283 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2284 *respLen = WFA_TLV_HDR_LEN + 4;
2285 return WFA_SUCCESS;
2286}
2287int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2288{
2289 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2290
2291 staWirelessResp->status = STATUS_COMPLETE;
2292 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2293 *respLen = WFA_TLV_HDR_LEN + 4;
2294 return WFA_SUCCESS;
2295}
2296
2297int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2298{
2299 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2300
2301 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2302 *respLen = WFA_TLV_HDR_LEN + 4;
2303 return WFA_SUCCESS;
2304}
2305
2306int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2307{
2308 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
2309
2310 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2311 *respLen = WFA_TLV_HDR_LEN + 4;
2312
2313 return WFA_SUCCESS;
2314
2315}
2316
2317int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2318{
2319 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2320
2321 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2322 *respLen = WFA_TLV_HDR_LEN + 4;
2323
2324 return WFA_SUCCESS;
2325
2326}
2327
2328int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2329{
2330 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2331 dutCmdResponse_t *ResetResp = &gGenericResp;
2332
2333
2334 // need to make your own command available for this, here is only an example
2335 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2336 system(gCmdStr);
2337
2338 ResetResp->status = STATUS_COMPLETE;
2339 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2340 *respLen = WFA_TLV_HDR_LEN + 4;
2341
2342 return WFA_SUCCESS;
2343}
2344
2345#else
2346
2347int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2348{
2349 dutCmdResponse_t *staCmdResp = &gGenericResp;
2350
2351 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2352 *respLen = WFA_TLV_HDR_LEN + 4;
2353
2354 return WFA_SUCCESS;
2355}
2356#endif
2357
2358/*
2359 * This is used to send a frame or action frame
2360 */
2361int wfaStaSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2362{
2363 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2364 /* uncomment it if needed */
2365 // char *ifname = cmd->intf;
2366 dutCmdResponse_t *staCmdResp = &gGenericResp;
2367 caStaSendFrame_t *sf = &cmd->cmdsu.sf;
2368
2369 /* processing the frame */
2370
2371 switch(sf->frame)
2372 {
2373 case FM_TYPE_PMF:
2374 {
2375 pmfFrame_t *pmf = &sf->frameType.pmf;
2376 switch(pmf->type)
2377 {
2378 case PMF_TYPE_DISASSOC:
2379 {
2380 /* use the protected to set what type of key to send */
2381
2382 }
2383 break;
2384 case PMF_TYPE_DEAUTH:
2385 {
2386
2387 }
2388 break;
2389 case PMF_TYPE_SAQUERY:
2390 {
2391
2392 }
2393 break;
2394 case PMF_TYPE_AUTH:
2395 {
2396 }
2397 break;
2398 case PMF_TYPE_ASSOCREQ:
2399 {
2400 }
2401 break;
2402 case PMF_TYPE_REASSOCREQ:
2403 {
2404 }
2405 break;
2406 }
2407 }
2408 break;
2409 case FM_TYPE_TDLS:
2410 {
2411 tdlsFrame_t *tdls = &sf->frameType.tdls;
2412 switch(tdls->type)
2413 {
2414 case TDLS_TYPE_DISCOVERY:
2415 /* use the peer mac address to send the frame */
2416 break;
2417 case TDLS_TYPE_SETUP:
2418 break;
2419 case TDLS_TYPE_TEARDOWN:
2420 break;
2421 case TDLS_TYPE_CHANNELSWITCH:
2422 break;
2423 case TDLS_TYPE_NULLFRAME:
2424 break;
2425 }
2426 }
2427 break;
2428 case FM_TYPE_VENT:
2429 {
2430 ventFrame_t *vent = &sf->frameType.vent;
2431 switch(vent->type)
2432 {
2433 case VENT_TYPE_NEIGREQ:
2434 break;
2435 case VENT_TYPE_TRANSMGMT:
2436 break;
2437 }
2438 }
2439 }
2440
2441 wfaEncodeTLV(WFA_STA_SENDFRAME_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2442 *respLen = WFA_TLV_HDR_LEN + 4;
2443
2444 return WFA_SUCCESS;
2445}
2446
2447/*
2448 * This is used to set a temporary MAC address of an interface
2449 */
2450int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2451{
2452 // Uncomment it if needed
2453 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2454 // char *ifname = cmd->intf;
2455 dutCmdResponse_t *staCmdResp = &gGenericResp;
2456 // Uncomment it if needed
2457 //char *macaddr = &cmd->cmdsu.macaddr[0];
2458
2459 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2460 *respLen = WFA_TLV_HDR_LEN + 4;
2461
2462 return WFA_SUCCESS;
2463}
2464
2465
2466int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2467{
2468 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2469 //char *intf = disc->intf;
2470 dutCmdResponse_t *staDiscResp = &gGenericResp;
2471
2472 // stop the supplicant
2473
2474 staDiscResp->status = STATUS_COMPLETE;
2475
2476 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2477 *respLen = WFA_TLV_HDR_LEN + 4;
2478
2479 return WFA_SUCCESS;
2480}
2481
2482/* Execute CLI, read the status from Environment variable */
2483int wfaExecuteCLI(char *CLI)
2484{
2485 char *retstr;
2486
2487 system(CLI);
2488
2489 retstr = getenv("WFA_CLI_STATUS");
2490 printf("cli status %s\n", retstr);
2491 return atoi(retstr);
2492}
2493
2494/* Supporting Functions */
2495
2496void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2497{
2498 int totalpkts;
2499 char cmdStr[128];
2500// char *addr = staPing->dipaddr;
2501#ifdef WFA_PC_CONSOLE
2502 char addr[20];
2503 char bflag[] = "-b";
2504 char *tmpstr;
2505 int inum=0;
2506#else
2507 char bflag[] = " ";
2508#endif
2509 totalpkts = staPing->duration * staPing->frameRate;
2510#ifdef WFA_PC_CONSOLE
2511
2512 printf("\nCS : The Stream ID is %d",streamid);
2513 printf("\nCS :the addr is %s ",addr);
2514 strcpy(addr,staPing->dipaddr);
2515 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2516 printf("\nCS :the addr is %s ",addr);
2517 tmpstr = strtok(addr, ".");
2518
2519 inum = atoi(tmpstr);
2520
2521 printf("interval %f\n", *interval);
2522
2523 if(inum >= 224 && inum <= 239) // multicast
2524 {
2525 }
2526 else // if not MC, check if it is BC address
2527 {
2528 printf("\nCS :Inside the BC address BLOCK");
2529 printf("\nCS :the inum %d",inum);
2530 strtok(NULL, ".");
2531 //strtok(NULL, ".");
2532 tmpstr = strtok(NULL, ".");
2533 printf("tmpstr %s\n", tmpstr);
2534 inum = atoi(tmpstr);
2535 printf("\nCS : The string is %s",tmpstr);
2536 if(inum != 255)
2537 memset(bflag, 0, strlen(bflag));
2538 }
2539#endif
2540 printf("\nCS : The Stream ID is %d",streamid);
2541
2542 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",
2543 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
2544 system(cmdStr);
2545 printf("\nCS : The command string is %s",cmdStr);
2546
2547 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
2548 system(cmdStr);
2549 printf("\nCS : The command string is %s",cmdStr);
2550
2551}
2552
2553int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2554{
2555 char strout[256];
2556 FILE *tmpfile = NULL;
2557 char cmdStr[128];
2558 printf("Ping stop id %d\n", streamid);
2559 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
2560 system(cmdStr);
2561
2562 printf("\nCS : The command string is %s",cmdStr);
2563
2564 system("stoping.sh /tmp/pid.txt ; sleep 2");
2565
2566 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
2567 system(cmdStr);
2568
2569 printf("\nCS : The command string is %s",cmdStr);
2570
2571 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2572
2573 if(tmpfile == NULL)
2574 {
2575 return WFA_FAILURE;
2576 }
2577
2578 if(fscanf(tmpfile, "%s", strout) != EOF)
2579 {
2580 if(*strout == '\0')
2581 {
2582 stpResp->cmdru.pingStp.sendCnt = 0;
2583 }
2584
2585 else
2586 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2587 }
2588
2589 printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
2590
2591
2592 if(fscanf(tmpfile, "%s", strout) != EOF)
2593 {
2594 if(*strout == '\0')
2595 {
2596 stpResp->cmdru.pingStp.repliedCnt = 0;
2597 }
2598 else
2599 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2600 }
2601 printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
2602
2603 fclose(tmpfile);
2604
2605 return WFA_SUCCESS;
2606}
2607
2608int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2609{
2610 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
2611 dutCmdResponse_t *staCmdResp = &gGenericResp;
2612 char *str;
2613 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
2614
2615 if(sr->mode == WFA_OFF)
2616 {
2617 // turn radio off
2618 }
2619 else
2620 {
2621 // always turn the radio on
2622 }
2623
2624 staCmdResp->status = STATUS_COMPLETE;
2625 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2626 *respLen = WFA_TLV_HDR_LEN + 4;
2627
2628 return WFA_SUCCESS;
2629}
2630
2631int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2632{
2633 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
2634 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
2635 dutCmdResponse_t *caResp = &gGenericResp;
2636 char *intf = dutCmd->intf;
2637
2638 if(strcasecmp(rfeat->prog, "tdls") == 0)
2639 {
2640
2641
2642 }
2643
2644 caResp->status = STATUS_COMPLETE;
2645 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
2646 *respLen = WFA_TLV_HDR_LEN + 4;
2647
2648 return WFA_SUCCESS;
2649}
2650
2651