blob: 6b1f5a2908c6583ec30821d969908a78c344dbbc [file] [log] [blame]
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001/****************************************************************************
Alan Tsaidfafa3a2016-09-23 16:53:35 -07002Copyright (c) 2016 Wi-Fi Alliance. All Rights Reserved
Dake Zhao97708202014-11-26 13:59:04 -08003
Dake Zhao0a832172015-01-06 11:08:47 -08004Permission to use, copy, modify, and/or distribute this software for any purpose with or
5without fee is hereby granted, provided that the above copyright notice and this permission
Dake Zhao97708202014-11-26 13:59:04 -08006notice appear in all copies.
7
Dake Zhao0a832172015-01-06 11:08:47 -08008THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
12FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
Dake Zhao97708202014-11-26 13:59:04 -080014THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16******************************************************************************/
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000017
Dake Zhao0a832172015-01-06 11:08:47 -080018/*
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000019 * File: wfa_cs.c -- configuration and setup
Dake Zhao0a832172015-01-06 11:08:47 -080020 * This file contains all implementation for the dut setup and control
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000021 * functions, such as network interfaces, ip address and wireless specific
22 * setup with its supplicant.
23 *
24 * The current implementation is to show how these functions
Dake Zhao0a832172015-01-06 11:08:47 -080025 * should be defined in order to support the Agent Control/Test Manager
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000026 * control commands. To simplify the current work and avoid any GPL licenses,
27 * the functions mostly invoke shell commands by calling linux system call,
Dake Zhao0a832172015-01-06 11:08:47 -080028 * system("<commands>").
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000029 *
30 * It depends on the differnt device and platform, vendors can choice their
31 * own ways to interact its systems, supplicants and process these commands
32 * such as using the native APIs.
33 *
Dake Zhao0a832172015-01-06 11:08:47 -080034 *
35 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000036#include <stdio.h>
37#include <unistd.h>
38#include <string.h>
39#include <stdlib.h>
40#include <sys/socket.h>
41#include <arpa/inet.h>
42#include <linux/types.h>
43#include <linux/socket.h>
44#include <poll.h>
45
46#include "wfa_portall.h"
47#include "wfa_debug.h"
48#include "wfa_ver.h"
49#include "wfa_main.h"
50#include "wfa_types.h"
51#include "wfa_ca.h"
52#include "wfa_tlv.h"
53#include "wfa_sock.h"
54#include "wfa_tg.h"
55#include "wfa_cmds.h"
56#include "wfa_rsp.h"
57#include "wfa_utils.h"
58#ifdef WFA_WMM_PS_EXT
59#include "wfa_wmmps.h"
60#endif
61
62#define CERTIFICATES_PATH "/etc/wpa_supplicant"
63
64/* Some device may only support UDP ECHO, activate this line */
65//#define WFA_PING_UDP_ECHO_ONLY 1
66
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080067#define WFA_ENABLED 1
68
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000069extern unsigned short wfa_defined_debug;
70int wfaExecuteCLI(char *CLI);
71
72/* Since the two definitions are used all over the CA function */
73char gCmdStr[WFA_CMD_STR_SZ];
74dutCmdResponse_t gGenericResp;
75int wfaTGSetPrio(int sockfd, int tgClass);
76void create_apts_msg(int msg, unsigned int txbuf[],int id);
77
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080078int sret = 0;
79
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000080extern char e2eResults[];
Dake Zhao862c94b2014-12-08 14:35:35 -080081
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000082FILE *e2efp = NULL;
83int chk_ret_status()
84{
85 char *ret = getenv(WFA_RET_ENV);
86
87 if(*ret == '1')
Dake Zhao0a832172015-01-06 11:08:47 -080088 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000089 else
Dake Zhao0a832172015-01-06 11:08:47 -080090 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000091}
92
93/*
94 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
95 * input: cmd --- not used
96 * valLen -- not used
97 * output: parms -- a buffer to store the version info response.
98 */
99int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
100{
101 dutCmdResponse_t *getverResp = &gGenericResp;
102
103 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
104
105 getverResp->status = STATUS_COMPLETE;
106 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
107
108 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
109
110 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
111
112 return WFA_SUCCESS;
113}
114
115/*
116 * wfaStaAssociate():
Dake Zhao0a832172015-01-06 11:08:47 -0800117 * The function is to force the station wireless I/F to re/associate
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000118 * with the AP.
119 */
120int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
121{
Dake Zhao0a832172015-01-06 11:08:47 -0800122 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
123 char *ifname = assoc->intf;
124 dutCmdResponse_t *staAssocResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000125
Dake Zhao0a832172015-01-06 11:08:47 -0800126 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
127 /*
128 * if bssid appears, station should associate with the specific
129 * BSSID AP at its initial association.
130 * If it is different to the current associating AP, it will be forced to
131 * roam the new AP
132 */
133 if(assoc->cmdsu.assoc.bssid[0] != '\0')
134 {
135 /* if (the first association) */
136 /* just do initial association to the BSSID */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000137
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000138
Dake Zhao0a832172015-01-06 11:08:47 -0800139 /* else (station already associate to an AP) */
140 /* Do forced roaming */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000141
Dake Zhao0a832172015-01-06 11:08:47 -0800142 }
143 else
144 {
145 /* use 'ifconfig' command to bring down the interface (linux specific) */
Ray Wangd11ca032015-05-29 18:25:46 -0700146 //sprintf(gCmdStr, "ifconfig %s down", ifname);
147 //sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000148
Dake Zhao0a832172015-01-06 11:08:47 -0800149 /* use 'ifconfig' command to bring up the interface (linux specific) */
Ray Wangd11ca032015-05-29 18:25:46 -0700150 //sprintf(gCmdStr, "ifconfig %s up", ifname);
151 //sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000152
Dake Zhao0a832172015-01-06 11:08:47 -0800153 /*
154 * use 'wpa_cli' command to force a 802.11 re/associate
155 * (wpa_supplicant specific)
156 */
157 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
158 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000159 }
160
161 /*
162 * Then report back to control PC for completion.
163 * This does not have failed/error status. The result only tells
164 * a completion.
165 */
166 staAssocResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -0800167 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000168 *respLen = WFA_TLV_HDR_LEN + 4;
169
Dake Zhao0a832172015-01-06 11:08:47 -0800170 return WFA_SUCCESS;
171}
172
173/*
174 * wfaStaReAssociate():
175 * The function is to force the station wireless I/F to re/associate
176 * with the AP.
177 */
178int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
179{
180 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
181 char *ifname = assoc->intf;
182 dutCmdResponse_t *staAssocResp = &gGenericResp;
183
184 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
185 /*
186 * if bssid appears, station should associate with the specific
187 * BSSID AP at its initial association.
188 * If it is different to the current associating AP, it will be forced to
189 * roam the new AP
190 */
191 if(assoc->cmdsu.assoc.bssid[0] != '\0')
192 {
193 /* if (the first association) */
194 /* just do initial association to the BSSID */
195
196
197 /* else (station already associate to an AP) */
198 /* Do forced roaming */
199
200 }
201 else
202 {
203 /* use 'ifconfig' command to bring down the interface (linux specific) */
204 sprintf(gCmdStr, "ifconfig %s down", ifname);
205 sret = system(gCmdStr);
206
207 /* use 'ifconfig' command to bring up the interface (linux specific) */
208 sprintf(gCmdStr, "ifconfig %s up", ifname);
209
210 /*
211 * use 'wpa_cli' command to force a 802.11 re/associate
212 * (wpa_supplicant specific)
213 */
214 sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname);
215 sret = system(gCmdStr);
216 }
217
218 /*
219 * Then report back to control PC for completion.
220 * This does not have failed/error status. The result only tells
221 * a completion.
222 */
223 staAssocResp->status = STATUS_COMPLETE;
224 wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf);
225 *respLen = WFA_TLV_HDR_LEN + 4;
226
227 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000228}
229
230/*
231 * wfaStaIsConnected():
Dake Zhao0a832172015-01-06 11:08:47 -0800232 * The function is to check whether the station's wireless I/F has
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000233 * already connected to an AP.
234 */
235int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
236{
Dake Zhao0a832172015-01-06 11:08:47 -0800237 dutCommand_t *connStat = (dutCommand_t *)caCmdBuf;
238 dutCmdResponse_t *staConnectResp = &gGenericResp;
239 char *ifname = connStat->intf;
240 FILE *tmpfile = NULL;
241 char result[32];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000242
243
Dake Zhao0a832172015-01-06 11:08:47 -0800244 DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000245
246#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800247 sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname);
248 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000249
Dake Zhao0a832172015-01-06 11:08:47 -0800250 if(chk_ret_status() == WFA_SUCCESS)
251 staConnectResp->cmdru.connected = 1;
252 else
253 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000254#else
Dake Zhao0a832172015-01-06 11:08:47 -0800255 /*
256 * use 'wpa_cli' command to check the interface status
257 * none, scanning or complete (wpa_supplicant specific)
258 */
259 sprintf(gCmdStr, "/sbin/wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname);
260 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000261
Dake Zhao0a832172015-01-06 11:08:47 -0800262 /*
263 * the status is saved in a file. Open the file and check it.
264 */
265 tmpfile = fopen("/tmp/.isConnected", "r+");
266 if(tmpfile == NULL)
267 {
268 staConnectResp->status = STATUS_ERROR;
269 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf);
270 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000271
Dake Zhao0a832172015-01-06 11:08:47 -0800272 DPRINT_ERR(WFA_ERR, "file open failed\n");
273 return WFA_FAILURE;
274 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000275
Dake Zhao0a832172015-01-06 11:08:47 -0800276 sret = fscanf(tmpfile, "%s", (char *)result);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000277
Dake Zhao0a832172015-01-06 11:08:47 -0800278 if(strncmp(result, "COMPLETED", 9) == 0)
279 staConnectResp->cmdru.connected = 1;
280 else
281 staConnectResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000282#endif
283
Dake Zhao0a832172015-01-06 11:08:47 -0800284 /*
285 * Report back the status: Complete or Failed.
286 */
287 staConnectResp->status = STATUS_COMPLETE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000288
Dake Zhao0a832172015-01-06 11:08:47 -0800289 wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf);
290 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
291
292 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000293}
294
295/*
296 * wfaStaGetIpConfig():
297 * This function is to retriev the ip info including
298 * 1. dhcp enable
299 * 2. ip address
Dake Zhao0a832172015-01-06 11:08:47 -0800300 * 3. mask
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000301 * 4. primary-dns
302 * 5. secondary-dns
303 *
304 * The current implementation is to use a script to find these information
Dake Zhao0a832172015-01-06 11:08:47 -0800305 * and store them in a file.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000306 */
307int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
308{
309 int slen, ret, i = 0;
310 dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf;
Dake Zhao0a832172015-01-06 11:08:47 -0800311 dutCmdResponse_t *ipconfigResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000312 char *ifname = getIpConf->intf;
313 caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig;
314
315 FILE *tmpfd;
316 char string[256];
317 char *str;
318
319 /*
320 * check a script file (the current implementation specific)
321 */
322 ret = access("/usr/local/sbin/getipconfig.sh", F_OK);
323 if(ret == -1)
324 {
Dake Zhao0a832172015-01-06 11:08:47 -0800325 ipconfigResp->status = STATUS_ERROR;
326 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
327 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000328
Dake Zhao0a832172015-01-06 11:08:47 -0800329 DPRINT_ERR(WFA_ERR, "file not exist\n");
330 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000331
332 }
333
334 strcpy(ifinfo->dns[0], "0");
335 strcpy(ifinfo->dns[1], "0");
Dake Zhao0a832172015-01-06 11:08:47 -0800336
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000337 /*
Dake Zhao0a832172015-01-06 11:08:47 -0800338 * Run the script file "getipconfig.sh" to check the ip status
339 * (current implementation specific).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000340 * note: "getipconfig.sh" is only defined for the current implementation
341 */
Dake Zhao0a832172015-01-06 11:08:47 -0800342 sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000343
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800344 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000345
346 /* open the output result and scan/retrieve the info */
347 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
348
349 if(tmpfd == NULL)
350 {
Dake Zhao0a832172015-01-06 11:08:47 -0800351 ipconfigResp->status = STATUS_ERROR;
352 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf);
353 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000354
Dake Zhao0a832172015-01-06 11:08:47 -0800355 DPRINT_ERR(WFA_ERR, "file open failed\n");
356 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000357 }
358
359 for(;;)
360 {
361 if(fgets(string, 256, tmpfd) == NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800362 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000363
364 /* check dhcp enabled */
365 if(strncmp(string, "dhcpcli", 7) ==0)
366 {
367 str = strtok(string, "=");
368 str = strtok(NULL, "=");
369 if(str != NULL)
Dake Zhao0a832172015-01-06 11:08:47 -0800370 ifinfo->isDhcp = 1;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000371 else
Dake Zhao0a832172015-01-06 11:08:47 -0800372 ifinfo->isDhcp = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000373 }
374
375 /* find out the ip address */
376 if(strncmp(string, "ipaddr", 6) == 0)
377 {
378 str = strtok(string, "=");
379 str = strtok(NULL, " ");
380 if(str != NULL)
381 {
Dake Zhao0a832172015-01-06 11:08:47 -0800382 wSTRNCPY(ifinfo->ipaddr, str, 15);
Dake Zhao97708202014-11-26 13:59:04 -0800383
Dake Zhao0a832172015-01-06 11:08:47 -0800384 ifinfo->ipaddr[15]='\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000385 }
386 else
Dake Zhao0a832172015-01-06 11:08:47 -0800387 wSTRNCPY(ifinfo->ipaddr, "none", 15);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000388 }
389
390 /* check the mask */
391 if(strncmp(string, "mask", 4) == 0)
392 {
393 char ttstr[16];
394 char *ttp = ttstr;
395
396 str = strtok_r(string, "=", &ttp);
397 if(*ttp != '\0')
398 {
Dake Zhao0a832172015-01-06 11:08:47 -0800399 strcpy(ifinfo->mask, ttp);
400 slen = strlen(ifinfo->mask);
401 ifinfo->mask[slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000402 }
403 else
Dake Zhao0a832172015-01-06 11:08:47 -0800404 strcpy(ifinfo->mask, "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000405 }
406
407 /* find out the dns server ip address */
408 if(strncmp(string, "nameserv", 8) == 0)
409 {
410 char ttstr[16];
411 char *ttp = ttstr;
Dake Zhao0a832172015-01-06 11:08:47 -0800412
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000413 str = strtok_r(string, " ", &ttp);
414 if(str != NULL && i < 2)
415 {
Dake Zhao0a832172015-01-06 11:08:47 -0800416 strcpy(ifinfo->dns[i], ttp);
417 slen = strlen(ifinfo->dns[i]);
418 ifinfo->dns[i][slen-1] = '\0';
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000419 }
420 else
Dake Zhao0a832172015-01-06 11:08:47 -0800421 strcpy(ifinfo->dns[i], "none");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000422
423 i++;
424 }
Dake Zhao0a832172015-01-06 11:08:47 -0800425 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000426
Dake Zhao0a832172015-01-06 11:08:47 -0800427 /*
428 * Report back the results
429 */
430 ipconfigResp->status = STATUS_COMPLETE;
431 wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000432
Dake Zhao0a832172015-01-06 11:08:47 -0800433 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000434
435#if 0
Dake Zhao0a832172015-01-06 11:08:47 -0800436 DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status,
437 ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask,
438 ifinfo->dns[0], ifinfo->dns[1], *respLen);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000439#endif
440
Dake Zhao0a832172015-01-06 11:08:47 -0800441 fclose(tmpfd);
442 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000443}
444
445/*
446 * wfaStaSetIpConfig():
447 * The function is to set the ip configuration to a wireless I/F.
448 * 1. IP address
449 * 2. Mac address
450 * 3. default gateway
Dake Zhao0a832172015-01-06 11:08:47 -0800451 * 4. dns nameserver (pri and sec).
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000452 */
453int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
454{
Dake Zhao0a832172015-01-06 11:08:47 -0800455 dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf;
456 caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig;
457 dutCmdResponse_t *staSetIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000458
Dake Zhao0a832172015-01-06 11:08:47 -0800459 DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000460
Dake Zhao0a832172015-01-06 11:08:47 -0800461 /*
462 * Use command 'ifconfig' to configure the interface ip address, mask.
463 * (Linux specific).
464 */
465 sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask);
466 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000467
Dake Zhao0a832172015-01-06 11:08:47 -0800468 /* use command 'route add' to set set gatewway (linux specific) */
469 if(ipconfig->defGateway[0] != '\0')
470 {
471 sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway);
472 sret = system(gCmdStr);
473 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000474
Dake Zhao0a832172015-01-06 11:08:47 -0800475 /* set dns (linux specific) */
476 sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk");
477 sret = system(gCmdStr);
478 sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns);
479 sret = system(gCmdStr);
480 sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns);
481 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000482
Dake Zhao0a832172015-01-06 11:08:47 -0800483 /*
484 * report status
485 */
486 staSetIpResp->status = STATUS_COMPLETE;
487 wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf);
488 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000489
Dake Zhao0a832172015-01-06 11:08:47 -0800490 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000491}
492
493/*
494 * wfaStaVerifyIpConnection():
495 * The function is to verify if the station has IP connection with an AP by
496 * send ICMP/pings to the AP.
Dake Zhao0a832172015-01-06 11:08:47 -0800497 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000498int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
499{
Dake Zhao0a832172015-01-06 11:08:47 -0800500 dutCommand_t *verip = (dutCommand_t *)caCmdBuf;
501 dutCmdResponse_t *verifyIpResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000502
503#ifndef WFA_PING_UDP_ECHO_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -0800504 char strout[64], *pcnt;
505 FILE *tmpfile;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000506
Dake Zhao0a832172015-01-06 11:08:47 -0800507 DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n");
508
509 /* set timeout value in case not set */
510 if(verip->cmdsu.verifyIp.timeout <= 0)
511 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000512 verip->cmdsu.verifyIp.timeout = 10;
Dake Zhao0a832172015-01-06 11:08:47 -0800513 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000514
Dake Zhao0a832172015-01-06 11:08:47 -0800515 /* execute the ping command and pipe the result to a tmp file */
516 sprintf(gCmdStr, "ping %s -c 3 -W %u | grep loss | cut -f3 -d, 1>& /tmp/pingout.txt", verip->cmdsu.verifyIp.dipaddr, verip->cmdsu.verifyIp.timeout);
517 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000518
Dake Zhao0a832172015-01-06 11:08:47 -0800519 /* scan/check the output */
520 tmpfile = fopen("/tmp/pingout.txt", "r+");
521 if(tmpfile == NULL)
522 {
523 verifyIpResp->status = STATUS_ERROR;
524 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
525 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000526
Dake Zhao0a832172015-01-06 11:08:47 -0800527 DPRINT_ERR(WFA_ERR, "file open failed\n");
528 return WFA_FAILURE;
529 }
530
531 verifyIpResp->status = STATUS_COMPLETE;
532 if(fscanf(tmpfile, "%s", strout) == EOF)
533 verifyIpResp->cmdru.connected = 0;
534 else
535 {
536 pcnt = strtok(strout, "%");
537
538 /* if the loss rate is 100%, not able to connect */
539 if(atoi(pcnt) == 100)
540 verifyIpResp->cmdru.connected = 0;
541 else
542 verifyIpResp->cmdru.connected = 1;
543 }
544
545 fclose(tmpfile);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000546#else
Dake Zhao0a832172015-01-06 11:08:47 -0800547 int btSockfd;
548 struct pollfd fds[2];
549 int timeout = 2000;
550 char anyBuf[64];
551 struct sockaddr_in toAddr;
552 int done = 1, cnt = 0, ret, nbytes;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000553
Dake Zhao0a832172015-01-06 11:08:47 -0800554 verifyIpResp->status = STATUS_COMPLETE;
555 verifyIpResp->cmdru.connected = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000556
Dake Zhao0a832172015-01-06 11:08:47 -0800557 btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000558
Dake Zhao0a832172015-01-06 11:08:47 -0800559 if(btSockfd == -1)
560 {
561 verifyIpResp->status = STATUS_ERROR;
562 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf);
563 *respLen = WFA_TLV_HDR_LEN + 4;
564 return WFA_FAILURE;;
565 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000566
Dake Zhao0a832172015-01-06 11:08:47 -0800567 toAddr.sin_family = AF_INET;
568 toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr);
569 toAddr.sin_port = htons(WFA_UDP_ECHO_PORT);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000570
Dake Zhao0a832172015-01-06 11:08:47 -0800571 while(done)
572 {
573 wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr);
574 cnt++;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000575
Dake Zhao0a832172015-01-06 11:08:47 -0800576 fds[0].fd = btSockfd;
577 fds[0].events = POLLIN | POLLOUT;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000578
Dake Zhao0a832172015-01-06 11:08:47 -0800579 ret = poll(fds, 1, timeout);
580 switch(ret)
581 {
582 case 0:
583 /* it is time out, count a packet lost*/
584 break;
585 case -1:
586 /* it is an error */
587 default:
588 {
589 switch(fds[0].revents)
590 {
591 case POLLIN:
592 case POLLPRI:
593 case POLLOUT:
594 nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr);
595 if(nbytes != 0)
596 verifyIpResp->cmdru.connected = 1;
597 done = 0;
598 break;
599 default:
600 /* errors but not care */
601 ;
602 }
603 }
604 }
605 if(cnt == 3)
606 {
607 done = 0;
608 }
609 }
610
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000611#endif
612
Dake Zhao0a832172015-01-06 11:08:47 -0800613 wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000614
Dake Zhao0a832172015-01-06 11:08:47 -0800615 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
616
617 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000618}
619
620/*
621 * wfaStaGetMacAddress()
622 * This function is to retrieve the MAC address of a wireless I/F.
623 */
624int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
625{
626 dutCommand_t *getMac = (dutCommand_t *)caCmdBuf;
627 dutCmdResponse_t *getmacResp = &gGenericResp;
628 char *str;
629 char *ifname = getMac->intf;
630
631 FILE *tmpfd;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800632 char string[257];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000633
634 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");
635 /*
636 * run the script "getipconfig.sh" to find out the mac
637 */
Dake Zhao0a832172015-01-06 11:08:47 -0800638 sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800639 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000640
641 tmpfd = fopen("/tmp/ipconfig.txt", "r+");
642 if(tmpfd == NULL)
643 {
Dake Zhao0a832172015-01-06 11:08:47 -0800644 getmacResp->status = STATUS_ERROR;
645 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf);
646 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000647
Dake Zhao0a832172015-01-06 11:08:47 -0800648 DPRINT_ERR(WFA_ERR, "file open failed\n");
649 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000650 }
651
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800652 if(fgets((char *)&string[0], 256, tmpfd) == NULL)
653 {
Dake Zhao0a832172015-01-06 11:08:47 -0800654 getmacResp->status = STATUS_ERROR;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000655 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800656
657 str = strtok(string, " ");
658 while(str && ((strcmp(str,"HWaddr")) != 0))
659 {
Dake Zhao0a832172015-01-06 11:08:47 -0800660 str = strtok(NULL, " ");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800661 }
Dake Zhao0a832172015-01-06 11:08:47 -0800662
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800663 /* get mac */
664 if(str)
665 {
666 str = strtok(NULL, " ");
667 strcpy(getmacResp->cmdru.mac, str);
668 getmacResp->status = STATUS_COMPLETE;
669 }
Dake Zhao0a832172015-01-06 11:08:47 -0800670
671 wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000672
673 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
674
675 fclose(tmpfd);
676 return WFA_SUCCESS;
677}
678
679/*
680 * wfaStaGetStats():
Dake Zhao0a832172015-01-06 11:08:47 -0800681 * The function is to retrieve the statistics of the I/F's layer 2 txFrames,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000682 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
Dake Zhao0a832172015-01-06 11:08:47 -0800683 * Currently there is not definition how to use these info.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000684 */
685int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
686{
Dake Zhao0a832172015-01-06 11:08:47 -0800687 dutCmdResponse_t *statsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000688
Dake Zhao0a832172015-01-06 11:08:47 -0800689 /* this is never used, you can skip this call */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000690
Dake Zhao0a832172015-01-06 11:08:47 -0800691 statsResp->status = STATUS_ERROR;
692 wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf);
693 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000694
695
Dake Zhao0a832172015-01-06 11:08:47 -0800696 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000697}
698
699/*
700 * wfaSetEncryption():
701 * The function is to set the wireless interface with WEP or none.
702 *
Dake Zhao0a832172015-01-06 11:08:47 -0800703 * Since WEP is optional test, current function is only used for
704 * resetting the Security to NONE/Plaintext (OPEN). To test WEP,
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000705 * this function should be replaced by the next one (wfaSetEncryption1())
706 *
Dake Zhao0a832172015-01-06 11:08:47 -0800707 * Input parameters:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000708 * 1. I/F
709 * 2. ssid
710 * 3. encpType - wep or none
711 * Optional:
712 * 4. key1
713 * 5. key2
714 * 6. key3
715 * 7. key4
716 * 8. activeKey Index
717 */
718
719int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
720{
Dake Zhao0a832172015-01-06 11:08:47 -0800721 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
722 dutCmdResponse_t *setEncrypResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000723
Dake Zhao0a832172015-01-06 11:08:47 -0800724 /*
725 * disable the network first
726 */
727 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
728 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000729
Dake Zhao0a832172015-01-06 11:08:47 -0800730 /*
731 * set SSID
732 */
733 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
734 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000735
Dake Zhao0a832172015-01-06 11:08:47 -0800736 /*
737 * Tell the supplicant for infrastructure mode (1)
738 */
739 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
740 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000741
Dake Zhao0a832172015-01-06 11:08:47 -0800742 /*
743 * set Key management to NONE (NO WPA) for plaintext or WEP
744 */
745 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
746 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000747
Dake Zhao0a832172015-01-06 11:08:47 -0800748 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
749 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000750
Dake Zhao0a832172015-01-06 11:08:47 -0800751 setEncrypResp->status = STATUS_COMPLETE;
752 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
753 *respLen = WFA_TLV_HDR_LEN + 4;
754
755 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000756}
757
758/*
759 * Since WEP is optional, this function could be used to replace
Dake Zhao0a832172015-01-06 11:08:47 -0800760 * wfaSetEncryption() if necessary.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000761 */
762int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
763{
Dake Zhao0a832172015-01-06 11:08:47 -0800764 caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf;
765 dutCmdResponse_t *setEncrypResp = &gGenericResp;
766 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000767
Dake Zhao0a832172015-01-06 11:08:47 -0800768 /*
769 * disable the network first
770 */
771 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf);
772 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000773
Dake Zhao0a832172015-01-06 11:08:47 -0800774 /*
775 * set SSID
776 */
777 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid);
778 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000779
Dake Zhao0a832172015-01-06 11:08:47 -0800780 /*
781 * Tell the supplicant for infrastructure mode (1)
782 */
783 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf);
784 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000785
Dake Zhao0a832172015-01-06 11:08:47 -0800786 /*
787 * set Key management to NONE (NO WPA) for plaintext or WEP
788 */
789 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf);
790 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000791
Dake Zhao0a832172015-01-06 11:08:47 -0800792 /* set keys */
793 if(setEncryp->encpType == 1)
794 {
795 for(i=0; i<4; i++)
796 {
797 if(setEncryp->keys[i][0] != '\0')
798 {
799 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s",
800 setEncryp->intf, i, setEncryp->keys[i]);
801 sret = system(gCmdStr);
802 }
803 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000804
Dake Zhao0a832172015-01-06 11:08:47 -0800805 /* set active key */
806 i = setEncryp->activeKeyIdx;
807 if(setEncryp->keys[i][0] != '\0')
808 {
809 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
810 setEncryp->intf, setEncryp->activeKeyIdx);
811 sret = system(gCmdStr);
812 }
813 }
814 else /* clearly remove the keys -- reported by p.schwann */
815 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000816
Dake Zhao0a832172015-01-06 11:08:47 -0800817 for(i = 0; i < 4; i++)
818 {
819 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i);
820 sret = system(gCmdStr);
821 }
822 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000823
Dake Zhao0a832172015-01-06 11:08:47 -0800824 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf);
825 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000826
Dake Zhao0a832172015-01-06 11:08:47 -0800827 setEncrypResp->status = STATUS_COMPLETE;
828 wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf);
829 *respLen = WFA_TLV_HDR_LEN + 4;
830
831 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000832}
833
834int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
835{
836 int ret = WFA_SUCCESS;
837
838 return ret;
839}
840
841/*
842 * wfaStaSetEapTLS():
843 * This is to set
844 * 1. ssid
845 * 2. encrypType - tkip or aes-ccmp
846 * 3. keyManagementType - wpa or wpa2
847 * 4. trustedRootCA
848 * 5. clientCertificate
849 */
850int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
851{
Dake Zhao0a832172015-01-06 11:08:47 -0800852 caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf;
853 char *ifname = setTLS->intf;
854 dutCmdResponse_t *setEapTlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000855
Dake Zhao0a832172015-01-06 11:08:47 -0800856 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000857
Dake Zhao0a832172015-01-06 11:08:47 -0800858 /*
859 * need to store the trustedROOTCA and clientCertificate into a file first.
860 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000861#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800862 sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate);
863 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000864#else
865
Dake Zhao0a832172015-01-06 11:08:47 -0800866 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
867 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000868
Dake Zhao0a832172015-01-06 11:08:47 -0800869 /* ssid */
870 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid);
871 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000872
Dake Zhao0a832172015-01-06 11:08:47 -0800873 /* key management */
874 if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0)
875 {
876 }
877 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0)
878 {
879 }
880 else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0)
881 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000882
Dake Zhao0a832172015-01-06 11:08:47 -0800883 }
884 else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0)
885 {
886 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
887 }
888 else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0)
889 {
890 // to take all and device to pick any one supported.
891 }
892 else
893 {
894 // ??
895 }
896 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000897
Dake Zhao0a832172015-01-06 11:08:47 -0800898 /* protocol WPA */
899 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
900 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000901
Dake Zhao0a832172015-01-06 11:08:47 -0800902 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname);
903 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000904
Dake Zhao0a832172015-01-06 11:08:47 -0800905 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA);
906 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000907
Dake Zhao0a832172015-01-06 11:08:47 -0800908 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname);
909 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000910
Dake Zhao0a832172015-01-06 11:08:47 -0800911 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate);
912 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000913
Dake Zhao0a832172015-01-06 11:08:47 -0800914 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname);
915 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000916
Dake Zhao0a832172015-01-06 11:08:47 -0800917 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
918 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000919#endif
920
Dake Zhao0a832172015-01-06 11:08:47 -0800921 setEapTlsResp->status = STATUS_COMPLETE;
922 wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf);
923 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000924
Dake Zhao0a832172015-01-06 11:08:47 -0800925 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000926}
927
928/*
Dake Zhao0a832172015-01-06 11:08:47 -0800929 * The function is to set
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000930 * 1. ssid
931 * 2. passPhrase
932 * 3. keyMangementType - wpa/wpa2
933 * 4. encrypType - tkip or aes-ccmp
934 */
935int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Dake Zhao0a832172015-01-06 11:08:47 -0800936{
937 /*Incompleted function*/
938 dutCmdResponse_t *setPskResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000939
Dake Zhaob7ed41a2014-12-04 11:24:58 -0800940#ifndef WFA_PC_CONSOLE
Dake Zhao0a832172015-01-06 11:08:47 -0800941 caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000942#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -0800943 sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase);
944 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000945#else
Dake Zhao0a832172015-01-06 11:08:47 -0800946 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid);
947 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000948
Dake Zhao0a832172015-01-06 11:08:47 -0800949 if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0)
950 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf);
951 else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0)
952 {
953 // take all and device to pick it supported.
954 }
955 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0)
956 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000957
Dake Zhao0a832172015-01-06 11:08:47 -0800958 }
959 else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0)
960 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000961
Dake Zhao0a832172015-01-06 11:08:47 -0800962 }
963 else if (strcasecmp(setPSK->keyMgmtType, "wpa2-wpa-psk") == 0)
964 {
Ray Wang9c508692014-04-01 17:04:59 -0700965
Dake Zhao0a832172015-01-06 11:08:47 -0800966 }
967 else
968 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -0800969
Dake Zhao0a832172015-01-06 11:08:47 -0800970 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000971
Dake Zhao0a832172015-01-06 11:08:47 -0800972 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase);
973 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000974
Dake Zhao0a832172015-01-06 11:08:47 -0800975 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf);
976 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000977
Dake Zhao0a832172015-01-06 11:08:47 -0800978 /* if PMF enable */
979 if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL)
980 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000981
Dake Zhao0a832172015-01-06 11:08:47 -0800982 }
983 else if(setPSK->pmf == WFA_REQUIRED)
984 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000985
Dake Zhao0a832172015-01-06 11:08:47 -0800986 }
987 else if(setPSK->pmf == WFA_F_REQUIRED)
988 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000989
Dake Zhao0a832172015-01-06 11:08:47 -0800990 }
991 else if(setPSK->pmf == WFA_F_DISABLED)
992 {
993
994 }
995 else
996 {
997 /* Disable PMF */
998
999 }
1000
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001001#endif
1002
Dake Zhaob7ed41a2014-12-04 11:24:58 -08001003#endif
1004
Dake Zhao0a832172015-01-06 11:08:47 -08001005 setPskResp->status = STATUS_COMPLETE;
1006 wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf);
1007 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001008
Dake Zhao0a832172015-01-06 11:08:47 -08001009 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001010}
1011
1012/*
Dake Zhao0a832172015-01-06 11:08:47 -08001013 * wfaStaGetInfo():
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001014 * Get vendor specific information in name/value pair by a wireless I/F.
1015 */
1016int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1017{
Dake Zhao0a832172015-01-06 11:08:47 -08001018 dutCmdResponse_t infoResp;
1019 dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001020
Dake Zhao0a832172015-01-06 11:08:47 -08001021 /*
1022 * Normally this is called to retrieve the vendor information
1023 * from a interface, no implement yet
1024 */
1025 sprintf(infoResp.cmdru.info, "interface,%s,vendor,XXX,cardtype,802.11a/b/g", getInfo->intf);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001026
Dake Zhao0a832172015-01-06 11:08:47 -08001027 infoResp.status = STATUS_COMPLETE;
1028 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
1029 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
1030
1031 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001032}
1033
1034/*
1035 * wfaStaSetEapTTLS():
1036 * This is to set
1037 * 1. ssid
1038 * 2. username
1039 * 3. passwd
1040 * 4. encrypType - tkip or aes-ccmp
1041 * 5. keyManagementType - wpa or wpa2
1042 * 6. trustedRootCA
1043 */
1044int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1045{
Dake Zhao0a832172015-01-06 11:08:47 -08001046 caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf;
1047 char *ifname = setTTLS->intf;
1048 dutCmdResponse_t *setEapTtlsResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001049
1050#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001051 sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA);
1052 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001053#else
1054
Dake Zhao0a832172015-01-06 11:08:47 -08001055 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1056 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001057
Dake Zhao0a832172015-01-06 11:08:47 -08001058 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid);
1059 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001060
Dake Zhao0a832172015-01-06 11:08:47 -08001061 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username);
1062 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001063
Dake Zhao0a832172015-01-06 11:08:47 -08001064 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd);
1065 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001066
Dake Zhao0a832172015-01-06 11:08:47 -08001067 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1068 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001069
Dake Zhao0a832172015-01-06 11:08:47 -08001070 /* This may not need to set. if it is not set, default to take all */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001071// sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype);
Dake Zhao0a832172015-01-06 11:08:47 -08001072 if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0)
1073 {
1074 }
1075 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0)
1076 {
1077 }
1078 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0)
1079 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001080
Dake Zhao0a832172015-01-06 11:08:47 -08001081 }
1082 else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0)
1083 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001084
Dake Zhao0a832172015-01-06 11:08:47 -08001085 }
1086 else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0)
1087 {
1088 // to take all and device to pick one it supported
1089 }
1090 else
1091 {
1092 // ??
1093 }
1094 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001095
Dake Zhao0a832172015-01-06 11:08:47 -08001096 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname);
1097 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001098
Dake Zhao0a832172015-01-06 11:08:47 -08001099 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA);
1100 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001101
Dake Zhao0a832172015-01-06 11:08:47 -08001102 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1103 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001104
Dake Zhao0a832172015-01-06 11:08:47 -08001105 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname);
1106 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001107
Dake Zhao0a832172015-01-06 11:08:47 -08001108 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1109 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001110#endif
1111
Dake Zhao0a832172015-01-06 11:08:47 -08001112 setEapTtlsResp->status = STATUS_COMPLETE;
1113 wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf);
1114 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001115
Dake Zhao0a832172015-01-06 11:08:47 -08001116 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001117}
1118
1119/*
1120 * wfaStaSetEapSIM():
1121 * This is to set
1122 * 1. ssid
1123 * 2. user name
1124 * 3. passwd
1125 * 4. encrypType - tkip or aes-ccmp
1126 * 5. keyMangementType - wpa or wpa2
1127 */
1128int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1129{
Dake Zhao0a832172015-01-06 11:08:47 -08001130 caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf;
1131 char *ifname = setSIM->intf;
1132 dutCmdResponse_t *setEapSimResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001133
1134#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001135 sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype);
1136 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001137#else
1138
Dake Zhao0a832172015-01-06 11:08:47 -08001139 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1140 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001141
Dake Zhao0a832172015-01-06 11:08:47 -08001142 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid);
1143 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001144
1145
Dake Zhao0a832172015-01-06 11:08:47 -08001146 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username);
1147 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001148
Dake Zhao0a832172015-01-06 11:08:47 -08001149 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype);
1150 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001151
Dake Zhao0a832172015-01-06 11:08:47 -08001152 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname);
1153 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001154
Dake Zhao0a832172015-01-06 11:08:47 -08001155 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname);
1156 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001157
Dake Zhao0a832172015-01-06 11:08:47 -08001158 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1159 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001160
Dake Zhao0a832172015-01-06 11:08:47 -08001161 if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0)
1162 {
1163 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1164 }
1165 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0)
1166 {
1167 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1168 }
1169 else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0)
1170 {
1171 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1172 }
1173 else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0)
1174 {
1175 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1176 }
1177 else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0)
1178 {
1179 // take all and device to pick one which is supported.
1180 }
1181 else
1182 {
1183 // ??
1184 }
1185 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001186
1187#endif
1188
Dake Zhao0a832172015-01-06 11:08:47 -08001189 setEapSimResp->status = STATUS_COMPLETE;
1190 wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf);
1191 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001192
Dake Zhao0a832172015-01-06 11:08:47 -08001193 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001194}
1195
1196/*
1197 * wfaStaSetPEAP()
1198 * This is to set
1199 * 1. ssid
1200 * 2. user name
1201 * 3. passwd
1202 * 4. encryType - tkip or aes-ccmp
1203 * 5. keyMgmtType - wpa or wpa2
1204 * 6. trustedRootCA
1205 * 7. innerEAP
1206 * 8. peapVersion
1207 */
1208int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1209{
Dake Zhao0a832172015-01-06 11:08:47 -08001210 caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf;
1211 char *ifname = setPEAP->intf;
1212 dutCmdResponse_t *setPeapResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001213
1214#ifdef WFA_NEW_CLI_FORMAT
Dake Zhao0a832172015-01-06 11:08:47 -08001215 sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username,
1216 setPEAP->passwd, setPEAP->trustedRootCA,
1217 setPEAP->encrptype, setPEAP->peapVersion,
1218 setPEAP->innerEAP);
1219 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001220#else
1221
Dake Zhao0a832172015-01-06 11:08:47 -08001222 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
1223 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001224
Dake Zhao0a832172015-01-06 11:08:47 -08001225 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid);
1226 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001227
Dake Zhao0a832172015-01-06 11:08:47 -08001228 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname);
1229 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001230
Dake Zhao0a832172015-01-06 11:08:47 -08001231 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname);
1232 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001233
Dake Zhao0a832172015-01-06 11:08:47 -08001234 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username);
1235 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001236
Dake Zhao0a832172015-01-06 11:08:47 -08001237 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd);
1238 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001239
Dake Zhao0a832172015-01-06 11:08:47 -08001240 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA);
1241 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001242
Dake Zhao0a832172015-01-06 11:08:47 -08001243 if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0)
1244 {
1245 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname);
1246 }
1247 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0)
1248 {
1249 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1250 }
1251 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0)
1252 {
1253 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname);
1254 }
1255 else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0)
1256 {
1257 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
1258 }
1259 else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0)
1260 {
1261 // take all and device to pick one which is supported.
1262 }
1263 else
1264 {
1265 // ??
1266 }
1267 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001268
Dake Zhao0a832172015-01-06 11:08:47 -08001269 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion);
1270 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001271
Dake Zhao0a832172015-01-06 11:08:47 -08001272 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP);
1273 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001274
Dake Zhao0a832172015-01-06 11:08:47 -08001275 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
1276 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001277#endif
1278
Dake Zhao0a832172015-01-06 11:08:47 -08001279 setPeapResp->status = STATUS_COMPLETE;
1280 wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf);
1281 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001282
Dake Zhao0a832172015-01-06 11:08:47 -08001283 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001284}
1285
1286/*
1287 * wfaStaSetUAPSD()
1288 * This is to set
1289 * 1. acBE
1290 * 2. acBK
1291 * 3. acVI
1292 * 4. acVO
1293 */
1294int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1295{
Dake Zhao0a832172015-01-06 11:08:47 -08001296 dutCmdResponse_t *setUAPSDResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001297#if 0 /* used for only one specific device, need to update to reflect yours */
Dake Zhao0a832172015-01-06 11:08:47 -08001298 caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf;
1299 char *ifname = setUAPSD->intf;
1300 char tmpStr[10];
1301 char line[100];
1302 char *pathl="/etc/Wireless/RT61STA";
1303 BYTE acBE=1;
1304 BYTE acBK=1;
1305 BYTE acVO=1;
1306 BYTE acVI=1;
1307 BYTE APSDCapable;
1308 FILE *pipe;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001309
Dake Zhao0a832172015-01-06 11:08:47 -08001310 /*
1311 * A series of setting need to be done before doing WMM-PS
1312 * Additional steps of configuration may be needed.
1313 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001314
Dake Zhao0a832172015-01-06 11:08:47 -08001315 /*
1316 * bring down the interface
1317 */
1318 sprintf(gCmdStr, "ifconfig %s down",ifname);
1319 sret = system(gCmdStr);
1320 /*
1321 * Unload the Driver
1322 */
1323 sprintf(gCmdStr, "rmmod rt61");
1324 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001325#ifndef WFA_WMM_AC
Dake Zhao0a832172015-01-06 11:08:47 -08001326 if(setUAPSD->acBE != 1)
1327 acBE=setUAPSD->acBE = 0;
1328 if(setUAPSD->acBK != 1)
1329 acBK=setUAPSD->acBK = 0;
1330 if(setUAPSD->acVO != 1)
1331 acVO=setUAPSD->acVO = 0;
1332 if(setUAPSD->acVI != 1)
1333 acVI=setUAPSD->acVI = 0;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001334#else
Dake Zhao0a832172015-01-06 11:08:47 -08001335 acBE=setUAPSD->acBE;
1336 acBK=setUAPSD->acBK;
1337 acVO=setUAPSD->acVO;
1338 acVI=setUAPSD->acVI;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001339#endif
1340
Dake Zhao0a832172015-01-06 11:08:47 -08001341 APSDCapable = acBE||acBK||acVO||acVI;
1342 /*
1343 * set other AC parameters
1344 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001345
Dake Zhao0a832172015-01-06 11:08:47 -08001346 sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO);
1347 sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl);
1348 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001349
Dake Zhao0a832172015-01-06 11:08:47 -08001350 sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl);
1351 sret = system(gCmdStr);
1352 pipe = popen("uname -r", "r");
1353 /* Read into line the output of uname*/
1354 fscanf(pipe,"%s",line);
1355 pclose(pipe);
1356
1357 /*
1358 * load the Driver
1359 */
1360 sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line);
1361 sret = system(gCmdStr);
1362
1363 sprintf(gCmdStr, "ifconfig %s up",ifname);
1364 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001365#endif
1366
Dake Zhao0a832172015-01-06 11:08:47 -08001367 setUAPSDResp->status = STATUS_COMPLETE;
1368 wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf);
1369 *respLen = WFA_TLV_HDR_LEN + 4;
1370 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001371}
1372
1373int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1374{
Dake Zhao0a832172015-01-06 11:08:47 -08001375 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
1376 caDevInfo_t *devInfo = &dutCmd->cmdsu.dev;
1377 dutCmdResponse_t *infoResp = &gGenericResp;
1378 /*a vendor can fill in the proper info or anything non-disclosure */
1379 caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER};
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001380
Dake Zhao0a832172015-01-06 11:08:47 -08001381 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001382
Dake Zhao0a832172015-01-06 11:08:47 -08001383 if(devInfo->fw == 0)
1384 memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t));
1385 else
1386 {
1387 // Call internal API to pull the version ID */
1388 memcpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15);
1389 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001390
Dake Zhao0a832172015-01-06 11:08:47 -08001391 infoResp->status = STATUS_COMPLETE;
1392 wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1393 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001394
Dake Zhao0a832172015-01-06 11:08:47 -08001395 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001396
1397}
1398
1399/*
1400 * This funciton is to retrieve a list of interfaces and return
1401 * the list back to Agent control.
1402 * ********************************************************************
1403 * Note: We intend to make this WLAN interface name as a hardcode name.
1404 * Therefore, for a particular device, you should know and change the name
Dake Zhao0a832172015-01-06 11:08:47 -08001405 * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in
1406 * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001407 * likely is hardcoded just for CAPI command responses.
1408 * *******************************************************************
Dake Zhao0a832172015-01-06 11:08:47 -08001409 *
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001410 */
1411int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1412{
Dake Zhao0a832172015-01-06 11:08:47 -08001413 dutCmdResponse_t *infoResp = &gGenericResp;
1414 dutCommand_t *ifList = (dutCommand_t *)caCmdBuf;
1415 caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001416
Dake Zhao0a832172015-01-06 11:08:47 -08001417 DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001418
Dake Zhao0a832172015-01-06 11:08:47 -08001419 switch(ifList->cmdsu.iftype)
1420 {
1421 case IF_80211:
1422 infoResp->status = STATUS_COMPLETE;
1423 ifListResp->iftype = IF_80211;
1424 strcpy(ifListResp->ifs[0], WFA_STAUT_IF);
1425 strcpy(ifListResp->ifs[1], "NULL");
1426 strcpy(ifListResp->ifs[2], "NULL");
1427 break;
1428 case IF_ETH:
1429 infoResp->status = STATUS_COMPLETE;
1430 ifListResp->iftype = IF_ETH;
1431 strcpy(ifListResp->ifs[0], "eth0");
1432 strcpy(ifListResp->ifs[1], "NULL");
1433 strcpy(ifListResp->ifs[2], "NULL");
1434 break;
1435 default:
1436 {
1437 infoResp->status = STATUS_ERROR;
1438 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf);
1439 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001440
Dake Zhao0a832172015-01-06 11:08:47 -08001441 return WFA_SUCCESS;
1442 }
1443 }
1444
1445 wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf);
1446 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1447
1448 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001449}
1450
1451int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1452{
Dake Zhao0a832172015-01-06 11:08:47 -08001453 dutCmdResponse_t *debugResp = &gGenericResp;
1454 dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001455
Dake Zhao0a832172015-01-06 11:08:47 -08001456 DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001457
Dake Zhao0a832172015-01-06 11:08:47 -08001458 if(debugSet->cmdsu.dbg.state == 1) /* enable */
1459 wfa_defined_debug |= debugSet->cmdsu.dbg.level;
1460 else
1461 wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001462
Dake Zhao0a832172015-01-06 11:08:47 -08001463 debugResp->status = STATUS_COMPLETE;
1464 wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf);
1465 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001466
1467
Dake Zhao0a832172015-01-06 11:08:47 -08001468 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001469}
1470
1471
1472/*
1473 * wfaStaGetBSSID():
1474 * This function is to retrieve BSSID of a specific wireless I/F.
Dake Zhao0a832172015-01-06 11:08:47 -08001475 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001476int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1477{
Dake Zhao0a832172015-01-06 11:08:47 -08001478 char string[64];
1479 char *str;
1480 FILE *tmpfd;
1481 dutCmdResponse_t *bssidResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001482
Dake Zhao0a832172015-01-06 11:08:47 -08001483 DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n");
1484 /* retrieve the BSSID */
1485 sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001486
Dake Zhao0a832172015-01-06 11:08:47 -08001487 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001488
Dake Zhao0a832172015-01-06 11:08:47 -08001489 tmpfd = fopen("/tmp/bssid.txt", "r+");
1490 if(tmpfd == NULL)
1491 {
1492 bssidResp->status = STATUS_ERROR;
1493 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf);
1494 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001495
Dake Zhao0a832172015-01-06 11:08:47 -08001496 DPRINT_ERR(WFA_ERR, "file open failed\n");
1497 return WFA_FAILURE;
1498 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001499
Dake Zhao0a832172015-01-06 11:08:47 -08001500 for(;;)
1501 {
1502 if(fscanf(tmpfd, "%s", string) == EOF)
1503 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001504 bssidResp->status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08001505 strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001506 break;
Dake Zhao0a832172015-01-06 11:08:47 -08001507 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001508
Dake Zhao0a832172015-01-06 11:08:47 -08001509 if(strncmp(string, "bssid", 5) == 0)
1510 {
1511 str = strtok(string, "=");
1512 str = strtok(NULL, "=");
1513 if(str != NULL)
1514 {
1515 strcpy(bssidResp->cmdru.bssid, str);
1516 bssidResp->status = STATUS_COMPLETE;
1517 break;
1518 }
1519 }
1520 }
1521
1522 wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf);
1523 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1524
1525 fclose(tmpfd);
1526 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001527}
1528
1529/*
1530 * wfaStaSetIBSS()
1531 * This is to set
1532 * 1. ssid
1533 * 2. channel
1534 * 3. encrypType - none or wep
1535 * optional
1536 * 4. key1
1537 * 5. key2
1538 * 6. key3
1539 * 7. key4
1540 * 8. activeIndex - 1, 2, 3, or 4
1541 */
1542int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1543{
Dake Zhao0a832172015-01-06 11:08:47 -08001544 caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf;
1545 dutCmdResponse_t *setIbssResp = &gGenericResp;
1546 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001547
Dake Zhao0a832172015-01-06 11:08:47 -08001548 /*
1549 * disable the network first
1550 */
1551 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf);
1552 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001553
Dake Zhao0a832172015-01-06 11:08:47 -08001554 /*
1555 * set SSID
1556 */
1557 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid);
1558 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001559
Dake Zhao0a832172015-01-06 11:08:47 -08001560 /*
1561 * Set channel for IBSS
1562 */
1563 sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel);
1564 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001565
Dake Zhao0a832172015-01-06 11:08:47 -08001566 /*
1567 * Tell the supplicant for IBSS mode (1)
1568 */
1569 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf);
1570 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001571
Dake Zhao0a832172015-01-06 11:08:47 -08001572 /*
1573 * set Key management to NONE (NO WPA) for plaintext or WEP
1574 */
1575 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf);
1576 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001577
Dake Zhao0a832172015-01-06 11:08:47 -08001578 if(setIBSS->encpType == 1)
1579 {
1580 for(i=0; i<4; i++)
1581 {
1582 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1583 {
1584 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"",
1585 setIBSS->intf, i, setIBSS->keys[i]);
1586 sret = system(gCmdStr);
1587 }
1588 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001589
Dake Zhao0a832172015-01-06 11:08:47 -08001590 i = setIBSS->activeKeyIdx;
1591 if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13)
1592 {
1593 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i",
1594 setIBSS->intf, setIBSS->activeKeyIdx);
1595 sret = system(gCmdStr);
1596 }
1597 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001598
Dake Zhao0a832172015-01-06 11:08:47 -08001599 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf);
1600 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001601
Dake Zhao0a832172015-01-06 11:08:47 -08001602 setIbssResp->status = STATUS_COMPLETE;
1603 wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf);
1604 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001605
Dake Zhao0a832172015-01-06 11:08:47 -08001606 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001607}
1608
1609/*
1610 * wfaSetMode():
Dake Zhao0a832172015-01-06 11:08:47 -08001611 * The function is to set the wireless interface with a given mode (possible
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001612 * adhoc)
1613 * Input parameters:
1614 * 1. I/F
1615 * 2. ssid
1616 * 3. mode adhoc or managed
1617 * 4. encType
1618 * 5. channel
1619 * 6. key(s)
1620 * 7. active key
Dake Zhao0a832172015-01-06 11:08:47 -08001621 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001622int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1623{
Dake Zhao0a832172015-01-06 11:08:47 -08001624 caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf;
1625 dutCmdResponse_t *SetModeResp = &gGenericResp;
1626 int i;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001627
Dake Zhao0a832172015-01-06 11:08:47 -08001628 /*
1629 * bring down the interface
1630 */
1631 sprintf(gCmdStr, "ifconfig %s down",setmode->intf);
1632 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001633
Dake Zhao0a832172015-01-06 11:08:47 -08001634 /*
1635 * distroy the interface
1636 */
1637 sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf);
1638 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001639
1640
Dake Zhao0a832172015-01-06 11:08:47 -08001641 /*
1642 * re-create the interface with the given mode
1643 */
1644 if(setmode->mode == 1)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001645 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf);
Dake Zhao0a832172015-01-06 11:08:47 -08001646 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001647 sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf);
1648
Dake Zhao0a832172015-01-06 11:08:47 -08001649 sret = system(gCmdStr);
1650 if(setmode->encpType == ENCRYPT_WEP)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001651 {
Dake Zhao0a832172015-01-06 11:08:47 -08001652 int j = setmode->activeKeyIdx;
1653 for(i=0; i<4; i++)
1654 {
1655 if(setmode->keys[i][0] != '\0')
1656 {
1657 sprintf(gCmdStr, "iwconfig %s key s:%s",
1658 setmode->intf, setmode->keys[i]);
1659 sret = system(gCmdStr);
1660 }
1661 /* set active key */
1662 if(setmode->keys[j][0] != '\0')
1663 sprintf(gCmdStr, "iwconfig %s key s:%s",
1664 setmode->intf, setmode->keys[j]);
1665 sret = system(gCmdStr);
1666 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001667
1668 }
Dake Zhao0a832172015-01-06 11:08:47 -08001669 /*
1670 * Set channel for IBSS
1671 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001672 if(setmode->channel)
1673 {
Dake Zhao0a832172015-01-06 11:08:47 -08001674 sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel);
1675 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001676 }
1677
1678
Dake Zhao0a832172015-01-06 11:08:47 -08001679 /*
1680 * set SSID
1681 */
1682 sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid);
1683 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001684
Dake Zhao0a832172015-01-06 11:08:47 -08001685 /*
1686 * bring up the interface
1687 */
1688 sprintf(gCmdStr, "ifconfig %s up",setmode->intf);
1689 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001690
Dake Zhao0a832172015-01-06 11:08:47 -08001691 SetModeResp->status = STATUS_COMPLETE;
1692 wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf);
1693 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001694
Dake Zhao0a832172015-01-06 11:08:47 -08001695 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001696}
1697
1698int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1699{
Dake Zhao0a832172015-01-06 11:08:47 -08001700 caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf;
1701 dutCmdResponse_t *SetPSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001702
Dake Zhao0a832172015-01-06 11:08:47 -08001703 sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode);
1704 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001705
1706
Dake Zhao0a832172015-01-06 11:08:47 -08001707 SetPSResp->status = STATUS_COMPLETE;
1708 wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf);
1709 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001710
Dake Zhao0a832172015-01-06 11:08:47 -08001711 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001712}
1713
1714int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1715{
Dake Zhao0a832172015-01-06 11:08:47 -08001716 caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload;
1717 dutCmdResponse_t *upLoadResp = &gGenericResp;
1718 caStaUploadResp_t *upld = &upLoadResp->cmdru.uld;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001719
Dake Zhao0a832172015-01-06 11:08:47 -08001720 if(upload->type == WFA_UPLOAD_VHSO_RPT)
1721 {
1722 int rbytes;
1723 /*
1724 * if asked for the first packet, always to open the file
1725 */
1726 if(upload->next == 1)
1727 {
1728 if(e2efp != NULL)
1729 {
1730 fclose(e2efp);
1731 e2efp = NULL;
1732 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001733
Dake Zhao0a832172015-01-06 11:08:47 -08001734 e2efp = fopen(e2eResults, "r");
1735 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001736
Dake Zhao0a832172015-01-06 11:08:47 -08001737 if(e2efp == NULL)
1738 {
1739 upLoadResp->status = STATUS_ERROR;
1740 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1741 *respLen = WFA_TLV_HDR_LEN + 4;
1742 return WFA_FAILURE;
1743 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001744
Dake Zhao0a832172015-01-06 11:08:47 -08001745 rbytes = fread(upld->bytes, 1, 256, e2efp);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001746
Dake Zhao0a832172015-01-06 11:08:47 -08001747 if(rbytes < 256)
1748 {
1749 /*
1750 * this means no more bytes after this read
1751 */
1752 upld->seqnum = 0;
1753 fclose(e2efp);
1754 e2efp=NULL;
1755 }
1756 else
1757 {
1758 upld->seqnum = upload->next;
1759 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001760
Dake Zhao0a832172015-01-06 11:08:47 -08001761 upld->nbytes = rbytes;
1762
1763 upLoadResp->status = STATUS_COMPLETE;
1764 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf);
1765 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
1766 }
1767 else
1768 {
1769 upLoadResp->status = STATUS_ERROR;
1770 wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf);
1771 *respLen = WFA_TLV_HDR_LEN + 4;
1772 }
1773
1774 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001775}
1776/*
1777 * wfaStaSetWMM()
1778 * TO be ported on a specific plaform for the DUT
1779 * This is to set the WMM related parameters at the DUT.
1780 * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF)
1781 * It is expected that this function will set all the WMM related parametrs for a particular GROUP .
1782 */
1783int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1784{
1785#ifdef WFA_WMM_AC
1786 caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf;
1787 char *ifname = setwmm->intf;
1788 dutCmdResponse_t *setwmmResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001789
1790 switch(setwmm->group)
1791 {
1792 case GROUP_WMMAC:
Dake Zhao0a832172015-01-06 11:08:47 -08001793 if (setwmm->send_trig)
1794 {
1795 int Sockfd;
1796 struct sockaddr_in psToAddr;
1797 unsigned int TxMsg[512];
1798
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001799 Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346);
Dake Zhao0a832172015-01-06 11:08:47 -08001800 memset(&psToAddr, 0, sizeof(psToAddr));
1801 psToAddr.sin_family = AF_INET;
1802 psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr);
1803 psToAddr.sin_port = htons(12346);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001804
1805
Dake Zhao0a832172015-01-06 11:08:47 -08001806 switch (setwmm->trig_ac)
1807 {
1808 case WMMAC_AC_VO:
1809 wfaTGSetPrio(Sockfd, 7);
1810 create_apts_msg(APTS_CK_VO, TxMsg, 0);
1811 printf("\r\nSending AC_VO trigger packet\n");
1812 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001813
Dake Zhao0a832172015-01-06 11:08:47 -08001814 case WMMAC_AC_VI:
1815 wfaTGSetPrio(Sockfd, 5);
1816 create_apts_msg(APTS_CK_VI, TxMsg, 0);
1817 printf("\r\nSending AC_VI trigger packet\n");
1818 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001819
Dake Zhao0a832172015-01-06 11:08:47 -08001820 case WMMAC_AC_BK:
1821 wfaTGSetPrio(Sockfd, 2);
1822 create_apts_msg(APTS_CK_BK, TxMsg, 0);
1823 printf("\r\nSending AC_BK trigger packet\n");
1824 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001825
Dake Zhao0a832172015-01-06 11:08:47 -08001826 default:
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001827 case WMMAC_AC_BE:
Dake Zhao0a832172015-01-06 11:08:47 -08001828 wfaTGSetPrio(Sockfd, 0);
1829 create_apts_msg(APTS_CK_BE, TxMsg, 0);
1830 printf("\r\nSending AC_BE trigger packet\n");
1831 break;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001832 }
1833
Dake Zhao0a832172015-01-06 11:08:47 -08001834 sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr,
1835 sizeof(struct sockaddr));
1836 close(Sockfd);
1837 usleep(1000000);
1838 }
1839 else if (setwmm->action == WMMAC_ADDTS)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001840 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001841 printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, "
Dake Zhao0a832172015-01-06 11:08:47 -08001842 "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d"
1843 "Fixed %d, MSDU Size: %d, Max MSDU Size %d, "
1844 "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, "
1845 "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, "
1846 "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, "
1847 "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, "
1848 "MEDIUM TIME: %d, ACCESSCAT: %d\n",
1849 setwmm->actions.addts.dialog_token,
1850 setwmm->actions.addts.tspec.tsinfo.TID,
1851 setwmm->actions.addts.tspec.tsinfo.direction,
1852 setwmm->actions.addts.tspec.tsinfo.PSB,
1853 setwmm->actions.addts.tspec.tsinfo.UP,
1854 setwmm->actions.addts.tspec.tsinfo.infoAck,
1855 setwmm->actions.addts.tspec.tsinfo.bstSzDef,
1856 setwmm->actions.addts.tspec.Fixed,
1857 setwmm->actions.addts.tspec.size,
1858 setwmm->actions.addts.tspec.maxsize,
1859 setwmm->actions.addts.tspec.min_srvc,
1860 setwmm->actions.addts.tspec.max_srvc,
1861 setwmm->actions.addts.tspec.inactivity,
1862 setwmm->actions.addts.tspec.suspension,
1863 setwmm->actions.addts.tspec.srvc_strt_tim,
1864 setwmm->actions.addts.tspec.mindatarate,
1865 setwmm->actions.addts.tspec.meandatarate,
1866 setwmm->actions.addts.tspec.peakdatarate,
1867 setwmm->actions.addts.tspec.burstsize,
1868 setwmm->actions.addts.tspec.delaybound,
1869 setwmm->actions.addts.tspec.PHYrate,
1870 setwmm->actions.addts.tspec.sba,
1871 setwmm->actions.addts.tspec.medium_time,
1872 setwmm->actions.addts.accesscat);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001873
Dake Zhao862c94b2014-12-08 14:35:35 -08001874 //tspec should be set here.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001875
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001876 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001877 }
1878 else if (setwmm->action == WMMAC_DELTS)
Dake Zhao0a832172015-01-06 11:08:47 -08001879 {
1880 // send del tspec
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001881 }
1882
1883 setwmmResp->status = STATUS_COMPLETE;
1884 break;
1885
1886 case GROUP_WMMCONF:
1887 sprintf(gCmdStr, "iwconfig %s rts %d",
1888 ifname,setwmm->actions.config.rts_thr);
1889
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001890 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001891 sprintf(gCmdStr, "iwconfig %s frag %d",
1892 ifname,setwmm->actions.config.frag_thr);
1893
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001894 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001895 sprintf(gCmdStr, "iwpriv %s wmmcfg %d",
1896 ifname, setwmm->actions.config.wmm);
1897
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001898 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001899 setwmmResp->status = STATUS_COMPLETE;
1900 break;
1901
1902 default:
1903 DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group);
1904 setwmmResp->status = STATUS_ERROR;
1905 break;
1906
1907 }
1908
1909 wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf);
1910 *respLen = WFA_TLV_HDR_LEN + 4;
1911#endif
1912
1913 return WFA_SUCCESS;
1914}
1915
1916int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1917{
Dake Zhao0a832172015-01-06 11:08:47 -08001918 dutCmdResponse_t *sendNeigReqResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001919
Dake Zhao0a832172015-01-06 11:08:47 -08001920 /*
1921 * run your device to send NEIGREQ
1922 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001923
Dake Zhao0a832172015-01-06 11:08:47 -08001924 sendNeigReqResp->status = STATUS_COMPLETE;
1925 wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf);
1926 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001927
Dake Zhao0a832172015-01-06 11:08:47 -08001928 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001929}
1930
1931int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
1932{
1933 caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf;
1934 char *ifname = setFAST->intf;
1935 dutCmdResponse_t *setEapFastResp = &gGenericResp;
1936
1937#ifdef WFA_NEW_CLI_FORMAT
1938 sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username,
Dake Zhao0a832172015-01-06 11:08:47 -08001939 setFAST->passwd, setFAST->pacFileName,
1940 setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001941 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001942#else
1943
1944 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001945 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001946
1947 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001948 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001949
1950 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001951 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001952
1953 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001954 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001955
1956 if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0)
1957 {
1958 }
1959 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0)
1960 {
1961 }
1962 else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0)
1963 {
Dake Zhao0a832172015-01-06 11:08:47 -08001964
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001965 }
1966 else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0)
1967 {
Dake Zhao0a832172015-01-06 11:08:47 -08001968 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001969 }
1970 else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0)
1971 {
Dake Zhao0a832172015-01-06 11:08:47 -08001972 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001973 }
1974 else
1975 {
Dake Zhao0a832172015-01-06 11:08:47 -08001976 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001977 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001978 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001979
1980 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001981 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001982
1983 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001984 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001985
1986 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001987 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001988
1989 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001990 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001991
1992 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001993 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001994
1995 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08001996 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001997#endif
1998
1999 setEapFastResp->status = STATUS_COMPLETE;
2000 wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf);
2001 *respLen = WFA_TLV_HDR_LEN + 4;
2002
2003 return WFA_SUCCESS;
2004}
2005
2006int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2007{
2008 caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf;
2009 char *ifname = setAKA->intf;
2010 dutCmdResponse_t *setEapAkaResp = &gGenericResp;
2011
2012#ifdef WFA_NEW_CLI_FORMAT
2013 sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002014 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002015#else
2016
2017 sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002018 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002019
2020 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002021 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002022
2023 if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0)
2024 {
2025 }
2026 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0)
2027 {
2028 }
2029 else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0)
2030 {
Dake Zhao0a832172015-01-06 11:08:47 -08002031
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002032 }
2033 else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0)
2034 {
Dake Zhao0a832172015-01-06 11:08:47 -08002035 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002036 }
2037 else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0)
2038 {
Dake Zhao0a832172015-01-06 11:08:47 -08002039 // take all and device to pick one which is supported.
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002040 }
2041 else
2042 {
Dake Zhao0a832172015-01-06 11:08:47 -08002043 // ??
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002044 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002045 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002046
2047 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002048 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002049 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002050 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002051
2052 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002053 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002054
2055 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002056 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002057
2058 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002059 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002060
2061 sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002062 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002063
2064 sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002065 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002066#endif
2067
2068 setEapAkaResp->status = STATUS_COMPLETE;
2069 wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf);
2070 *respLen = WFA_TLV_HDR_LEN + 4;
2071
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002072 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002073}
2074
2075int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2076{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002077 caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf;
2078 dutCmdResponse_t *setSystimeResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002079
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002080 DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002081
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002082 sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year);
2083 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002084
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002085 sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds);
2086 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002087
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002088 setSystimeResp->status = STATUS_COMPLETE;
2089 wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf);
2090 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002091
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002092 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002093}
2094
2095#ifdef WFA_STA_TB
2096int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2097{
Dake Zhao0a832172015-01-06 11:08:47 -08002098 dutCmdResponse_t *PresetParamsResp = &gGenericResp;
2099 caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf;
2100 BYTE presetDone = 1;
2101 int st = 0;
Ray Wangd11ca032015-05-29 18:25:46 -07002102 char cmdStr[128];
2103 char string[256];
2104 FILE *tmpfd = NULL;
2105 long val;
2106 char *endptr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002107
Dake Zhao0a832172015-01-06 11:08:47 -08002108 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002109
Ray Wangd11ca032015-05-29 18:25:46 -07002110 if (presetParams->supplicant == eWpaSupplicant)
2111 {
2112 st = access("/tmp/processid.txt", F_OK);
2113 if (st != -1)
2114 {
2115 st = remove("/tmp/processid.txt");
2116 }
2117
2118 sprintf(cmdStr, "/usr/local/sbin/findprocess.sh %s /tmp/processid.txt\n", "wpa_supplicant");
2119 st = system(cmdStr);
2120
2121 tmpfd = fopen("/tmp/processid.txt", "r+");
2122 if (tmpfd == NULL)
2123 {
2124 DPRINT_ERR(WFA_ERR, "process id file not exist\n");
2125 return WFA_FAILURE;
2126 }
2127
2128 for (;;)
2129 {
2130 if (fgets(string, 256, tmpfd) == NULL)
2131 break;
2132
2133 errno = 0;
2134 val = strtol(string, &endptr, 10);
2135 if (errno != 0 && val == 0)
2136 {
2137 DPRINT_ERR(WFA_ERR, "strtol error\n");
2138 return WFA_FAILURE;
2139 }
2140
2141 if (endptr == string)
2142 {
2143 DPRINT_ERR(WFA_ERR, "No wpa_supplicant instance was found\n");
2144 }
2145
2146 presetDone = 1;
2147 }
2148 }
2149
Dake Zhao0a832172015-01-06 11:08:47 -08002150 if(presetParams->wmmFlag)
2151 {
2152 st = wfaExecuteCLI(gCmdStr);
2153 switch(st)
2154 {
2155 case 0:
2156 presetDone = 1;
2157 break;
2158 case 1:
2159 presetDone = 0;
2160 break;
2161 case 2:
2162 presetDone = 0;
2163 break;
2164 }
2165 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002166
Dake Zhao0a832172015-01-06 11:08:47 -08002167 if(presetParams->modeFlag != 0)
2168 {
2169 switch(presetParams->wirelessMode)
2170 {
2171 default:
2172 printf("other mode does not need to support\n");
2173 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002174
Dake Zhao0a832172015-01-06 11:08:47 -08002175 st = wfaExecuteCLI(gCmdStr);
2176 switch(st)
2177 {
2178 case 0:
2179 presetDone = 1;
2180 break;
2181 case 1:
2182 presetDone = 0;
2183 case 2:
2184 presetDone = 0;
2185 break;
2186 }
2187 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002188
2189
Dake Zhao0a832172015-01-06 11:08:47 -08002190 if(presetParams->psFlag)
2191 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002192
Dake Zhao0a832172015-01-06 11:08:47 -08002193 printf("%s\n", gCmdStr);
2194 sret = system(gCmdStr);
2195 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002196
Dake Zhao0a832172015-01-06 11:08:47 -08002197 /************the followings are used for Voice Enterprise **************/
2198 if(presetParams->program == PROG_TYPE_VENT)
2199 {
2200 if(presetParams->ftoa == eEnable)
2201 {
2202 // enable Fast BSS Transition Over the Air
2203 }
2204 else
2205 {
2206 // disable Fast BSS Transition Over the Air
2207 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002208
Dake Zhao0a832172015-01-06 11:08:47 -08002209 if(presetParams->ftds == eEnable)
2210 {
2211 // enable Fast BSS Transition Over the DS
2212 }
2213 else
2214 {
2215 // disable Fast BSS Transition Over the DS
2216 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002217
Dake Zhao0a832172015-01-06 11:08:47 -08002218 if(presetParams->activescan == eEnable)
2219 {
2220 // Enable Active Scan on STA
2221 }
2222 else
2223 {
2224 // disable Active Scan on STA
2225 }
2226 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002227
Dake Zhao0a832172015-01-06 11:08:47 -08002228 /************the followings are used for Wi-Fi Display *************/
2229 if(presetParams->program == PROG_TYPE_WFD)
2230 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002231
Dake Zhao0a832172015-01-06 11:08:47 -08002232 if(presetParams->tdlsFlag)
2233 {
2234 // enable / disable tdls based on tdls
2235 }
2236 if(presetParams->wfdDevTypeFlag)
2237 {
2238 // set WFD device type to source/sink/dual based on wfdDevType
2239 }
2240 if(presetParams->wfdUibcGenFlag)
2241 {
2242 // enable / disable the feature
2243 }
2244 if(presetParams->wfdUibcHidFlag)
2245 {
2246 // enable / disable feature
2247 }
2248 if(presetParams->wfdUiInputFlag)
2249 {
2250 // set the UI input as mentioned
2251 }
2252 if(presetParams->wfdHdcpFlag)
2253 {
2254 // enable / disable feature
2255 }
2256 if(presetParams->wfdFrameSkipFlag)
2257 {
2258 // enable / disable feature
2259 }
2260 if(presetParams->wfdAvChangeFlag)
2261 {
2262 // enable / disable feature
2263 }
2264 if(presetParams->wfdStandByFlag)
2265 {
2266 // enable / disable feature
2267 }
2268 if(presetParams->wfdInVideoFlag)
2269 {
2270 // select the input vide as protecteed or non-protetcted or protected audio
2271 // or unprotected audio etc.
2272 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002273
Dake Zhao0a832172015-01-06 11:08:47 -08002274 if(presetParams->wfdVideoFmatFlag)
2275 {
2276 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002277
Dake Zhao0a832172015-01-06 11:08:47 -08002278 //switch(presetParams->wfdVideoFmt )
2279 //{
2280 // case e640x480p60:
2281 // ;
2282 // default:
2283 // set the mandatory
2284 // }
2285 }
2286 if(presetParams->wfdAudioFmatFlag)
2287 {
2288 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002289
Dake Zhao0a832172015-01-06 11:08:47 -08002290 //switch(presetParams->wfdAudioFmt )
2291 //{
2292 // case eMandatoryAudioMode:
2293 // ;
2294 // case eDefaultAudioMode:
2295 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002296
Dake Zhao0a832172015-01-06 11:08:47 -08002297 // default:
2298 // set the mandatory
2299 // }
2300 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002301
Dake Zhao0a832172015-01-06 11:08:47 -08002302 if(presetParams->wfdI2cFlag)
2303 {
2304 // enable / disable feature
2305 }
2306 if(presetParams->wfdVideoRecoveryFlag)
2307 {
2308 // enable / disable feature
2309 }
2310 if(presetParams->wfdPrefDisplayFlag)
2311 {
2312 // enable / disable feature
2313 }
2314 if(presetParams->wfdServiceDiscoveryFlag)
2315 {
2316 // enable / disable feature
2317 }
2318 if(presetParams->wfd3dVideoFlag)
2319 {
2320 // enable / disable feature
2321 }
2322 if(presetParams->wfdMultiTxStreamFlag)
2323 {
2324 // enable / disable feature
2325 }
2326 if(presetParams->wfdTimeSyncFlag)
2327 {
2328 // enable / disable feature
2329 }
2330 if(presetParams->wfdEDIDFlag)
2331 {
2332 // enable / disable feature
2333 }
2334 if(presetParams->wfdUIBCPrepareFlag)
2335 {
2336 // Provdes information to start valid WFD session to check UIBC operation.
2337 }
2338 if(presetParams->wfdCoupledCapFlag)
2339 {
2340 // enable / disable feature
2341 }
2342 if(presetParams->wfdOptionalFeatureFlag)
2343 {
2344 // disable all program specific optional features
2345 }
2346 if(presetParams->wfdSessionAvailFlag)
2347 {
2348 // enable / disable session available bit
2349 }
2350 if(presetParams->wfdDeviceDiscoverabilityFlag)
2351 {
2352 // enable / disable feature
2353 }
2354 }
2355
Dake Zhao655efed2015-03-11 17:39:13 -07002356 if(presetParams->program == PROG_TYPE_WFDS)
2357 {
2358
2359 if(presetParams->wfdsType == eAcceptPD)
2360 {
2361 // preset to accept PD request
2362 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2363 {
2364 // use presetParams->wfdsConnectionCapability and set role accordingly
2365 }
2366
2367 }
2368 if(presetParams->wfdsType == eRejectPD)
2369 {
2370 // preset to Reject PD request
2371 }
2372 if(presetParams->wfdsType == eIgnorePD)
2373 {
2374 // preset to Ignore PD request
2375 }
2376 if(presetParams->wfdsType == eRejectSession)
2377 {
2378 // preset to reject Session request
2379 }
2380
2381 }
2382
2383 if (presetDone)
2384 {
2385 PresetParamsResp->status = STATUS_COMPLETE;
2386 }
2387 else
2388 {
2389 PresetParamsResp->status = STATUS_INVALID;
2390 }
Dake Zhao0a832172015-01-06 11:08:47 -08002391
2392 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2393 *respLen = WFA_TLV_HDR_LEN + 4;
2394
2395 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002396}
2397
2398int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2399{
2400 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2401
2402 v11nParamsResp->status = STATUS_COMPLETE;
2403 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2404 *respLen = WFA_TLV_HDR_LEN + 4;
2405 return WFA_SUCCESS;
2406}
2407int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2408{
2409 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2410
2411 staWirelessResp->status = STATUS_COMPLETE;
2412 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2413 *respLen = WFA_TLV_HDR_LEN + 4;
2414 return WFA_SUCCESS;
2415}
2416
2417int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2418{
2419 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2420
2421 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2422 *respLen = WFA_TLV_HDR_LEN + 4;
2423 return WFA_SUCCESS;
2424}
2425
2426int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2427{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002428 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002429
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002430 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2431 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002432
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002433 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002434}
2435
2436int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2437{
2438 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2439
2440 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2441 *respLen = WFA_TLV_HDR_LEN + 4;
2442
2443 return WFA_SUCCESS;
2444
2445}
2446
2447int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2448{
Dake Zhao0a832172015-01-06 11:08:47 -08002449 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2450 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002451
2452
Dake Zhao0a832172015-01-06 11:08:47 -08002453 // need to make your own command available for this, here is only an example
2454 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2455 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002456
Dake Zhao0a832172015-01-06 11:08:47 -08002457 ResetResp->status = STATUS_COMPLETE;
2458 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2459 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002460
Dake Zhao0a832172015-01-06 11:08:47 -08002461 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002462}
2463
2464#else
2465
2466int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2467{
2468 dutCmdResponse_t *staCmdResp = &gGenericResp;
2469
2470 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2471 *respLen = WFA_TLV_HDR_LEN + 4;
2472
2473 return WFA_SUCCESS;
2474}
2475#endif
2476
2477/*
2478 * This is used to send a frame or action frame
2479 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002480int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002481{
Dake Zhao0a832172015-01-06 11:08:47 -08002482 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2483 /* uncomment it if needed */
2484 // char *ifname = cmd->intf;
2485 dutCmdResponse_t *devSendResp = &gGenericResp;
2486 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002487
Dake Zhao0a832172015-01-06 11:08:47 -08002488 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2489 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002490
Dake Zhao0a832172015-01-06 11:08:47 -08002491 switch(sf->program)
2492 {
2493 case PROG_TYPE_PMF:
2494 {
2495 pmfFrame_t *pmf = &sf->frameType.pmf;
2496 switch(pmf->eFrameName)
2497 {
2498 case PMF_TYPE_DISASSOC:
2499 {
2500 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002501
Dake Zhao0a832172015-01-06 11:08:47 -08002502 }
2503 break;
2504 case PMF_TYPE_DEAUTH:
2505 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002506
Dake Zhao0a832172015-01-06 11:08:47 -08002507 }
2508 break;
2509 case PMF_TYPE_SAQUERY:
2510 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002511
Dake Zhao0a832172015-01-06 11:08:47 -08002512 }
2513 break;
2514 case PMF_TYPE_AUTH:
2515 {
2516 }
2517 break;
2518 case PMF_TYPE_ASSOCREQ:
2519 {
2520 }
2521 break;
2522 case PMF_TYPE_REASSOCREQ:
2523 {
2524 }
2525 break;
2526 }
2527 }
2528 break;
2529 case PROG_TYPE_TDLS:
2530 {
2531 tdlsFrame_t *tdls = &sf->frameType.tdls;
2532 switch(tdls->eFrameName)
2533 {
2534 case TDLS_TYPE_DISCOVERY:
2535 /* use the peer mac address to send the frame */
2536 break;
2537 case TDLS_TYPE_SETUP:
2538 break;
2539 case TDLS_TYPE_TEARDOWN:
2540 break;
2541 case TDLS_TYPE_CHANNELSWITCH:
2542 break;
2543 case TDLS_TYPE_NULLFRAME:
2544 break;
2545 }
2546 }
2547 break;
2548 case PROG_TYPE_VENT:
2549 {
2550 ventFrame_t *vent = &sf->frameType.vent;
2551 switch(vent->type)
2552 {
2553 case VENT_TYPE_NEIGREQ:
2554 break;
2555 case VENT_TYPE_TRANSMGMT:
2556 break;
2557 }
2558 }
2559 break;
2560 case PROG_TYPE_WFD:
2561 {
2562 wfdFrame_t *wfd = &sf->frameType.wfd;
2563 switch(wfd->eframe)
2564 {
2565 case WFD_FRAME_PRBREQ:
2566 {
2567 /* send probe req */
2568 }
2569 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002570
Dake Zhao0a832172015-01-06 11:08:47 -08002571 case WFD_FRAME_PRBREQ_TDLS_REQ:
2572 {
2573 /* send tunneled tdls probe req */
2574 }
2575 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002576
Dake Zhao0a832172015-01-06 11:08:47 -08002577 case WFD_FRAME_11V_TIMING_MSR_REQ:
2578 {
2579 /* send 11v timing mearurement request */
2580 }
2581 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002582
Dake Zhao0a832172015-01-06 11:08:47 -08002583 case WFD_FRAME_RTSP:
2584 {
2585 /* send WFD RTSP messages*/
2586 // fetch the type of RTSP message and send it.
2587 switch(wfd->eRtspMsgType)
2588 {
2589 case WFD_RTSP_PAUSE:
2590 break;
2591 case WFD_RTSP_PLAY:
2592 //send RTSP PLAY
2593 break;
2594 case WFD_RTSP_TEARDOWN:
2595 //send RTSP TEARDOWN
2596 break;
2597 case WFD_RTSP_TRIG_PAUSE:
2598 //send RTSP TRIGGER PAUSE
2599 break;
2600 case WFD_RTSP_TRIG_PLAY:
2601 //send RTSP TRIGGER PLAY
2602 break;
2603 case WFD_RTSP_TRIG_TEARDOWN:
2604 //send RTSP TRIGGER TEARDOWN
2605 break;
2606 case WFD_RTSP_SET_PARAMETER:
2607 //send RTSP SET PARAMETER
2608 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2609 {
2610 //send RTSP SET PARAMETER message for UIBC keyboard
2611 }
2612 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2613 {
2614 //send RTSP SET PARAMETER message for UIBC Mouse
2615 }
2616 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2617 {
2618 //send RTSP SET PARAMETER message Capability re-negotiation
2619 }
2620 else if (wfd->eSetParams == WFD_STANDBY)
2621 {
2622 //send RTSP SET PARAMETER message for standby
2623 }
2624 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2625 {
2626 //send RTSP SET PARAMETER message for UIBC settings enable
2627 }
2628 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2629 {
2630 //send RTSP SET PARAMETER message for UIBC settings disable
2631 }
2632 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2633 {
2634 //send RTSP SET PARAMETER message for route audio
2635 }
2636 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2637 {
2638 //send RTSP SET PARAMETER message for 3D video parameters
2639 }
2640 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2641 {
2642 //send RTSP SET PARAMETER message for 2D video parameters
2643 }
2644 break;
Dake Zhao97708202014-11-26 13:59:04 -08002645 }
Dake Zhao0a832172015-01-06 11:08:47 -08002646 }
2647 break;
2648 }
2649 }
2650 break;
2651 /* not need to support HS2 release 1, due to very short time period */
2652 case PROG_TYPE_HS2_R2:
2653 {
2654 /* type of frames */
2655 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2656 switch(hs2->eframe)
2657 {
2658 case HS2_FRAME_ANQPQuery:
2659 {
Dake Zhao97708202014-11-26 13:59:04 -08002660
Dake Zhao0a832172015-01-06 11:08:47 -08002661 }
2662 break;
2663 case HS2_FRAME_DLSRequest:
2664 {
Dake Zhao97708202014-11-26 13:59:04 -08002665
Dake Zhao0a832172015-01-06 11:08:47 -08002666 }
2667 break;
2668 case HS2_FRAME_GARPReq:
2669 {
Dake Zhao97708202014-11-26 13:59:04 -08002670
Dake Zhao0a832172015-01-06 11:08:47 -08002671 }
2672 break;
2673 case HS2_FRAME_GARPRes:
2674 {
2675 }
2676 break;
2677 case HS2_FRAME_NeighAdv:
2678 {
2679 }
2680 case HS2_FRAME_ARPProbe:
2681 {
2682 }
2683 case HS2_FRAME_ARPAnnounce:
2684 {
Dake Zhao97708202014-11-26 13:59:04 -08002685
Dake Zhao0a832172015-01-06 11:08:47 -08002686 }
2687 break;
2688 case HS2_FRAME_NeighSolicitReq:
2689 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002690
Dake Zhao0a832172015-01-06 11:08:47 -08002691 }
2692 break;
2693 case HS2_FRAME_ARPReply:
2694 {
2695
2696 }
2697 break;
2698 }
2699
2700 }/* PROG_TYPE_HS2-R2 */
2701 case PROG_TYPE_GEN:
2702 {
2703 /* General frames */
2704 }
2705
2706
2707 }
2708 devSendResp->status = STATUS_COMPLETE;
2709 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2710 *respLen = WFA_TLV_HDR_LEN + 4;
2711
2712 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002713}
2714
2715/*
2716 * This is used to set a temporary MAC address of an interface
2717 */
2718int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2719{
Dake Zhao0a832172015-01-06 11:08:47 -08002720 // Uncomment it if needed
2721 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2722 // char *ifname = cmd->intf;
2723 dutCmdResponse_t *staCmdResp = &gGenericResp;
2724 // Uncomment it if needed
2725 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002726
Dake Zhao0a832172015-01-06 11:08:47 -08002727 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2728 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002729
Dake Zhao0a832172015-01-06 11:08:47 -08002730 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002731}
2732
2733
2734int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2735{
2736 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2737 //char *intf = disc->intf;
2738 dutCmdResponse_t *staDiscResp = &gGenericResp;
2739
2740 // stop the supplicant
2741
2742 staDiscResp->status = STATUS_COMPLETE;
2743
2744 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2745 *respLen = WFA_TLV_HDR_LEN + 4;
2746
2747 return WFA_SUCCESS;
2748}
2749
2750/* Execute CLI, read the status from Environment variable */
2751int wfaExecuteCLI(char *CLI)
2752{
Dake Zhao0a832172015-01-06 11:08:47 -08002753 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002754
Dake Zhao0a832172015-01-06 11:08:47 -08002755 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002756
Dake Zhao0a832172015-01-06 11:08:47 -08002757 retstr = getenv("WFA_CLI_STATUS");
2758 printf("cli status %s\n", retstr);
2759 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002760}
2761
2762/* Supporting Functions */
2763
2764void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2765{
Dake Zhao97708202014-11-26 13:59:04 -08002766 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002767 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002768// char *addr = staPing->dipaddr;
2769#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002770 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002771 char bflag[] = "-b";
2772 char *tmpstr;
2773 int inum=0;
2774#else
2775 char bflag[] = " ";
2776#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002777
Ray Wang9b47f362014-03-19 16:51:10 -07002778 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002779
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002780#ifdef WFA_PC_CONSOLE
2781
Dake Zhao353c55e2015-07-20 18:54:45 -07002782 printf("\nwfa_cs.c wfaSendPing CS : The Stream ID is %d",streamid);
2783
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002784 strcpy(addr,staPing->dipaddr);
Dake Zhao353c55e2015-07-20 18:54:45 -07002785 printf("\nCS :the addr is %s ",addr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002786 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2787 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002788 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002789 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002790 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002791 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002792 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002793 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002794 tmpstr = strtok(addr, ".");
2795 inum = atoi(tmpstr);
2796
2797 printf("interval %f\n", *interval);
2798
2799 if(inum >= 224 && inum <= 239) // multicast
2800 {
2801 }
2802 else // if not MC, check if it is BC address
2803 {
2804 printf("\nCS :Inside the BC address BLOCK");
2805 printf("\nCS :the inum %d",inum);
2806 strtok(NULL, ".");
2807 //strtok(NULL, ".");
2808 tmpstr = strtok(NULL, ".");
2809 printf("tmpstr %s\n", tmpstr);
2810 inum = atoi(tmpstr);
2811 printf("\nCS : The string is %s",tmpstr);
2812 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002813 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002814 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002815 }
2816#endif
Dake Zhao97708202014-11-26 13:59:04 -08002817 if ( staPing->dscp >= 0)
2818 {
Dake Zhao0a832172015-01-06 11:08:47 -08002819 tos= convertDscpToTos(staPing->dscp);
2820 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002821 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2822 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002823 printf("\nwfa_cs.c wfaSendPing : The Stream ID=%d IPtype=%i\n",streamid, staPing->iptype);
Dake Zhao97708202014-11-26 13:59:04 -08002824 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002825
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002826 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002827 {
Dake Zhao97708202014-11-26 13:59:04 -08002828 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002829 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",
2830 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002831 else
Dake Zhao0a832172015-01-06 11:08:47 -08002832 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",
2833 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002834 sret = system(cmdStr);
2835 printf("\nCS : The command string is %s",cmdStr);
2836 }
2837 else
2838 {
Dake Zhao97708202014-11-26 13:59:04 -08002839 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002840 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",
2841 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002842 else
Dake Zhao0a832172015-01-06 11:08:47 -08002843 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",
2844 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002845 sret = system(cmdStr);
2846 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002847 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002848 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002849 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002850 printf("\nCS : The command string is %s",cmdStr);
2851
2852}
2853
2854int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2855{
2856 char strout[256];
2857 FILE *tmpfile = NULL;
2858 char cmdStr[128];
Dake Zhao353c55e2015-07-20 18:54:45 -07002859 printf("\nwfa_cs.c wfaStopPing:: stream id=%d\n", streamid);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002860 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002861 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002862
2863 printf("\nCS : The command string is %s",cmdStr);
2864
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002865 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002866
2867 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002868 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002869
2870 printf("\nCS : The command string is %s",cmdStr);
2871
2872 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2873
2874 if(tmpfile == NULL)
2875 {
2876 return WFA_FAILURE;
2877 }
2878
2879 if(fscanf(tmpfile, "%s", strout) != EOF)
2880 {
2881 if(*strout == '\0')
2882 {
2883 stpResp->cmdru.pingStp.sendCnt = 0;
2884 }
2885
2886 else
2887 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2888 }
2889
Dake Zhao353c55e2015-07-20 18:54:45 -07002890 printf("\nwfaStopPing after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002891
2892
2893 if(fscanf(tmpfile, "%s", strout) != EOF)
2894 {
2895 if(*strout == '\0')
2896 {
2897 stpResp->cmdru.pingStp.repliedCnt = 0;
2898 }
2899 else
2900 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2901 }
Dake Zhao353c55e2015-07-20 18:54:45 -07002902 printf("wfaStopPing after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002903
2904 fclose(tmpfile);
2905
2906 return WFA_SUCCESS;
2907}
2908
Ankur Vachhanic485b712012-02-15 23:29:49 +00002909/*
Dake Zhao0a832172015-01-06 11:08:47 -08002910 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002911 */
2912int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2913{
Dake Zhao0a832172015-01-06 11:08:47 -08002914 dutCmdResponse_t infoResp;
2915 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002916
Dake Zhao0a832172015-01-06 11:08:47 -08002917 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002918
Dake Zhao0a832172015-01-06 11:08:47 -08002919 // Fetch the device ID and store into infoResp->cmdru.devid
2920 //strcpy(infoResp->cmdru.devid, str);
2921 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002922
Dake Zhao0a832172015-01-06 11:08:47 -08002923 infoResp.status = STATUS_COMPLETE;
2924 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2925 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2926
2927 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002928}
2929
2930
2931
2932/*
Dake Zhao0a832172015-01-06 11:08:47 -08002933 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002934 */
2935int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2936{
Dake Zhao0a832172015-01-06 11:08:47 -08002937 dutCmdResponse_t infoResp;
2938 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00002939
Dake Zhao0a832172015-01-06 11:08:47 -08002940 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002941
Dake Zhao0a832172015-01-06 11:08:47 -08002942 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002943
Dake Zhao0a832172015-01-06 11:08:47 -08002944 infoResp.status = STATUS_COMPLETE;
2945 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2946 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2947
2948 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002949}
2950/*
Dake Zhao0a832172015-01-06 11:08:47 -08002951 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002952 */
2953int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2954{
Dake Zhao0a832172015-01-06 11:08:47 -08002955 dutCmdResponse_t infoResp;
2956 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002957
Dake Zhao0a832172015-01-06 11:08:47 -08002958 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002959
Dake Zhao0a832172015-01-06 11:08:47 -08002960 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002961
Ankur Vachhanic485b712012-02-15 23:29:49 +00002962
Dake Zhao0a832172015-01-06 11:08:47 -08002963 infoResp.status = STATUS_COMPLETE;
2964 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2965 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2966
2967 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002968}
2969
2970/*
Dake Zhao0a832172015-01-06 11:08:47 -08002971 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002972 */
2973int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2974{
Dake Zhao0a832172015-01-06 11:08:47 -08002975 dutCmdResponse_t infoResp;
2976 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002977
Dake Zhao0a832172015-01-06 11:08:47 -08002978 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002979
Dake Zhao0a832172015-01-06 11:08:47 -08002980 // Fetch the group ID and store into infoResp->cmdru.grpid
2981 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002982
Dake Zhao0a832172015-01-06 11:08:47 -08002983 infoResp.status = STATUS_COMPLETE;
2984 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2985 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2986
2987 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002988}
2989
2990
2991
2992
2993/*
Dake Zhao0a832172015-01-06 11:08:47 -08002994 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002995 */
2996int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2997{
Dake Zhao0a832172015-01-06 11:08:47 -08002998 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002999
Dake Zhao0a832172015-01-06 11:08:47 -08003000 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003001
Dake Zhao0a832172015-01-06 11:08:47 -08003002 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
3003 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003004
Ankur Vachhanic485b712012-02-15 23:29:49 +00003005
Dake Zhao0a832172015-01-06 11:08:47 -08003006 infoResp.status = STATUS_COMPLETE;
3007 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3008 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3009
3010 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003011}
3012
3013
3014/*
Dake Zhao0a832172015-01-06 11:08:47 -08003015 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003016 */
3017int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3018{
Dake Zhao0a832172015-01-06 11:08:47 -08003019 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003020
Dake Zhao0a832172015-01-06 11:08:47 -08003021 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003022
Dake Zhao0a832172015-01-06 11:08:47 -08003023 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003024
Dake Zhao0a832172015-01-06 11:08:47 -08003025 infoResp.status = STATUS_COMPLETE;
3026 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3027 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3028
3029 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003030}
3031
3032/*
Dake Zhao0a832172015-01-06 11:08:47 -08003033 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003034 */
3035int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3036{
Dake Zhao0a832172015-01-06 11:08:47 -08003037 dutCmdResponse_t infoResp;
3038 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003039
Dake Zhao0a832172015-01-06 11:08:47 -08003040 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003041
Dake Zhao0a832172015-01-06 11:08:47 -08003042 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003043
Dake Zhao0a832172015-01-06 11:08:47 -08003044 infoResp.status = STATUS_COMPLETE;
3045 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3046 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3047
3048 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003049}
3050
3051
3052/*
Dake Zhao0a832172015-01-06 11:08:47 -08003053 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003054 */
3055int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3056{
Dake Zhao0a832172015-01-06 11:08:47 -08003057 dutCmdResponse_t infoResp;
3058 /* uncomment and use it
3059 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3060 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003061
Dake Zhao0a832172015-01-06 11:08:47 -08003062 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003063
Dake Zhao0a832172015-01-06 11:08:47 -08003064 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003065
Dake Zhao0a832172015-01-06 11:08:47 -08003066 infoResp.status = STATUS_COMPLETE;
3067 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3068 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3069
3070 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003071}
3072
3073
3074/*
Dake Zhao0a832172015-01-06 11:08:47 -08003075 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003076 */
3077int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3078{
Dake Zhao0a832172015-01-06 11:08:47 -08003079 dutCmdResponse_t infoResp;
3080 /* uncomment and use it
3081 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3082 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003083
Dake Zhao0a832172015-01-06 11:08:47 -08003084 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003085
Dake Zhao0a832172015-01-06 11:08:47 -08003086 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003087
Dake Zhao0a832172015-01-06 11:08:47 -08003088 infoResp.status = STATUS_COMPLETE;
3089 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3090 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3091
3092 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003093}
3094
3095/*
Dake Zhao0a832172015-01-06 11:08:47 -08003096 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003097 */
3098int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3099{
Dake Zhao0a832172015-01-06 11:08:47 -08003100 dutCmdResponse_t infoResp;
3101 /* uncomment and use it
3102 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3103 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003104
Dake Zhao0a832172015-01-06 11:08:47 -08003105 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003106
Dake Zhao0a832172015-01-06 11:08:47 -08003107 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003108
Dake Zhao0a832172015-01-06 11:08:47 -08003109 infoResp.status = STATUS_COMPLETE;
3110 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3111 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3112
3113 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003114}
3115
3116/*
Dake Zhao0a832172015-01-06 11:08:47 -08003117 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003118 */
3119int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3120{
Dake Zhao0a832172015-01-06 11:08:47 -08003121 dutCmdResponse_t infoResp;
3122 /* uncomment and use it
3123 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3124 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003125
Dake Zhao0a832172015-01-06 11:08:47 -08003126 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003127
Dake Zhao0a832172015-01-06 11:08:47 -08003128 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3129 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3130 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003131
Ankur Vachhanic485b712012-02-15 23:29:49 +00003132
Dake Zhao0a832172015-01-06 11:08:47 -08003133 infoResp.status = STATUS_COMPLETE;
3134 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3135 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3136
3137 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003138}
3139
3140
3141
3142/*
Dake Zhao0a832172015-01-06 11:08:47 -08003143 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003144 */
3145int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3146{
Dake Zhao0a832172015-01-06 11:08:47 -08003147 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003148
Dake Zhao0a832172015-01-06 11:08:47 -08003149 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003150
Dake Zhao0a832172015-01-06 11:08:47 -08003151 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3152 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3153 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003154
Ankur Vachhanic485b712012-02-15 23:29:49 +00003155
Dake Zhao0a832172015-01-06 11:08:47 -08003156 infoResp.status = STATUS_COMPLETE;
3157 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3158 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3159
3160 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003161}
3162
3163
3164/*
Dake Zhao0a832172015-01-06 11:08:47 -08003165 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003166 */
3167int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3168{
Dake Zhao0a832172015-01-06 11:08:47 -08003169 dutCmdResponse_t infoResp;
3170 /* uncomment and use it
3171 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3172 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003173
Dake Zhao0a832172015-01-06 11:08:47 -08003174 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003175
Dake Zhao0a832172015-01-06 11:08:47 -08003176 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003177
Ankur Vachhanic485b712012-02-15 23:29:49 +00003178
Dake Zhao0a832172015-01-06 11:08:47 -08003179 infoResp.status = STATUS_COMPLETE;
3180 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3181 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3182
3183 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003184}
3185
3186
3187/*
Dake Zhao0a832172015-01-06 11:08:47 -08003188 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003189 */
3190int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3191{
Dake Zhao0a832172015-01-06 11:08:47 -08003192 dutCmdResponse_t infoResp;
3193 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003194
Dake Zhao0a832172015-01-06 11:08:47 -08003195 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003196
3197
Dake Zhao0a832172015-01-06 11:08:47 -08003198 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3199 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3200 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003201
Ankur Vachhanic485b712012-02-15 23:29:49 +00003202
Dake Zhao0a832172015-01-06 11:08:47 -08003203 infoResp.status = STATUS_COMPLETE;
3204 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3205 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3206
3207 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003208}
3209
3210/*
Dake Zhao0a832172015-01-06 11:08:47 -08003211 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003212 */
3213int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3214{
Dake Zhao0a832172015-01-06 11:08:47 -08003215 dutCmdResponse_t infoResp;
3216 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003217
Dake Zhao0a832172015-01-06 11:08:47 -08003218 printf("\n Entry wfaStaP2pReset... ");
3219 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003220
Dake Zhao0a832172015-01-06 11:08:47 -08003221 infoResp.status = STATUS_COMPLETE;
3222 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3223 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3224
3225 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003226}
3227
3228
3229
3230/*
Dake Zhao0a832172015-01-06 11:08:47 -08003231 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003232 */
3233int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3234{
Dake Zhao0a832172015-01-06 11:08:47 -08003235 dutCmdResponse_t infoResp;
3236 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003237
Dake Zhao0a832172015-01-06 11:08:47 -08003238 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003239
Dake Zhao0a832172015-01-06 11:08:47 -08003240 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003241
Dake Zhao0a832172015-01-06 11:08:47 -08003242 ifinfo->isDhcp =0;
3243 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3244 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3245 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3246 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3247
3248 infoResp.status = STATUS_COMPLETE;
3249 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3250 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3251
3252 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003253}
3254
3255
3256
3257
3258/*
Dake Zhao0a832172015-01-06 11:08:47 -08003259 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003260 */
3261int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3262{
Dake Zhao0a832172015-01-06 11:08:47 -08003263 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003264
Dake Zhao0a832172015-01-06 11:08:47 -08003265 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3266 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003267
Dake Zhao0a832172015-01-06 11:08:47 -08003268
3269 infoResp.status = STATUS_COMPLETE;
3270 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3271 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3272
3273 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003274}
3275
3276
3277
3278/*
Dake Zhao0a832172015-01-06 11:08:47 -08003279 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003280 */
3281int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3282{
Dake Zhao0a832172015-01-06 11:08:47 -08003283 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003284
Dake Zhao0a832172015-01-06 11:08:47 -08003285 infoResp.status = STATUS_COMPLETE;
3286 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3287 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003288
Dake Zhao0a832172015-01-06 11:08:47 -08003289 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003290}
3291
3292/*
Dake Zhao0a832172015-01-06 11:08:47 -08003293 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003294 */
3295int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3296{
Dake Zhao0a832172015-01-06 11:08:47 -08003297 dutCmdResponse_t infoResp;
3298 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003299
Dake Zhao0a832172015-01-06 11:08:47 -08003300 printf("\n Entry wfaStaSetSleepReq... ");
3301 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003302
Dake Zhao0a832172015-01-06 11:08:47 -08003303
3304 infoResp.status = STATUS_COMPLETE;
3305 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3306 *respLen = WFA_TLV_HDR_LEN +4;
3307
3308 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003309}
3310
3311/*
Dake Zhao0a832172015-01-06 11:08:47 -08003312 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003313 */
3314int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3315{
Dake Zhao0a832172015-01-06 11:08:47 -08003316 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003317
Dake Zhao0a832172015-01-06 11:08:47 -08003318 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3319 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003320
Dake Zhao0a832172015-01-06 11:08:47 -08003321
3322 infoResp.status = STATUS_COMPLETE;
3323 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3324 *respLen = WFA_TLV_HDR_LEN + 4;
3325
3326 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003327}
3328#ifndef WFA_STA_TB
3329/*
Dake Zhao0a832172015-01-06 11:08:47 -08003330 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003331 */
3332
3333int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3334{
Dake Zhao0a832172015-01-06 11:08:47 -08003335 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003336
Dake Zhao0a832172015-01-06 11:08:47 -08003337 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003338
Dake Zhao0a832172015-01-06 11:08:47 -08003339 // Implement the function and its sub commands
3340 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003341
Dake Zhao0a832172015-01-06 11:08:47 -08003342 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3343 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003344
Dake Zhao0a832172015-01-06 11:08:47 -08003345 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003346}
Dake Zhao0a832172015-01-06 11:08:47 -08003347int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003348{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003349
3350 dutCmdResponse_t infoResp;
3351 dutCmdResponse_t *v11nParamsResp = &infoResp;
3352
3353#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003354
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003355 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3356
3357 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003358
3359 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003360
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003361 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3362 {
Dake Zhao0a832172015-01-06 11:08:47 -08003363 // implement the funciton
3364 if(st != 0)
3365 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003366 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003367 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3368 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3369 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3370 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003371 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003372 }
Dake Zhao0a832172015-01-06 11:08:47 -08003373
Ankur Vachhanic485b712012-02-15 23:29:49 +00003374 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003375 {
Dake Zhao0a832172015-01-06 11:08:47 -08003376 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003377
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003378 if(st != 0)
3379 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003380 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003381 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3382 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3383 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3384 return FALSE;
3385 }
3386 }
3387
Ankur Vachhanic485b712012-02-15 23:29:49 +00003388 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003389 {
Dake Zhao0a832172015-01-06 11:08:47 -08003390 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003391 if(st != 0)
3392 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003393 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003394 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3395 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3396 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003397 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003398 }
3399 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003400
3401 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003402 {
3403 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003404 if(st != 0)
3405 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003406 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003407 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3408 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3409 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3410 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003411 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003412 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003413
3414 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003415 {
Dake Zhao0a832172015-01-06 11:08:47 -08003416 // implement the funciton
3417 //st = wfaExecuteCLI(gCmdStr);
3418 if(st != 0)
3419 {
3420 v11nParamsResp->status = STATUS_ERROR;
3421 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3422 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3423 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3424 return FALSE;
3425 }
3426 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003427 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3428 {
3429 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003430 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003431 if(st != 0)
3432 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003433 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003434 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003435 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3436 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003437 return FALSE;
3438 }
Dake Zhao0a832172015-01-06 11:08:47 -08003439 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003440 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3441 {
3442 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003443 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003444 if(st != 0)
3445 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003446 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003447 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003448 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3449 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003450 return FALSE;
3451 }
3452 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003453
3454 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003455 {
3456 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003457 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003458 if(st != 0)
3459 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003460 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003461 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003462 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3463 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003464 return FALSE;
3465 }
3466 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003467
3468 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003469 {
3470 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003471 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003472 if(st != 0)
3473 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003474 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003475 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3476 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3477 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3478 return FALSE;
3479 }
3480 }
3481
3482 if(v11nParams->smps != 0xFFFF)
3483 {
3484 if(v11nParams->smps == 0)
3485 {
Dake Zhao0a832172015-01-06 11:08:47 -08003486 // implement the funciton
3487 //st = wfaExecuteCLI(gCmdStr);
3488 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003489 else if(v11nParams->smps == 1)
3490 {
Dake Zhao0a832172015-01-06 11:08:47 -08003491 // implement the funciton
3492 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003493 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003494 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003495 else if(v11nParams->smps == 2)
3496 {
Dake Zhao0a832172015-01-06 11:08:47 -08003497 // implement the funciton
3498 //st = wfaExecuteCLI(gCmdStr);
3499 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003500 }
3501 if(st != 0)
3502 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003503 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003504 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3505 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3506 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3507 return FALSE;
3508 }
3509 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003510
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 if(v11nParams->stbc_rx != 0xFFFF)
3512 {
3513 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003514 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003515 if(st != 0)
3516 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003517 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003518 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003519 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3520 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003521 return FALSE;
3522 }
3523 }
Dake Zhao0a832172015-01-06 11:08:47 -08003524
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003525 if(v11nParams->width[0] != '\0')
3526 {
3527 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003528 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003529 if(st != 0)
3530 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003531 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003532 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3533 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3534 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3535 return FALSE;
3536 }
3537 }
Dake Zhao0a832172015-01-06 11:08:47 -08003538
Ankur Vachhanic485b712012-02-15 23:29:49 +00003539 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003540 {
3541 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003542 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003543 if(st != 0)
3544 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003545 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003546 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3547 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3548 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3549 return FALSE;
3550 }
3551 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003552
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003553 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3554 {
3555 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003556 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003557 if(st != 0)
3558 {
3559 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003560 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003561 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3562 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3563 return FALSE;
3564 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003565
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003566 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003567
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003568 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3569 {
3570 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003571 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003572 if(st != 0)
3573 {
3574 v11nParamsResp->status = STATUS_ERROR;
3575 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3576 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3577 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3578 return FALSE;
3579 }
3580 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003581
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003582#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003583
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003584 v11nParamsResp->status = STATUS_COMPLETE;
3585 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3586 *respLen = WFA_TLV_HDR_LEN + 4;
3587 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003588}
3589#endif
3590/*
Dake Zhao0a832172015-01-06 11:08:47 -08003591 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003592 */
3593int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3594{
Dake Zhao0a832172015-01-06 11:08:47 -08003595 dutCmdResponse_t infoResp;
3596 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003597
Dake Zhao0a832172015-01-06 11:08:47 -08003598 printf("\n Entry wfastaAddARPTableEntry... ");
3599 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003600
Dake Zhao0a832172015-01-06 11:08:47 -08003601 infoResp.status = STATUS_COMPLETE;
3602 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3603 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3604
3605 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003606}
3607
3608/*
Dake Zhao0a832172015-01-06 11:08:47 -08003609 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003610 */
3611int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3612{
Dake Zhao0a832172015-01-06 11:08:47 -08003613 dutCmdResponse_t infoResp;
3614 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003615
Dake Zhao0a832172015-01-06 11:08:47 -08003616 printf("\n Entry wfaStaBlockICMPResponse... ");
3617 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003618
Dake Zhao0a832172015-01-06 11:08:47 -08003619 infoResp.status = STATUS_COMPLETE;
3620 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3621 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3622
3623 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003624}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003625
3626/*
Dake Zhao0a832172015-01-06 11:08:47 -08003627 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003628 */
3629
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003630int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3631{
3632 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3633 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003634 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3635
3636 if(sr->mode == WFA_OFF)
3637 {
Dake Zhao0a832172015-01-06 11:08:47 -08003638 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003639 }
3640 else
3641 {
Dake Zhao0a832172015-01-06 11:08:47 -08003642 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003643 }
3644
3645 staCmdResp->status = STATUS_COMPLETE;
3646 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3647 *respLen = WFA_TLV_HDR_LEN + 4;
3648
3649 return WFA_SUCCESS;
3650}
3651
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003652/*
Dake Zhao0a832172015-01-06 11:08:47 -08003653 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003654 */
3655
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003656int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3657{
Dake Zhao0a832172015-01-06 11:08:47 -08003658 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3659 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3660 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003661
Dake Zhao0a832172015-01-06 11:08:47 -08003662 if(strcasecmp(rfeat->prog, "tdls") == 0)
3663 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003664
3665
Dake Zhao0a832172015-01-06 11:08:47 -08003666 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003667
Dake Zhao0a832172015-01-06 11:08:47 -08003668 caResp->status = STATUS_COMPLETE;
3669 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3670 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003671
Dake Zhao0a832172015-01-06 11:08:47 -08003672 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003673}
3674
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003675/*
Dake Zhao0a832172015-01-06 11:08:47 -08003676 * wfaStaStartWfdConnection():
3677 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003678int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3679{
Dake Zhao0a832172015-01-06 11:08:47 -08003680 dutCmdResponse_t infoResp;
3681 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003682
Dake Zhao0a832172015-01-06 11:08:47 -08003683 printf("\n Entry wfaStaStartWfdConnection... ");
3684
3685
3686 // Fetch the GrpId and WFD session and return
3687 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3688 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3689 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3690
3691 infoResp.status = STATUS_COMPLETE;
3692 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3693 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3694
3695 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003696}
3697/*
Dake Zhao0a832172015-01-06 11:08:47 -08003698 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003699 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003700
Ankur Vachhanic485b712012-02-15 23:29:49 +00003701int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3702{
Dake Zhao0a832172015-01-06 11:08:47 -08003703 char cmdName[32];
3704 char *pcmdStr=NULL, *str;
3705 int st = 1;
3706 char CmdStr[WFA_CMD_STR_SZ];
3707 FILE *wfaCliFd;
3708 char wfaCliBuff[64];
3709 char retstr[256];
3710 int CmdReturnFlag =0;
3711 char tmp[256];
3712 FILE * sh_pipe;
3713 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003714
Dake Zhao0a832172015-01-06 11:08:47 -08003715 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3716 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3717 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003718
Dake Zhao0a832172015-01-06 11:08:47 -08003719 for(;;)
3720 {
3721 // construct CLI standard cmd string
3722 str = strtok_r(NULL, ",", &pcmdStr);
3723 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003724 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003725 else
3726 {
3727 sprintf(CmdStr, "%s /%s",CmdStr,str);
3728 str = strtok_r(NULL, ",", &pcmdStr);
3729 sprintf(CmdStr, "%s %s",CmdStr,str);
3730 }
3731 }
3732 // check the return process
3733 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3734 if(wfaCliFd!= NULL)
3735 {
3736 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3737 {
3738 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3739 if(ferror(wfaCliFd))
3740 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003741
Dake Zhao0a832172015-01-06 11:08:47 -08003742 str=strtok(wfaCliBuff,"-");
3743 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003744 {
Dake Zhao0a832172015-01-06 11:08:47 -08003745 str=strtok(NULL,",");
3746 if (str != NULL)
3747 {
3748 if(strcmp(str,"TRUE") == 0)
3749 CmdReturnFlag =1;
3750 }
3751 else
3752 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3753 break;
Dake Zhao97708202014-11-26 13:59:04 -08003754 }
Dake Zhao0a832172015-01-06 11:08:47 -08003755 }
3756 fclose(wfaCliFd);
3757 }
3758 else
3759 {
3760 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3761 goto cleanup;
3762 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003763
Dake Zhao0a832172015-01-06 11:08:47 -08003764 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3765 memset(&retstr[0],'\0',255);
3766 memset(&tmp[0],'\0',255);
3767 sprintf(gCmdStr, "%s", CmdStr);
3768 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003769
Dake Zhao0a832172015-01-06 11:08:47 -08003770 sh_pipe = popen(gCmdStr,"r");
3771 if(!sh_pipe)
3772 {
3773 printf ("Error in opening pipe\n");
3774 goto cleanup;
3775 }
Dake Zhao97708202014-11-26 13:59:04 -08003776
Dake Zhao0a832172015-01-06 11:08:47 -08003777 sleep(5);
3778 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3779 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3780 {
3781 printf("Getting NULL string in popen return\n");
3782 goto cleanup;
3783 }
3784 else
3785 printf("popen return str=%s\n",retstr);
3786
3787 sleep(2);
3788 if(pclose(sh_pipe) == -1)
3789 {
3790 printf("Error in closing shell cmd pipe\n");
3791 goto cleanup;
3792 }
3793 sleep(2);
3794
3795 // find status first in output
3796 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3797 if (str != NULL)
3798 {
3799 memset(tmp, 0, 10);
3800 memcpy(tmp, str, 2);
3801 printf("cli status=%s\n",tmp);
3802 if(strlen(tmp) > 0)
3803 st = atoi(tmp);
3804 else printf("Missing status code\n");
3805 }
3806 else
3807 {
3808 printf("wfaStaCliCommand no return code found\n");
3809 }
3810 infoResp.resFlag=CmdReturnFlag;
3811
Dake Zhao97708202014-11-26 13:59:04 -08003812cleanup:
Dake Zhao0a832172015-01-06 11:08:47 -08003813
3814 switch(st)
3815 {
3816 case 0:
3817 infoResp.status = STATUS_COMPLETE;
3818 if (CmdReturnFlag)
3819 {
3820 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3821 {
3822 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003823 strncpy(&infoResp.result[0], pcmdStr ,(strlen(pcmdStr) < WFA_CLI_CMD_RESP_LEN ) ? strlen(pcmdStr) : (WFA_CLI_CMD_RESP_LEN-2) );
Dake Zhao0a832172015-01-06 11:08:47 -08003824 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3825 }
3826 else
3827 {
Dake Zhao97708202014-11-26 13:59:04 -08003828 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003829 }
3830 }
3831 break;
3832 case 1:
3833 infoResp.status = STATUS_ERROR;
3834 break;
3835 case 2:
3836 infoResp.status = STATUS_INVALID;
3837 break;
3838 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003839
Dake Zhao0a832172015-01-06 11:08:47 -08003840 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3841 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003842
Dake Zhao0a832172015-01-06 11:08:47 -08003843 printf("Exit from wfaStaCliCommand\n");
3844 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003845
Ankur Vachhanic485b712012-02-15 23:29:49 +00003846}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003847/*
Dake Zhao0a832172015-01-06 11:08:47 -08003848 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003849 */
3850
3851int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3852{
3853 dutCmdResponse_t infoResp;
3854// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003855
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003856 printf("\n Entry wfaStaConnectGoStartWfd... ");
3857
Dake Zhao0a832172015-01-06 11:08:47 -08003858 // connect the specified GO and then establish the wfd session
3859
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003860 // Fetch WFD session and return
3861 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3862
3863 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003864 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003865 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003866
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003867 return WFA_SUCCESS;
3868}
3869
3870/*
Dake Zhao0a832172015-01-06 11:08:47 -08003871 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003872 */
3873
3874int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3875{
3876 dutCmdResponse_t infoResp;
3877 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3878 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003879
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003880 printf("\n Entry wfaStaGenerateEvent... ");
3881
3882
3883 // Geneate the specified action and return with complete/error.
3884 if(staGenerateEvent->program == PROG_TYPE_WFD)
3885 {
3886 wfdGenEvent = &staGenerateEvent->wfdEvent;
3887 if(wfdGenEvent ->type == eUibcGen)
3888 {
Dake Zhao0a832172015-01-06 11:08:47 -08003889 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003890 else if(wfdGenEvent ->type == eUibcHid)
3891 {
Dake Zhao0a832172015-01-06 11:08:47 -08003892 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003893 else if(wfdGenEvent ->type == eFrameSkip)
3894 {
3895
3896 }
3897 else if(wfdGenEvent ->type == eI2cRead)
3898 {
3899 }
3900 else if(wfdGenEvent ->type == eI2cWrite)
3901 {
Dake Zhao0a832172015-01-06 11:08:47 -08003902 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003903 else if(wfdGenEvent ->type == eInputContent)
3904 {
Dake Zhao0a832172015-01-06 11:08:47 -08003905 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003906 else if(wfdGenEvent ->type == eIdrReq)
3907 {
Dake Zhao0a832172015-01-06 11:08:47 -08003908 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003909 }
Dake Zhao0a832172015-01-06 11:08:47 -08003910
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003911 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003912 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003913 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003914
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003915 return WFA_SUCCESS;
3916}
3917
Dake Zhao0a832172015-01-06 11:08:47 -08003918
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003919
3920
3921/*
Dake Zhao0a832172015-01-06 11:08:47 -08003922 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003923 */
3924
3925int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3926{
3927 dutCmdResponse_t infoResp;
3928// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003929
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003930 printf("\n Entry wfaStaReinvokeWfdSession... ");
3931
3932 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08003933
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003934
3935 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003936 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003937 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003938
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003939 return WFA_SUCCESS;
3940}
3941
3942
3943int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3944{
Dake Zhao0a832172015-01-06 11:08:47 -08003945 dutCmdResponse_t infoResp;
3946 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003947
3948
Dake Zhao0a832172015-01-06 11:08:47 -08003949 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003950
Dake Zhao0a832172015-01-06 11:08:47 -08003951 printf("\n Entry wfaStaGetParameter... ");
3952
3953 // Check the program type
3954 if(staGetParam->program == PROG_TYPE_WFD)
3955 {
3956 if(staGetParam->getParamValue == eDiscoveredDevList )
3957 {
3958 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3959 paramList->getParamType = eDiscoveredDevList;
3960 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3961 }
3962 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003963
Dake Zhao655efed2015-03-11 17:39:13 -07003964 if(staGetParam->program == PROG_TYPE_WFDS)
3965 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003966
Dake Zhao655efed2015-03-11 17:39:13 -07003967 if(staGetParam->getParamValue == eDiscoveredDevList )
3968 {
3969 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3970 paramList->getParamType = eDiscoveredDevList;
3971 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3972
3973 }
3974 if(staGetParam->getParamValue == eOpenPorts)
3975 {
3976 // Run the port checker tool
3977 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
3978 paramList->getParamType = eOpenPorts;
3979 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
3980
3981 }
3982
3983 }
Dake Zhaocda4a1d2015-06-11 10:14:15 -07003984 if(staGetParam->program == PROG_TYPE_NAN)
3985 {
3986 if(staGetParam->getParamValue == eMasterPref )
3987 {
3988 // Get the master preference of the device and return the value
3989 paramList->getParamType = eMasterPref;
3990 strcpy((char *)&paramList->masterPref, "0xff");
3991 }
3992 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003993
Dake Zhao655efed2015-03-11 17:39:13 -07003994 infoResp.status = STATUS_COMPLETE;
3995 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3996 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3997
3998 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003999}
4000
Ankur Vachhanic485b712012-02-15 23:29:49 +00004001
Dake Zhao655efed2015-03-11 17:39:13 -07004002int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4003{
4004
4005 dutCmdResponse_t infoResp;
4006 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
4007
4008 printf("\n Entry wfaStaNfcAction... ");
4009
4010 if(getStaNfcAction->nfcOperation == eNfcHandOver)
4011 {
4012 printf("\n NfcAction - HandOver... ");
4013
4014 }
4015 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
4016 {
4017 printf("\n NfcAction - Read Tag... ");
4018
4019 }
4020 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
4021 {
4022 printf("\n NfcAction - Write Select... ");
4023
4024 }
4025 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
4026 {
4027 printf("\n NfcAction - Write Config... ");
4028
4029 }
4030 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
4031 {
4032 printf("\n NfcAction - Write Password... ");
4033
4034 }
4035 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
4036 {
4037 printf("\n NfcAction - WPS Handover... ");
4038
4039 }
4040
4041 // Fetch the device mode and put in infoResp->cmdru.p2presult
4042 //strcpy(infoResp->cmdru.p2presult, "GO");
4043
4044 // Fetch the device grp id and put in infoResp->cmdru.grpid
4045 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4046
4047 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
4048 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4049 infoResp.cmdru.staNfcAction.peerRole = 1;
4050
4051
4052
4053
4054 infoResp.status = STATUS_COMPLETE;
4055 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4056 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4057
4058 return WFA_SUCCESS;
4059}
4060
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004061int wfaStaExecAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4062{
4063
4064 dutCmdResponse_t infoResp;
4065 caStaExecAction_t *staExecAction = (caStaExecAction_t *)caCmdBuf; //comment if not used
4066
4067 printf("\n Entry wfaStaExecAction... ");
4068
4069 if(staExecAction->prog == PROG_TYPE_NAN)
4070 {
4071 // Perform necessary configurations and actions
4072 // return the MAC address conditionally as per CAPI specification
4073 }
4074
4075 infoResp.status = STATUS_COMPLETE;
4076 wfaEncodeTLV(WFA_STA_EXEC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4077 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4078
4079 return WFA_SUCCESS;
4080}
4081
Dake Zhao655efed2015-03-11 17:39:13 -07004082int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4083{
4084
4085 dutCmdResponse_t infoResp;
4086 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4087
4088 printf("\n Entry wfaStaInvokeCommand... ");
4089
4090
4091 // based on the command type , invoke API or complete the required procedures
4092 // return the defined parameters based on the command that is received ( example response below)
4093
4094 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4095 {
4096 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4097 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4098 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4099 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4100 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4101 }
4102 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4103 {
4104 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4105 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4106 }
4107 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4108 {
4109 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4110 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4111 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4112 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4113
4114 }
4115 infoResp.status = STATUS_COMPLETE;
4116 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4117 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4118
4119 return WFA_SUCCESS;
4120}
4121
4122
4123int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4124{
4125
4126 dutCmdResponse_t infoResp;
4127 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4128
4129 printf("\n Entry wfaStaManageService... ");
4130
4131 // based on the manage service type , invoke API's or complete the required procedures
4132 // return the defined parameters based on the command that is received ( example response below)
4133 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4134 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4135 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4136
4137 infoResp.status = STATUS_COMPLETE;
4138 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4139 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4140
4141 return WFA_SUCCESS;
4142}
4143
4144
4145
4146int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4147{
4148
4149 dutCmdResponse_t infoResp;
Dake Zhao353c55e2015-07-20 18:54:45 -07004150 caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
Dake Zhao655efed2015-03-11 17:39:13 -07004151
4152 printf("\n Entry wfaStaGetEvents... ");
Dake Zhaocda4a1d2015-06-11 10:14:15 -07004153
4154 if(staGetEvents->program == PROG_TYPE_NAN)
4155 {
4156 // Get all the events from the Log file or stored events
4157 // return the received/recorded event details - eventName, remoteInstanceID, localInstanceID, mac
4158 }
Dake Zhao655efed2015-03-11 17:39:13 -07004159
4160 // Get all the event from the Log file or stored events
4161 // return the received/recorded events as space seperated list ( example response below)
4162 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4163
4164 infoResp.status = STATUS_COMPLETE;
4165 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4166 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4167
4168 return WFA_SUCCESS;
4169}
4170
4171int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4172{
4173
4174 dutCmdResponse_t infoResp;
4175 caStaGetEventDetails_t *getStaGetEventDetails = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4176
4177 printf("\n Entry wfaStaGetEventDetails... ");
4178
4179
4180 // based on the Requested Event type
4181 // return the latest corresponding evnet detailed parameters ( example response below)
4182
4183 if(getStaGetEventDetails->eventId== eSearchResult )
4184 {
4185 // fetch from log file or event history for the search result event and return the parameters
4186 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4187
4188 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4189 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4190 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4191 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4192
4193 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4194 }
4195 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4196 { // fetch from log file or event history for the search terminated event and return the parameters
4197 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4198 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4199 }
4200 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4201 {// fetch from log file or event history for the Advertise Status event and return the parameters
4202 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4203 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4204
4205 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4206 }
4207 else if (getStaGetEventDetails->eventId == eSessionRequest)
4208 {// fetch from log file or event history for the session request event and return the parameters
4209 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4210 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4211 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4212 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4213 }
4214 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4215 {// fetch from log file or event history for the session status event and return the parameters
4216 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4217 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4218 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4219 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4220 }
4221 else if (getStaGetEventDetails->eventId == eConnectStatus)
4222 {
4223 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4224 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4225 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4226 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4227
4228 }
4229 else if (getStaGetEventDetails->eventId == ePortStatus)
4230 {
4231 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4232 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4233 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4234 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4235 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4236 }
4237
4238
4239
4240 infoResp.status = STATUS_COMPLETE;
4241 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4242 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4243
4244 return WFA_SUCCESS;
4245}
4246
4247
4248
4249