blob: 9b2d1310e054967c2c26ad95325661867342b135 [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
2311 if (presetDone)
2312 {
2313 PresetParamsResp->status = STATUS_COMPLETE;
2314 }
2315 else
2316 {
2317 PresetParamsResp->status = STATUS_INVALID;
2318 }
2319
2320 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf);
2321 *respLen = WFA_TLV_HDR_LEN + 4;
2322
2323 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002324}
2325
2326int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2327{
2328 dutCmdResponse_t *v11nParamsResp = &gGenericResp;
2329
2330 v11nParamsResp->status = STATUS_COMPLETE;
2331 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
2332 *respLen = WFA_TLV_HDR_LEN + 4;
2333 return WFA_SUCCESS;
2334}
2335int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2336{
2337 dutCmdResponse_t *staWirelessResp = &gGenericResp;
2338
2339 staWirelessResp->status = STATUS_COMPLETE;
2340 wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf);
2341 *respLen = WFA_TLV_HDR_LEN + 4;
2342 return WFA_SUCCESS;
2343}
2344
2345int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2346{
2347 dutCmdResponse_t *staSendADDBAResp = &gGenericResp;
2348
2349 wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf);
2350 *respLen = WFA_TLV_HDR_LEN + 4;
2351 return WFA_SUCCESS;
2352}
2353
2354int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2355{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002356 dutCmdResponse_t *staSetRIFSResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002357
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002358 wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf);
2359 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002360
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002361 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002362}
2363
2364int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2365{
2366 dutCmdResponse_t *staSendMGMTResp = &gGenericResp;
2367
2368 wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf);
2369 *respLen = WFA_TLV_HDR_LEN + 4;
2370
2371 return WFA_SUCCESS;
2372
2373}
2374
2375int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2376{
Dake Zhao0a832172015-01-06 11:08:47 -08002377 caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf;
2378 dutCmdResponse_t *ResetResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002379
2380
Dake Zhao0a832172015-01-06 11:08:47 -08002381 // need to make your own command available for this, here is only an example
2382 sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog);
2383 sret = system(gCmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002384
Dake Zhao0a832172015-01-06 11:08:47 -08002385 ResetResp->status = STATUS_COMPLETE;
2386 wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf);
2387 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002388
Dake Zhao0a832172015-01-06 11:08:47 -08002389 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002390}
2391
2392#else
2393
2394int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2395{
2396 dutCmdResponse_t *staCmdResp = &gGenericResp;
2397
2398 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2399 *respLen = WFA_TLV_HDR_LEN + 4;
2400
2401 return WFA_SUCCESS;
2402}
2403#endif
2404
2405/*
2406 * This is used to send a frame or action frame
2407 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002408int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002409{
Dake Zhao0a832172015-01-06 11:08:47 -08002410 dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2411 /* uncomment it if needed */
2412 // char *ifname = cmd->intf;
2413 dutCmdResponse_t *devSendResp = &gGenericResp;
2414 caStaDevSendFrame_t *sf = &cmd->cmdsu.sf;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002415
Dake Zhao0a832172015-01-06 11:08:47 -08002416 DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n");
2417 /* processing the frame */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002418
Dake Zhao0a832172015-01-06 11:08:47 -08002419 switch(sf->program)
2420 {
2421 case PROG_TYPE_PMF:
2422 {
2423 pmfFrame_t *pmf = &sf->frameType.pmf;
2424 switch(pmf->eFrameName)
2425 {
2426 case PMF_TYPE_DISASSOC:
2427 {
2428 /* use the protected to set what type of key to send */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002429
Dake Zhao0a832172015-01-06 11:08:47 -08002430 }
2431 break;
2432 case PMF_TYPE_DEAUTH:
2433 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002434
Dake Zhao0a832172015-01-06 11:08:47 -08002435 }
2436 break;
2437 case PMF_TYPE_SAQUERY:
2438 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002439
Dake Zhao0a832172015-01-06 11:08:47 -08002440 }
2441 break;
2442 case PMF_TYPE_AUTH:
2443 {
2444 }
2445 break;
2446 case PMF_TYPE_ASSOCREQ:
2447 {
2448 }
2449 break;
2450 case PMF_TYPE_REASSOCREQ:
2451 {
2452 }
2453 break;
2454 }
2455 }
2456 break;
2457 case PROG_TYPE_TDLS:
2458 {
2459 tdlsFrame_t *tdls = &sf->frameType.tdls;
2460 switch(tdls->eFrameName)
2461 {
2462 case TDLS_TYPE_DISCOVERY:
2463 /* use the peer mac address to send the frame */
2464 break;
2465 case TDLS_TYPE_SETUP:
2466 break;
2467 case TDLS_TYPE_TEARDOWN:
2468 break;
2469 case TDLS_TYPE_CHANNELSWITCH:
2470 break;
2471 case TDLS_TYPE_NULLFRAME:
2472 break;
2473 }
2474 }
2475 break;
2476 case PROG_TYPE_VENT:
2477 {
2478 ventFrame_t *vent = &sf->frameType.vent;
2479 switch(vent->type)
2480 {
2481 case VENT_TYPE_NEIGREQ:
2482 break;
2483 case VENT_TYPE_TRANSMGMT:
2484 break;
2485 }
2486 }
2487 break;
2488 case PROG_TYPE_WFD:
2489 {
2490 wfdFrame_t *wfd = &sf->frameType.wfd;
2491 switch(wfd->eframe)
2492 {
2493 case WFD_FRAME_PRBREQ:
2494 {
2495 /* send probe req */
2496 }
2497 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002498
Dake Zhao0a832172015-01-06 11:08:47 -08002499 case WFD_FRAME_PRBREQ_TDLS_REQ:
2500 {
2501 /* send tunneled tdls probe req */
2502 }
2503 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002504
Dake Zhao0a832172015-01-06 11:08:47 -08002505 case WFD_FRAME_11V_TIMING_MSR_REQ:
2506 {
2507 /* send 11v timing mearurement request */
2508 }
2509 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002510
Dake Zhao0a832172015-01-06 11:08:47 -08002511 case WFD_FRAME_RTSP:
2512 {
2513 /* send WFD RTSP messages*/
2514 // fetch the type of RTSP message and send it.
2515 switch(wfd->eRtspMsgType)
2516 {
2517 case WFD_RTSP_PAUSE:
2518 break;
2519 case WFD_RTSP_PLAY:
2520 //send RTSP PLAY
2521 break;
2522 case WFD_RTSP_TEARDOWN:
2523 //send RTSP TEARDOWN
2524 break;
2525 case WFD_RTSP_TRIG_PAUSE:
2526 //send RTSP TRIGGER PAUSE
2527 break;
2528 case WFD_RTSP_TRIG_PLAY:
2529 //send RTSP TRIGGER PLAY
2530 break;
2531 case WFD_RTSP_TRIG_TEARDOWN:
2532 //send RTSP TRIGGER TEARDOWN
2533 break;
2534 case WFD_RTSP_SET_PARAMETER:
2535 //send RTSP SET PARAMETER
2536 if (wfd->eSetParams == WFD_CAP_UIBC_KEYBOARD)
2537 {
2538 //send RTSP SET PARAMETER message for UIBC keyboard
2539 }
2540 if (wfd->eSetParams == WFD_CAP_UIBC_MOUSE)
2541 {
2542 //send RTSP SET PARAMETER message for UIBC Mouse
2543 }
2544 else if (wfd->eSetParams == WFD_CAP_RE_NEGO)
2545 {
2546 //send RTSP SET PARAMETER message Capability re-negotiation
2547 }
2548 else if (wfd->eSetParams == WFD_STANDBY)
2549 {
2550 //send RTSP SET PARAMETER message for standby
2551 }
2552 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_ENABLE)
2553 {
2554 //send RTSP SET PARAMETER message for UIBC settings enable
2555 }
2556 else if (wfd->eSetParams == WFD_UIBC_SETTINGS_DISABLE)
2557 {
2558 //send RTSP SET PARAMETER message for UIBC settings disable
2559 }
2560 else if (wfd->eSetParams == WFD_ROUTE_AUDIO)
2561 {
2562 //send RTSP SET PARAMETER message for route audio
2563 }
2564 else if (wfd->eSetParams == WFD_3D_VIDEOPARAM)
2565 {
2566 //send RTSP SET PARAMETER message for 3D video parameters
2567 }
2568 else if (wfd->eSetParams == WFD_2D_VIDEOPARAM)
2569 {
2570 //send RTSP SET PARAMETER message for 2D video parameters
2571 }
2572 break;
Dake Zhao97708202014-11-26 13:59:04 -08002573 }
Dake Zhao0a832172015-01-06 11:08:47 -08002574 }
2575 break;
2576 }
2577 }
2578 break;
2579 /* not need to support HS2 release 1, due to very short time period */
2580 case PROG_TYPE_HS2_R2:
2581 {
2582 /* type of frames */
2583 hs2Frame_t *hs2 = &sf->frameType.hs2_r2;
2584 switch(hs2->eframe)
2585 {
2586 case HS2_FRAME_ANQPQuery:
2587 {
Dake Zhao97708202014-11-26 13:59:04 -08002588
Dake Zhao0a832172015-01-06 11:08:47 -08002589 }
2590 break;
2591 case HS2_FRAME_DLSRequest:
2592 {
Dake Zhao97708202014-11-26 13:59:04 -08002593
Dake Zhao0a832172015-01-06 11:08:47 -08002594 }
2595 break;
2596 case HS2_FRAME_GARPReq:
2597 {
Dake Zhao97708202014-11-26 13:59:04 -08002598
Dake Zhao0a832172015-01-06 11:08:47 -08002599 }
2600 break;
2601 case HS2_FRAME_GARPRes:
2602 {
2603 }
2604 break;
2605 case HS2_FRAME_NeighAdv:
2606 {
2607 }
2608 case HS2_FRAME_ARPProbe:
2609 {
2610 }
2611 case HS2_FRAME_ARPAnnounce:
2612 {
Dake Zhao97708202014-11-26 13:59:04 -08002613
Dake Zhao0a832172015-01-06 11:08:47 -08002614 }
2615 break;
2616 case HS2_FRAME_NeighSolicitReq:
2617 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002618
Dake Zhao0a832172015-01-06 11:08:47 -08002619 }
2620 break;
2621 case HS2_FRAME_ARPReply:
2622 {
2623
2624 }
2625 break;
2626 }
2627
2628 }/* PROG_TYPE_HS2-R2 */
2629 case PROG_TYPE_GEN:
2630 {
2631 /* General frames */
2632 }
2633
2634
2635 }
2636 devSendResp->status = STATUS_COMPLETE;
2637 wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf);
2638 *respLen = WFA_TLV_HDR_LEN + 4;
2639
2640 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002641}
2642
2643/*
2644 * This is used to set a temporary MAC address of an interface
2645 */
2646int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2647{
Dake Zhao0a832172015-01-06 11:08:47 -08002648 // Uncomment it if needed
2649 //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf;
2650 // char *ifname = cmd->intf;
2651 dutCmdResponse_t *staCmdResp = &gGenericResp;
2652 // Uncomment it if needed
2653 //char *macaddr = &cmd->cmdsu.macaddr[0];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002654
Dake Zhao0a832172015-01-06 11:08:47 -08002655 wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
2656 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002657
Dake Zhao0a832172015-01-06 11:08:47 -08002658 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002659}
2660
2661
2662int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2663{
2664 //dutCommand_t *disc = (dutCommand_t *)caCmdBuf;
2665 //char *intf = disc->intf;
2666 dutCmdResponse_t *staDiscResp = &gGenericResp;
2667
2668 // stop the supplicant
2669
2670 staDiscResp->status = STATUS_COMPLETE;
2671
2672 wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf);
2673 *respLen = WFA_TLV_HDR_LEN + 4;
2674
2675 return WFA_SUCCESS;
2676}
2677
2678/* Execute CLI, read the status from Environment variable */
2679int wfaExecuteCLI(char *CLI)
2680{
Dake Zhao0a832172015-01-06 11:08:47 -08002681 char *retstr;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002682
Dake Zhao0a832172015-01-06 11:08:47 -08002683 sret = system(CLI);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002684
Dake Zhao0a832172015-01-06 11:08:47 -08002685 retstr = getenv("WFA_CLI_STATUS");
2686 printf("cli status %s\n", retstr);
2687 return atoi(retstr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002688}
2689
2690/* Supporting Functions */
2691
2692void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid)
2693{
Dake Zhao97708202014-11-26 13:59:04 -08002694 int totalpkts, tos=-1;
Naveen Kumard549d4b2014-03-13 10:56:56 -07002695 char cmdStr[256];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002696// char *addr = staPing->dipaddr;
2697#ifdef WFA_PC_CONSOLE
Naveen Kumard549d4b2014-03-13 10:56:56 -07002698 char addr[40];
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002699 char bflag[] = "-b";
2700 char *tmpstr;
2701 int inum=0;
2702#else
2703 char bflag[] = " ";
2704#endif
Dake Zhao0a832172015-01-06 11:08:47 -08002705
Ray Wang9b47f362014-03-19 16:51:10 -07002706 totalpkts = (int)(staPing->duration * staPing->frameRate);
Dake Zhao0a832172015-01-06 11:08:47 -08002707
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002708#ifdef WFA_PC_CONSOLE
2709
2710 printf("\nCS : The Stream ID is %d",streamid);
2711 printf("\nCS :the addr is %s ",addr);
2712 strcpy(addr,staPing->dipaddr);
2713 printf("\nCS :Inside the WFA_PC_CONSLE BLOCK");
2714 printf("\nCS :the addr is %s ",addr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002715 if (staPing->iptype == 2)
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002716 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002717 memset(bflag, 0, strlen(bflag));
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002718 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002719 else
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002720 {
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002721 tmpstr = strtok(addr, ".");
2722 inum = atoi(tmpstr);
2723
2724 printf("interval %f\n", *interval);
2725
2726 if(inum >= 224 && inum <= 239) // multicast
2727 {
2728 }
2729 else // if not MC, check if it is BC address
2730 {
2731 printf("\nCS :Inside the BC address BLOCK");
2732 printf("\nCS :the inum %d",inum);
2733 strtok(NULL, ".");
2734 //strtok(NULL, ".");
2735 tmpstr = strtok(NULL, ".");
2736 printf("tmpstr %s\n", tmpstr);
2737 inum = atoi(tmpstr);
2738 printf("\nCS : The string is %s",tmpstr);
2739 if(inum != 255)
Dake Zhao0a832172015-01-06 11:08:47 -08002740 memset(bflag, 0, strlen(bflag));
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002741 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002742 }
2743#endif
Dake Zhao97708202014-11-26 13:59:04 -08002744 if ( staPing->dscp >= 0)
2745 {
Dake Zhao0a832172015-01-06 11:08:47 -08002746 tos= convertDscpToTos(staPing->dscp);
2747 if (tos < 0)
Dake Zhao97708202014-11-26 13:59:04 -08002748 printf("\nwfaSendPing invalid tos converted, dscp=%d", staPing->dscp);
2749 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002750 printf("\nCS : The Stream ID is %d",streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002751 printf("IPtype : %i tos=%d",staPing->iptype, tos);
Dake Zhao0a832172015-01-06 11:08:47 -08002752
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002753 if (staPing->iptype == 2)
Dake Zhao0a832172015-01-06 11:08:47 -08002754 {
Dake Zhao97708202014-11-26 13:59:04 -08002755 if ( tos>0)
Dake Zhao0a832172015-01-06 11:08:47 -08002756 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",
2757 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002758 else
Dake Zhao0a832172015-01-06 11:08:47 -08002759 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",
2760 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002761 sret = system(cmdStr);
2762 printf("\nCS : The command string is %s",cmdStr);
2763 }
2764 else
2765 {
Dake Zhao97708202014-11-26 13:59:04 -08002766 if (tos > 0)
Dake Zhao0a832172015-01-06 11:08:47 -08002767 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",
2768 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, tos, staPing->frameSize,streamid);
Dake Zhao97708202014-11-26 13:59:04 -08002769 else
Dake Zhao0a832172015-01-06 11:08:47 -08002770 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",
2771 streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002772 sret = system(cmdStr);
2773 printf("\nCS : The command string is %s",cmdStr);
Dake Zhao0a832172015-01-06 11:08:47 -08002774 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002775 sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002776 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002777 printf("\nCS : The command string is %s",cmdStr);
2778
2779}
2780
2781int wfaStopPing(dutCmdResponse_t *stpResp, int streamid)
2782{
2783 char strout[256];
2784 FILE *tmpfile = NULL;
2785 char cmdStr[128];
2786 printf("Ping stop id %d\n", streamid);
2787 sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002788 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002789
2790 printf("\nCS : The command string is %s",cmdStr);
2791
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002792 sret = system("stoping.sh /tmp/pid.txt ; sleep 2");
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002793
2794 sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08002795 sret = system(cmdStr);
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00002796
2797 printf("\nCS : The command string is %s",cmdStr);
2798
2799 tmpfile = fopen("/tmp/stpsta.txt", "r+");
2800
2801 if(tmpfile == NULL)
2802 {
2803 return WFA_FAILURE;
2804 }
2805
2806 if(fscanf(tmpfile, "%s", strout) != EOF)
2807 {
2808 if(*strout == '\0')
2809 {
2810 stpResp->cmdru.pingStp.sendCnt = 0;
2811 }
2812
2813 else
2814 stpResp->cmdru.pingStp.sendCnt = atoi(strout);
2815 }
2816
2817 printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt);
2818
2819
2820 if(fscanf(tmpfile, "%s", strout) != EOF)
2821 {
2822 if(*strout == '\0')
2823 {
2824 stpResp->cmdru.pingStp.repliedCnt = 0;
2825 }
2826 else
2827 stpResp->cmdru.pingStp.repliedCnt = atoi(strout);
2828 }
2829 printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt);
2830
2831 fclose(tmpfile);
2832
2833 return WFA_SUCCESS;
2834}
2835
Ankur Vachhanic485b712012-02-15 23:29:49 +00002836/*
Dake Zhao0a832172015-01-06 11:08:47 -08002837 * wfaStaGetP2pDevAddress():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002838 */
2839int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2840{
Dake Zhao0a832172015-01-06 11:08:47 -08002841 dutCmdResponse_t infoResp;
2842 /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002843
Dake Zhao0a832172015-01-06 11:08:47 -08002844 printf("\n Entry wfaStaGetP2pDevAddress... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002845
Dake Zhao0a832172015-01-06 11:08:47 -08002846 // Fetch the device ID and store into infoResp->cmdru.devid
2847 //strcpy(infoResp->cmdru.devid, str);
2848 strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002849
Dake Zhao0a832172015-01-06 11:08:47 -08002850 infoResp.status = STATUS_COMPLETE;
2851 wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2852 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2853
2854 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002855}
2856
2857
2858
2859/*
Dake Zhao0a832172015-01-06 11:08:47 -08002860 * wfaStaSetP2p():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002861 */
2862int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2863{
Dake Zhao0a832172015-01-06 11:08:47 -08002864 dutCmdResponse_t infoResp;
2865 /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/
Ankur Vachhanic485b712012-02-15 23:29:49 +00002866
Dake Zhao0a832172015-01-06 11:08:47 -08002867 printf("\n Entry wfaStaSetP2p... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002868
Dake Zhao0a832172015-01-06 11:08:47 -08002869 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002870
Dake Zhao0a832172015-01-06 11:08:47 -08002871 infoResp.status = STATUS_COMPLETE;
2872 wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2873 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2874
2875 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002876}
2877/*
Dake Zhao0a832172015-01-06 11:08:47 -08002878 * wfaStaP2pConnect():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002879 */
2880int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2881{
Dake Zhao0a832172015-01-06 11:08:47 -08002882 dutCmdResponse_t infoResp;
2883 /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002884
Dake Zhao0a832172015-01-06 11:08:47 -08002885 printf("\n Entry wfaStaP2pConnect... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002886
Dake Zhao0a832172015-01-06 11:08:47 -08002887 // Implement the function and does not return anything.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002888
Ankur Vachhanic485b712012-02-15 23:29:49 +00002889
Dake Zhao0a832172015-01-06 11:08:47 -08002890 infoResp.status = STATUS_COMPLETE;
2891 wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2892 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2893
2894 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002895}
2896
2897/*
Dake Zhao0a832172015-01-06 11:08:47 -08002898 * wfaStaStartAutoGo():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002899 */
2900int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2901{
Dake Zhao0a832172015-01-06 11:08:47 -08002902 dutCmdResponse_t infoResp;
2903 //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002904
Dake Zhao0a832172015-01-06 11:08:47 -08002905 printf("\n Entry wfaStaStartAutoGo... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002906
Dake Zhao0a832172015-01-06 11:08:47 -08002907 // Fetch the group ID and store into infoResp->cmdru.grpid
2908 strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002909
Dake Zhao0a832172015-01-06 11:08:47 -08002910 infoResp.status = STATUS_COMPLETE;
2911 wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2912 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2913
2914 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002915}
2916
2917
2918
2919
2920/*
Dake Zhao0a832172015-01-06 11:08:47 -08002921 * wfaStaP2pStartGrpFormation():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002922 */
2923int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2924{
Dake Zhao0a832172015-01-06 11:08:47 -08002925 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002926
Dake Zhao0a832172015-01-06 11:08:47 -08002927 printf("\n Entry wfaStaP2pStartGrpFormation... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002928
Dake Zhao0a832172015-01-06 11:08:47 -08002929 strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT");
2930 strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002931
Ankur Vachhanic485b712012-02-15 23:29:49 +00002932
Dake Zhao0a832172015-01-06 11:08:47 -08002933 infoResp.status = STATUS_COMPLETE;
2934 wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2935 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2936
2937 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002938}
2939
2940
2941/*
Dake Zhao0a832172015-01-06 11:08:47 -08002942 * wfaStaP2pDissolve():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002943 */
2944int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2945{
Dake Zhao0a832172015-01-06 11:08:47 -08002946 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002947
Dake Zhao0a832172015-01-06 11:08:47 -08002948 printf("\n Entry wfaStaP2pDissolve... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002949
Dake Zhao0a832172015-01-06 11:08:47 -08002950 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002951
Dake Zhao0a832172015-01-06 11:08:47 -08002952 infoResp.status = STATUS_COMPLETE;
2953 wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2954 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2955
2956 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002957}
2958
2959/*
Dake Zhao0a832172015-01-06 11:08:47 -08002960 * wfaStaSendP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002961 */
2962int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2963{
Dake Zhao0a832172015-01-06 11:08:47 -08002964 dutCmdResponse_t infoResp;
2965 /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002966
Dake Zhao0a832172015-01-06 11:08:47 -08002967 printf("\n Entry wfaStaSendP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002968
Dake Zhao0a832172015-01-06 11:08:47 -08002969 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002970
Dake Zhao0a832172015-01-06 11:08:47 -08002971 infoResp.status = STATUS_COMPLETE;
2972 wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2973 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2974
2975 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002976}
2977
2978
2979/*
Dake Zhao0a832172015-01-06 11:08:47 -08002980 * wfaStaAcceptP2pInvReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00002981 */
2982int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
2983{
Dake Zhao0a832172015-01-06 11:08:47 -08002984 dutCmdResponse_t infoResp;
2985 /* uncomment and use it
2986 * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf;
2987 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00002988
Dake Zhao0a832172015-01-06 11:08:47 -08002989 printf("\n Entry wfaStaAcceptP2pInvReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00002990
Dake Zhao0a832172015-01-06 11:08:47 -08002991 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00002992
Dake Zhao0a832172015-01-06 11:08:47 -08002993 infoResp.status = STATUS_COMPLETE;
2994 wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
2995 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
2996
2997 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00002998}
2999
3000
3001/*
Dake Zhao0a832172015-01-06 11:08:47 -08003002 * wfaStaSendP2pProvDisReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003003 */
3004int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3005{
Dake Zhao0a832172015-01-06 11:08:47 -08003006 dutCmdResponse_t infoResp;
3007 /* uncomment and use it
3008 * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf;
3009 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003010
Dake Zhao0a832172015-01-06 11:08:47 -08003011 printf("\n Entry wfaStaSendP2pProvDisReq... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003012
Dake Zhao0a832172015-01-06 11:08:47 -08003013 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003014
Dake Zhao0a832172015-01-06 11:08:47 -08003015 infoResp.status = STATUS_COMPLETE;
3016 wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3017 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3018
3019 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003020}
3021
3022/*
Dake Zhao0a832172015-01-06 11:08:47 -08003023 * wfaStaSetWpsPbc():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003024 */
3025int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3026{
Dake Zhao0a832172015-01-06 11:08:47 -08003027 dutCmdResponse_t infoResp;
3028 /* uncomment and use it
3029 * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf;
3030 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003031
Dake Zhao0a832172015-01-06 11:08:47 -08003032 printf("\n Entry wfaStaSetWpsPbc... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003033
Dake Zhao0a832172015-01-06 11:08:47 -08003034 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003035
Dake Zhao0a832172015-01-06 11:08:47 -08003036 infoResp.status = STATUS_COMPLETE;
3037 wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3038 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3039
3040 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003041}
3042
3043/*
Dake Zhao0a832172015-01-06 11:08:47 -08003044 * wfaStaWpsReadPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003045 */
3046int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3047{
Dake Zhao0a832172015-01-06 11:08:47 -08003048 dutCmdResponse_t infoResp;
3049 /* uncomment and use it
3050 * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf;
3051 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003052
Dake Zhao0a832172015-01-06 11:08:47 -08003053 printf("\n Entry wfaStaWpsReadPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003054
Dake Zhao0a832172015-01-06 11:08:47 -08003055 // Fetch the device PIN and put in infoResp->cmdru.wpsPin
3056 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3057 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003058
Ankur Vachhanic485b712012-02-15 23:29:49 +00003059
Dake Zhao0a832172015-01-06 11:08:47 -08003060 infoResp.status = STATUS_COMPLETE;
3061 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3062 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3063
3064 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003065}
3066
3067
3068
3069/*
Dake Zhao0a832172015-01-06 11:08:47 -08003070 * wfaStaWpsReadLabel():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003071 */
3072int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3073{
Dake Zhao0a832172015-01-06 11:08:47 -08003074 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003075
Dake Zhao0a832172015-01-06 11:08:47 -08003076 printf("\n Entry wfaStaWpsReadLabel... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003077
Dake Zhao0a832172015-01-06 11:08:47 -08003078 // Fetch the device Label and put in infoResp->cmdru.wpsPin
3079 //strcpy(infoResp->cmdru.wpsPin, "12345678");
3080 strcpy(&infoResp.cmdru.wpsPin[0], "1234456");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003081
Ankur Vachhanic485b712012-02-15 23:29:49 +00003082
Dake Zhao0a832172015-01-06 11:08:47 -08003083 infoResp.status = STATUS_COMPLETE;
3084 wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3085 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3086
3087 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003088}
3089
3090
3091/*
Dake Zhao0a832172015-01-06 11:08:47 -08003092 * wfaStaWpsEnterPin():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003093 */
3094int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3095{
Dake Zhao0a832172015-01-06 11:08:47 -08003096 dutCmdResponse_t infoResp;
3097 /* uncomment and use it
3098 * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf;
3099 */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003100
Dake Zhao0a832172015-01-06 11:08:47 -08003101 printf("\n Entry wfaStaWpsEnterPin... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003102
Dake Zhao0a832172015-01-06 11:08:47 -08003103 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003104
Ankur Vachhanic485b712012-02-15 23:29:49 +00003105
Dake Zhao0a832172015-01-06 11:08:47 -08003106 infoResp.status = STATUS_COMPLETE;
3107 wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3108 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3109
3110 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003111}
3112
3113
3114/*
Dake Zhao0a832172015-01-06 11:08:47 -08003115 * wfaStaGetPsk():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003116 */
3117int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3118{
Dake Zhao0a832172015-01-06 11:08:47 -08003119 dutCmdResponse_t infoResp;
3120 /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003121
Dake Zhao0a832172015-01-06 11:08:47 -08003122 printf("\n Entry wfaStaGetPsk... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003123
3124
Dake Zhao0a832172015-01-06 11:08:47 -08003125 // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo
3126 strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456");
3127 strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003128
Ankur Vachhanic485b712012-02-15 23:29:49 +00003129
Dake Zhao0a832172015-01-06 11:08:47 -08003130 infoResp.status = STATUS_COMPLETE;
3131 wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3132 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3133
3134 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003135}
3136
3137/*
Dake Zhao0a832172015-01-06 11:08:47 -08003138 * wfaStaP2pReset():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003139 */
3140int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3141{
Dake Zhao0a832172015-01-06 11:08:47 -08003142 dutCmdResponse_t infoResp;
3143 /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003144
Dake Zhao0a832172015-01-06 11:08:47 -08003145 printf("\n Entry wfaStaP2pReset... ");
3146 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003147
Dake Zhao0a832172015-01-06 11:08:47 -08003148 infoResp.status = STATUS_COMPLETE;
3149 wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3150 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3151
3152 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003153}
3154
3155
3156
3157/*
Dake Zhao0a832172015-01-06 11:08:47 -08003158 * wfaStaGetP2pIpConfig():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003159 */
3160int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3161{
Dake Zhao0a832172015-01-06 11:08:47 -08003162 dutCmdResponse_t infoResp;
3163 /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003164
Dake Zhao0a832172015-01-06 11:08:47 -08003165 caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003166
Dake Zhao0a832172015-01-06 11:08:47 -08003167 printf("\n Entry wfaStaGetP2pIpConfig... ");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003168
Dake Zhao0a832172015-01-06 11:08:47 -08003169 ifinfo->isDhcp =0;
3170 strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111");
3171 strcpy(&(ifinfo->mask[0]), "255.255.255.0");
3172 strcpy(&(ifinfo->dns[0][0]), "192.165.100.1");
3173 strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba");
3174
3175 infoResp.status = STATUS_COMPLETE;
3176 wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_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
3185/*
Dake Zhao0a832172015-01-06 11:08:47 -08003186 * wfaStaSendServiceDiscoveryReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003187 */
3188int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3189{
Dake Zhao0a832172015-01-06 11:08:47 -08003190 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003191
Dake Zhao0a832172015-01-06 11:08:47 -08003192 printf("\n Entry wfaStaSendServiceDiscoveryReq... ");
3193 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003194
Dake Zhao0a832172015-01-06 11:08:47 -08003195
3196 infoResp.status = STATUS_COMPLETE;
3197 wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3198 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3199
3200 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003201}
3202
3203
3204
3205/*
Dake Zhao0a832172015-01-06 11:08:47 -08003206 * wfaStaSendP2pPresenceReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003207 */
3208int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3209{
Dake Zhao0a832172015-01-06 11:08:47 -08003210 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003211
Dake Zhao0a832172015-01-06 11:08:47 -08003212 infoResp.status = STATUS_COMPLETE;
3213 wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3214 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003215
Dake Zhao0a832172015-01-06 11:08:47 -08003216 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003217}
3218
3219/*
Dake Zhao0a832172015-01-06 11:08:47 -08003220 * wfaStaSetSleepReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003221 */
3222int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3223{
Dake Zhao0a832172015-01-06 11:08:47 -08003224 dutCmdResponse_t infoResp;
3225 /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003226
Dake Zhao0a832172015-01-06 11:08:47 -08003227 printf("\n Entry wfaStaSetSleepReq... ");
3228 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003229
Dake Zhao0a832172015-01-06 11:08:47 -08003230
3231 infoResp.status = STATUS_COMPLETE;
3232 wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3233 *respLen = WFA_TLV_HDR_LEN +4;
3234
3235 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003236}
3237
3238/*
Dake Zhao0a832172015-01-06 11:08:47 -08003239 * wfaStaSetOpportunisticPsReq():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003240 */
3241int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3242{
Dake Zhao0a832172015-01-06 11:08:47 -08003243 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003244
Dake Zhao0a832172015-01-06 11:08:47 -08003245 printf("\n Entry wfaStaSetOpportunisticPsReq... ");
3246 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003247
Dake Zhao0a832172015-01-06 11:08:47 -08003248
3249 infoResp.status = STATUS_COMPLETE;
3250 wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3251 *respLen = WFA_TLV_HDR_LEN + 4;
3252
3253 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003254}
3255#ifndef WFA_STA_TB
3256/*
Dake Zhao0a832172015-01-06 11:08:47 -08003257 * wfaStaPresetParams():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003258 */
3259
3260int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3261{
Dake Zhao0a832172015-01-06 11:08:47 -08003262 dutCmdResponse_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003263
Dake Zhao0a832172015-01-06 11:08:47 -08003264 DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003265
Dake Zhao0a832172015-01-06 11:08:47 -08003266 // Implement the function and its sub commands
3267 infoResp.status = STATUS_COMPLETE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003268
Dake Zhao0a832172015-01-06 11:08:47 -08003269 wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf);
3270 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003271
Dake Zhao0a832172015-01-06 11:08:47 -08003272 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003273}
Dake Zhao0a832172015-01-06 11:08:47 -08003274int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
Ankur Vachhanic485b712012-02-15 23:29:49 +00003275{
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003276
3277 dutCmdResponse_t infoResp;
3278 dutCmdResponse_t *v11nParamsResp = &infoResp;
3279
3280#ifdef WFA_11N_SUPPORT_ONLY
Dake Zhao0a832172015-01-06 11:08:47 -08003281
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003282 caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf;
3283
3284 int st =0; // SUCCESS
Dake Zhao0a832172015-01-06 11:08:47 -08003285
3286 DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n");
Ankur Vachhanic485b712012-02-15 23:29:49 +00003287
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003288 if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2)
3289 {
Dake Zhao0a832172015-01-06 11:08:47 -08003290 // implement the funciton
3291 if(st != 0)
3292 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003293 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003294 strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed");
3295 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3296 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3297 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003298 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003299 }
Dake Zhao0a832172015-01-06 11:08:47 -08003300
Ankur Vachhanic485b712012-02-15 23:29:49 +00003301 if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003302 {
Dake Zhao0a832172015-01-06 11:08:47 -08003303 // implement the funciton
Ankur Vachhanic485b712012-02-15 23:29:49 +00003304
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003305 if(st != 0)
3306 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003307 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003308 strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed");
3309 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3310 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3311 return FALSE;
3312 }
3313 }
3314
Ankur Vachhanic485b712012-02-15 23:29:49 +00003315 if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003316 {
Dake Zhao0a832172015-01-06 11:08:47 -08003317 // implement the funciton
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003318 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_amsdu failed");
3322 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3323 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Dake Zhao0a832172015-01-06 11:08:47 -08003324 return FALSE;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003325 }
3326 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003327
3328 if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003329 {
3330 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003331 if(st != 0)
3332 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003333 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003334 strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed");
3335 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3336 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3337 return FALSE;
Dake Zhao0a832172015-01-06 11:08:47 -08003338 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003339 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003340
3341 if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003342 {
Dake Zhao0a832172015-01-06 11:08:47 -08003343 // implement the funciton
3344 //st = wfaExecuteCLI(gCmdStr);
3345 if(st != 0)
3346 {
3347 v11nParamsResp->status = STATUS_ERROR;
3348 strcpy(v11nParamsResp->cmdru.info, "set_mcs failed");
3349 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3350 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3351 return FALSE;
3352 }
3353 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003354 else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0')
3355 {
3356 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003357 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -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_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003362 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3363 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003364 return FALSE;
3365 }
Dake Zhao0a832172015-01-06 11:08:47 -08003366 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003367 else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0')
3368 {
3369 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003370 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003371 if(st != 0)
3372 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003373 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003374 strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003375 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3376 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003377 return FALSE;
3378 }
3379 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003380
3381 if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003382 {
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_rifs_test 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 }
3393 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003394
3395 if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003396 {
3397 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003398 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003399 if(st != 0)
3400 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003401 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003402 strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed");
3403 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3404 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3405 return FALSE;
3406 }
3407 }
3408
3409 if(v11nParams->smps != 0xFFFF)
3410 {
3411 if(v11nParams->smps == 0)
3412 {
Dake Zhao0a832172015-01-06 11:08:47 -08003413 // implement the funciton
3414 //st = wfaExecuteCLI(gCmdStr);
3415 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003416 else if(v11nParams->smps == 1)
3417 {
Dake Zhao0a832172015-01-06 11:08:47 -08003418 // implement the funciton
3419 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003420 ;
Dake Zhao0a832172015-01-06 11:08:47 -08003421 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003422 else if(v11nParams->smps == 2)
3423 {
Dake Zhao0a832172015-01-06 11:08:47 -08003424 // implement the funciton
3425 //st = wfaExecuteCLI(gCmdStr);
3426 ;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003427 }
3428 if(st != 0)
3429 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003430 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003431 strcpy(v11nParamsResp->cmdru.info, "set_smps failed");
3432 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3433 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3434 return FALSE;
3435 }
3436 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003437
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003438 if(v11nParams->stbc_rx != 0xFFFF)
3439 {
3440 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003441 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003442 if(st != 0)
3443 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003444 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003445 strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed");
Dake Zhao0a832172015-01-06 11:08:47 -08003446 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3447 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003448 return FALSE;
3449 }
3450 }
Dake Zhao0a832172015-01-06 11:08:47 -08003451
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003452 if(v11nParams->width[0] != '\0')
3453 {
3454 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003455 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003456 if(st != 0)
3457 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003458 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003459 strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed");
3460 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3461 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3462 return FALSE;
3463 }
3464 }
Dake Zhao0a832172015-01-06 11:08:47 -08003465
Ankur Vachhanic485b712012-02-15 23:29:49 +00003466 if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2)
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003467 {
3468 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003469 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003470 if(st != 0)
3471 {
Ankur Vachhanic485b712012-02-15 23:29:49 +00003472 v11nParamsResp->status = STATUS_ERROR;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003473 strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed");
3474 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3475 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3476 return FALSE;
3477 }
3478 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003479
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003480 if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4)
3481 {
3482 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003483 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003484 if(st != 0)
3485 {
3486 v11nParamsResp->status = STATUS_ERROR;
Dake Zhao0a832172015-01-06 11:08:47 -08003487 strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream failed");
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003488 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3489 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3490 return FALSE;
3491 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003492
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003493 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003494
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003495 if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4)
3496 {
3497 // implement the funciton
Dake Zhao0a832172015-01-06 11:08:47 -08003498 //st = wfaExecuteCLI(gCmdStr);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003499 if(st != 0)
3500 {
3501 v11nParamsResp->status = STATUS_ERROR;
3502 strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed");
3503 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf);
3504 *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
3505 return FALSE;
3506 }
3507 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003508
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003509#endif
Ankur Vachhanic485b712012-02-15 23:29:49 +00003510
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003511 v11nParamsResp->status = STATUS_COMPLETE;
3512 wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf);
3513 *respLen = WFA_TLV_HDR_LEN + 4;
3514 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003515}
3516#endif
3517/*
Dake Zhao0a832172015-01-06 11:08:47 -08003518 * wfaStaAddArpTableEntry():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003519 */
3520int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3521{
Dake Zhao0a832172015-01-06 11:08:47 -08003522 dutCmdResponse_t infoResp;
3523 /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003524
Dake Zhao0a832172015-01-06 11:08:47 -08003525 printf("\n Entry wfastaAddARPTableEntry... ");
3526 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003527
Dake Zhao0a832172015-01-06 11:08:47 -08003528 infoResp.status = STATUS_COMPLETE;
3529 wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3530 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3531
3532 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003533}
3534
3535/*
Dake Zhao0a832172015-01-06 11:08:47 -08003536 * wfaStaBlockICMPResponse():
Ankur Vachhanic485b712012-02-15 23:29:49 +00003537 */
3538int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3539{
Dake Zhao0a832172015-01-06 11:08:47 -08003540 dutCmdResponse_t infoResp;
3541 /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */
Ankur Vachhanic485b712012-02-15 23:29:49 +00003542
Dake Zhao0a832172015-01-06 11:08:47 -08003543 printf("\n Entry wfaStaBlockICMPResponse... ");
3544 // Implement the function and this does not return any thing back.
Ankur Vachhanic485b712012-02-15 23:29:49 +00003545
Dake Zhao0a832172015-01-06 11:08:47 -08003546 infoResp.status = STATUS_COMPLETE;
3547 wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3548 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3549
3550 return WFA_SUCCESS;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003551}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003552
3553/*
Dake Zhao0a832172015-01-06 11:08:47 -08003554 * wfaStaSetRadio():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003555 */
3556
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003557int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3558{
3559 dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf;
3560 dutCmdResponse_t *staCmdResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003561 caStaSetRadio_t *sr = &setRadio->cmdsu.sr;
3562
3563 if(sr->mode == WFA_OFF)
3564 {
Dake Zhao0a832172015-01-06 11:08:47 -08003565 // turn radio off
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003566 }
3567 else
3568 {
Dake Zhao0a832172015-01-06 11:08:47 -08003569 // always turn the radio on
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003570 }
3571
3572 staCmdResp->status = STATUS_COMPLETE;
3573 wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf);
3574 *respLen = WFA_TLV_HDR_LEN + 4;
3575
3576 return WFA_SUCCESS;
3577}
3578
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003579/*
Dake Zhao0a832172015-01-06 11:08:47 -08003580 * wfaStaSetRFeature():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003581 */
3582
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003583int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3584{
Dake Zhao0a832172015-01-06 11:08:47 -08003585 dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf;
3586 caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat;
3587 dutCmdResponse_t *caResp = &gGenericResp;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003588
Dake Zhao0a832172015-01-06 11:08:47 -08003589 if(strcasecmp(rfeat->prog, "tdls") == 0)
3590 {
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003591
3592
Dake Zhao0a832172015-01-06 11:08:47 -08003593 }
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003594
Dake Zhao0a832172015-01-06 11:08:47 -08003595 caResp->status = STATUS_COMPLETE;
3596 wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf);
3597 *respLen = WFA_TLV_HDR_LEN + 4;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003598
Dake Zhao0a832172015-01-06 11:08:47 -08003599 return WFA_SUCCESS;
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003600}
3601
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003602/*
Dake Zhao0a832172015-01-06 11:08:47 -08003603 * wfaStaStartWfdConnection():
3604 */
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003605int wfaStaStartWfdConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3606{
Dake Zhao0a832172015-01-06 11:08:47 -08003607 dutCmdResponse_t infoResp;
3608 //caStaStartWfdConn_t *staStartWfdConn= (caStaStartWfdConn_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003609
Dake Zhao0a832172015-01-06 11:08:47 -08003610 printf("\n Entry wfaStaStartWfdConnection... ");
3611
3612
3613 // Fetch the GrpId and WFD session and return
3614 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3615 strcpy(&infoResp.cmdru.wfdConnInfo.p2pGrpId[0], "WIFI_DISPLAY");
3616 strcpy(&infoResp.cmdru.wfdConnInfo.result[0], "GO");
3617
3618 infoResp.status = STATUS_COMPLETE;
3619 wfaEncodeTLV(WFA_STA_START_WFD_CONNECTION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3620 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
3621
3622 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003623}
3624/*
Dake Zhao0a832172015-01-06 11:08:47 -08003625 * wfaStaCliCommand():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003626 */
Ankur Vachhanie1b4fbc2011-12-26 09:40:02 +00003627
Ankur Vachhanic485b712012-02-15 23:29:49 +00003628int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3629{
Dake Zhao0a832172015-01-06 11:08:47 -08003630 char cmdName[32];
3631 char *pcmdStr=NULL, *str;
3632 int st = 1;
3633 char CmdStr[WFA_CMD_STR_SZ];
3634 FILE *wfaCliFd;
3635 char wfaCliBuff[64];
3636 char retstr[256];
3637 int CmdReturnFlag =0;
3638 char tmp[256];
3639 FILE * sh_pipe;
3640 caStaCliCmdResp_t infoResp;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003641
Dake Zhao0a832172015-01-06 11:08:47 -08003642 printf("\nEntry wfaStaCliCommand; command Received: %s\n",caCmdBuf);
3643 memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32);
3644 sprintf(CmdStr, "%s",cmdName);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003645
Dake Zhao0a832172015-01-06 11:08:47 -08003646 for(;;)
3647 {
3648 // construct CLI standard cmd string
3649 str = strtok_r(NULL, ",", &pcmdStr);
3650 if(str == NULL || str[0] == '\0')
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003651 break;
Dake Zhao0a832172015-01-06 11:08:47 -08003652 else
3653 {
3654 sprintf(CmdStr, "%s /%s",CmdStr,str);
3655 str = strtok_r(NULL, ",", &pcmdStr);
3656 sprintf(CmdStr, "%s %s",CmdStr,str);
3657 }
3658 }
3659 // check the return process
3660 wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r");
3661 if(wfaCliFd!= NULL)
3662 {
3663 while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL)
3664 {
3665 //printf("\nLine read from CLI file : %s",wfaCliBuff);
3666 if(ferror(wfaCliFd))
3667 break;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003668
Dake Zhao0a832172015-01-06 11:08:47 -08003669 str=strtok(wfaCliBuff,"-");
3670 if(strcmp(str,cmdName) == 0)
Dake Zhao97708202014-11-26 13:59:04 -08003671 {
Dake Zhao0a832172015-01-06 11:08:47 -08003672 str=strtok(NULL,",");
3673 if (str != NULL)
3674 {
3675 if(strcmp(str,"TRUE") == 0)
3676 CmdReturnFlag =1;
3677 }
3678 else
3679 printf("ERR wfa_cli.txt, inside line format not end with , or missing TRUE/FALSE\n");
3680 break;
Dake Zhao97708202014-11-26 13:59:04 -08003681 }
Dake Zhao0a832172015-01-06 11:08:47 -08003682 }
3683 fclose(wfaCliFd);
3684 }
3685 else
3686 {
3687 printf("/etc/WfaEndpoint/wfa_cli.txt is not exist\n");
3688 goto cleanup;
3689 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003690
Dake Zhao0a832172015-01-06 11:08:47 -08003691 //printf("\n Command Return Flag : %d",CmdReturnFlag);
3692 memset(&retstr[0],'\0',255);
3693 memset(&tmp[0],'\0',255);
3694 sprintf(gCmdStr, "%s", CmdStr);
3695 printf("\nCLI Command -- %s\n", gCmdStr);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003696
Dake Zhao0a832172015-01-06 11:08:47 -08003697 sh_pipe = popen(gCmdStr,"r");
3698 if(!sh_pipe)
3699 {
3700 printf ("Error in opening pipe\n");
3701 goto cleanup;
3702 }
Dake Zhao97708202014-11-26 13:59:04 -08003703
Dake Zhao0a832172015-01-06 11:08:47 -08003704 sleep(5);
3705 //tmp_val=getdelim(&retstr,255,"\n",sh_pipe);
3706 if (fgets(&retstr[0], 255, sh_pipe) == NULL)
3707 {
3708 printf("Getting NULL string in popen return\n");
3709 goto cleanup;
3710 }
3711 else
3712 printf("popen return str=%s\n",retstr);
3713
3714 sleep(2);
3715 if(pclose(sh_pipe) == -1)
3716 {
3717 printf("Error in closing shell cmd pipe\n");
3718 goto cleanup;
3719 }
3720 sleep(2);
3721
3722 // find status first in output
3723 str = strtok_r((char *)retstr, "-", (char **)&pcmdStr);
3724 if (str != NULL)
3725 {
3726 memset(tmp, 0, 10);
3727 memcpy(tmp, str, 2);
3728 printf("cli status=%s\n",tmp);
3729 if(strlen(tmp) > 0)
3730 st = atoi(tmp);
3731 else printf("Missing status code\n");
3732 }
3733 else
3734 {
3735 printf("wfaStaCliCommand no return code found\n");
3736 }
3737 infoResp.resFlag=CmdReturnFlag;
3738
Dake Zhao97708202014-11-26 13:59:04 -08003739cleanup:
Dake Zhao0a832172015-01-06 11:08:47 -08003740
3741 switch(st)
3742 {
3743 case 0:
3744 infoResp.status = STATUS_COMPLETE;
3745 if (CmdReturnFlag)
3746 {
3747 if((pcmdStr != NULL) && (strlen(pcmdStr) > 0) )
3748 {
3749 memset(&(infoResp.result[0]),'\0',WFA_CLI_CMD_RESP_LEN-1);
Dake Zhao97708202014-11-26 13:59:04 -08003750 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 -08003751 printf("Return CLI result string to CA=%s\n", &(infoResp.result[0]));
3752 }
3753 else
3754 {
Dake Zhao97708202014-11-26 13:59:04 -08003755 strcpy(&infoResp.result[0], "No return string found\n");
Dake Zhao0a832172015-01-06 11:08:47 -08003756 }
3757 }
3758 break;
3759 case 1:
3760 infoResp.status = STATUS_ERROR;
3761 break;
3762 case 2:
3763 infoResp.status = STATUS_INVALID;
3764 break;
3765 }
Ankur Vachhanic485b712012-02-15 23:29:49 +00003766
Dake Zhao0a832172015-01-06 11:08:47 -08003767 wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3768 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Ankur Vachhanic485b712012-02-15 23:29:49 +00003769
Dake Zhao0a832172015-01-06 11:08:47 -08003770 printf("Exit from wfaStaCliCommand\n");
3771 return TRUE;
Ankur Vachhanic485b712012-02-15 23:29:49 +00003772
Ankur Vachhanic485b712012-02-15 23:29:49 +00003773}
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003774/*
Dake Zhao0a832172015-01-06 11:08:47 -08003775 * wfaStaConnectGoStartWfd():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003776 */
3777
3778int wfaStaConnectGoStartWfd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3779{
3780 dutCmdResponse_t infoResp;
3781// caStaConnectGoStartWfd_t *staConnecGoStartWfd= (caStaConnectGoStartWfd_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003782
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003783 printf("\n Entry wfaStaConnectGoStartWfd... ");
3784
Dake Zhao0a832172015-01-06 11:08:47 -08003785 // connect the specified GO and then establish the wfd session
3786
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003787 // Fetch WFD session and return
3788 strcpy(&infoResp.cmdru.wfdConnInfo.wfdSessionId[0], "1234567890");
3789
3790 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003791 wfaEncodeTLV(WFA_STA_CONNECT_GO_START_WFD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003792 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003793
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003794 return WFA_SUCCESS;
3795}
3796
3797/*
Dake Zhao0a832172015-01-06 11:08:47 -08003798 * wfaStaGenerateEvent():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003799 */
3800
3801int wfaStaGenerateEvent(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3802{
3803 dutCmdResponse_t infoResp;
3804 caStaGenEvent_t *staGenerateEvent= (caStaGenEvent_t *)caCmdBuf; //uncomment and use it
3805 caWfdStaGenEvent_t *wfdGenEvent;
Dake Zhao0a832172015-01-06 11:08:47 -08003806
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003807 printf("\n Entry wfaStaGenerateEvent... ");
3808
3809
3810 // Geneate the specified action and return with complete/error.
3811 if(staGenerateEvent->program == PROG_TYPE_WFD)
3812 {
3813 wfdGenEvent = &staGenerateEvent->wfdEvent;
3814 if(wfdGenEvent ->type == eUibcGen)
3815 {
Dake Zhao0a832172015-01-06 11:08:47 -08003816 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003817 else if(wfdGenEvent ->type == eUibcHid)
3818 {
Dake Zhao0a832172015-01-06 11:08:47 -08003819 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003820 else if(wfdGenEvent ->type == eFrameSkip)
3821 {
3822
3823 }
3824 else if(wfdGenEvent ->type == eI2cRead)
3825 {
3826 }
3827 else if(wfdGenEvent ->type == eI2cWrite)
3828 {
Dake Zhao0a832172015-01-06 11:08:47 -08003829 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003830 else if(wfdGenEvent ->type == eInputContent)
3831 {
Dake Zhao0a832172015-01-06 11:08:47 -08003832 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003833 else if(wfdGenEvent ->type == eIdrReq)
3834 {
Dake Zhao0a832172015-01-06 11:08:47 -08003835 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003836 }
Dake Zhao0a832172015-01-06 11:08:47 -08003837
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003838 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003839 wfaEncodeTLV(WFA_STA_GENERATE_EVENT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003840 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003841
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003842 return WFA_SUCCESS;
3843}
3844
Dake Zhao0a832172015-01-06 11:08:47 -08003845
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003846
3847
3848/*
Dake Zhao0a832172015-01-06 11:08:47 -08003849 * wfaStaReinvokeWfdSession():
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003850 */
3851
3852int wfaStaReinvokeWfdSession(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3853{
3854 dutCmdResponse_t infoResp;
3855// caStaReinvokeWfdSession_t *staReinvokeSession= (caStaReinvokeWfdSession_t *)caCmdBuf; //uncomment and use it
Dake Zhao0a832172015-01-06 11:08:47 -08003856
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003857 printf("\n Entry wfaStaReinvokeWfdSession... ");
3858
3859 // Reinvoke the WFD session by accepting the p2p invitation or sending p2p invitation
Dake Zhao0a832172015-01-06 11:08:47 -08003860
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003861
3862 infoResp.status = STATUS_COMPLETE;
Dake Zhao0a832172015-01-06 11:08:47 -08003863 wfaEncodeTLV(WFA_STA_REINVOKE_WFD_SESSION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003864 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Dake Zhao0a832172015-01-06 11:08:47 -08003865
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003866 return WFA_SUCCESS;
3867}
3868
3869
3870int wfaStaGetParameter(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
3871{
Dake Zhao0a832172015-01-06 11:08:47 -08003872 dutCmdResponse_t infoResp;
3873 caStaGetParameter_t *staGetParam= (caStaGetParameter_t *)caCmdBuf; //uncomment and use it
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003874
3875
Dake Zhao0a832172015-01-06 11:08:47 -08003876 caStaGetParameterResp_t *paramList = &infoResp.cmdru.getParamValue;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003877
Dake Zhao0a832172015-01-06 11:08:47 -08003878 printf("\n Entry wfaStaGetParameter... ");
3879
3880 // Check the program type
3881 if(staGetParam->program == PROG_TYPE_WFD)
3882 {
3883 if(staGetParam->getParamValue == eDiscoveredDevList )
3884 {
3885 // Get the discovered devices, make space seperated list and return, check list is not bigger than 128 bytes.
3886 paramList->getParamType = eDiscoveredDevList;
3887 strcpy((char *)&paramList->devList, "11:22:33:44:55:66 22:33:44:55:66:77 33:44:55:66:77:88");
3888 }
3889 }
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003890
3891
Dake Zhao0a832172015-01-06 11:08:47 -08003892 infoResp.status = STATUS_COMPLETE;
3893 wfaEncodeTLV(WFA_STA_GET_PARAMETER_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf);
3894 *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp);
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003895
Dake Zhao0a832172015-01-06 11:08:47 -08003896 return WFA_SUCCESS;
Harsh Madhiwalla8e496e02014-02-25 14:54:53 -08003897}
3898
Ankur Vachhanic485b712012-02-15 23:29:49 +00003899