blob: ea42dc6a2836cd6b4f8406cd9a7ba334cabc989b [file] [log] [blame]
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00001/****************************************************************************
Dake Zhao97708202014-11-26 13:59:04 -08002(c) Copyright 2014 Wi-Fi Alliance. All Rights Reserved
3
Dake Zhao0a832172015-01-06 11:08:47 -08004Permission to use, copy, modify, and/or distribute this software for any purpose with or
5without fee is hereby granted, provided that the above copyright notice and this permission
Dake Zhao97708202014-11-26 13:59:04 -08006notice appear in all copies.
7
Dake Zhao0a832172015-01-06 11:08:47 -08008THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
12FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
Dake Zhao97708202014-11-26 13:59:04 -080014THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16******************************************************************************/
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000017
Dake Zhao0a832172015-01-06 11:08:47 -080018/*
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000019 * File: wfa_cs.c -- configuration and setup
Dake Zhao0a832172015-01-06 11:08:47 -080020 * This file contains all implementation for the dut setup and control
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000021 * functions, such as network interfaces, ip address and wireless specific
22 * setup with its supplicant.
23 *
24 * The current implementation is to show how these functions
Dake Zhao0a832172015-01-06 11:08:47 -080025 * should be defined in order to support the Agent Control/Test Manager
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000026 * control commands. To simplify the current work and avoid any GPL licenses,
27 * the functions mostly invoke shell commands by calling linux system call,
Dake Zhao0a832172015-01-06 11:08:47 -080028 * system("<commands>").
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000029 *
30 * It depends on the differnt device and platform, vendors can choice their
31 * own ways to interact its systems, supplicants and process these commands
32 * such as using the native APIs.
33 *
Dake Zhao0a832172015-01-06 11:08:47 -080034 *
35 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000036#include <stdio.h>
37#include <unistd.h>
38#include <string.h>
39#include <stdlib.h>
40#include <sys/socket.h>
41#include <arpa/inet.h>
42#include <linux/types.h>
43#include <linux/socket.h>
44#include <poll.h>
45
46#include "wfa_portall.h"
47#include "wfa_debug.h"
48#include "wfa_ver.h"
49#include "wfa_main.h"
50#include "wfa_types.h"
51#include "wfa_ca.h"
52#include "wfa_tlv.h"
53#include "wfa_sock.h"
54#include "wfa_tg.h"
55#include "wfa_cmds.h"
56#include "wfa_rsp.h"
57#include "wfa_utils.h"
58#ifdef WFA_WMM_PS_EXT
59#include "wfa_wmmps.h"
60#endif
61
62#define CERTIFICATES_PATH "/etc/wpa_supplicant"
63
64/* Some device may only support UDP ECHO, activate this line */
65//#define WFA_PING_UDP_ECHO_ONLY 1
66
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080067#define WFA_ENABLED 1
68
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000069extern unsigned short wfa_defined_debug;
70int wfaExecuteCLI(char *CLI);
71
72/* Since the two definitions are used all over the CA function */
73char gCmdStr[WFA_CMD_STR_SZ];
74dutCmdResponse_t gGenericResp;
75int wfaTGSetPrio(int sockfd, int tgClass);
76void create_apts_msg(int msg, unsigned int txbuf[],int id);
77
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -080078int sret = 0;
79
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000080extern char e2eResults[];
Dake Zhao862c94b2014-12-08 14:35:35 -080081
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000082FILE *e2efp = NULL;
83int chk_ret_status()
84{
85 char *ret = getenv(WFA_RET_ENV);
86
87 if(*ret == '1')
Dake Zhao0a832172015-01-06 11:08:47 -080088 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000089 else
Dake Zhao0a832172015-01-06 11:08:47 -080090 return WFA_FAILURE;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +000091}
92
93/*
94 * agtCmdProcGetVersion(): response "ca_get_version" command to controller
95 * input: cmd --- not used
96 * valLen -- not used
97 * output: parms -- a buffer to store the version info response.
98 */
99int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf)
100{
101 dutCmdResponse_t *getverResp = &gGenericResp;
102
103 DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n");
104
105 getverResp->status = STATUS_COMPLETE;
106 wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN);
107
108 wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf);
109
110 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
111
112 return WFA_SUCCESS;
113}
114
115/*
116 * wfaStaAssociate():
Dake Zhao0a832172015-01-06 11:08:47 -0800117 * The function is to force the station wireless I/F to re/associate
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000118 * with the AP.
119 */
120int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
121{
Dake Zhao0a832172015-01-06 11:08:47 -0800122 dutCommand_t *assoc = (dutCommand_t *)caCmdBuf;
123 char *ifname = assoc->intf;
124 dutCmdResponse_t *staAssocResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000125
Dake Zhao0a832172015-01-06 11:08:47 -0800126 DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n");
127 /*
128 * if bssid appears, station should associate with the specific
129 * BSSID AP at its initial association.
130 * If it is different to the current associating AP, it will be forced to
131 * roam the new AP
132 */
133 if(assoc->cmdsu.assoc.bssid[0] != '\0')
134 {
135 /* if (the first association) */
136 /* just do initial association to the BSSID */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000137
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000138
Dake Zhao0a832172015-01-06 11:08:47 -0800139 /* else (station already associate to an AP) */
140 /* Do forced roaming */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +0000141
Dake Zhao0a832172015-01-06 11:08:47 -0800142 }
143 else
144 {
145 /* use 'ifconfig' command to bring down the interface (linux specific) */
146 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) */
150 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;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002102
Dake Zhao0a832172015-01-06 11:08:47 -08002103 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002104
Dake Zhao0a832172015-01-06 11:08:47 -08002105 if(presetParams->wmmFlag)
2106 {
2107 st = wfaExecuteCLI(gCmdStr);
2108 switch(st)
2109 {
2110 case 0:
2111 presetDone = 1;
2112 break;
2113 case 1:
2114 presetDone = 0;
2115 break;
2116 case 2:
2117 presetDone = 0;
2118 break;
2119 }
2120 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002121
Dake Zhao0a832172015-01-06 11:08:47 -08002122 if(presetParams->modeFlag != 0)
2123 {
2124 switch(presetParams->wirelessMode)
2125 {
2126 default:
2127 printf("other mode does not need to support\n");
2128 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002129
Dake Zhao0a832172015-01-06 11:08:47 -08002130 st = wfaExecuteCLI(gCmdStr);
2131 switch(st)
2132 {
2133 case 0:
2134 presetDone = 1;
2135 break;
2136 case 1:
2137 presetDone = 0;
2138 case 2:
2139 presetDone = 0;
2140 break;
2141 }
2142 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002143
2144
Dake Zhao0a832172015-01-06 11:08:47 -08002145 if(presetParams->psFlag)
2146 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002147
Dake Zhao0a832172015-01-06 11:08:47 -08002148 printf("%s\n", gCmdStr);
2149 sret = system(gCmdStr);
2150 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002151
Dake Zhao0a832172015-01-06 11:08:47 -08002152 /************the followings are used for Voice Enterprise **************/
2153 if(presetParams->program == PROG_TYPE_VENT)
2154 {
2155 if(presetParams->ftoa == eEnable)
2156 {
2157 // enable Fast BSS Transition Over the Air
2158 }
2159 else
2160 {
2161 // disable Fast BSS Transition Over the Air
2162 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002163
Dake Zhao0a832172015-01-06 11:08:47 -08002164 if(presetParams->ftds == eEnable)
2165 {
2166 // enable Fast BSS Transition Over the DS
2167 }
2168 else
2169 {
2170 // disable Fast BSS Transition Over the DS
2171 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002172
Dake Zhao0a832172015-01-06 11:08:47 -08002173 if(presetParams->activescan == eEnable)
2174 {
2175 // Enable Active Scan on STA
2176 }
2177 else
2178 {
2179 // disable Active Scan on STA
2180 }
2181 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002182
Dake Zhao0a832172015-01-06 11:08:47 -08002183 /************the followings are used for Wi-Fi Display *************/
2184 if(presetParams->program == PROG_TYPE_WFD)
2185 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002186
Dake Zhao0a832172015-01-06 11:08:47 -08002187 if(presetParams->tdlsFlag)
2188 {
2189 // enable / disable tdls based on tdls
2190 }
2191 if(presetParams->wfdDevTypeFlag)
2192 {
2193 // set WFD device type to source/sink/dual based on wfdDevType
2194 }
2195 if(presetParams->wfdUibcGenFlag)
2196 {
2197 // enable / disable the feature
2198 }
2199 if(presetParams->wfdUibcHidFlag)
2200 {
2201 // enable / disable feature
2202 }
2203 if(presetParams->wfdUiInputFlag)
2204 {
2205 // set the UI input as mentioned
2206 }
2207 if(presetParams->wfdHdcpFlag)
2208 {
2209 // enable / disable feature
2210 }
2211 if(presetParams->wfdFrameSkipFlag)
2212 {
2213 // enable / disable feature
2214 }
2215 if(presetParams->wfdAvChangeFlag)
2216 {
2217 // enable / disable feature
2218 }
2219 if(presetParams->wfdStandByFlag)
2220 {
2221 // enable / disable feature
2222 }
2223 if(presetParams->wfdInVideoFlag)
2224 {
2225 // select the input vide as protecteed or non-protetcted or protected audio
2226 // or unprotected audio etc.
2227 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002228
Dake Zhao0a832172015-01-06 11:08:47 -08002229 if(presetParams->wfdVideoFmatFlag)
2230 {
2231 // set the video format as requested
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002232
Dake Zhao0a832172015-01-06 11:08:47 -08002233 //switch(presetParams->wfdVideoFmt )
2234 //{
2235 // case e640x480p60:
2236 // ;
2237 // default:
2238 // set the mandatory
2239 // }
2240 }
2241 if(presetParams->wfdAudioFmatFlag)
2242 {
2243 // set the Audio format as requested
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002244
Dake Zhao0a832172015-01-06 11:08:47 -08002245 //switch(presetParams->wfdAudioFmt )
2246 //{
2247 // case eMandatoryAudioMode:
2248 // ;
2249 // case eDefaultAudioMode:
2250 // ;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002251
Dake Zhao0a832172015-01-06 11:08:47 -08002252 // default:
2253 // set the mandatory
2254 // }
2255 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002256
Dake Zhao0a832172015-01-06 11:08:47 -08002257 if(presetParams->wfdI2cFlag)
2258 {
2259 // enable / disable feature
2260 }
2261 if(presetParams->wfdVideoRecoveryFlag)
2262 {
2263 // enable / disable feature
2264 }
2265 if(presetParams->wfdPrefDisplayFlag)
2266 {
2267 // enable / disable feature
2268 }
2269 if(presetParams->wfdServiceDiscoveryFlag)
2270 {
2271 // enable / disable feature
2272 }
2273 if(presetParams->wfd3dVideoFlag)
2274 {
2275 // enable / disable feature
2276 }
2277 if(presetParams->wfdMultiTxStreamFlag)
2278 {
2279 // enable / disable feature
2280 }
2281 if(presetParams->wfdTimeSyncFlag)
2282 {
2283 // enable / disable feature
2284 }
2285 if(presetParams->wfdEDIDFlag)
2286 {
2287 // enable / disable feature
2288 }
2289 if(presetParams->wfdUIBCPrepareFlag)
2290 {
2291 // Provdes information to start valid WFD session to check UIBC operation.
2292 }
2293 if(presetParams->wfdCoupledCapFlag)
2294 {
2295 // enable / disable feature
2296 }
2297 if(presetParams->wfdOptionalFeatureFlag)
2298 {
2299 // disable all program specific optional features
2300 }
2301 if(presetParams->wfdSessionAvailFlag)
2302 {
2303 // enable / disable session available bit
2304 }
2305 if(presetParams->wfdDeviceDiscoverabilityFlag)
2306 {
2307 // enable / disable feature
2308 }
2309 }
2310
Dake Zhao655efed2015-03-11 17:39:13 -07002311 if(presetParams->program == PROG_TYPE_WFDS)
2312 {
2313
2314 if(presetParams->wfdsType == eAcceptPD)
2315 {
2316 // preset to accept PD request
2317 if (presetParams->wfdsConnectionCapabilityFlag == 1)
2318 {
2319 // use presetParams->wfdsConnectionCapability and set role accordingly
2320 }
2321
2322 }
2323 if(presetParams->wfdsType == eRejectPD)
2324 {
2325 // preset to Reject PD request
2326 }
2327 if(presetParams->wfdsType == eIgnorePD)
2328 {
2329 // preset to Ignore PD request
2330 }
2331 if(presetParams->wfdsType == eRejectSession)
2332 {
2333 // preset to reject Session request
2334 }
2335
2336 }
2337
2338 if (presetDone)
2339 {
2340 PresetParamsResp->status = STATUS_COMPLETE;
2341 }
2342 else
2343 {
2344 PresetParamsResp->status = STATUS_INVALID;
2345 }
Dake Zhao0a832172015-01-06 11:08:47 -08002346
2347 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2348 *respLen = WFA_TLV_HDR_LEN + 4;
2349
2350 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002351}
2352
2353int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2354{
2355 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2356
2357 v11nParamsResp->status = STATUS_COMPLETE;
2358 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2359 *respLen = WFA_TLV_HDR_LEN + 4;
2360 return WFA_SUCCESS;
2361}
2362int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2363{
2364 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2365
2366 staWirelessResp->status = STATUS_COMPLETE;
2367 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2368 *respLen = WFA_TLV_HDR_LEN + 4;
2369 return WFA_SUCCESS;
2370}
2371
2372int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2373{
2374 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2375
2376 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2377 *respLen = WFA_TLV_HDR_LEN + 4;
2378 return WFA_SUCCESS;
2379}
2380
2381int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2382{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002383 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002384
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002385 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2386 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002387
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002388 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002389}
2390
2391int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2392{
2393 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2394
2395 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2396 *respLen = WFA_TLV_HDR_LEN + 4;
2397
2398 return WFA_SUCCESS;
2399
2400}
2401
2402int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2403{
Dake Zhao0a832172015-01-06 11:08:47 -08002404 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2405 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002406
2407
Dake Zhao0a832172015-01-06 11:08:47 -08002408 // need to make your own command available for this, here is only an example
2409 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2410 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002411
Dake Zhao0a832172015-01-06 11:08:47 -08002412 ResetResp->status = STATUS_COMPLETE;
2413 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2414 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002415
Dake Zhao0a832172015-01-06 11:08:47 -08002416 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002417}
2418
2419#else
2420
2421int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2422{
2423 dutCmdResponse_t *staCmdResp = &gGenericResp;
2424
2425 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2426 *respLen = WFA_TLV_HDR_LEN + 4;
2427
2428 return WFA_SUCCESS;
2429}
2430#endif
2431
2432/*
2433 * This is used to send a frame or action frame
2434 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002435int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002436{
Dake Zhao0a832172015-01-06 11:08:47 -08002437 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2438 /* uncomment it if needed */
2439 // char *ifname = cmd->intf;
2440 dutCmdResponse_t *devSendResp = &gGenericResp;
2441 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002442
Dake Zhao0a832172015-01-06 11:08:47 -08002443 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2444 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002445
Dake Zhao0a832172015-01-06 11:08:47 -08002446 switch(sf->program)
2447 {
2448 case PROG_TYPE_PMF:
2449 {
2450 pmfFrame_t *pmf = &sf->frameType.pmf;
2451 switch(pmf->eFrameName)
2452 {
2453 case PMF_TYPE_DISASSOC:
2454 {
2455 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002456
Dake Zhao0a832172015-01-06 11:08:47 -08002457 }
2458 break;
2459 case PMF_TYPE_DEAUTH:
2460 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002461
Dake Zhao0a832172015-01-06 11:08:47 -08002462 }
2463 break;
2464 case PMF_TYPE_SAQUERY:
2465 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002466
Dake Zhao0a832172015-01-06 11:08:47 -08002467 }
2468 break;
2469 case PMF_TYPE_AUTH:
2470 {
2471 }
2472 break;
2473 case PMF_TYPE_ASSOCREQ:
2474 {
2475 }
2476 break;
2477 case PMF_TYPE_REASSOCREQ:
2478 {
2479 }
2480 break;
2481 }
2482 }
2483 break;
2484 case PROG_TYPE_TDLS:
2485 {
2486 tdlsFrame_t *tdls = &sf->frameType.tdls;
2487 switch(tdls->eFrameName)
2488 {
2489 case TDLS_TYPE_DISCOVERY:
2490 /* use the peer mac address to send the frame */
2491 break;
2492 case TDLS_TYPE_SETUP:
2493 break;
2494 case TDLS_TYPE_TEARDOWN:
2495 break;
2496 case TDLS_TYPE_CHANNELSWITCH:
2497 break;
2498 case TDLS_TYPE_NULLFRAME:
2499 break;
2500 }
2501 }
2502 break;
2503 case PROG_TYPE_VENT:
2504 {
2505 ventFrame_t *vent = &sf->frameType.vent;
2506 switch(vent->type)
2507 {
2508 case VENT_TYPE_NEIGREQ:
2509 break;
2510 case VENT_TYPE_TRANSMGMT:
2511 break;
2512 }
2513 }
2514 break;
2515 case PROG_TYPE_WFD:
2516 {
2517 wfdFrame_t *wfd = &sf->frameType.wfd;
2518 switch(wfd->eframe)
2519 {
2520 case WFD_FRAME_PRBREQ:
2521 {
2522 /* send probe req */
2523 }
2524 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002525
Dake Zhao0a832172015-01-06 11:08:47 -08002526 case WFD_FRAME_PRBREQ_TDLS_REQ:
2527 {
2528 /* send tunneled tdls probe req */
2529 }
2530 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002531
Dake Zhao0a832172015-01-06 11:08:47 -08002532 case WFD_FRAME_11V_TIMING_MSR_REQ:
2533 {
2534 /* send 11v timing mearurement request */
2535 }
2536 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002537
Dake Zhao0a832172015-01-06 11:08:47 -08002538 case WFD_FRAME_RTSP:
2539 {
2540 /* send WFD RTSP messages*/
2541 // fetch the type of RTSP message and send it.
2542 switch(wfd->eRtspMsgType)
2543 {
2544 case WFD_RTSP_PAUSE:
2545 break;
2546 case WFD_RTSP_PLAY:
2547 //send RTSP PLAY
2548 break;
2549 case WFD_RTSP_TEARDOWN:
2550 //send RTSP TEARDOWN
2551 break;
2552 case WFD_RTSP_TRIG_PAUSE:
2553 //send RTSP TRIGGER PAUSE
2554 break;
2555 case WFD_RTSP_TRIG_PLAY:
2556 //send RTSP TRIGGER PLAY
2557 break;
2558 case WFD_RTSP_TRIG_TEARDOWN:
2559 //send RTSP TRIGGER TEARDOWN
2560 break;
2561 case WFD_RTSP_SET_PARAMETER:
2562 //send RTSP SET PARAMETER
2563 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2564 {
2565 //send RTSP SET PARAMETER message for UIBC keyboard
2566 }
2567 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2568 {
2569 //send RTSP SET PARAMETER message for UIBC Mouse
2570 }
2571 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2572 {
2573 //send RTSP SET PARAMETER message Capability re-negotiation
2574 }
2575 else if (wfd->eSetParams == WFD_STANDBY)
2576 {
2577 //send RTSP SET PARAMETER message for standby
2578 }
2579 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2580 {
2581 //send RTSP SET PARAMETER message for UIBC settings enable
2582 }
2583 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2584 {
2585 //send RTSP SET PARAMETER message for UIBC settings disable
2586 }
2587 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2588 {
2589 //send RTSP SET PARAMETER message for route audio
2590 }
2591 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2592 {
2593 //send RTSP SET PARAMETER message for 3D video parameters
2594 }
2595 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2596 {
2597 //send RTSP SET PARAMETER message for 2D video parameters
2598 }
2599 break;
Dake Zhao97708202014-11-26 13:59:04 -08002600 }
Dake Zhao0a832172015-01-06 11:08:47 -08002601 }
2602 break;
2603 }
2604 }
2605 break;
2606 /* not need to support HS2 release 1, due to very short time period */
2607 case PROG_TYPE_HS2_R2:
2608 {
2609 /* type of frames */
2610 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2611 switch(hs2->eframe)
2612 {
2613 case HS2_FRAME_ANQPQuery:
2614 {
Dake Zhao97708202014-11-26 13:59:04 -08002615
Dake Zhao0a832172015-01-06 11:08:47 -08002616 }
2617 break;
2618 case HS2_FRAME_DLSRequest:
2619 {
Dake Zhao97708202014-11-26 13:59:04 -08002620
Dake Zhao0a832172015-01-06 11:08:47 -08002621 }
2622 break;
2623 case HS2_FRAME_GARPReq:
2624 {
Dake Zhao97708202014-11-26 13:59:04 -08002625
Dake Zhao0a832172015-01-06 11:08:47 -08002626 }
2627 break;
2628 case HS2_FRAME_GARPRes:
2629 {
2630 }
2631 break;
2632 case HS2_FRAME_NeighAdv:
2633 {
2634 }
2635 case HS2_FRAME_ARPProbe:
2636 {
2637 }
2638 case HS2_FRAME_ARPAnnounce:
2639 {
Dake Zhao97708202014-11-26 13:59:04 -08002640
Dake Zhao0a832172015-01-06 11:08:47 -08002641 }
2642 break;
2643 case HS2_FRAME_NeighSolicitReq:
2644 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002645
Dake Zhao0a832172015-01-06 11:08:47 -08002646 }
2647 break;
2648 case HS2_FRAME_ARPReply:
2649 {
2650
2651 }
2652 break;
2653 }
2654
2655 }/* PROG_TYPE_HS2-R2 */
2656 case PROG_TYPE_GEN:
2657 {
2658 /* General frames */
2659 }
2660
2661
2662 }
2663 devSendResp->status = STATUS_COMPLETE;
2664 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2665 *respLen = WFA_TLV_HDR_LEN + 4;
2666
2667 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002668}
2669
2670/*
2671 * This is used to set a temporary MAC address of an interface
2672 */
2673int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2674{
Dake Zhao0a832172015-01-06 11:08:47 -08002675 // Uncomment it if needed
2676 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2677 // char *ifname = cmd->intf;
2678 dutCmdResponse_t *staCmdResp = &gGenericResp;
2679 // Uncomment it if needed
2680 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002681
Dake Zhao0a832172015-01-06 11:08:47 -08002682 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2683 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002684
Dake Zhao0a832172015-01-06 11:08:47 -08002685 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002686}
2687
2688
2689int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2690{
2691 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2692 //char *intf = disc->intf;
2693 dutCmdResponse_t *staDiscResp = &gGenericResp;
2694
2695 // stop the supplicant
2696
2697 staDiscResp->status = STATUS_COMPLETE;
2698
2699 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2700 *respLen = WFA_TLV_HDR_LEN + 4;
2701
2702 return WFA_SUCCESS;
2703}
2704
2705/* Execute CLI, read the status from Environment variable */
2706int wfaExecuteCLI(char *CLI)
2707{
Dake Zhao0a832172015-01-06 11:08:47 -08002708 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002709
Dake Zhao0a832172015-01-06 11:08:47 -08002710 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002711
Dake Zhao0a832172015-01-06 11:08:47 -08002712 retstr = getenv("WFA_CLI_STATUS");
2713 printf("cli status %s\n", retstr);
2714 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002715}
2716
2717/* Supporting Functions */
2718
2719void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2720{
Dake Zhao97708202014-11-26 13:59:04 -08002721 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002722 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002723// char *addr = staPing->dipaddr;
2724#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002725 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002726 char bflag[] = "-b";
2727 char *tmpstr;
2728 int inum=0;
2729#else
2730 char bflag[] = " ";
2731#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002732
Ray Wang9b47f362014-03-19 16:51:10 -07002733 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002734
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002735#ifdef WFA_PC_CONSOLE
2736
2737 printf("\nCS : The Stream ID is %d",streamid);
2738 printf("\nCS :the addr is %s ",addr);
2739 strcpy(addr,staPing->dipaddr);
2740 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2741 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002742 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002743 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002744 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002745 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002746 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002747 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002748 tmpstr = strtok(addr, ".");
2749 inum = atoi(tmpstr);
2750
2751 printf("interval %f\n", *interval);
2752
2753 if(inum >= 224 && inum <= 239) // multicast
2754 {
2755 }
2756 else // if not MC, check if it is BC address
2757 {
2758 printf("\nCS :Inside the BC address BLOCK");
2759 printf("\nCS :the inum %d",inum);
2760 strtok(NULL, ".");
2761 //strtok(NULL, ".");
2762 tmpstr = strtok(NULL, ".");
2763 printf("tmpstr %s\n", tmpstr);
2764 inum = atoi(tmpstr);
2765 printf("\nCS : The string is %s",tmpstr);
2766 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002767 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002768 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002769 }
2770#endif
Dake Zhao97708202014-11-26 13:59:04 -08002771 if ( staPing->dscp >= 0)
2772 {
Dake Zhao0a832172015-01-06 11:08:47 -08002773 tos= convertDscpToTos(staPing->dscp);
2774 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002775 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2776 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002777 printf("\nCS : The Stream ID is %d",streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002778 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002779
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002780 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002781 {
Dake Zhao97708202014-11-26 13:59:04 -08002782 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002783 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",
2784 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002785 else
Dake Zhao0a832172015-01-06 11:08:47 -08002786 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",
2787 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002788 sret = system(cmdStr);
2789 printf("\nCS : The command string is %s",cmdStr);
2790 }
2791 else
2792 {
Dake Zhao97708202014-11-26 13:59:04 -08002793 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002794 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",
2795 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002796 else
Dake Zhao0a832172015-01-06 11:08:47 -08002797 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",
2798 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002799 sret = system(cmdStr);
2800 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002801 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002802 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002803 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002804 printf("\nCS : The command string is %s",cmdStr);
2805
2806}
2807
2808int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2809{
2810 char strout[256];
2811 FILE *tmpfile = NULL;
2812 char cmdStr[128];
2813 printf("Ping stop id %d\n", streamid);
2814 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002815 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002816
2817 printf("\nCS : The command string is %s",cmdStr);
2818
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002819 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002820
2821 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002822 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002823
2824 printf("\nCS : The command string is %s",cmdStr);
2825
2826 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2827
2828 if(tmpfile == NULL)
2829 {
2830 return WFA_FAILURE;
2831 }
2832
2833 if(fscanf(tmpfile, "%s", strout) != EOF)
2834 {
2835 if(*strout == '\0')
2836 {
2837 stpResp->cmdru.pingStp.sendCnt = 0;
2838 }
2839
2840 else
2841 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2842 }
2843
2844 printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
2845
2846
2847 if(fscanf(tmpfile, "%s", strout) != EOF)
2848 {
2849 if(*strout == '\0')
2850 {
2851 stpResp->cmdru.pingStp.repliedCnt = 0;
2852 }
2853 else
2854 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2855 }
2856 printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
2857
2858 fclose(tmpfile);
2859
2860 return WFA_SUCCESS;
2861}
2862
Ankur Vachhanic485b712012-02-15 23:29:49 +00002863/*
Dake Zhao0a832172015-01-06 11:08:47 -08002864 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002865 */
2866int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2867{
Dake Zhao0a832172015-01-06 11:08:47 -08002868 dutCmdResponse_t infoResp;
2869 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002870
Dake Zhao0a832172015-01-06 11:08:47 -08002871 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002872
Dake Zhao0a832172015-01-06 11:08:47 -08002873 // Fetch the device ID and store into infoResp->cmdru.devid
2874 //strcpy(infoResp->cmdru.devid, str);
2875 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002876
Dake Zhao0a832172015-01-06 11:08:47 -08002877 infoResp.status = STATUS_COMPLETE;
2878 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2879 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2880
2881 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002882}
2883
2884
2885
2886/*
Dake Zhao0a832172015-01-06 11:08:47 -08002887 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002888 */
2889int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2890{
Dake Zhao0a832172015-01-06 11:08:47 -08002891 dutCmdResponse_t infoResp;
2892 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00002893
Dake Zhao0a832172015-01-06 11:08:47 -08002894 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002895
Dake Zhao0a832172015-01-06 11:08:47 -08002896 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002897
Dake Zhao0a832172015-01-06 11:08:47 -08002898 infoResp.status = STATUS_COMPLETE;
2899 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2900 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2901
2902 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002903}
2904/*
Dake Zhao0a832172015-01-06 11:08:47 -08002905 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002906 */
2907int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2908{
Dake Zhao0a832172015-01-06 11:08:47 -08002909 dutCmdResponse_t infoResp;
2910 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002911
Dake Zhao0a832172015-01-06 11:08:47 -08002912 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002913
Dake Zhao0a832172015-01-06 11:08:47 -08002914 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002915
Ankur Vachhanic485b712012-02-15 23:29:49 +00002916
Dake Zhao0a832172015-01-06 11:08:47 -08002917 infoResp.status = STATUS_COMPLETE;
2918 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2919 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2920
2921 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002922}
2923
2924/*
Dake Zhao0a832172015-01-06 11:08:47 -08002925 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002926 */
2927int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2928{
Dake Zhao0a832172015-01-06 11:08:47 -08002929 dutCmdResponse_t infoResp;
2930 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002931
Dake Zhao0a832172015-01-06 11:08:47 -08002932 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002933
Dake Zhao0a832172015-01-06 11:08:47 -08002934 // Fetch the group ID and store into infoResp->cmdru.grpid
2935 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002936
Dake Zhao0a832172015-01-06 11:08:47 -08002937 infoResp.status = STATUS_COMPLETE;
2938 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2939 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2940
2941 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002942}
2943
2944
2945
2946
2947/*
Dake Zhao0a832172015-01-06 11:08:47 -08002948 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002949 */
2950int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2951{
Dake Zhao0a832172015-01-06 11:08:47 -08002952 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002953
Dake Zhao0a832172015-01-06 11:08:47 -08002954 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002955
Dake Zhao0a832172015-01-06 11:08:47 -08002956 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
2957 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002958
Ankur Vachhanic485b712012-02-15 23:29:49 +00002959
Dake Zhao0a832172015-01-06 11:08:47 -08002960 infoResp.status = STATUS_COMPLETE;
2961 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2962 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2963
2964 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002965}
2966
2967
2968/*
Dake Zhao0a832172015-01-06 11:08:47 -08002969 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002970 */
2971int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2972{
Dake Zhao0a832172015-01-06 11:08:47 -08002973 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002974
Dake Zhao0a832172015-01-06 11:08:47 -08002975 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002976
Dake Zhao0a832172015-01-06 11:08:47 -08002977 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002978
Dake Zhao0a832172015-01-06 11:08:47 -08002979 infoResp.status = STATUS_COMPLETE;
2980 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2981 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2982
2983 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002984}
2985
2986/*
Dake Zhao0a832172015-01-06 11:08:47 -08002987 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002988 */
2989int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2990{
Dake Zhao0a832172015-01-06 11:08:47 -08002991 dutCmdResponse_t infoResp;
2992 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002993
Dake Zhao0a832172015-01-06 11:08:47 -08002994 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002995
Dake Zhao0a832172015-01-06 11:08:47 -08002996 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002997
Dake Zhao0a832172015-01-06 11:08:47 -08002998 infoResp.status = STATUS_COMPLETE;
2999 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3000 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3001
3002 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003003}
3004
3005
3006/*
Dake Zhao0a832172015-01-06 11:08:47 -08003007 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003008 */
3009int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3010{
Dake Zhao0a832172015-01-06 11:08:47 -08003011 dutCmdResponse_t infoResp;
3012 /* uncomment and use it
3013 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
3014 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003015
Dake Zhao0a832172015-01-06 11:08:47 -08003016 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003017
Dake Zhao0a832172015-01-06 11:08:47 -08003018 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003019
Dake Zhao0a832172015-01-06 11:08:47 -08003020 infoResp.status = STATUS_COMPLETE;
3021 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3022 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3023
3024 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003025}
3026
3027
3028/*
Dake Zhao0a832172015-01-06 11:08:47 -08003029 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003030 */
3031int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3032{
Dake Zhao0a832172015-01-06 11:08:47 -08003033 dutCmdResponse_t infoResp;
3034 /* uncomment and use it
3035 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3036 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003037
Dake Zhao0a832172015-01-06 11:08:47 -08003038 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003039
Dake Zhao0a832172015-01-06 11:08:47 -08003040 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003041
Dake Zhao0a832172015-01-06 11:08:47 -08003042 infoResp.status = STATUS_COMPLETE;
3043 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3044 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3045
3046 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003047}
3048
3049/*
Dake Zhao0a832172015-01-06 11:08:47 -08003050 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003051 */
3052int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3053{
Dake Zhao0a832172015-01-06 11:08:47 -08003054 dutCmdResponse_t infoResp;
3055 /* uncomment and use it
3056 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3057 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003058
Dake Zhao0a832172015-01-06 11:08:47 -08003059 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003060
Dake Zhao0a832172015-01-06 11:08:47 -08003061 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003062
Dake Zhao0a832172015-01-06 11:08:47 -08003063 infoResp.status = STATUS_COMPLETE;
3064 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3065 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3066
3067 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003068}
3069
3070/*
Dake Zhao0a832172015-01-06 11:08:47 -08003071 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003072 */
3073int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3074{
Dake Zhao0a832172015-01-06 11:08:47 -08003075 dutCmdResponse_t infoResp;
3076 /* uncomment and use it
3077 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3078 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003079
Dake Zhao0a832172015-01-06 11:08:47 -08003080 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003081
Dake Zhao0a832172015-01-06 11:08:47 -08003082 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3083 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3084 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003085
Ankur Vachhanic485b712012-02-15 23:29:49 +00003086
Dake Zhao0a832172015-01-06 11:08:47 -08003087 infoResp.status = STATUS_COMPLETE;
3088 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3089 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3090
3091 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003092}
3093
3094
3095
3096/*
Dake Zhao0a832172015-01-06 11:08:47 -08003097 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003098 */
3099int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3100{
Dake Zhao0a832172015-01-06 11:08:47 -08003101 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003102
Dake Zhao0a832172015-01-06 11:08:47 -08003103 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003104
Dake Zhao0a832172015-01-06 11:08:47 -08003105 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3106 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3107 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003108
Ankur Vachhanic485b712012-02-15 23:29:49 +00003109
Dake Zhao0a832172015-01-06 11:08:47 -08003110 infoResp.status = STATUS_COMPLETE;
3111 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3112 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3113
3114 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003115}
3116
3117
3118/*
Dake Zhao0a832172015-01-06 11:08:47 -08003119 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003120 */
3121int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3122{
Dake Zhao0a832172015-01-06 11:08:47 -08003123 dutCmdResponse_t infoResp;
3124 /* uncomment and use it
3125 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3126 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003127
Dake Zhao0a832172015-01-06 11:08:47 -08003128 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003129
Dake Zhao0a832172015-01-06 11:08:47 -08003130 // Implement the function and this does not return any thing back.
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_ENTER_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/*
Dake Zhao0a832172015-01-06 11:08:47 -08003142 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003143 */
3144int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3145{
Dake Zhao0a832172015-01-06 11:08:47 -08003146 dutCmdResponse_t infoResp;
3147 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003148
Dake Zhao0a832172015-01-06 11:08:47 -08003149 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003150
3151
Dake Zhao0a832172015-01-06 11:08:47 -08003152 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3153 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3154 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003155
Ankur Vachhanic485b712012-02-15 23:29:49 +00003156
Dake Zhao0a832172015-01-06 11:08:47 -08003157 infoResp.status = STATUS_COMPLETE;
3158 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3159 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3160
3161 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003162}
3163
3164/*
Dake Zhao0a832172015-01-06 11:08:47 -08003165 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003166 */
3167int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3168{
Dake Zhao0a832172015-01-06 11:08:47 -08003169 dutCmdResponse_t infoResp;
3170 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003171
Dake Zhao0a832172015-01-06 11:08:47 -08003172 printf("\n Entry wfaStaP2pReset... ");
3173 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003174
Dake Zhao0a832172015-01-06 11:08:47 -08003175 infoResp.status = STATUS_COMPLETE;
3176 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3177 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3178
3179 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003180}
3181
3182
3183
3184/*
Dake Zhao0a832172015-01-06 11:08:47 -08003185 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003186 */
3187int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3188{
Dake Zhao0a832172015-01-06 11:08:47 -08003189 dutCmdResponse_t infoResp;
3190 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003191
Dake Zhao0a832172015-01-06 11:08:47 -08003192 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003193
Dake Zhao0a832172015-01-06 11:08:47 -08003194 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003195
Dake Zhao0a832172015-01-06 11:08:47 -08003196 ifinfo->isDhcp =0;
3197 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3198 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3199 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3200 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3201
3202 infoResp.status = STATUS_COMPLETE;
3203 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3204 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3205
3206 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003207}
3208
3209
3210
3211
3212/*
Dake Zhao0a832172015-01-06 11:08:47 -08003213 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003214 */
3215int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3216{
Dake Zhao0a832172015-01-06 11:08:47 -08003217 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003218
Dake Zhao0a832172015-01-06 11:08:47 -08003219 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3220 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003221
Dake Zhao0a832172015-01-06 11:08:47 -08003222
3223 infoResp.status = STATUS_COMPLETE;
3224 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3225 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3226
3227 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003228}
3229
3230
3231
3232/*
Dake Zhao0a832172015-01-06 11:08:47 -08003233 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003234 */
3235int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3236{
Dake Zhao0a832172015-01-06 11:08:47 -08003237 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003238
Dake Zhao0a832172015-01-06 11:08:47 -08003239 infoResp.status = STATUS_COMPLETE;
3240 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3241 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003242
Dake Zhao0a832172015-01-06 11:08:47 -08003243 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003244}
3245
3246/*
Dake Zhao0a832172015-01-06 11:08:47 -08003247 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003248 */
3249int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3250{
Dake Zhao0a832172015-01-06 11:08:47 -08003251 dutCmdResponse_t infoResp;
3252 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003253
Dake Zhao0a832172015-01-06 11:08:47 -08003254 printf("\n Entry wfaStaSetSleepReq... ");
3255 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003256
Dake Zhao0a832172015-01-06 11:08:47 -08003257
3258 infoResp.status = STATUS_COMPLETE;
3259 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3260 *respLen = WFA_TLV_HDR_LEN +4;
3261
3262 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003263}
3264
3265/*
Dake Zhao0a832172015-01-06 11:08:47 -08003266 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003267 */
3268int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3269{
Dake Zhao0a832172015-01-06 11:08:47 -08003270 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003271
Dake Zhao0a832172015-01-06 11:08:47 -08003272 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3273 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003274
Dake Zhao0a832172015-01-06 11:08:47 -08003275
3276 infoResp.status = STATUS_COMPLETE;
3277 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3278 *respLen = WFA_TLV_HDR_LEN + 4;
3279
3280 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003281}
3282#ifndef WFA_STA_TB
3283/*
Dake Zhao0a832172015-01-06 11:08:47 -08003284 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003285 */
3286
3287int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3288{
Dake Zhao0a832172015-01-06 11:08:47 -08003289 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003290
Dake Zhao0a832172015-01-06 11:08:47 -08003291 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003292
Dake Zhao0a832172015-01-06 11:08:47 -08003293 // Implement the function and its sub commands
3294 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003295
Dake Zhao0a832172015-01-06 11:08:47 -08003296 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3297 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003298
Dake Zhao0a832172015-01-06 11:08:47 -08003299 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003300}
Dake Zhao0a832172015-01-06 11:08:47 -08003301int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003302{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003303
3304 dutCmdResponse_t infoResp;
3305 dutCmdResponse_t *v11nParamsResp = &infoResp;
3306
3307#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003308
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003309 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3310
3311 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003312
3313 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003314
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003315 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3316 {
Dake Zhao0a832172015-01-06 11:08:47 -08003317 // implement the funciton
3318 if(st != 0)
3319 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003320 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003321 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3322 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3323 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3324 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003325 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003326 }
Dake Zhao0a832172015-01-06 11:08:47 -08003327
Ankur Vachhanic485b712012-02-15 23:29:49 +00003328 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003329 {
Dake Zhao0a832172015-01-06 11:08:47 -08003330 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003331
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003332 if(st != 0)
3333 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003334 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003335 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3336 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3337 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3338 return FALSE;
3339 }
3340 }
3341
Ankur Vachhanic485b712012-02-15 23:29:49 +00003342 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003343 {
Dake Zhao0a832172015-01-06 11:08:47 -08003344 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003345 if(st != 0)
3346 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003347 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003348 strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed");
3349 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3350 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003351 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003352 }
3353 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003354
3355 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003356 {
3357 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003358 if(st != 0)
3359 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003360 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003361 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3362 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3363 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3364 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003365 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003366 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003367
3368 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003369 {
Dake Zhao0a832172015-01-06 11:08:47 -08003370 // implement the funciton
3371 //st = wfaExecuteCLI(gCmdStr);
3372 if(st != 0)
3373 {
3374 v11nParamsResp->status = STATUS_ERROR;
3375 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3376 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3377 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3378 return FALSE;
3379 }
3380 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003381 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3382 {
3383 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003384 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003385 if(st != 0)
3386 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003387 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003388 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003389 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3390 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003391 return FALSE;
3392 }
Dake Zhao0a832172015-01-06 11:08:47 -08003393 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003394 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3395 {
3396 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003397 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003398 if(st != 0)
3399 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003400 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003401 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003402 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3403 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003404 return FALSE;
3405 }
3406 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003407
3408 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003409 {
3410 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003411 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003412 if(st != 0)
3413 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003414 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003415 strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003416 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3417 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003418 return FALSE;
3419 }
3420 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003421
3422 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003423 {
3424 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003425 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003426 if(st != 0)
3427 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003428 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003429 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3430 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3431 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3432 return FALSE;
3433 }
3434 }
3435
3436 if(v11nParams->smps != 0xFFFF)
3437 {
3438 if(v11nParams->smps == 0)
3439 {
Dake Zhao0a832172015-01-06 11:08:47 -08003440 // implement the funciton
3441 //st = wfaExecuteCLI(gCmdStr);
3442 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003443 else if(v11nParams->smps == 1)
3444 {
Dake Zhao0a832172015-01-06 11:08:47 -08003445 // implement the funciton
3446 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003447 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003448 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003449 else if(v11nParams->smps == 2)
3450 {
Dake Zhao0a832172015-01-06 11:08:47 -08003451 // implement the funciton
3452 //st = wfaExecuteCLI(gCmdStr);
3453 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003454 }
3455 if(st != 0)
3456 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003457 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003458 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3459 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3460 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3461 return FALSE;
3462 }
3463 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003464
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003465 if(v11nParams->stbc_rx != 0xFFFF)
3466 {
3467 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003468 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003469 if(st != 0)
3470 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003471 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003472 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003473 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3474 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003475 return FALSE;
3476 }
3477 }
Dake Zhao0a832172015-01-06 11:08:47 -08003478
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003479 if(v11nParams->width[0] != '\0')
3480 {
3481 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003482 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003483 if(st != 0)
3484 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003485 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003486 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3487 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3488 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3489 return FALSE;
3490 }
3491 }
Dake Zhao0a832172015-01-06 11:08:47 -08003492
Ankur Vachhanic485b712012-02-15 23:29:49 +00003493 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003494 {
3495 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003496 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003497 if(st != 0)
3498 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003499 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003500 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3501 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3502 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3503 return FALSE;
3504 }
3505 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003506
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003507 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3508 {
3509 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003510 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 if(st != 0)
3512 {
3513 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003514 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003515 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3516 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3517 return FALSE;
3518 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003519
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003520 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003521
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003522 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3523 {
3524 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003525 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003526 if(st != 0)
3527 {
3528 v11nParamsResp->status = STATUS_ERROR;
3529 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3530 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3531 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3532 return FALSE;
3533 }
3534 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003535
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003536#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003537
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003538 v11nParamsResp->status = STATUS_COMPLETE;
3539 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3540 *respLen = WFA_TLV_HDR_LEN + 4;
3541 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003542}
3543#endif
3544/*
Dake Zhao0a832172015-01-06 11:08:47 -08003545 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003546 */
3547int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3548{
Dake Zhao0a832172015-01-06 11:08:47 -08003549 dutCmdResponse_t infoResp;
3550 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003551
Dake Zhao0a832172015-01-06 11:08:47 -08003552 printf("\n Entry wfastaAddARPTableEntry... ");
3553 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003554
Dake Zhao0a832172015-01-06 11:08:47 -08003555 infoResp.status = STATUS_COMPLETE;
3556 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3557 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3558
3559 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003560}
3561
3562/*
Dake Zhao0a832172015-01-06 11:08:47 -08003563 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003564 */
3565int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3566{
Dake Zhao0a832172015-01-06 11:08:47 -08003567 dutCmdResponse_t infoResp;
3568 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003569
Dake Zhao0a832172015-01-06 11:08:47 -08003570 printf("\n Entry wfaStaBlockICMPResponse... ");
3571 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003572
Dake Zhao0a832172015-01-06 11:08:47 -08003573 infoResp.status = STATUS_COMPLETE;
3574 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3575 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3576
3577 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003578}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003579
3580/*
Dake Zhao0a832172015-01-06 11:08:47 -08003581 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003582 */
3583
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003584int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3585{
3586 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3587 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003588 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3589
3590 if(sr->mode == WFA_OFF)
3591 {
Dake Zhao0a832172015-01-06 11:08:47 -08003592 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003593 }
3594 else
3595 {
Dake Zhao0a832172015-01-06 11:08:47 -08003596 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003597 }
3598
3599 staCmdResp->status = STATUS_COMPLETE;
3600 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3601 *respLen = WFA_TLV_HDR_LEN + 4;
3602
3603 return WFA_SUCCESS;
3604}
3605
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003606/*
Dake Zhao0a832172015-01-06 11:08:47 -08003607 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003608 */
3609
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003610int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3611{
Dake Zhao0a832172015-01-06 11:08:47 -08003612 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3613 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3614 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003615
Dake Zhao0a832172015-01-06 11:08:47 -08003616 if(strcasecmp(rfeat->prog, "tdls") == 0)
3617 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003618
3619
Dake Zhao0a832172015-01-06 11:08:47 -08003620 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003621
Dake Zhao0a832172015-01-06 11:08:47 -08003622 caResp->status = STATUS_COMPLETE;
3623 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3624 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003625
Dake Zhao0a832172015-01-06 11:08:47 -08003626 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003627}
3628
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003629/*
Dake Zhao0a832172015-01-06 11:08:47 -08003630 * wfaStaStartWfdConnection():
3631 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003632int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3633{
Dake Zhao0a832172015-01-06 11:08:47 -08003634 dutCmdResponse_t infoResp;
3635 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003636
Dake Zhao0a832172015-01-06 11:08:47 -08003637 printf("\n Entry wfaStaStartWfdConnection... ");
3638
3639
3640 // Fetch the GrpId and WFD session and return
3641 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3642 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3643 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3644
3645 infoResp.status = STATUS_COMPLETE;
3646 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3647 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3648
3649 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003650}
3651/*
Dake Zhao0a832172015-01-06 11:08:47 -08003652 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003653 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003654
Ankur Vachhanic485b712012-02-15 23:29:49 +00003655int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3656{
Dake Zhao0a832172015-01-06 11:08:47 -08003657 char cmdName[32];
3658 char *pcmdStr=NULL, *str;
3659 int st = 1;
3660 char CmdStr[WFA_CMD_STR_SZ];
3661 FILE *wfaCliFd;
3662 char wfaCliBuff[64];
3663 char retstr[256];
3664 int CmdReturnFlag =0;
3665 char tmp[256];
3666 FILE * sh_pipe;
3667 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003668
Dake Zhao0a832172015-01-06 11:08:47 -08003669 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3670 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3671 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003672
Dake Zhao0a832172015-01-06 11:08:47 -08003673 for(;;)
3674 {
3675 // construct CLI standard cmd string
3676 str = strtok_r(NULL, ",", &pcmdStr);
3677 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003678 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003679 else
3680 {
3681 sprintf(CmdStr, "%s /%s",CmdStr,str);
3682 str = strtok_r(NULL, ",", &pcmdStr);
3683 sprintf(CmdStr, "%s %s",CmdStr,str);
3684 }
3685 }
3686 // check the return process
3687 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3688 if(wfaCliFd!= NULL)
3689 {
3690 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3691 {
3692 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3693 if(ferror(wfaCliFd))
3694 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003695
Dake Zhao0a832172015-01-06 11:08:47 -08003696 str=strtok(wfaCliBuff,"-");
3697 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003698 {
Dake Zhao0a832172015-01-06 11:08:47 -08003699 str=strtok(NULL,",");
3700 if (str != NULL)
3701 {
3702 if(strcmp(str,"TRUE") == 0)
3703 CmdReturnFlag =1;
3704 }
3705 else
3706 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3707 break;
Dake Zhao97708202014-11-26 13:59:04 -08003708 }
Dake Zhao0a832172015-01-06 11:08:47 -08003709 }
3710 fclose(wfaCliFd);
3711 }
3712 else
3713 {
3714 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3715 goto cleanup;
3716 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003717
Dake Zhao0a832172015-01-06 11:08:47 -08003718 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3719 memset(&retstr[0],'\0',255);
3720 memset(&tmp[0],'\0',255);
3721 sprintf(gCmdStr, "%s", CmdStr);
3722 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003723
Dake Zhao0a832172015-01-06 11:08:47 -08003724 sh_pipe = popen(gCmdStr,"r");
3725 if(!sh_pipe)
3726 {
3727 printf ("Error in opening pipe\n");
3728 goto cleanup;
3729 }
Dake Zhao97708202014-11-26 13:59:04 -08003730
Dake Zhao0a832172015-01-06 11:08:47 -08003731 sleep(5);
3732 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3733 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3734 {
3735 printf("Getting NULL string in popen return\n");
3736 goto cleanup;
3737 }
3738 else
3739 printf("popen return str=%s\n",retstr);
3740
3741 sleep(2);
3742 if(pclose(sh_pipe) == -1)
3743 {
3744 printf("Error in closing shell cmd pipe\n");
3745 goto cleanup;
3746 }
3747 sleep(2);
3748
3749 // find status first in output
3750 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3751 if (str != NULL)
3752 {
3753 memset(tmp, 0, 10);
3754 memcpy(tmp, str, 2);
3755 printf("cli status=%s\n",tmp);
3756 if(strlen(tmp) > 0)
3757 st = atoi(tmp);
3758 else printf("Missing status code\n");
3759 }
3760 else
3761 {
3762 printf("wfaStaCliCommand no return code found\n");
3763 }
3764 infoResp.resFlag=CmdReturnFlag;
3765
Dake Zhao97708202014-11-26 13:59:04 -08003766cleanup:
Dake Zhao0a832172015-01-06 11:08:47 -08003767
3768 switch(st)
3769 {
3770 case 0:
3771 infoResp.status = STATUS_COMPLETE;
3772 if (CmdReturnFlag)
3773 {
3774 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3775 {
3776 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003777 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 -08003778 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3779 }
3780 else
3781 {
Dake Zhao97708202014-11-26 13:59:04 -08003782 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003783 }
3784 }
3785 break;
3786 case 1:
3787 infoResp.status = STATUS_ERROR;
3788 break;
3789 case 2:
3790 infoResp.status = STATUS_INVALID;
3791 break;
3792 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003793
Dake Zhao0a832172015-01-06 11:08:47 -08003794 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3795 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003796
Dake Zhao0a832172015-01-06 11:08:47 -08003797 printf("Exit from wfaStaCliCommand\n");
3798 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003799
Ankur Vachhanic485b712012-02-15 23:29:49 +00003800}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003801/*
Dake Zhao0a832172015-01-06 11:08:47 -08003802 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003803 */
3804
3805int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3806{
3807 dutCmdResponse_t infoResp;
3808// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003809
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003810 printf("\n Entry wfaStaConnectGoStartWfd... ");
3811
Dake Zhao0a832172015-01-06 11:08:47 -08003812 // connect the specified GO and then establish the wfd session
3813
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003814 // Fetch WFD session and return
3815 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3816
3817 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003818 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003819 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003820
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003821 return WFA_SUCCESS;
3822}
3823
3824/*
Dake Zhao0a832172015-01-06 11:08:47 -08003825 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003826 */
3827
3828int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3829{
3830 dutCmdResponse_t infoResp;
3831 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3832 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003833
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003834 printf("\n Entry wfaStaGenerateEvent... ");
3835
3836
3837 // Geneate the specified action and return with complete/error.
3838 if(staGenerateEvent->program == PROG_TYPE_WFD)
3839 {
3840 wfdGenEvent = &staGenerateEvent->wfdEvent;
3841 if(wfdGenEvent ->type == eUibcGen)
3842 {
Dake Zhao0a832172015-01-06 11:08:47 -08003843 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003844 else if(wfdGenEvent ->type == eUibcHid)
3845 {
Dake Zhao0a832172015-01-06 11:08:47 -08003846 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003847 else if(wfdGenEvent ->type == eFrameSkip)
3848 {
3849
3850 }
3851 else if(wfdGenEvent ->type == eI2cRead)
3852 {
3853 }
3854 else if(wfdGenEvent ->type == eI2cWrite)
3855 {
Dake Zhao0a832172015-01-06 11:08:47 -08003856 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003857 else if(wfdGenEvent ->type == eInputContent)
3858 {
Dake Zhao0a832172015-01-06 11:08:47 -08003859 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003860 else if(wfdGenEvent ->type == eIdrReq)
3861 {
Dake Zhao0a832172015-01-06 11:08:47 -08003862 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003863 }
Dake Zhao0a832172015-01-06 11:08:47 -08003864
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003865 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003866 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003867 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003868
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003869 return WFA_SUCCESS;
3870}
3871
Dake Zhao0a832172015-01-06 11:08:47 -08003872
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003873
3874
3875/*
Dake Zhao0a832172015-01-06 11:08:47 -08003876 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003877 */
3878
3879int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3880{
3881 dutCmdResponse_t infoResp;
3882// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003883
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003884 printf("\n Entry wfaStaReinvokeWfdSession... ");
3885
3886 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08003887
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003888
3889 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003890 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003891 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003892
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003893 return WFA_SUCCESS;
3894}
3895
3896
3897int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3898{
Dake Zhao0a832172015-01-06 11:08:47 -08003899 dutCmdResponse_t infoResp;
3900 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003901
3902
Dake Zhao0a832172015-01-06 11:08:47 -08003903 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003904
Dake Zhao0a832172015-01-06 11:08:47 -08003905 printf("\n Entry wfaStaGetParameter... ");
3906
3907 // Check the program type
3908 if(staGetParam->program == PROG_TYPE_WFD)
3909 {
3910 if(staGetParam->getParamValue == eDiscoveredDevList )
3911 {
3912 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3913 paramList->getParamType = eDiscoveredDevList;
3914 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3915 }
3916 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003917
Dake Zhao655efed2015-03-11 17:39:13 -07003918 if(staGetParam->program == PROG_TYPE_WFDS)
3919 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003920
Dake Zhao655efed2015-03-11 17:39:13 -07003921 if(staGetParam->getParamValue == eDiscoveredDevList )
3922 {
3923 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3924 paramList->getParamType = eDiscoveredDevList;
3925 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3926
3927 }
3928 if(staGetParam->getParamValue == eOpenPorts)
3929 {
3930 // Run the port checker tool
3931 // Get all the open ports and make space seperated list and return, check list is not bigger than 128 bytes.
3932 paramList->getParamType = eOpenPorts;
3933 strcpy((char *)&paramList->devList, "22 139 445 68 9700");
3934
3935 }
3936
3937 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003938
Dake Zhao655efed2015-03-11 17:39:13 -07003939 infoResp.status = STATUS_COMPLETE;
3940 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3941 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3942
3943 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003944}
3945
Ankur Vachhanic485b712012-02-15 23:29:49 +00003946
Dake Zhao655efed2015-03-11 17:39:13 -07003947int wfaStaNfcAction(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3948{
3949
3950 dutCmdResponse_t infoResp;
3951 caStaNfcAction_t *getStaNfcAction = (caStaNfcAction_t *)caCmdBuf; //uncomment and use it
3952
3953 printf("\n Entry wfaStaNfcAction... ");
3954
3955 if(getStaNfcAction->nfcOperation == eNfcHandOver)
3956 {
3957 printf("\n NfcAction - HandOver... ");
3958
3959 }
3960 else if(getStaNfcAction->nfcOperation == eNfcReadTag)
3961 {
3962 printf("\n NfcAction - Read Tag... ");
3963
3964 }
3965 else if(getStaNfcAction->nfcOperation == eNfcWriteSelect)
3966 {
3967 printf("\n NfcAction - Write Select... ");
3968
3969 }
3970 else if(getStaNfcAction->nfcOperation == eNfcWriteConfig)
3971 {
3972 printf("\n NfcAction - Write Config... ");
3973
3974 }
3975 else if(getStaNfcAction->nfcOperation == eNfcWritePasswd)
3976 {
3977 printf("\n NfcAction - Write Password... ");
3978
3979 }
3980 else if(getStaNfcAction->nfcOperation == eNfcWpsHandOver)
3981 {
3982 printf("\n NfcAction - WPS Handover... ");
3983
3984 }
3985
3986 // Fetch the device mode and put in infoResp->cmdru.p2presult
3987 //strcpy(infoResp->cmdru.p2presult, "GO");
3988
3989 // Fetch the device grp id and put in infoResp->cmdru.grpid
3990 //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
3991
3992 strcpy(infoResp.cmdru.staNfcAction.result, "CLIENT");
3993 strcpy(infoResp.cmdru.staNfcAction.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
3994 infoResp.cmdru.staNfcAction.peerRole = 1;
3995
3996
3997
3998
3999 infoResp.status = STATUS_COMPLETE;
4000 wfaEncodeTLV(WFA_STA_NFC_ACTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4001 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4002
4003 return WFA_SUCCESS;
4004}
4005
4006int wfaStaInvokeCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4007{
4008
4009 dutCmdResponse_t infoResp;
4010 caStaInvokeCmd_t *staInvokeCmd = (caStaInvokeCmd_t *)caCmdBuf; //uncomment and use it
4011
4012 printf("\n Entry wfaStaInvokeCommand... ");
4013
4014
4015 // based on the command type , invoke API or complete the required procedures
4016 // return the defined parameters based on the command that is received ( example response below)
4017
4018 if(staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeAdvt )
4019 {
4020 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeAdvt;
4021 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.numServInfo = 1;
4022 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].servName,"org.wi-fi.wfds.send.rx");
4023 infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].advtID = 0x0000f;
4024 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.advRsp.servAdvInfo[0].serviceMac,"ab:cd:ef:gh:ij:kl");
4025 }
4026 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeSeek)
4027 {
4028 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeSeek;
4029 infoResp.cmdru.staInvokeCmd.invokeCmdResp.seekRsp.searchID = 0x000ff;
4030 }
4031 else if (staInvokeCmd->cmdType == ePrimitiveCmdType && staInvokeCmd->InvokeCmds.primtiveType.PrimType == eCmdPrimTypeConnSession)
4032 {
4033 infoResp.cmdru.staInvokeCmd.invokeCmdRspType = eCmdPrimTypeConnSession;
4034 infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.sessionID = 0x000ff;
4035 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.result,"GO");
4036 strcpy(infoResp.cmdru.staInvokeCmd.invokeCmdResp.connSessResp.grpId,"DIRECT-AB WFADUT");
4037
4038 }
4039 infoResp.status = STATUS_COMPLETE;
4040 wfaEncodeTLV(WFA_STA_INVOKE_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4041 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4042
4043 return WFA_SUCCESS;
4044}
4045
4046
4047int wfaStaManageService(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4048{
4049
4050 dutCmdResponse_t infoResp;
4051 //caStaMngServ_t *staMngServ = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4052
4053 printf("\n Entry wfaStaManageService... ");
4054
4055 // based on the manage service type , invoke API's or complete the required procedures
4056 // return the defined parameters based on the command that is received ( example response below)
4057 strcpy(infoResp.cmdru.staManageServ.result, "CLIENT");
4058 strcpy(infoResp.cmdru.staManageServ.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
4059 infoResp.cmdru.staManageServ.sessionID = 0x000ff;
4060
4061 infoResp.status = STATUS_COMPLETE;
4062 wfaEncodeTLV(WFA_STA_MANAGE_SERVICE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4063 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4064
4065 return WFA_SUCCESS;
4066}
4067
4068
4069
4070int wfaStaGetEvents(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4071{
4072
4073 dutCmdResponse_t infoResp;
4074 //caStaGetEvents_t *staGetEvents = (caStaGetEvents_t *)caCmdBuf; //uncomment and use it
4075
4076 printf("\n Entry wfaStaGetEvents... ");
4077
4078 // Get all the event from the Log file or stored events
4079 // return the received/recorded events as space seperated list ( example response below)
4080 strcpy(infoResp.cmdru.staGetEvents.result, "SearchResult SearchTerminated AdvertiseStatus SessionRequest ConnectStatus SessionStatus PortStatus");
4081
4082 infoResp.status = STATUS_COMPLETE;
4083 wfaEncodeTLV(WFA_STA_GET_EVENTS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4084 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4085
4086 return WFA_SUCCESS;
4087}
4088
4089int wfaStaGetEventDetails(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
4090{
4091
4092 dutCmdResponse_t infoResp;
4093 caStaGetEventDetails_t *getStaGetEventDetails = (caStaMngServ_t *)caCmdBuf; //uncomment and use it
4094
4095 printf("\n Entry wfaStaGetEventDetails... ");
4096
4097
4098 // based on the Requested Event type
4099 // return the latest corresponding evnet detailed parameters ( example response below)
4100
4101 if(getStaGetEventDetails->eventId== eSearchResult )
4102 {
4103 // fetch from log file or event history for the search result event and return the parameters
4104 infoResp.cmdru.staGetEventDetails.eventID= eSearchResult;
4105
4106 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.searchID = 0x00abcd;
4107 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceMac,"ab:cd:ef:gh:ij:kl");
4108 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.advID = 0x00dcba;
4109 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceName,"org.wi-fi.wfds.send.rx");
4110
4111 infoResp.cmdru.staGetEventDetails.getEventDetails.searchResult.serviceStatus = eServiceAvilable;
4112 }
4113 else if (getStaGetEventDetails->eventId == eSearchTerminated)
4114 { // fetch from log file or event history for the search terminated event and return the parameters
4115 infoResp.cmdru.staGetEventDetails.eventID= eSearchTerminated;
4116 infoResp.cmdru.staGetEventDetails.getEventDetails.searchTerminated.searchID = 0x00abcd;
4117 }
4118 else if (getStaGetEventDetails->eventId == eAdvertiseStatus)
4119 {// fetch from log file or event history for the Advertise Status event and return the parameters
4120 infoResp.cmdru.staGetEventDetails.eventID= eAdvertiseStatus;
4121 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.advID = 0x00dcba;
4122
4123 infoResp.cmdru.staGetEventDetails.getEventDetails.advStatus.status = eAdvertised;
4124 }
4125 else if (getStaGetEventDetails->eventId == eSessionRequest)
4126 {// fetch from log file or event history for the session request event and return the parameters
4127 infoResp.cmdru.staGetEventDetails.eventID= eSessionRequest;
4128 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.advID = 0x00dcba;
4129 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionMac,"ab:cd:ef:gh:ij:kl");
4130 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionReq.sessionID = 0x00baba;
4131 }
4132 else if (getStaGetEventDetails->eventId ==eSessionStatus )
4133 {// fetch from log file or event history for the session status event and return the parameters
4134 infoResp.cmdru.staGetEventDetails.eventID= eSessionStatus;
4135 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionID = 0x00baba;
4136 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4137 infoResp.cmdru.staGetEventDetails.getEventDetails.sessionStatus.state = eSessionStateOpen;
4138 }
4139 else if (getStaGetEventDetails->eventId == eConnectStatus)
4140 {
4141 infoResp.cmdru.staGetEventDetails.eventID= eConnectStatus;
4142 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionID = 0x00baba;
4143 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4144 infoResp.cmdru.staGetEventDetails.getEventDetails.connStatus.status = eGroupFormationComplete;
4145
4146 }
4147 else if (getStaGetEventDetails->eventId == ePortStatus)
4148 {
4149 infoResp.cmdru.staGetEventDetails.eventID= ePortStatus;
4150 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionID = 0x00baba;
4151 strcpy(infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.sessionMac,"ab:cd:ef:gh:ij:kl");
4152 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.port = 1009;
4153 infoResp.cmdru.staGetEventDetails.getEventDetails.portStatus.status = eLocalPortAllowed;
4154 }
4155
4156
4157
4158 infoResp.status = STATUS_COMPLETE;
4159 wfaEncodeTLV(WFA_STA_GET_EVENT_DETAILS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
4160 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
4161
4162 return WFA_SUCCESS;
4163}
4164
4165
4166
4167