Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 1 | |
| 2 | /**************************************************************************** |
| 3 | * (c) Copyright 2007 Wi-Fi Alliance. All Rights Reserved |
| 4 | * |
| 5 | * |
| 6 | * LICENSE |
| 7 | * |
| 8 | * License is granted only to Wi-Fi Alliance members and designated |
| 9 | * contractors ($B!H(BAuthorized Licensees$B!I(B)..AN Authorized Licensees are granted |
| 10 | * the non-exclusive, worldwide, limited right to use, copy, import, export |
| 11 | * and distribute this software: |
| 12 | * (i) solely for noncommercial applications and solely for testing Wi-Fi |
| 13 | * equipment; and |
| 14 | * (ii) solely for the purpose of embedding the software into Authorized |
| 15 | * Licensee$B!G(Bs proprietary equipment and software products for distribution to |
| 16 | * its customers under a license with at least the same restrictions as |
| 17 | * contained in this License, including, without limitation, the disclaimer of |
| 18 | * warranty and limitation of liability, below..AN The distribution rights |
| 19 | * granted in clause |
| 20 | * (ii), above, include distribution to third party companies who will |
| 21 | * redistribute the Authorized Licensee$B!G(Bs product to their customers with or |
| 22 | * without such third party$B!G(Bs private label. Other than expressly granted |
| 23 | * herein, this License is not transferable or sublicensable, and it does not |
| 24 | * extend to and may not be used with non-Wi-Fi applications..AN Wi-Fi Alliance |
| 25 | * reserves all rights not expressly granted herein..AN |
| 26 | *.AN |
| 27 | * Except as specifically set forth above, commercial derivative works of |
| 28 | * this software or applications that use the Wi-Fi scripts generated by this |
| 29 | * software are NOT AUTHORIZED without specific prior written permission from |
| 30 | * Wi-Fi Alliance. |
| 31 | *.AN |
| 32 | * Non-Commercial derivative works of this software for internal use are |
| 33 | * authorized and are limited by the same restrictions; provided, however, |
| 34 | * that the Authorized Licensee shall provide Wi-Fi Alliance with a copy of |
| 35 | * such derivative works under a perpetual, payment-free license to use, |
| 36 | * modify, and distribute such derivative works for purposes of testing Wi-Fi |
| 37 | * equipment. |
| 38 | *.AN |
| 39 | * Neither the name of the author nor "Wi-Fi Alliance" may be used to endorse |
| 40 | * or promote products that are derived from or that use this software without |
| 41 | * specific prior written permission from Wi-Fi Alliance. |
| 42 | * |
| 43 | * THIS SOFTWARE IS PROVIDED BY WI-FI ALLIANCE "AS IS" AND ANY EXPRESS OR |
| 44 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 45 | * OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A.AN PARTICULAR PURPOSE, |
| 46 | * ARE DISCLAIMED. IN NO EVENT SHALL WI-FI ALLIANCE BE LIABLE FOR ANY DIRECT, |
| 47 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 48 | * (INCLUDING, BUT NOT LIMITED TO, THE COST OF PROCUREMENT OF SUBSTITUTE |
| 49 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 50 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 51 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE) ARISING IN ANY WAY OUT OF |
| 52 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ****************************************************************************** |
| 53 | */ |
| 54 | |
| 55 | /* |
| 56 | * File: wfa_cs.c -- configuration and setup |
| 57 | * This file contains all implementation for the dut setup and control |
| 58 | * functions, such as network interfaces, ip address and wireless specific |
| 59 | * setup with its supplicant. |
| 60 | * |
| 61 | * The current implementation is to show how these functions |
| 62 | * should be defined in order to support the Agent Control/Test Manager |
| 63 | * control commands. To simplify the current work and avoid any GPL licenses, |
| 64 | * the functions mostly invoke shell commands by calling linux system call, |
| 65 | * system("<commands>"). |
| 66 | * |
| 67 | * It depends on the differnt device and platform, vendors can choice their |
| 68 | * own ways to interact its systems, supplicants and process these commands |
| 69 | * such as using the native APIs. |
| 70 | * |
| 71 | * Revision History: |
| 72 | * 2006/03/10 -- initially created by qhu |
| 73 | * 2006/06/01 -- BETA Release by qhu |
| 74 | * 2006/06/13 -- 00.02 Release by qhu |
| 75 | * 2006/06/30 -- 00.10 Release by qhu |
| 76 | * 2006/07/10 -- 01.00 Release by qhu |
| 77 | * 2006/09/01 -- 01.05 Release by qhu |
| 78 | * 2006/10/26 -- 01.06 Released by qhu |
| 79 | * replace hardcoded buf size with macro |
| 80 | * 2006/12/02 -- bugs: 1. fixes incorrect order of getipconfig.sh |
| 81 | * input parameters reported by p.schwann |
| 82 | * 2. will add a new network for wap_cli command |
| 83 | * in case the network id 0 not present, |
| 84 | * recommended by c.benson |
| 85 | * the solution is to reimplement with calling |
| 86 | * native C API |
| 87 | * 2007/01/11 -- 01.10 released by qhu |
| 88 | * 2007/02/15 -- WMM Extension Beta released by qhu, mkaroshi |
| 89 | * 2007/03/18 -- add file close statements |
| 90 | * 2007/03/21 -- rename the file to avoid the confusion. |
| 91 | * 2007/03/30 -- 01.40 WPA2 and Official WMM Beta Release by qhu |
| 92 | * 2007/04/20 -- 02.00 WPA2 and Official WMM Release by qhu |
| 93 | * 2007/08/15 -- 02.10 WMM-Power Save release by qhu |
| 94 | * 2007/10/10 -- 02.20 Voice SOHO beta -- qhu |
| 95 | * 2007/11/07 -- 02.30 Voice HSO -- qhu |
| 96 | * 2007/12/10 -- 02.32 Add a function to upload test results. |
| 97 | * 2008/01/03 -- 02.34 Support the result upload command. |
| 98 | * 2008/03/12 -- 02.41 Bug #16, incorrect file descriptor used. Change |
| 99 | * the "tmpfile" to "tmpfd" and a few places. Make a macro |
| 100 | * WFA_STAUT_IF in file "inc/wfa_cs.h" for WLAN interface |
| 101 | * name in the function "wfaDeviceListIF() |
| 102 | * |
| 103 | * Not A Bug. Put back to the function from |
| 104 | * wfaSetEncryption1() to wfaSetEncryption() for |
| 105 | * supporting WEP. Porting could select which should be |
| 106 | * used according to WEP support or not. |
| 107 | * |
| 108 | * |
| 109 | */ |
| 110 | #include <stdio.h> |
| 111 | #include <unistd.h> |
| 112 | #include <string.h> |
| 113 | #include <stdlib.h> |
| 114 | #include <sys/socket.h> |
| 115 | #include <arpa/inet.h> |
| 116 | #include <linux/types.h> |
| 117 | #include <linux/socket.h> |
| 118 | #include <poll.h> |
| 119 | |
| 120 | #include "wfa_portall.h" |
| 121 | #include "wfa_debug.h" |
| 122 | #include "wfa_ver.h" |
| 123 | #include "wfa_main.h" |
| 124 | #include "wfa_types.h" |
| 125 | #include "wfa_ca.h" |
| 126 | #include "wfa_tlv.h" |
| 127 | #include "wfa_sock.h" |
| 128 | #include "wfa_tg.h" |
| 129 | #include "wfa_cmds.h" |
| 130 | #include "wfa_rsp.h" |
| 131 | #include "wfa_utils.h" |
| 132 | #ifdef WFA_WMM_PS_EXT |
| 133 | #include "wfa_wmmps.h" |
| 134 | #endif |
| 135 | |
| 136 | #define CERTIFICATES_PATH "/etc/wpa_supplicant" |
| 137 | |
| 138 | /* Some device may only support UDP ECHO, activate this line */ |
| 139 | //#define WFA_PING_UDP_ECHO_ONLY 1 |
| 140 | |
| 141 | extern unsigned short wfa_defined_debug; |
| 142 | int wfaExecuteCLI(char *CLI); |
| 143 | |
| 144 | /* Since the two definitions are used all over the CA function */ |
| 145 | char gCmdStr[WFA_CMD_STR_SZ]; |
| 146 | dutCmdResponse_t gGenericResp; |
| 147 | int wfaTGSetPrio(int sockfd, int tgClass); |
| 148 | void create_apts_msg(int msg, unsigned int txbuf[],int id); |
| 149 | |
| 150 | extern char e2eResults[]; |
| 151 | //extern char *e2eResults; |
| 152 | FILE *e2efp = NULL; |
| 153 | int chk_ret_status() |
| 154 | { |
| 155 | char *ret = getenv(WFA_RET_ENV); |
| 156 | |
| 157 | if(*ret == '1') |
| 158 | return WFA_SUCCESS; |
| 159 | else |
| 160 | return WFA_FAILURE; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * agtCmdProcGetVersion(): response "ca_get_version" command to controller |
| 165 | * input: cmd --- not used |
| 166 | * valLen -- not used |
| 167 | * output: parms -- a buffer to store the version info response. |
| 168 | */ |
| 169 | int agtCmdProcGetVersion(int len, BYTE *parms, int *respLen, BYTE *respBuf) |
| 170 | { |
| 171 | dutCmdResponse_t *getverResp = &gGenericResp; |
| 172 | |
| 173 | DPRINT_INFO(WFA_OUT, "entering agtCmdProcGetVersion ...\n"); |
| 174 | |
| 175 | getverResp->status = STATUS_COMPLETE; |
| 176 | wSTRNCPY(getverResp->cmdru.version, WFA_SYSTEM_VER, WFA_VERNAM_LEN); |
| 177 | |
| 178 | wfaEncodeTLV(WFA_GET_VERSION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getverResp, respBuf); |
| 179 | |
| 180 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 181 | |
| 182 | return WFA_SUCCESS; |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * wfaStaAssociate(): |
| 187 | * The function is to force the station wireless I/F to re/associate |
| 188 | * with the AP. |
| 189 | */ |
| 190 | int wfaStaAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 191 | { |
| 192 | dutCommand_t *assoc = (dutCommand_t *)caCmdBuf; |
| 193 | char *ifname = assoc->intf; |
| 194 | dutCmdResponse_t *staAssocResp = &gGenericResp; |
| 195 | |
| 196 | DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n"); |
| 197 | /* |
| 198 | * if bssid appears, station should associate with the specific |
| 199 | * BSSID AP at its initial association. |
| 200 | * If it is different to the current associating AP, it will be forced to |
| 201 | * roam the new AP |
| 202 | */ |
| 203 | if(assoc->cmdsu.assoc.bssid[0] != '\0') |
| 204 | { |
| 205 | /* if (the first association) */ |
| 206 | /* just do initial association to the BSSID */ |
| 207 | |
| 208 | |
| 209 | /* else (station already associate to an AP) */ |
| 210 | /* Do forced roaming */ |
| 211 | |
| 212 | } |
| 213 | else |
| 214 | { |
| 215 | /* use 'ifconfig' command to bring down the interface (linux specific) */ |
| 216 | sprintf(gCmdStr, "ifconfig %s down", ifname); |
| 217 | system(gCmdStr); |
| 218 | |
| 219 | /* use 'ifconfig' command to bring up the interface (linux specific) */ |
| 220 | sprintf(gCmdStr, "ifconfig %s up", ifname); |
| 221 | system(gCmdStr); |
| 222 | |
| 223 | /* |
| 224 | * use 'wpa_cli' command to force a 802.11 re/associate |
| 225 | * (wpa_supplicant specific) |
| 226 | */ |
| 227 | sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname); |
| 228 | system(gCmdStr); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Then report back to control PC for completion. |
| 233 | * This does not have failed/error status. The result only tells |
| 234 | * a completion. |
| 235 | */ |
| 236 | staAssocResp->status = STATUS_COMPLETE; |
| 237 | wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf); |
| 238 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 239 | |
| 240 | return WFA_SUCCESS; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * wfaStaReAssociate(): |
| 245 | * The function is to force the station wireless I/F to re/associate |
| 246 | * with the AP. |
| 247 | */ |
| 248 | int wfaStaReAssociate(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 249 | { |
| 250 | dutCommand_t *assoc = (dutCommand_t *)caCmdBuf; |
| 251 | char *ifname = assoc->intf; |
| 252 | dutCmdResponse_t *staAssocResp = &gGenericResp; |
| 253 | |
| 254 | DPRINT_INFO(WFA_OUT, "entering wfaStaAssociate ...\n"); |
| 255 | /* |
| 256 | * if bssid appears, station should associate with the specific |
| 257 | * BSSID AP at its initial association. |
| 258 | * If it is different to the current associating AP, it will be forced to |
| 259 | * roam the new AP |
| 260 | */ |
| 261 | if(assoc->cmdsu.assoc.bssid[0] != '\0') |
| 262 | { |
| 263 | /* if (the first association) */ |
| 264 | /* just do initial association to the BSSID */ |
| 265 | |
| 266 | |
| 267 | /* else (station already associate to an AP) */ |
| 268 | /* Do forced roaming */ |
| 269 | |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | /* use 'ifconfig' command to bring down the interface (linux specific) */ |
| 274 | sprintf(gCmdStr, "ifconfig %s down", ifname); |
| 275 | system(gCmdStr); |
| 276 | |
| 277 | /* use 'ifconfig' command to bring up the interface (linux specific) */ |
| 278 | sprintf(gCmdStr, "ifconfig %s up", ifname); |
| 279 | |
| 280 | /* |
| 281 | * use 'wpa_cli' command to force a 802.11 re/associate |
| 282 | * (wpa_supplicant specific) |
| 283 | */ |
| 284 | sprintf(gCmdStr, "wpa_cli -i%s reassociate", ifname); |
| 285 | system(gCmdStr); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Then report back to control PC for completion. |
| 290 | * This does not have failed/error status. The result only tells |
| 291 | * a completion. |
| 292 | */ |
| 293 | staAssocResp->status = STATUS_COMPLETE; |
| 294 | wfaEncodeTLV(WFA_STA_ASSOCIATE_RESP_TLV, 4, (BYTE *)staAssocResp, respBuf); |
| 295 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 296 | |
| 297 | return WFA_SUCCESS; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * wfaStaIsConnected(): |
| 302 | * The function is to check whether the station's wireless I/F has |
| 303 | * already connected to an AP. |
| 304 | */ |
| 305 | int wfaStaIsConnected(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 306 | { |
| 307 | dutCommand_t *connStat = (dutCommand_t *)caCmdBuf; |
| 308 | dutCmdResponse_t *staConnectResp = &gGenericResp; |
| 309 | char *ifname = connStat->intf; |
| 310 | FILE *tmpfile = NULL; |
| 311 | char result[32]; |
| 312 | |
| 313 | |
| 314 | DPRINT_INFO(WFA_OUT, "Entering isConnected ...\n"); |
| 315 | |
| 316 | #ifdef WFA_NEW_CLI_FORMAT |
| 317 | sprintf(gCmdStr, "wfa_chkconnect %s\n", ifname); |
| 318 | system(gCmdStr); |
| 319 | |
| 320 | if(chk_ret_status() == WFA_SUCCESS) |
| 321 | staConnectResp->cmdru.connected = 1; |
| 322 | else |
| 323 | staConnectResp->cmdru.connected = 0; |
| 324 | #else |
| 325 | /* |
| 326 | * use 'wpa_cli' command to check the interface status |
| 327 | * none, scanning or complete (wpa_supplicant specific) |
| 328 | */ |
| 329 | sprintf(gCmdStr, "/sbin/wpa_cli -i%s status | grep ^wpa_state= | cut -f2- -d= > /tmp/.isConnected", ifname); |
| 330 | system(gCmdStr); |
| 331 | |
| 332 | /* |
| 333 | * the status is saved in a file. Open the file and check it. |
| 334 | */ |
| 335 | tmpfile = fopen("/tmp/.isConnected", "r+"); |
| 336 | if(tmpfile == NULL) |
| 337 | { |
| 338 | staConnectResp->status = STATUS_ERROR; |
| 339 | wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, 4, (BYTE *)staConnectResp, respBuf); |
| 340 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 341 | |
| 342 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 343 | return WFA_FAILURE; |
| 344 | } |
| 345 | |
| 346 | fscanf(tmpfile, "%s", result); |
| 347 | |
| 348 | if(strncmp(result, "COMPLETED", 9) == 0) |
| 349 | staConnectResp->cmdru.connected = 1; |
| 350 | else |
| 351 | staConnectResp->cmdru.connected = 0; |
| 352 | #endif |
| 353 | |
| 354 | /* |
| 355 | * Report back the status: Complete or Failed. |
| 356 | */ |
| 357 | staConnectResp->status = STATUS_COMPLETE; |
| 358 | |
| 359 | wfaEncodeTLV(WFA_STA_IS_CONNECTED_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)staConnectResp, respBuf); |
| 360 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 361 | |
| 362 | return WFA_SUCCESS; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * wfaStaGetIpConfig(): |
| 367 | * This function is to retriev the ip info including |
| 368 | * 1. dhcp enable |
| 369 | * 2. ip address |
| 370 | * 3. mask |
| 371 | * 4. primary-dns |
| 372 | * 5. secondary-dns |
| 373 | * |
| 374 | * The current implementation is to use a script to find these information |
| 375 | * and store them in a file. |
| 376 | */ |
| 377 | int wfaStaGetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 378 | { |
| 379 | int slen, ret, i = 0; |
| 380 | dutCommand_t *getIpConf = (dutCommand_t *)caCmdBuf; |
| 381 | dutCmdResponse_t *ipconfigResp = &gGenericResp; |
| 382 | char *ifname = getIpConf->intf; |
| 383 | caStaGetIpConfigResp_t *ifinfo = &ipconfigResp->cmdru.getIfconfig; |
| 384 | |
| 385 | FILE *tmpfd; |
| 386 | char string[256]; |
| 387 | char *str; |
| 388 | |
| 389 | /* |
| 390 | * check a script file (the current implementation specific) |
| 391 | */ |
| 392 | ret = access("/usr/local/sbin/getipconfig.sh", F_OK); |
| 393 | if(ret == -1) |
| 394 | { |
| 395 | ipconfigResp->status = STATUS_ERROR; |
| 396 | wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf); |
| 397 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 398 | |
| 399 | DPRINT_ERR(WFA_ERR, "file not exist\n"); |
| 400 | return WFA_FAILURE; |
| 401 | |
| 402 | } |
| 403 | |
| 404 | strcpy(ifinfo->dns[0], "0"); |
| 405 | strcpy(ifinfo->dns[1], "0"); |
| 406 | |
| 407 | /* |
| 408 | * Run the script file "getipconfig.sh" to check the ip status |
| 409 | * (current implementation specific). |
| 410 | * note: "getipconfig.sh" is only defined for the current implementation |
| 411 | */ |
| 412 | sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s\n", ifname); |
| 413 | |
| 414 | system(gCmdStr); |
| 415 | |
| 416 | /* open the output result and scan/retrieve the info */ |
| 417 | tmpfd = fopen("/tmp/ipconfig.txt", "r+"); |
| 418 | |
| 419 | if(tmpfd == NULL) |
| 420 | { |
| 421 | ipconfigResp->status = STATUS_ERROR; |
| 422 | wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, 4, (BYTE *)ipconfigResp, respBuf); |
| 423 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 424 | |
| 425 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 426 | return WFA_FAILURE; |
| 427 | } |
| 428 | |
| 429 | for(;;) |
| 430 | { |
| 431 | if(fgets(string, 256, tmpfd) == NULL) |
| 432 | break; |
| 433 | |
| 434 | /* check dhcp enabled */ |
| 435 | if(strncmp(string, "dhcpcli", 7) ==0) |
| 436 | { |
| 437 | str = strtok(string, "="); |
| 438 | str = strtok(NULL, "="); |
| 439 | if(str != NULL) |
| 440 | ifinfo->isDhcp = 1; |
| 441 | else |
| 442 | ifinfo->isDhcp = 0; |
| 443 | } |
| 444 | |
| 445 | /* find out the ip address */ |
| 446 | if(strncmp(string, "ipaddr", 6) == 0) |
| 447 | { |
| 448 | str = strtok(string, "="); |
| 449 | str = strtok(NULL, " "); |
| 450 | if(str != NULL) |
| 451 | { |
| 452 | wSTRNCPY(ifinfo->ipaddr, str, 15); |
| 453 | ifinfo->ipaddr[15]='\0'; |
| 454 | } |
| 455 | else |
| 456 | wSTRNCPY(ifinfo->ipaddr, "none", 15); |
| 457 | } |
| 458 | |
| 459 | /* check the mask */ |
| 460 | if(strncmp(string, "mask", 4) == 0) |
| 461 | { |
| 462 | char ttstr[16]; |
| 463 | char *ttp = ttstr; |
| 464 | |
| 465 | str = strtok_r(string, "=", &ttp); |
| 466 | if(*ttp != '\0') |
| 467 | { |
| 468 | strcpy(ifinfo->mask, ttp); |
| 469 | slen = strlen(ifinfo->mask); |
| 470 | ifinfo->mask[slen-1] = '\0'; |
| 471 | } |
| 472 | else |
| 473 | strcpy(ifinfo->mask, "none"); |
| 474 | } |
| 475 | |
| 476 | /* find out the dns server ip address */ |
| 477 | if(strncmp(string, "nameserv", 8) == 0) |
| 478 | { |
| 479 | char ttstr[16]; |
| 480 | char *ttp = ttstr; |
| 481 | |
| 482 | str = strtok_r(string, " ", &ttp); |
| 483 | if(str != NULL && i < 2) |
| 484 | { |
| 485 | strcpy(ifinfo->dns[i], ttp); |
| 486 | slen = strlen(ifinfo->dns[i]); |
| 487 | ifinfo->dns[i][slen-1] = '\0'; |
| 488 | } |
| 489 | else |
| 490 | strcpy(ifinfo->dns[i], "none"); |
| 491 | |
| 492 | i++; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * Report back the results |
| 498 | */ |
| 499 | ipconfigResp->status = STATUS_COMPLETE; |
| 500 | wfaEncodeTLV(WFA_STA_GET_IP_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)ipconfigResp, respBuf); |
| 501 | |
| 502 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 503 | |
| 504 | #if 0 |
| 505 | DPRINT_INFO(WFA_OUT, "%i %i %s %s %s %s %i\n", ipconfigResp->status, |
| 506 | ifinfo->isDhcp, ifinfo->ipaddr, ifinfo->mask, |
| 507 | ifinfo->dns[0], ifinfo->dns[1], *respLen); |
| 508 | #endif |
| 509 | |
| 510 | fclose(tmpfd); |
| 511 | return WFA_SUCCESS; |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * wfaStaSetIpConfig(): |
| 516 | * The function is to set the ip configuration to a wireless I/F. |
| 517 | * 1. IP address |
| 518 | * 2. Mac address |
| 519 | * 3. default gateway |
| 520 | * 4. dns nameserver (pri and sec). |
| 521 | */ |
| 522 | int wfaStaSetIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 523 | { |
| 524 | dutCommand_t *setIpConf = (dutCommand_t *)caCmdBuf; |
| 525 | caStaSetIpConfig_t *ipconfig = &setIpConf->cmdsu.ipconfig; |
| 526 | dutCmdResponse_t *staSetIpResp = &gGenericResp; |
| 527 | |
| 528 | DPRINT_INFO(WFA_OUT, "entering wfaStaSetIpConfig ...\n"); |
| 529 | |
| 530 | /* |
| 531 | * Use command 'ifconfig' to configure the interface ip address, mask. |
| 532 | * (Linux specific). |
| 533 | */ |
| 534 | sprintf(gCmdStr, "/sbin/ifconfig %s %s netmask %s > /dev/null 2>&1 ", ipconfig->intf, ipconfig->ipaddr, ipconfig->mask); |
| 535 | system(gCmdStr); |
| 536 | |
| 537 | /* use command 'route add' to set set gatewway (linux specific) */ |
| 538 | if(ipconfig->defGateway[0] != '\0') |
| 539 | { |
| 540 | sprintf(gCmdStr, "/sbin/route add default gw %s > /dev/null 2>&1", ipconfig->defGateway); |
| 541 | system(gCmdStr); |
| 542 | } |
| 543 | |
| 544 | /* set dns (linux specific) */ |
| 545 | sprintf(gCmdStr, "cp /etc/resolv.conf /tmp/resolv.conf.bk"); |
| 546 | system(gCmdStr); |
| 547 | sprintf(gCmdStr, "echo nameserv %s > /etc/resolv.conf", ipconfig->pri_dns); |
| 548 | system(gCmdStr); |
| 549 | sprintf(gCmdStr, "echo nameserv %s >> /etc/resolv.conf", ipconfig->sec_dns); |
| 550 | system(gCmdStr); |
| 551 | |
| 552 | /* |
| 553 | * report status |
| 554 | */ |
| 555 | staSetIpResp->status = STATUS_COMPLETE; |
| 556 | wfaEncodeTLV(WFA_STA_SET_IP_CONFIG_RESP_TLV, 4, (BYTE *)staSetIpResp, respBuf); |
| 557 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 558 | |
| 559 | return WFA_SUCCESS; |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * wfaStaVerifyIpConnection(): |
| 564 | * The function is to verify if the station has IP connection with an AP by |
| 565 | * send ICMP/pings to the AP. |
| 566 | */ |
| 567 | int wfaStaVerifyIpConnection(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 568 | { |
| 569 | dutCommand_t *verip = (dutCommand_t *)caCmdBuf; |
| 570 | dutCmdResponse_t *verifyIpResp = &gGenericResp; |
| 571 | |
| 572 | #ifndef WFA_PING_UDP_ECHO_ONLY |
| 573 | char strout[64], *pcnt; |
| 574 | FILE *tmpfile; |
| 575 | |
| 576 | DPRINT_INFO(WFA_OUT, "Entering wfaStaVerifyIpConnection ...\n"); |
| 577 | |
| 578 | /* set timeout value in case not set */ |
| 579 | if(verip->cmdsu.verifyIp.timeout <= 0) |
| 580 | { |
| 581 | verip->cmdsu.verifyIp.timeout = 10; |
| 582 | } |
| 583 | |
| 584 | /* execute the ping command and pipe the result to a tmp file */ |
| 585 | sprintf(gCmdStr, "ping %s -c 3 -W %u | grep loss | cut -f3 -d, 1>& /tmp/pingout.txt", verip->cmdsu.verifyIp.dipaddr, verip->cmdsu.verifyIp.timeout); |
| 586 | system(gCmdStr); |
| 587 | |
| 588 | /* scan/check the output */ |
| 589 | tmpfile = fopen("/tmp/pingout.txt", "r+"); |
| 590 | if(tmpfile == NULL) |
| 591 | { |
| 592 | verifyIpResp->status = STATUS_ERROR; |
| 593 | wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf); |
| 594 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 595 | |
| 596 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 597 | return WFA_FAILURE; |
| 598 | } |
| 599 | |
| 600 | verifyIpResp->status = STATUS_COMPLETE; |
| 601 | if(fscanf(tmpfile, "%s", strout) == EOF) |
| 602 | verifyIpResp->cmdru.connected = 0; |
| 603 | else |
| 604 | { |
| 605 | pcnt = strtok(strout, "%"); |
| 606 | |
| 607 | /* if the loss rate is 100%, not able to connect */ |
| 608 | if(atoi(pcnt) == 100) |
| 609 | verifyIpResp->cmdru.connected = 0; |
| 610 | else |
| 611 | verifyIpResp->cmdru.connected = 1; |
| 612 | } |
| 613 | |
| 614 | fclose(tmpfile); |
| 615 | #else |
| 616 | int btSockfd; |
| 617 | struct pollfd fds[2]; |
| 618 | int timeout = 2000; |
| 619 | char anyBuf[64]; |
| 620 | struct sockaddr_in toAddr; |
| 621 | int done = 1, cnt = 0, ret, nbytes; |
| 622 | |
| 623 | verifyIpResp->status = STATUS_COMPLETE; |
| 624 | verifyIpResp->cmdru.connected = 0; |
| 625 | |
| 626 | btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT); |
| 627 | |
| 628 | if(btSockfd == -1) |
| 629 | { |
| 630 | verifyIpResp->status = STATUS_ERROR; |
| 631 | wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, 4, (BYTE *)verifyIpResp, respBuf); |
| 632 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 633 | return WFA_FAILURE;; |
| 634 | } |
| 635 | |
| 636 | toAddr.sin_family = AF_INET; |
| 637 | toAddr.sin_addr.s_addr = inet_addr(verip->cmdsu.verifyIp.dipaddr); |
| 638 | toAddr.sin_port = htons(WFA_UDP_ECHO_PORT); |
| 639 | |
| 640 | while(done) |
| 641 | { |
| 642 | wfaTrafficSendTo(btSockfd, (char *)anyBuf, 64, (struct sockaddr *)&toAddr); |
| 643 | cnt++; |
| 644 | |
| 645 | fds[0].fd = btSockfd; |
| 646 | fds[0].events = POLLIN | POLLOUT; |
| 647 | |
| 648 | ret = poll(fds, 1, timeout); |
| 649 | switch(ret) |
| 650 | { |
| 651 | case 0: |
| 652 | /* it is time out, count a packet lost*/ |
| 653 | break; |
| 654 | case -1: |
| 655 | /* it is an error */ |
| 656 | default: |
| 657 | { |
| 658 | switch(fds[0].revents) |
| 659 | { |
| 660 | case POLLIN: |
| 661 | case POLLPRI: |
| 662 | case POLLOUT: |
| 663 | nbytes = wfaTrafficRecv(btSockfd, (char *)anyBuf, (struct sockaddr *)&toAddr); |
| 664 | if(nbytes != 0) |
| 665 | verifyIpResp->cmdru.connected = 1; |
| 666 | done = 0; |
| 667 | break; |
| 668 | default: |
| 669 | /* errors but not care */ |
| 670 | ; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | if(cnt == 3) |
| 675 | { |
| 676 | done = 0; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | #endif |
| 681 | |
| 682 | wfaEncodeTLV(WFA_STA_VERIFY_IP_CONNECTION_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)verifyIpResp, respBuf); |
| 683 | |
| 684 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 685 | |
| 686 | return WFA_SUCCESS; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * wfaStaGetMacAddress() |
| 691 | * This function is to retrieve the MAC address of a wireless I/F. |
| 692 | */ |
| 693 | int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 694 | { |
| 695 | dutCommand_t *getMac = (dutCommand_t *)caCmdBuf; |
| 696 | dutCmdResponse_t *getmacResp = &gGenericResp; |
| 697 | char *str; |
| 698 | char *ifname = getMac->intf; |
| 699 | |
| 700 | FILE *tmpfd; |
| 701 | char string[128]; |
| 702 | |
| 703 | DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n"); |
| 704 | /* |
| 705 | * run the script "getipconfig.sh" to find out the mac |
| 706 | */ |
| 707 | //sprintf(gCmdStr, "getipconfig.sh /tmp/ipconfig.txt %s", ifname); |
| 708 | sprintf(gCmdStr, "ifconfig %s > /tmp/ipconfig.txt ", ifname); |
| 709 | system(gCmdStr); |
| 710 | |
| 711 | tmpfd = fopen("/tmp/ipconfig.txt", "r+"); |
| 712 | if(tmpfd == NULL) |
| 713 | { |
| 714 | getmacResp->status = STATUS_ERROR; |
| 715 | wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)getmacResp, respBuf); |
| 716 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 717 | |
| 718 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 719 | return WFA_FAILURE; |
| 720 | } |
| 721 | |
| 722 | if(fgets(string, 256, tmpfd) == NULL) |
| 723 | { |
| 724 | getmacResp->status = STATUS_ERROR; |
| 725 | } |
| 726 | |
| 727 | str = strtok(string, " "); |
| 728 | while(str && ((strcmp(str,"HWaddr")) != 0)) |
| 729 | { |
| 730 | str = strtok(NULL, " "); |
| 731 | } |
| 732 | |
| 733 | /* get mac */ |
| 734 | if(str) |
| 735 | { |
| 736 | str = strtok(NULL, " "); |
| 737 | strcpy(getmacResp->cmdru.mac, str); |
| 738 | getmacResp->status = STATUS_COMPLETE; |
| 739 | } |
| 740 | |
| 741 | |
| 742 | wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)getmacResp, respBuf); |
| 743 | |
| 744 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 745 | |
| 746 | fclose(tmpfd); |
| 747 | return WFA_SUCCESS; |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | * wfaStaGetStats(): |
| 752 | * The function is to retrieve the statistics of the I/F's layer 2 txFrames, |
| 753 | * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries. |
| 754 | * Currently there is not definition how to use these info. |
| 755 | */ |
| 756 | int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 757 | { |
| 758 | dutCmdResponse_t *statsResp = &gGenericResp; |
| 759 | |
| 760 | /* this is never used, you can skip this call */ |
| 761 | |
| 762 | statsResp->status = STATUS_ERROR; |
| 763 | wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)statsResp, respBuf); |
| 764 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 765 | |
| 766 | |
| 767 | return WFA_SUCCESS; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * wfaSetEncryption(): |
| 772 | * The function is to set the wireless interface with WEP or none. |
| 773 | * |
| 774 | * Since WEP is optional test, current function is only used for |
| 775 | * resetting the Security to NONE/Plaintext (OPEN). To test WEP, |
| 776 | * this function should be replaced by the next one (wfaSetEncryption1()) |
| 777 | * |
| 778 | * Input parameters: |
| 779 | * 1. I/F |
| 780 | * 2. ssid |
| 781 | * 3. encpType - wep or none |
| 782 | * Optional: |
| 783 | * 4. key1 |
| 784 | * 5. key2 |
| 785 | * 6. key3 |
| 786 | * 7. key4 |
| 787 | * 8. activeKey Index |
| 788 | */ |
| 789 | |
| 790 | int wfaSetEncryption1(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 791 | { |
| 792 | caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf; |
| 793 | dutCmdResponse_t *setEncrypResp = &gGenericResp; |
| 794 | |
| 795 | /* |
| 796 | * disable the network first |
| 797 | */ |
| 798 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf); |
| 799 | system(gCmdStr); |
| 800 | |
| 801 | /* |
| 802 | * set SSID |
| 803 | */ |
| 804 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid); |
| 805 | system(gCmdStr); |
| 806 | |
| 807 | /* |
| 808 | * Tell the supplicant for infrastructure mode (1) |
| 809 | */ |
| 810 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf); |
| 811 | system(gCmdStr); |
| 812 | |
| 813 | /* |
| 814 | * set Key management to NONE (NO WPA) for plaintext or WEP |
| 815 | */ |
| 816 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf); |
| 817 | system(gCmdStr); |
| 818 | |
| 819 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf); |
| 820 | system(gCmdStr); |
| 821 | |
| 822 | setEncrypResp->status = STATUS_COMPLETE; |
| 823 | wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf); |
| 824 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 825 | |
| 826 | return WFA_SUCCESS; |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * Since WEP is optional, this function could be used to replace |
| 831 | * wfaSetEncryption() if necessary. |
| 832 | */ |
| 833 | int wfaSetEncryption(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 834 | { |
| 835 | caStaSetEncryption_t *setEncryp = (caStaSetEncryption_t *)caCmdBuf; |
| 836 | dutCmdResponse_t *setEncrypResp = &gGenericResp; |
| 837 | int i; |
| 838 | |
| 839 | /* |
| 840 | * disable the network first |
| 841 | */ |
| 842 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setEncryp->intf); |
| 843 | system(gCmdStr); |
| 844 | |
| 845 | /* |
| 846 | * set SSID |
| 847 | */ |
| 848 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setEncryp->intf, setEncryp->ssid); |
| 849 | system(gCmdStr); |
| 850 | |
| 851 | /* |
| 852 | * Tell the supplicant for infrastructure mode (1) |
| 853 | */ |
| 854 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 0", setEncryp->intf); |
| 855 | system(gCmdStr); |
| 856 | |
| 857 | /* |
| 858 | * set Key management to NONE (NO WPA) for plaintext or WEP |
| 859 | */ |
| 860 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setEncryp->intf); |
| 861 | system(gCmdStr); |
| 862 | |
| 863 | /* set keys */ |
| 864 | if(setEncryp->encpType == 1) |
| 865 | { |
| 866 | for(i=0; i<4; i++) |
| 867 | { |
| 868 | if(setEncryp->keys[i][0] != '\0') |
| 869 | { |
| 870 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i %s", |
| 871 | setEncryp->intf, i, setEncryp->keys[i]); |
| 872 | system(gCmdStr); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | /* set active key */ |
| 877 | i = setEncryp->activeKeyIdx; |
| 878 | if(setEncryp->keys[i][0] != '\0') |
| 879 | { |
| 880 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i", |
| 881 | setEncryp->intf, setEncryp->activeKeyIdx); |
| 882 | system(gCmdStr); |
| 883 | } |
| 884 | } |
| 885 | else /* clearly remove the keys -- reported by p.schwann */ |
| 886 | { |
| 887 | |
| 888 | for(i = 0; i < 4; i++) |
| 889 | { |
| 890 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"\"", setEncryp->intf, i); |
| 891 | system(gCmdStr); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setEncryp->intf); |
| 896 | system(gCmdStr); |
| 897 | |
| 898 | setEncrypResp->status = STATUS_COMPLETE; |
| 899 | wfaEncodeTLV(WFA_STA_SET_ENCRYPTION_RESP_TLV, 4, (BYTE *)setEncrypResp, respBuf); |
| 900 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 901 | |
| 902 | return WFA_SUCCESS; |
| 903 | } |
| 904 | |
| 905 | int wfaStaSetSecurity(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 906 | { |
| 907 | int ret = WFA_SUCCESS; |
| 908 | |
| 909 | return ret; |
| 910 | } |
| 911 | |
| 912 | /* |
| 913 | * wfaStaSetEapTLS(): |
| 914 | * This is to set |
| 915 | * 1. ssid |
| 916 | * 2. encrypType - tkip or aes-ccmp |
| 917 | * 3. keyManagementType - wpa or wpa2 |
| 918 | * 4. trustedRootCA |
| 919 | * 5. clientCertificate |
| 920 | */ |
| 921 | int wfaStaSetEapTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 922 | { |
| 923 | caStaSetEapTLS_t *setTLS = (caStaSetEapTLS_t *)caCmdBuf; |
| 924 | char *ifname = setTLS->intf; |
| 925 | dutCmdResponse_t *setEapTlsResp = &gGenericResp; |
| 926 | |
| 927 | DPRINT_INFO(WFA_OUT, "Entering wfaStaSetEapTLS ...\n"); |
| 928 | |
| 929 | /* |
| 930 | * need to store the trustedROOTCA and clientCertificate into a file first. |
| 931 | */ |
| 932 | #ifdef WFA_NEW_CLI_FORMAT |
| 933 | sprintf(gCmdStr, "wfa_set_eaptls -i %s %s %s %s", ifname, setTLS->ssid, setTLS->trustedRootCA, setTLS->clientCertificate); |
| 934 | system(gCmdStr); |
| 935 | #else |
| 936 | |
| 937 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname); |
| 938 | system(gCmdStr); |
| 939 | |
| 940 | /* ssid */ |
| 941 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTLS->ssid); |
| 942 | system(gCmdStr); |
| 943 | |
| 944 | /* key management */ |
| 945 | if(strcasecmp(setTLS->keyMgmtType, "wpa2-sha256") == 0) |
| 946 | { |
| 947 | } |
| 948 | else if(strcasecmp(setTLS->keyMgmtType, "wpa2-eap") == 0) |
| 949 | { |
| 950 | } |
| 951 | else if(strcasecmp(setTLS->keyMgmtType, "wpa2-ft") == 0) |
| 952 | { |
| 953 | |
| 954 | } |
| 955 | else if(strcasecmp(setTLS->keyMgmtType, "wpa") == 0) |
| 956 | { |
| 957 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 958 | } |
| 959 | else if(strcasecmp(setTLS->keyMgmtType, "wpa2") == 0) |
| 960 | { |
| 961 | // to take all and device to pick any one supported. |
| 962 | } |
| 963 | else |
| 964 | { |
| 965 | // ?? |
| 966 | } |
| 967 | system(gCmdStr); |
| 968 | |
| 969 | /* protocol WPA */ |
| 970 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname); |
| 971 | system(gCmdStr); |
| 972 | |
| 973 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TLS", ifname); |
| 974 | system(gCmdStr); |
| 975 | |
| 976 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s\"'", ifname, setTLS->trustedRootCA); |
| 977 | system(gCmdStr); |
| 978 | |
| 979 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"wifi-user@wifilabs.local\"'", ifname); |
| 980 | system(gCmdStr); |
| 981 | |
| 982 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTLS->clientCertificate); |
| 983 | system(gCmdStr); |
| 984 | |
| 985 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 private_key_passwd '\"wifi\"'", ifname); |
| 986 | system(gCmdStr); |
| 987 | |
| 988 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname); |
| 989 | system(gCmdStr); |
| 990 | #endif |
| 991 | |
| 992 | setEapTlsResp->status = STATUS_COMPLETE; |
| 993 | wfaEncodeTLV(WFA_STA_SET_EAPTLS_RESP_TLV, 4, (BYTE *)setEapTlsResp, respBuf); |
| 994 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 995 | |
| 996 | return WFA_SUCCESS; |
| 997 | } |
| 998 | |
| 999 | /* |
| 1000 | * The function is to set |
| 1001 | * 1. ssid |
| 1002 | * 2. passPhrase |
| 1003 | * 3. keyMangementType - wpa/wpa2 |
| 1004 | * 4. encrypType - tkip or aes-ccmp |
| 1005 | */ |
| 1006 | int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1007 | { |
| 1008 | caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf; |
| 1009 | dutCmdResponse_t *setPskResp = &gGenericResp; |
| 1010 | |
| 1011 | #ifndef WFA_PC_CONSOLE |
| 1012 | |
| 1013 | #ifdef WFA_NEW_CLI_FORMAT |
| 1014 | sprintf(gCmdStr, "wfa_set_psk %s %s %s", setPSK->intf, setPSK->ssid, setPSK->passphrase); |
| 1015 | system(gCmdStr); |
| 1016 | #else |
| 1017 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setPSK->intf, setPSK->ssid); |
| 1018 | system(gCmdStr); |
| 1019 | |
| 1020 | if(strcasecmp(setPSK->keyMgmtType, "wpa2-sha256") == 0) |
| 1021 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA2-SHA256", setPSK->intf); |
| 1022 | else if(strcasecmp(setPSK->keyMgmtType, "wpa2") == 0) |
| 1023 | { |
| 1024 | // take all and device to pick it supported. |
| 1025 | } |
| 1026 | else if(strcasecmp(setPSK->keyMgmtType, "wpa2-psk") == 0) |
| 1027 | { |
| 1028 | |
| 1029 | } |
| 1030 | else if(strcasecmp(setPSK->keyMgmtType, "wpa2-ft") == 0) |
| 1031 | { |
| 1032 | |
| 1033 | } |
| 1034 | else |
| 1035 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-PSK", setPSK->intf); |
| 1036 | system(gCmdStr); |
| 1037 | |
| 1038 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 psk '\"%s\"'", setPSK->intf, setPSK->passphrase); |
| 1039 | system(gCmdStr); |
| 1040 | |
| 1041 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setPSK->intf); |
| 1042 | system(gCmdStr); |
| 1043 | |
| 1044 | /* if PMF enable */ |
| 1045 | if(setPSK->pmf == WFA_ENABLED || setPSK->pmf == WFA_OPTIONAL) |
| 1046 | { |
| 1047 | |
| 1048 | } |
| 1049 | else if(setPSK->pmf == WFA_REQUIRED) |
| 1050 | { |
| 1051 | |
| 1052 | } |
| 1053 | else if(setPSK->pmf == WFA_F_REQUIRED) |
| 1054 | { |
| 1055 | |
| 1056 | } |
| 1057 | else if(setPSK->pmf == WFA_F_DISABLED) |
| 1058 | { |
| 1059 | |
| 1060 | } |
| 1061 | else |
| 1062 | { /* Disable PMF */ |
| 1063 | |
| 1064 | } |
| 1065 | |
| 1066 | #endif |
| 1067 | |
| 1068 | #endif |
| 1069 | |
| 1070 | setPskResp->status = STATUS_COMPLETE; |
| 1071 | wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)setPskResp, respBuf); |
| 1072 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1073 | |
| 1074 | return WFA_SUCCESS; |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | * wfaStaGetInfo(): |
| 1079 | * Get vendor specific information in name/value pair by a wireless I/F. |
| 1080 | */ |
| 1081 | int wfaStaGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1082 | { |
| 1083 | dutCmdResponse_t infoResp; |
| 1084 | dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; |
| 1085 | |
| 1086 | /* |
| 1087 | * Normally this is called to retrieve the vendor information |
| 1088 | * from a interface, no implement yet |
| 1089 | */ |
| 1090 | sprintf(infoResp.cmdru.info, "interface,%s,vendor,XXX,cardtype,802.11a/b/g", getInfo->intf); |
| 1091 | |
| 1092 | infoResp.status = STATUS_COMPLETE; |
| 1093 | wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 1094 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 1095 | |
| 1096 | return WFA_SUCCESS; |
| 1097 | } |
| 1098 | |
| 1099 | /* |
| 1100 | * wfaStaSetEapTTLS(): |
| 1101 | * This is to set |
| 1102 | * 1. ssid |
| 1103 | * 2. username |
| 1104 | * 3. passwd |
| 1105 | * 4. encrypType - tkip or aes-ccmp |
| 1106 | * 5. keyManagementType - wpa or wpa2 |
| 1107 | * 6. trustedRootCA |
| 1108 | */ |
| 1109 | int wfaStaSetEapTTLS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1110 | { |
| 1111 | caStaSetEapTTLS_t *setTTLS = (caStaSetEapTTLS_t *)caCmdBuf; |
| 1112 | char *ifname = setTTLS->intf; |
| 1113 | dutCmdResponse_t *setEapTtlsResp = &gGenericResp; |
| 1114 | |
| 1115 | #ifdef WFA_NEW_CLI_FORMAT |
| 1116 | sprintf(gCmdStr, "wfa_set_eapttls %s %s %s %s %s", ifname, setTTLS->ssid, setTTLS->username, setTTLS->passwd, setTTLS->trustedRootCA); |
| 1117 | system(gCmdStr); |
| 1118 | #else |
| 1119 | |
| 1120 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname); |
| 1121 | system(gCmdStr); |
| 1122 | |
| 1123 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setTTLS->ssid); |
| 1124 | system(gCmdStr); |
| 1125 | |
| 1126 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setTTLS->username); |
| 1127 | system(gCmdStr); |
| 1128 | |
| 1129 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setTTLS->passwd); |
| 1130 | system(gCmdStr); |
| 1131 | |
| 1132 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 1133 | system(gCmdStr); |
| 1134 | |
| 1135 | /* This may not need to set. if it is not set, default to take all */ |
| 1136 | // sprintf(cmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"", ifname, setTTLS->encrptype); |
| 1137 | if(strcasecmp(setTTLS->keyMgmtType, "wpa2-sha256") == 0) |
| 1138 | { |
| 1139 | } |
| 1140 | else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-eap") == 0) |
| 1141 | { |
| 1142 | } |
| 1143 | else if(strcasecmp(setTTLS->keyMgmtType, "wpa2-ft") == 0) |
| 1144 | { |
| 1145 | |
| 1146 | } |
| 1147 | else if(strcasecmp(setTTLS->keyMgmtType, "wpa") == 0) |
| 1148 | { |
| 1149 | |
| 1150 | } |
| 1151 | else if(strcasecmp(setTTLS->keyMgmtType, "wpa2") == 0) |
| 1152 | { |
| 1153 | // to take all and device to pick one it supported |
| 1154 | } |
| 1155 | else |
| 1156 | { |
| 1157 | // ?? |
| 1158 | } |
| 1159 | system(gCmdStr); |
| 1160 | |
| 1161 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap TTLS", ifname); |
| 1162 | system(gCmdStr); |
| 1163 | |
| 1164 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setTTLS->trustedRootCA); |
| 1165 | system(gCmdStr); |
| 1166 | |
| 1167 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname); |
| 1168 | system(gCmdStr); |
| 1169 | |
| 1170 | // sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname); |
| 1171 | // system(gCmdStr); |
| 1172 | |
| 1173 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=MSCHAPV2\"'", ifname); |
| 1174 | system(gCmdStr); |
| 1175 | |
| 1176 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname); |
| 1177 | system(gCmdStr); |
| 1178 | #endif |
| 1179 | |
| 1180 | setEapTtlsResp->status = STATUS_COMPLETE; |
| 1181 | wfaEncodeTLV(WFA_STA_SET_EAPTTLS_RESP_TLV, 4, (BYTE *)setEapTtlsResp, respBuf); |
| 1182 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1183 | |
| 1184 | return WFA_SUCCESS; |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | * wfaStaSetEapSIM(): |
| 1189 | * This is to set |
| 1190 | * 1. ssid |
| 1191 | * 2. user name |
| 1192 | * 3. passwd |
| 1193 | * 4. encrypType - tkip or aes-ccmp |
| 1194 | * 5. keyMangementType - wpa or wpa2 |
| 1195 | */ |
| 1196 | int wfaStaSetEapSIM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1197 | { |
| 1198 | caStaSetEapSIM_t *setSIM = (caStaSetEapSIM_t *)caCmdBuf; |
| 1199 | char *ifname = setSIM->intf; |
| 1200 | dutCmdResponse_t *setEapSimResp = &gGenericResp; |
| 1201 | |
| 1202 | #ifdef WFA_NEW_CLI_FORMAT |
| 1203 | sprintf(gCmdStr, "wfa_set_eapsim %s %s %s %s", ifname, setSIM->ssid, setSIM->username, setSIM->encrptype); |
| 1204 | system(gCmdStr); |
| 1205 | #else |
| 1206 | |
| 1207 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname); |
| 1208 | system(gCmdStr); |
| 1209 | |
| 1210 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setSIM->ssid); |
| 1211 | system(gCmdStr); |
| 1212 | |
| 1213 | |
| 1214 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setSIM->username); |
| 1215 | system(gCmdStr); |
| 1216 | |
| 1217 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setSIM->encrptype); |
| 1218 | system(gCmdStr); |
| 1219 | |
| 1220 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap SIM", ifname); |
| 1221 | system(gCmdStr); |
| 1222 | |
| 1223 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA", ifname); |
| 1224 | system(gCmdStr); |
| 1225 | |
| 1226 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname); |
| 1227 | system(gCmdStr); |
| 1228 | |
| 1229 | if(strcasecmp(setSIM->keyMgmtType, "wpa2-sha256") == 0) |
| 1230 | { |
| 1231 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname); |
| 1232 | } |
| 1233 | else if(strcasecmp(setSIM->keyMgmtType, "wpa2-eap") == 0) |
| 1234 | { |
| 1235 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 1236 | } |
| 1237 | else if(strcasecmp(setSIM->keyMgmtType, "wpa2-ft") == 0) |
| 1238 | { |
| 1239 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname); |
| 1240 | } |
| 1241 | else if(strcasecmp(setSIM->keyMgmtType, "wpa") == 0) |
| 1242 | { |
| 1243 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 1244 | } |
| 1245 | else if(strcasecmp(setSIM->keyMgmtType, "wpa2") == 0) |
| 1246 | { |
| 1247 | // take all and device to pick one which is supported. |
| 1248 | } |
| 1249 | else |
| 1250 | { |
| 1251 | // ?? |
| 1252 | } |
| 1253 | system(gCmdStr); |
| 1254 | |
| 1255 | #endif |
| 1256 | |
| 1257 | setEapSimResp->status = STATUS_COMPLETE; |
| 1258 | wfaEncodeTLV(WFA_STA_SET_EAPSIM_RESP_TLV, 4, (BYTE *)setEapSimResp, respBuf); |
| 1259 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1260 | |
| 1261 | return WFA_SUCCESS; |
| 1262 | } |
| 1263 | |
| 1264 | /* |
| 1265 | * wfaStaSetPEAP() |
| 1266 | * This is to set |
| 1267 | * 1. ssid |
| 1268 | * 2. user name |
| 1269 | * 3. passwd |
| 1270 | * 4. encryType - tkip or aes-ccmp |
| 1271 | * 5. keyMgmtType - wpa or wpa2 |
| 1272 | * 6. trustedRootCA |
| 1273 | * 7. innerEAP |
| 1274 | * 8. peapVersion |
| 1275 | */ |
| 1276 | int wfaStaSetPEAP(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1277 | { |
| 1278 | caStaSetEapPEAP_t *setPEAP = (caStaSetEapPEAP_t *)caCmdBuf; |
| 1279 | char *ifname = setPEAP->intf; |
| 1280 | dutCmdResponse_t *setPeapResp = &gGenericResp; |
| 1281 | |
| 1282 | #ifdef WFA_NEW_CLI_FORMAT |
| 1283 | sprintf(gCmdStr, "wfa_set_peap %s %s %s %s %s %s %i %s", ifname, setPEAP->ssid, setPEAP->username, |
| 1284 | setPEAP->passwd, setPEAP->trustedRootCA, |
| 1285 | setPEAP->encrptype, setPEAP->peapVersion, |
| 1286 | setPEAP->innerEAP); |
| 1287 | system(gCmdStr); |
| 1288 | #else |
| 1289 | |
| 1290 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname); |
| 1291 | system(gCmdStr); |
| 1292 | |
| 1293 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setPEAP->ssid); |
| 1294 | system(gCmdStr); |
| 1295 | |
| 1296 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap PEAP", ifname); |
| 1297 | system(gCmdStr); |
| 1298 | |
| 1299 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"' ", ifname); |
| 1300 | system(gCmdStr); |
| 1301 | |
| 1302 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setPEAP->username); |
| 1303 | system(gCmdStr); |
| 1304 | |
| 1305 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setPEAP->passwd); |
| 1306 | system(gCmdStr); |
| 1307 | |
| 1308 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ca_cert '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setPEAP->trustedRootCA); |
| 1309 | system(gCmdStr); |
| 1310 | |
| 1311 | /* if this not set, default to set support all */ |
| 1312 | //sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pairwise '\"%s\"'", ifname, setPEAP->encrptype); |
| 1313 | //system(gCmdStr); |
| 1314 | |
| 1315 | if(strcasecmp(setPEAP->keyMgmtType, "wpa2-sha256") == 0) |
| 1316 | { |
| 1317 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-SHA256", ifname); |
| 1318 | } |
| 1319 | else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-eap") == 0) |
| 1320 | { |
| 1321 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 1322 | } |
| 1323 | else if(strcasecmp(setPEAP->keyMgmtType, "wpa2-ft") == 0) |
| 1324 | { |
| 1325 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-FT", ifname); |
| 1326 | } |
| 1327 | else if(strcasecmp(setPEAP->keyMgmtType, "wpa") == 0) |
| 1328 | { |
| 1329 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 1330 | } |
| 1331 | else if(strcasecmp(setPEAP->keyMgmtType, "wpa2") == 0) |
| 1332 | { |
| 1333 | // take all and device to pick one which is supported. |
| 1334 | } |
| 1335 | else |
| 1336 | { |
| 1337 | // ?? |
| 1338 | } |
| 1339 | system(gCmdStr); |
| 1340 | |
| 1341 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"peaplabel=%i\"'", ifname, setPEAP->peapVersion); |
| 1342 | system(gCmdStr); |
| 1343 | |
| 1344 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname, setPEAP->innerEAP); |
| 1345 | system(gCmdStr); |
| 1346 | |
| 1347 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname); |
| 1348 | system(gCmdStr); |
| 1349 | #endif |
| 1350 | |
| 1351 | setPeapResp->status = STATUS_COMPLETE; |
| 1352 | wfaEncodeTLV(WFA_STA_SET_PEAP_RESP_TLV, 4, (BYTE *)setPeapResp, respBuf); |
| 1353 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1354 | |
| 1355 | return WFA_SUCCESS; |
| 1356 | } |
| 1357 | |
| 1358 | /* |
| 1359 | * wfaStaSetUAPSD() |
| 1360 | * This is to set |
| 1361 | * 1. acBE |
| 1362 | * 2. acBK |
| 1363 | * 3. acVI |
| 1364 | * 4. acVO |
| 1365 | */ |
| 1366 | int wfaStaSetUAPSD(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1367 | { |
| 1368 | dutCmdResponse_t *setUAPSDResp = &gGenericResp; |
| 1369 | #if 0 /* used for only one specific device, need to update to reflect yours */ |
| 1370 | caStaSetUAPSD_t *setUAPSD = (caStaSetUAPSD_t *)caCmdBuf; |
| 1371 | char *ifname = setUAPSD->intf; |
| 1372 | char tmpStr[10]; |
| 1373 | char line[100]; |
| 1374 | char *pathl="/etc/Wireless/RT61STA"; |
| 1375 | BYTE acBE=1; |
| 1376 | BYTE acBK=1; |
| 1377 | BYTE acVO=1; |
| 1378 | BYTE acVI=1; |
| 1379 | BYTE APSDCapable; |
| 1380 | FILE *pipe; |
| 1381 | |
| 1382 | /* |
| 1383 | * A series of setting need to be done before doing WMM-PS |
| 1384 | * Additional steps of configuration may be needed. |
| 1385 | */ |
| 1386 | |
| 1387 | /* |
| 1388 | * bring down the interface |
| 1389 | */ |
| 1390 | sprintf(gCmdStr, "ifconfig %s down",ifname); |
| 1391 | system(gCmdStr); |
| 1392 | /* |
| 1393 | * Unload the Driver |
| 1394 | */ |
| 1395 | sprintf(gCmdStr, "rmmod rt61"); |
| 1396 | system(gCmdStr); |
| 1397 | #ifndef WFA_WMM_AC |
| 1398 | if(setUAPSD->acBE != 1) |
| 1399 | acBE=setUAPSD->acBE = 0; |
| 1400 | if(setUAPSD->acBK != 1) |
| 1401 | acBK=setUAPSD->acBK = 0; |
| 1402 | if(setUAPSD->acVO != 1) |
| 1403 | acVO=setUAPSD->acVO = 0; |
| 1404 | if(setUAPSD->acVI != 1) |
| 1405 | acVI=setUAPSD->acVI = 0; |
| 1406 | #else |
| 1407 | acBE=setUAPSD->acBE; |
| 1408 | acBK=setUAPSD->acBK; |
| 1409 | acVO=setUAPSD->acVO; |
| 1410 | acVI=setUAPSD->acVI; |
| 1411 | #endif |
| 1412 | |
| 1413 | APSDCapable = acBE||acBK||acVO||acVI; |
| 1414 | /* |
| 1415 | * set other AC parameters |
| 1416 | */ |
| 1417 | |
| 1418 | sprintf(tmpStr,"%d;%d;%d;%d",setUAPSD->acBE,setUAPSD->acBK,setUAPSD->acVI,setUAPSD->acVO); |
| 1419 | sprintf(gCmdStr, "sed -e \"s/APSDCapable=.*/APSDCapable=%d/g\" -e \"s/APSDAC=.*/APSDAC=%s/g\" %s/rt61sta.dat >/tmp/wfa_tmp",APSDCapable,tmpStr,pathl); |
| 1420 | system(gCmdStr); |
| 1421 | |
| 1422 | sprintf(gCmdStr, "mv /tmp/wfa_tmp %s/rt61sta.dat",pathl); |
| 1423 | system(gCmdStr); |
| 1424 | pipe = popen("uname -r", "r"); |
| 1425 | /* Read into line the output of uname*/ |
| 1426 | fscanf(pipe,"%s",line); |
| 1427 | pclose(pipe); |
| 1428 | |
| 1429 | /* |
| 1430 | * load the Driver |
| 1431 | */ |
| 1432 | sprintf(gCmdStr, "insmod /lib/modules/%s/extra/rt61.ko",line); |
| 1433 | system(gCmdStr); |
| 1434 | |
| 1435 | sprintf(gCmdStr, "ifconfig %s up",ifname); |
| 1436 | system(gCmdStr); |
| 1437 | #endif |
| 1438 | |
| 1439 | setUAPSDResp->status = STATUS_COMPLETE; |
| 1440 | wfaEncodeTLV(WFA_STA_SET_UAPSD_RESP_TLV, 4, (BYTE *)setUAPSDResp, respBuf); |
| 1441 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1442 | return WFA_SUCCESS; |
| 1443 | } |
| 1444 | |
| 1445 | int wfaDeviceGetInfo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1446 | { |
| 1447 | dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf; |
| 1448 | caDevInfo_t *devInfo = &dutCmd->cmdsu.dev; |
| 1449 | dutCmdResponse_t *infoResp = &gGenericResp; |
| 1450 | /*a vendor can fill in the proper info or anything non-disclosure */ |
| 1451 | caDeviceGetInfoResp_t dinfo = {"WFA Lab", "DemoUnit", WFA_SYSTEM_VER}; |
| 1452 | |
| 1453 | DPRINT_INFO(WFA_OUT, "Entering wfaDeviceGetInfo ...\n"); |
| 1454 | |
| 1455 | if(devInfo->fw == 0) |
| 1456 | memcpy(&infoResp->cmdru.devInfo, &dinfo, sizeof(caDeviceGetInfoResp_t)); |
| 1457 | else |
| 1458 | { |
| 1459 | // Call internal API to pull the version ID */ |
| 1460 | memcpy(infoResp->cmdru.devInfo.firmware, "NOVERSION", 15); |
| 1461 | } |
| 1462 | |
| 1463 | infoResp->status = STATUS_COMPLETE; |
| 1464 | wfaEncodeTLV(WFA_DEVICE_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf); |
| 1465 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 1466 | |
| 1467 | return WFA_SUCCESS; |
| 1468 | |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * This funciton is to retrieve a list of interfaces and return |
| 1473 | * the list back to Agent control. |
| 1474 | * ******************************************************************** |
| 1475 | * Note: We intend to make this WLAN interface name as a hardcode name. |
| 1476 | * Therefore, for a particular device, you should know and change the name |
| 1477 | * for that device while doing porting. The MACRO "WFA_STAUT_IF" is defined in |
| 1478 | * the file "inc/wfa_ca.h". If the device OS is not linux-like, this most |
| 1479 | * likely is hardcoded just for CAPI command responses. |
| 1480 | * ******************************************************************* |
| 1481 | * |
| 1482 | */ |
| 1483 | int wfaDeviceListIF(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1484 | { |
| 1485 | dutCmdResponse_t *infoResp = &gGenericResp; |
| 1486 | dutCommand_t *ifList = (dutCommand_t *)caCmdBuf; |
| 1487 | caDeviceListIFResp_t *ifListResp = &infoResp->cmdru.ifList; |
| 1488 | |
| 1489 | DPRINT_INFO(WFA_OUT, "Entering wfaDeviceListIF ...\n"); |
| 1490 | |
| 1491 | switch(ifList->cmdsu.iftype) |
| 1492 | { |
| 1493 | case IF_80211: |
| 1494 | infoResp->status = STATUS_COMPLETE; |
| 1495 | ifListResp->iftype = IF_80211; |
| 1496 | strcpy(ifListResp->ifs[0], WFA_STAUT_IF); |
| 1497 | strcpy(ifListResp->ifs[1], "NULL"); |
| 1498 | strcpy(ifListResp->ifs[2], "NULL"); |
| 1499 | break; |
| 1500 | case IF_ETH: |
| 1501 | infoResp->status = STATUS_COMPLETE; |
| 1502 | ifListResp->iftype = IF_ETH; |
| 1503 | strcpy(ifListResp->ifs[0], "eth0"); |
| 1504 | strcpy(ifListResp->ifs[1], "NULL"); |
| 1505 | strcpy(ifListResp->ifs[2], "NULL"); |
| 1506 | break; |
| 1507 | default: |
| 1508 | { |
| 1509 | infoResp->status = STATUS_ERROR; |
| 1510 | wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, 4, (BYTE *)infoResp, respBuf); |
| 1511 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1512 | |
| 1513 | return WFA_SUCCESS; |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | wfaEncodeTLV(WFA_DEVICE_LIST_IF_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)infoResp, respBuf); |
| 1518 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 1519 | |
| 1520 | return WFA_SUCCESS; |
| 1521 | } |
| 1522 | |
| 1523 | int wfaStaDebugSet(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1524 | { |
| 1525 | dutCmdResponse_t *debugResp = &gGenericResp; |
| 1526 | dutCommand_t *debugSet = (dutCommand_t *)caCmdBuf; |
| 1527 | |
| 1528 | DPRINT_INFO(WFA_OUT, "Entering wfaStaDebugSet ...\n"); |
| 1529 | |
| 1530 | if(debugSet->cmdsu.dbg.state == 1) /* enable */ |
| 1531 | wfa_defined_debug |= debugSet->cmdsu.dbg.level; |
| 1532 | else |
| 1533 | wfa_defined_debug = (~debugSet->cmdsu.dbg.level & wfa_defined_debug); |
| 1534 | |
| 1535 | debugResp->status = STATUS_COMPLETE; |
| 1536 | wfaEncodeTLV(WFA_STA_GET_INFO_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)debugResp, respBuf); |
| 1537 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 1538 | |
| 1539 | |
| 1540 | return WFA_SUCCESS; |
| 1541 | } |
| 1542 | |
| 1543 | |
| 1544 | /* |
| 1545 | * wfaStaGetBSSID(): |
| 1546 | * This function is to retrieve BSSID of a specific wireless I/F. |
| 1547 | */ |
| 1548 | int wfaStaGetBSSID(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1549 | { |
| 1550 | char string[64]; |
| 1551 | char *str; |
| 1552 | FILE *tmpfd; |
| 1553 | dutCmdResponse_t *bssidResp = &gGenericResp; |
| 1554 | |
| 1555 | DPRINT_INFO(WFA_OUT, "Entering wfaStaGetBSSID ...\n"); |
| 1556 | /* retrieve the BSSID */ |
| 1557 | sprintf(gCmdStr, "wpa_cli status > /tmp/bssid.txt"); |
| 1558 | |
| 1559 | system(gCmdStr); |
| 1560 | |
| 1561 | tmpfd = fopen("/tmp/bssid.txt", "r+"); |
| 1562 | if(tmpfd == NULL) |
| 1563 | { |
| 1564 | bssidResp->status = STATUS_ERROR; |
| 1565 | wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, 4, (BYTE *)bssidResp, respBuf); |
| 1566 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1567 | |
| 1568 | DPRINT_ERR(WFA_ERR, "file open failed\n"); |
| 1569 | return WFA_FAILURE; |
| 1570 | } |
| 1571 | |
| 1572 | for(;;) |
| 1573 | { |
| 1574 | if(fscanf(tmpfd, "%s", string) == EOF) |
| 1575 | { |
| 1576 | bssidResp->status = STATUS_COMPLETE; |
| 1577 | strcpy(bssidResp->cmdru.bssid, "00:00:00:00:00:00"); |
| 1578 | break; |
| 1579 | } |
| 1580 | |
| 1581 | if(strncmp(string, "bssid", 5) == 0) |
| 1582 | { |
| 1583 | str = strtok(string, "="); |
| 1584 | str = strtok(NULL, "="); |
| 1585 | if(str != NULL) |
| 1586 | { |
| 1587 | strcpy(bssidResp->cmdru.bssid, str); |
| 1588 | bssidResp->status = STATUS_COMPLETE; |
| 1589 | break; |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | wfaEncodeTLV(WFA_STA_GET_BSSID_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)bssidResp, respBuf); |
| 1595 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 1596 | |
| 1597 | fclose(tmpfd); |
| 1598 | return WFA_SUCCESS; |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | * wfaStaSetIBSS() |
| 1603 | * This is to set |
| 1604 | * 1. ssid |
| 1605 | * 2. channel |
| 1606 | * 3. encrypType - none or wep |
| 1607 | * optional |
| 1608 | * 4. key1 |
| 1609 | * 5. key2 |
| 1610 | * 6. key3 |
| 1611 | * 7. key4 |
| 1612 | * 8. activeIndex - 1, 2, 3, or 4 |
| 1613 | */ |
| 1614 | int wfaStaSetIBSS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1615 | { |
| 1616 | caStaSetIBSS_t *setIBSS = (caStaSetIBSS_t *)caCmdBuf; |
| 1617 | dutCmdResponse_t *setIbssResp = &gGenericResp; |
| 1618 | int i; |
| 1619 | |
| 1620 | /* |
| 1621 | * disable the network first |
| 1622 | */ |
| 1623 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", setIBSS->intf); |
| 1624 | system(gCmdStr); |
| 1625 | |
| 1626 | /* |
| 1627 | * set SSID |
| 1628 | */ |
| 1629 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", setIBSS->intf, setIBSS->ssid); |
| 1630 | system(gCmdStr); |
| 1631 | |
| 1632 | /* |
| 1633 | * Set channel for IBSS |
| 1634 | */ |
| 1635 | sprintf(gCmdStr, "iwconfig %s channel %i", setIBSS->intf, setIBSS->channel); |
| 1636 | system(gCmdStr); |
| 1637 | |
| 1638 | /* |
| 1639 | * Tell the supplicant for IBSS mode (1) |
| 1640 | */ |
| 1641 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 mode 1", setIBSS->intf); |
| 1642 | system(gCmdStr); |
| 1643 | |
| 1644 | /* |
| 1645 | * set Key management to NONE (NO WPA) for plaintext or WEP |
| 1646 | */ |
| 1647 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt NONE", setIBSS->intf); |
| 1648 | system(gCmdStr); |
| 1649 | |
| 1650 | if(setIBSS->encpType == 1) |
| 1651 | { |
| 1652 | for(i=0; i<4; i++) |
| 1653 | { |
| 1654 | if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13) |
| 1655 | { |
| 1656 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_key%i \"%s\"", |
| 1657 | setIBSS->intf, i, setIBSS->keys[i]); |
| 1658 | system(gCmdStr); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | i = setIBSS->activeKeyIdx; |
| 1663 | if(strlen(setIBSS->keys[i]) ==5 || strlen(setIBSS->keys[i]) == 13) |
| 1664 | { |
| 1665 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 wep_tx_keyidx %i", |
| 1666 | setIBSS->intf, setIBSS->activeKeyIdx); |
| 1667 | system(gCmdStr); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", setIBSS->intf); |
| 1672 | system(gCmdStr); |
| 1673 | |
| 1674 | setIbssResp->status = STATUS_COMPLETE; |
| 1675 | wfaEncodeTLV(WFA_STA_SET_IBSS_RESP_TLV, 4, (BYTE *)setIbssResp, respBuf); |
| 1676 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1677 | |
| 1678 | return WFA_SUCCESS; |
| 1679 | } |
| 1680 | |
| 1681 | /* |
| 1682 | * wfaSetMode(): |
| 1683 | * The function is to set the wireless interface with a given mode (possible |
| 1684 | * adhoc) |
| 1685 | * Input parameters: |
| 1686 | * 1. I/F |
| 1687 | * 2. ssid |
| 1688 | * 3. mode adhoc or managed |
| 1689 | * 4. encType |
| 1690 | * 5. channel |
| 1691 | * 6. key(s) |
| 1692 | * 7. active key |
| 1693 | */ |
| 1694 | int wfaStaSetMode(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1695 | { |
| 1696 | caStaSetMode_t *setmode = (caStaSetMode_t *)caCmdBuf; |
| 1697 | dutCmdResponse_t *SetModeResp = &gGenericResp; |
| 1698 | int i; |
| 1699 | |
| 1700 | /* |
| 1701 | * bring down the interface |
| 1702 | */ |
| 1703 | sprintf(gCmdStr, "ifconfig %s down",setmode->intf); |
| 1704 | system(gCmdStr); |
| 1705 | |
| 1706 | /* |
| 1707 | * distroy the interface |
| 1708 | */ |
| 1709 | sprintf(gCmdStr, "wlanconfig %s destroy",setmode->intf); |
| 1710 | system(gCmdStr); |
| 1711 | |
| 1712 | |
| 1713 | /* |
| 1714 | * re-create the interface with the given mode |
| 1715 | */ |
| 1716 | if(setmode->mode == 1) |
| 1717 | sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode adhoc",setmode->intf); |
| 1718 | else |
| 1719 | sprintf(gCmdStr, "wlanconfig %s create wlandev wifi0 wlanmode managed",setmode->intf); |
| 1720 | |
| 1721 | system(gCmdStr); |
| 1722 | if(setmode->encpType == ENCRYPT_WEP) |
| 1723 | { |
| 1724 | int j = setmode->activeKeyIdx; |
| 1725 | for(i=0; i<4; i++) |
| 1726 | { |
| 1727 | if(setmode->keys[i][0] != '\0') |
| 1728 | { |
| 1729 | sprintf(gCmdStr, "iwconfig %s key s:%s", |
| 1730 | setmode->intf, setmode->keys[i]); |
| 1731 | system(gCmdStr); |
| 1732 | } |
| 1733 | /* set active key */ |
| 1734 | if(setmode->keys[j][0] != '\0') |
| 1735 | sprintf(gCmdStr, "iwconfig %s key s:%s", |
| 1736 | setmode->intf, setmode->keys[j]); |
| 1737 | system(gCmdStr); |
| 1738 | } |
| 1739 | |
| 1740 | } |
| 1741 | /* |
| 1742 | * Set channel for IBSS |
| 1743 | */ |
| 1744 | if(setmode->channel) |
| 1745 | { |
| 1746 | sprintf(gCmdStr, "iwconfig %s channel %i", setmode->intf, setmode->channel); |
| 1747 | system(gCmdStr); |
| 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | /* |
| 1752 | * set SSID |
| 1753 | */ |
| 1754 | sprintf(gCmdStr, "iwconfig %s essid %s", setmode->intf, setmode->ssid); |
| 1755 | system(gCmdStr); |
| 1756 | |
| 1757 | /* |
| 1758 | * bring up the interface |
| 1759 | */ |
| 1760 | sprintf(gCmdStr, "ifconfig %s up",setmode->intf); |
| 1761 | system(gCmdStr); |
| 1762 | |
| 1763 | SetModeResp->status = STATUS_COMPLETE; |
| 1764 | wfaEncodeTLV(WFA_STA_SET_MODE_RESP_TLV, 4, (BYTE *)SetModeResp, respBuf); |
| 1765 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1766 | |
| 1767 | return WFA_SUCCESS; |
| 1768 | } |
| 1769 | |
| 1770 | int wfaStaSetPwrSave(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1771 | { |
| 1772 | caStaSetPwrSave_t *setps = (caStaSetPwrSave_t *)caCmdBuf; |
| 1773 | dutCmdResponse_t *SetPSResp = &gGenericResp; |
| 1774 | |
| 1775 | sprintf(gCmdStr, "iwconfig %s power %s", setps->intf, setps->mode); |
| 1776 | system(gCmdStr); |
| 1777 | |
| 1778 | |
| 1779 | SetPSResp->status = STATUS_COMPLETE; |
| 1780 | wfaEncodeTLV(WFA_STA_SET_PWRSAVE_RESP_TLV, 4, (BYTE *)SetPSResp, respBuf); |
| 1781 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1782 | |
| 1783 | return WFA_SUCCESS; |
| 1784 | } |
| 1785 | |
| 1786 | int wfaStaUpload(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1787 | { |
| 1788 | caStaUpload_t *upload = &((dutCommand_t *)caCmdBuf)->cmdsu.upload; |
| 1789 | dutCmdResponse_t *upLoadResp = &gGenericResp; |
| 1790 | caStaUploadResp_t *upld = &upLoadResp->cmdru.uld; |
| 1791 | |
| 1792 | if(upload->type == WFA_UPLOAD_VHSO_RPT) |
| 1793 | { |
| 1794 | int rbytes; |
| 1795 | /* |
| 1796 | * if asked for the first packet, always to open the file |
| 1797 | */ |
| 1798 | if(upload->next == 1) |
| 1799 | { |
| 1800 | if(e2efp != NULL) |
| 1801 | { |
| 1802 | fclose(e2efp); |
| 1803 | e2efp = NULL; |
| 1804 | } |
| 1805 | |
| 1806 | e2efp = fopen(e2eResults, "r"); |
| 1807 | } |
| 1808 | |
| 1809 | if(e2efp == NULL) |
| 1810 | { |
| 1811 | upLoadResp->status = STATUS_ERROR; |
| 1812 | wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf); |
| 1813 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1814 | return WFA_FAILURE; |
| 1815 | } |
| 1816 | |
| 1817 | rbytes = fread(upld->bytes, 1, 256, e2efp); |
| 1818 | |
| 1819 | if(rbytes < 256) |
| 1820 | { |
| 1821 | /* |
| 1822 | * this means no more bytes after this read |
| 1823 | */ |
| 1824 | upld->seqnum = 0; |
| 1825 | fclose(e2efp); |
| 1826 | e2efp=NULL; |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | upld->seqnum = upload->next; |
| 1831 | } |
| 1832 | |
| 1833 | upld->nbytes = rbytes; |
| 1834 | |
| 1835 | upLoadResp->status = STATUS_COMPLETE; |
| 1836 | wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)upLoadResp, respBuf); |
| 1837 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 1838 | } |
| 1839 | else |
| 1840 | { |
| 1841 | upLoadResp->status = STATUS_ERROR; |
| 1842 | wfaEncodeTLV(WFA_STA_UPLOAD_RESP_TLV, 4, (BYTE *)upLoadResp, respBuf); |
| 1843 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1844 | } |
| 1845 | |
| 1846 | return WFA_SUCCESS; |
| 1847 | } |
| 1848 | /* |
| 1849 | * wfaStaSetWMM() |
| 1850 | * TO be ported on a specific plaform for the DUT |
| 1851 | * This is to set the WMM related parameters at the DUT. |
| 1852 | * Currently the function is used for GROUPS WMM-AC and WMM general configuration for setting RTS Threshhold, Fragmentation threshold and wmm (ON/OFF) |
| 1853 | * It is expected that this function will set all the WMM related parametrs for a particular GROUP . |
| 1854 | */ |
| 1855 | int wfaStaSetWMM(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1856 | { |
| 1857 | #ifdef WFA_WMM_AC |
| 1858 | caStaSetWMM_t *setwmm = (caStaSetWMM_t *)caCmdBuf; |
| 1859 | char *ifname = setwmm->intf; |
| 1860 | dutCmdResponse_t *setwmmResp = &gGenericResp; |
| 1861 | //IEEEtypes_WMM_TSPEC_t tspec; |
| 1862 | |
| 1863 | switch(setwmm->group) |
| 1864 | { |
| 1865 | case GROUP_WMMAC: |
| 1866 | if (setwmm->send_trig) |
| 1867 | { |
| 1868 | int Sockfd; |
| 1869 | struct sockaddr_in psToAddr; |
| 1870 | unsigned int TxMsg[512]; |
| 1871 | |
| 1872 | Sockfd = wfaCreateUDPSock(setwmm->dipaddr, 12346); |
| 1873 | memset(&psToAddr, 0, sizeof(psToAddr)); |
| 1874 | psToAddr.sin_family = AF_INET; |
| 1875 | psToAddr.sin_addr.s_addr = inet_addr(setwmm->dipaddr); |
| 1876 | psToAddr.sin_port = htons(12346); |
| 1877 | |
| 1878 | |
| 1879 | switch (setwmm->trig_ac) |
| 1880 | { |
| 1881 | case WMMAC_AC_VO: |
| 1882 | wfaTGSetPrio(Sockfd, 7); |
| 1883 | create_apts_msg(APTS_CK_VO, TxMsg, 0); |
| 1884 | printf("\r\nSending AC_VO trigger packet\n"); |
| 1885 | break; |
| 1886 | |
| 1887 | case WMMAC_AC_VI: |
| 1888 | wfaTGSetPrio(Sockfd, 5); |
| 1889 | create_apts_msg(APTS_CK_VI, TxMsg, 0); |
| 1890 | printf("\r\nSending AC_VI trigger packet\n"); |
| 1891 | break; |
| 1892 | |
| 1893 | case WMMAC_AC_BK: |
| 1894 | wfaTGSetPrio(Sockfd, 2); |
| 1895 | create_apts_msg(APTS_CK_BK, TxMsg, 0); |
| 1896 | printf("\r\nSending AC_BK trigger packet\n"); |
| 1897 | break; |
| 1898 | |
| 1899 | default: |
| 1900 | case WMMAC_AC_BE: |
| 1901 | wfaTGSetPrio(Sockfd, 0); |
| 1902 | create_apts_msg(APTS_CK_BE, TxMsg, 0); |
| 1903 | printf("\r\nSending AC_BE trigger packet\n"); |
| 1904 | break; |
| 1905 | } |
| 1906 | |
| 1907 | sendto(Sockfd, TxMsg, 256, 0, (struct sockaddr *)&psToAddr, |
| 1908 | sizeof(struct sockaddr)); |
| 1909 | close(Sockfd); |
| 1910 | usleep(1000000); |
| 1911 | } |
| 1912 | else if (setwmm->action == WMMAC_ADDTS) |
| 1913 | { |
| 1914 | //wmmtspec_t* pCmdTspec = &(setwmm->actions.addts.tspec); |
| 1915 | printf("ADDTS AC PARAMS: dialog id: %d, TID: %d, " |
| 1916 | "DIRECTION: %d, PSB: %d, UP: %d, INFOACK: %d BURST SIZE DEF: %d" |
| 1917 | "Fixed %d, MSDU Size: %d, Max MSDU Size %d, " |
| 1918 | "MIN SERVICE INTERVAL: %d, MAX SERVICE INTERVAL: %d, " |
| 1919 | "INACTIVITY: %d, SUSPENSION %d, SERVICE START TIME: %d, " |
| 1920 | "MIN DATARATE: %d, MEAN DATA RATE: %d, PEAK DATA RATE: %d, " |
| 1921 | "BURSTSIZE or MSDU Aggreg: %d, DELAY BOUND: %d, PHYRATE: %d, SPLUSBW: %f, " |
| 1922 | "MEDIUM TIME: %d, ACCESSCAT: %d\n", |
| 1923 | setwmm->actions.addts.dialog_token, |
| 1924 | setwmm->actions.addts.tspec.tsinfo.TID, |
| 1925 | setwmm->actions.addts.tspec.tsinfo.direction, |
| 1926 | setwmm->actions.addts.tspec.tsinfo.PSB, |
| 1927 | setwmm->actions.addts.tspec.tsinfo.UP, |
| 1928 | setwmm->actions.addts.tspec.tsinfo.infoAck, |
| 1929 | setwmm->actions.addts.tspec.tsinfo.bstSzDef, |
| 1930 | setwmm->actions.addts.tspec.Fixed, |
| 1931 | setwmm->actions.addts.tspec.size, |
| 1932 | setwmm->actions.addts.tspec.maxsize, |
| 1933 | setwmm->actions.addts.tspec.min_srvc, |
| 1934 | setwmm->actions.addts.tspec.max_srvc, |
| 1935 | setwmm->actions.addts.tspec.inactivity, |
| 1936 | setwmm->actions.addts.tspec.suspension, |
| 1937 | setwmm->actions.addts.tspec.srvc_strt_tim, |
| 1938 | setwmm->actions.addts.tspec.mindatarate, |
| 1939 | setwmm->actions.addts.tspec.meandatarate, |
| 1940 | setwmm->actions.addts.tspec.peakdatarate, |
| 1941 | setwmm->actions.addts.tspec.burstsize, |
| 1942 | setwmm->actions.addts.tspec.delaybound, |
| 1943 | setwmm->actions.addts.tspec.PHYrate, |
| 1944 | setwmm->actions.addts.tspec.sba, |
| 1945 | setwmm->actions.addts.tspec.medium_time, |
| 1946 | setwmm->actions.addts.accesscat); |
| 1947 | |
| 1948 | // you should set your tspec here. |
| 1949 | |
| 1950 | system(gCmdStr); |
| 1951 | } |
| 1952 | else if (setwmm->action == WMMAC_DELTS) |
| 1953 | { |
| 1954 | // send del tspec |
| 1955 | } |
| 1956 | |
| 1957 | setwmmResp->status = STATUS_COMPLETE; |
| 1958 | break; |
| 1959 | |
| 1960 | case GROUP_WMMCONF: |
| 1961 | sprintf(gCmdStr, "iwconfig %s rts %d", |
| 1962 | ifname,setwmm->actions.config.rts_thr); |
| 1963 | |
| 1964 | system(gCmdStr); |
| 1965 | sprintf(gCmdStr, "iwconfig %s frag %d", |
| 1966 | ifname,setwmm->actions.config.frag_thr); |
| 1967 | |
| 1968 | system(gCmdStr); |
| 1969 | sprintf(gCmdStr, "iwpriv %s wmmcfg %d", |
| 1970 | ifname, setwmm->actions.config.wmm); |
| 1971 | |
| 1972 | system(gCmdStr); |
| 1973 | setwmmResp->status = STATUS_COMPLETE; |
| 1974 | break; |
| 1975 | |
| 1976 | default: |
| 1977 | DPRINT_ERR(WFA_ERR, "The group %d is not supported\n",setwmm->group); |
| 1978 | setwmmResp->status = STATUS_ERROR; |
| 1979 | break; |
| 1980 | |
| 1981 | } |
| 1982 | |
| 1983 | wfaEncodeTLV(WFA_STA_SET_WMM_RESP_TLV, 4, (BYTE *)setwmmResp, respBuf); |
| 1984 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 1985 | #endif |
| 1986 | |
| 1987 | return WFA_SUCCESS; |
| 1988 | } |
| 1989 | |
| 1990 | int wfaStaSendNeigReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 1991 | { |
| 1992 | //dutCommand_t *sendNeigReq = (dutCommand_t *)caCmdBuf; |
| 1993 | dutCmdResponse_t *sendNeigReqResp = &gGenericResp; |
| 1994 | |
| 1995 | /* |
| 1996 | * run your device to send NEIGREQ |
| 1997 | */ |
| 1998 | |
| 1999 | sendNeigReqResp->status = STATUS_COMPLETE; |
| 2000 | wfaEncodeTLV(WFA_STA_SEND_NEIGREQ_RESP_TLV, 4, (BYTE *)sendNeigReqResp, respBuf); |
| 2001 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2002 | |
| 2003 | return WFA_SUCCESS; |
| 2004 | } |
| 2005 | |
| 2006 | int wfaStaSetEapFAST(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2007 | { |
| 2008 | caStaSetEapFAST_t *setFAST= (caStaSetEapFAST_t *)caCmdBuf; |
| 2009 | char *ifname = setFAST->intf; |
| 2010 | dutCmdResponse_t *setEapFastResp = &gGenericResp; |
| 2011 | |
| 2012 | #ifdef WFA_NEW_CLI_FORMAT |
| 2013 | sprintf(gCmdStr, "wfa_set_eapfast %s %s %s %s %s %s", ifname, setFAST->ssid, setFAST->username, |
| 2014 | setFAST->passwd, setFAST->pacFileName, |
| 2015 | setFAST->innerEAP); |
| 2016 | system(gCmdStr); |
| 2017 | #else |
| 2018 | |
| 2019 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname); |
| 2020 | system(gCmdStr); |
| 2021 | |
| 2022 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setFAST->ssid); |
| 2023 | system(gCmdStr); |
| 2024 | |
| 2025 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setFAST->username); |
| 2026 | system(gCmdStr); |
| 2027 | |
| 2028 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setFAST->passwd); |
| 2029 | system(gCmdStr); |
| 2030 | |
| 2031 | if(strcasecmp(setFAST->keyMgmtType, "wpa2-sha256") == 0) |
| 2032 | { |
| 2033 | } |
| 2034 | else if(strcasecmp(setFAST->keyMgmtType, "wpa2-eap") == 0) |
| 2035 | { |
| 2036 | } |
| 2037 | else if(strcasecmp(setFAST->keyMgmtType, "wpa2-ft") == 0) |
| 2038 | { |
| 2039 | |
| 2040 | } |
| 2041 | else if(strcasecmp(setFAST->keyMgmtType, "wpa") == 0) |
| 2042 | { |
| 2043 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 2044 | } |
| 2045 | else if(strcasecmp(setFAST->keyMgmtType, "wpa2") == 0) |
| 2046 | { |
| 2047 | // take all and device to pick one which is supported. |
| 2048 | } |
| 2049 | else |
| 2050 | { |
| 2051 | // ?? |
| 2052 | } |
| 2053 | system(gCmdStr); |
| 2054 | |
| 2055 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap FAST", ifname); |
| 2056 | system(gCmdStr); |
| 2057 | |
| 2058 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 pac_file '\"%s/%s\"'", ifname, CERTIFICATES_PATH, setFAST->pacFileName); |
| 2059 | system(gCmdStr); |
| 2060 | |
| 2061 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 anonymous_identity '\"anonymous\"'", ifname); |
| 2062 | system(gCmdStr); |
| 2063 | |
| 2064 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 '\"fast_provisioning=1\"'", ifname); |
| 2065 | system(gCmdStr); |
| 2066 | |
| 2067 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase2 '\"auth=%s\"'", ifname,setFAST->innerEAP); |
| 2068 | system(gCmdStr); |
| 2069 | |
| 2070 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname); |
| 2071 | system(gCmdStr); |
| 2072 | #endif |
| 2073 | |
| 2074 | setEapFastResp->status = STATUS_COMPLETE; |
| 2075 | wfaEncodeTLV(WFA_STA_SET_EAPFAST_RESP_TLV, 4, (BYTE *)setEapFastResp, respBuf); |
| 2076 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2077 | |
| 2078 | return WFA_SUCCESS; |
| 2079 | } |
| 2080 | |
| 2081 | int wfaStaSetEapAKA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2082 | { |
| 2083 | caStaSetEapAKA_t *setAKA= (caStaSetEapAKA_t *)caCmdBuf; |
| 2084 | char *ifname = setAKA->intf; |
| 2085 | dutCmdResponse_t *setEapAkaResp = &gGenericResp; |
| 2086 | |
| 2087 | #ifdef WFA_NEW_CLI_FORMAT |
| 2088 | sprintf(gCmdStr, "wfa_set_eapaka %s %s %s %s", ifname, setAKA->ssid, setAKA->username, setAKA->passwd); |
| 2089 | system(gCmdStr); |
| 2090 | #else |
| 2091 | |
| 2092 | sprintf(gCmdStr, "wpa_cli -i %s disable_network 0", ifname); |
| 2093 | system(gCmdStr); |
| 2094 | |
| 2095 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 ssid '\"%s\"'", ifname, setAKA->ssid); |
| 2096 | system(gCmdStr); |
| 2097 | |
| 2098 | if(strcasecmp(setAKA->keyMgmtType, "wpa2-sha256") == 0) |
| 2099 | { |
| 2100 | } |
| 2101 | else if(strcasecmp(setAKA->keyMgmtType, "wpa2-eap") == 0) |
| 2102 | { |
| 2103 | } |
| 2104 | else if(strcasecmp(setAKA->keyMgmtType, "wpa2-ft") == 0) |
| 2105 | { |
| 2106 | |
| 2107 | } |
| 2108 | else if(strcasecmp(setAKA->keyMgmtType, "wpa") == 0) |
| 2109 | { |
| 2110 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 key_mgmt WPA-EAP", ifname); |
| 2111 | } |
| 2112 | else if(strcasecmp(setAKA->keyMgmtType, "wpa2") == 0) |
| 2113 | { |
| 2114 | // take all and device to pick one which is supported. |
| 2115 | } |
| 2116 | else |
| 2117 | { |
| 2118 | // ?? |
| 2119 | } |
| 2120 | system(gCmdStr); |
| 2121 | |
| 2122 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto WPA2", ifname); |
| 2123 | system(gCmdStr); |
| 2124 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 proto CCMP", ifname); |
| 2125 | system(gCmdStr); |
| 2126 | |
| 2127 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 eap AKA", ifname); |
| 2128 | system(gCmdStr); |
| 2129 | |
| 2130 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 phase1 \"result_ind=1\"", ifname); |
| 2131 | system(gCmdStr); |
| 2132 | |
| 2133 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 identity '\"%s\"'", ifname, setAKA->username); |
| 2134 | system(gCmdStr); |
| 2135 | |
| 2136 | sprintf(gCmdStr, "wpa_cli -i %s set_network 0 password '\"%s\"'", ifname, setAKA->passwd); |
| 2137 | system(gCmdStr); |
| 2138 | |
| 2139 | sprintf(gCmdStr, "wpa_cli -i %s enable_network 0", ifname); |
| 2140 | system(gCmdStr); |
| 2141 | #endif |
| 2142 | |
| 2143 | setEapAkaResp->status = STATUS_COMPLETE; |
| 2144 | wfaEncodeTLV(WFA_STA_SET_EAPAKA_RESP_TLV, 4, (BYTE *)setEapAkaResp, respBuf); |
| 2145 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2146 | |
| 2147 | return WFA_SUCCESS; |
| 2148 | } |
| 2149 | |
| 2150 | int wfaStaSetSystime(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2151 | { |
| 2152 | caStaSetSystime_t *systime = (caStaSetSystime_t *)caCmdBuf; |
| 2153 | dutCmdResponse_t *setSystimeResp = &gGenericResp; |
| 2154 | |
| 2155 | DPRINT_INFO(WFA_OUT, "Entering wfaStaSetSystime ...\n"); |
| 2156 | |
| 2157 | sprintf(gCmdStr, "date %d-%d-%d",systime->month,systime->date,systime->year); |
| 2158 | system(gCmdStr); |
| 2159 | |
| 2160 | sprintf(gCmdStr, "time %d:%d:%d", systime->hours,systime->minutes,systime->seconds); |
| 2161 | system(gCmdStr); |
| 2162 | |
| 2163 | setSystimeResp->status = STATUS_COMPLETE; |
| 2164 | wfaEncodeTLV(WFA_STA_SET_SYSTIME_RESP_TLV, 4, (BYTE *)setSystimeResp, respBuf); |
| 2165 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2166 | |
| 2167 | return WFA_SUCCESS; |
| 2168 | } |
| 2169 | |
| 2170 | #ifdef WFA_STA_TB |
| 2171 | int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2172 | { |
| 2173 | dutCmdResponse_t *PresetParamsResp = &gGenericResp; |
| 2174 | caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf; |
| 2175 | //int ret; |
| 2176 | //char *intfname = presetParams->intf; |
| 2177 | BYTE presetDone = 1; |
| 2178 | int st = 0; |
| 2179 | |
| 2180 | DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n"); |
| 2181 | |
| 2182 | if(presetParams->wmmFlag) |
| 2183 | { |
| 2184 | st = wfaExecuteCLI(gCmdStr); |
| 2185 | switch(st) |
| 2186 | { |
| 2187 | case 0: |
| 2188 | presetDone = 1; |
| 2189 | break; |
| 2190 | case 1: |
| 2191 | presetDone = 0; |
| 2192 | break; |
| 2193 | case 2: |
| 2194 | presetDone = 0; |
| 2195 | break; |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | if(presetParams->modeFlag != 0) |
| 2200 | { |
| 2201 | switch(presetParams->wirelessMode) |
| 2202 | { |
| 2203 | default: |
| 2204 | printf("other mode does not need to support\n"); |
| 2205 | } |
| 2206 | |
| 2207 | st = wfaExecuteCLI(gCmdStr); |
| 2208 | switch(st) |
| 2209 | { |
| 2210 | case 0: |
| 2211 | presetDone = 1; |
| 2212 | break; |
| 2213 | case 1: |
| 2214 | presetDone = 0; |
| 2215 | case 2: |
| 2216 | presetDone = 0; |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | |
| 2222 | if(presetParams->psFlag) |
| 2223 | { |
| 2224 | |
| 2225 | printf("%s\n", gCmdStr); |
| 2226 | system(gCmdStr); |
| 2227 | } |
| 2228 | |
| 2229 | /************the followings are used for Voice Enterprise **************/ |
| 2230 | if(presetParams->ftoa == eEnable) |
| 2231 | { |
| 2232 | // enable Fast BSS Transition Over the Air |
| 2233 | } |
| 2234 | else |
| 2235 | { |
| 2236 | // disable Fast BSS Transition Over the Air |
| 2237 | |
| 2238 | } |
| 2239 | |
| 2240 | if(presetParams->ftds == eEnable) |
| 2241 | { |
| 2242 | // enable Fast BSS Transition Over the DS |
| 2243 | |
| 2244 | } |
| 2245 | else |
| 2246 | { |
| 2247 | // disable Fast BSS Transition Over the DS |
| 2248 | |
| 2249 | } |
| 2250 | |
| 2251 | if(presetParams->activescan == eEnable) |
| 2252 | { |
| 2253 | // Enable Active Scan on STA |
| 2254 | |
| 2255 | } |
| 2256 | else |
| 2257 | { |
| 2258 | // disable Active Scan on STA |
| 2259 | |
| 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | if (presetDone) |
| 2264 | { |
| 2265 | PresetParamsResp->status = STATUS_COMPLETE; |
| 2266 | } |
| 2267 | else |
| 2268 | { |
| 2269 | PresetParamsResp->status = STATUS_INVALID; |
| 2270 | } |
| 2271 | |
| 2272 | wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)PresetParamsResp, respBuf); |
| 2273 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2274 | |
| 2275 | return WFA_SUCCESS; |
| 2276 | } |
| 2277 | |
| 2278 | int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2279 | { |
| 2280 | dutCmdResponse_t *v11nParamsResp = &gGenericResp; |
| 2281 | |
| 2282 | v11nParamsResp->status = STATUS_COMPLETE; |
| 2283 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf); |
| 2284 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2285 | return WFA_SUCCESS; |
| 2286 | } |
| 2287 | int wfaStaSetWireless(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2288 | { |
| 2289 | dutCmdResponse_t *staWirelessResp = &gGenericResp; |
| 2290 | |
| 2291 | staWirelessResp->status = STATUS_COMPLETE; |
| 2292 | wfaEncodeTLV(WFA_STA_SET_WIRELESS_RESP_TLV, 4, (BYTE *)staWirelessResp, respBuf); |
| 2293 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2294 | return WFA_SUCCESS; |
| 2295 | } |
| 2296 | |
| 2297 | int wfaStaSendADDBA(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2298 | { |
| 2299 | dutCmdResponse_t *staSendADDBAResp = &gGenericResp; |
| 2300 | |
| 2301 | wfaEncodeTLV(WFA_STA_SET_SEND_ADDBA_RESP_TLV, 4, (BYTE *)staSendADDBAResp, respBuf); |
| 2302 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2303 | return WFA_SUCCESS; |
| 2304 | } |
| 2305 | |
| 2306 | int wfaStaSetRIFS(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2307 | { |
| 2308 | dutCmdResponse_t *staSetRIFSResp = &gGenericResp; |
| 2309 | |
| 2310 | wfaEncodeTLV(WFA_STA_SET_RIFS_TEST_RESP_TLV, 4, (BYTE *)staSetRIFSResp, respBuf); |
| 2311 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2312 | |
| 2313 | return WFA_SUCCESS; |
| 2314 | |
| 2315 | } |
| 2316 | |
| 2317 | int wfaStaSendCoExistMGMT(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2318 | { |
| 2319 | dutCmdResponse_t *staSendMGMTResp = &gGenericResp; |
| 2320 | |
| 2321 | wfaEncodeTLV(WFA_STA_SEND_COEXIST_MGMT_RESP_TLV, 4, (BYTE *)staSendMGMTResp, respBuf); |
| 2322 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2323 | |
| 2324 | return WFA_SUCCESS; |
| 2325 | |
| 2326 | } |
| 2327 | |
| 2328 | int wfaStaResetDefault(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2329 | { |
| 2330 | caStaResetDefault_t *reset = (caStaResetDefault_t *)caCmdBuf; |
| 2331 | dutCmdResponse_t *ResetResp = &gGenericResp; |
| 2332 | |
| 2333 | |
| 2334 | // need to make your own command available for this, here is only an example |
| 2335 | sprintf(gCmdStr, "myresetdefault %s program %s", reset->intf, reset->prog); |
| 2336 | system(gCmdStr); |
| 2337 | |
| 2338 | ResetResp->status = STATUS_COMPLETE; |
| 2339 | wfaEncodeTLV(WFA_STA_RESET_DEFAULT_RESP_TLV, 4, (BYTE *)ResetResp, respBuf); |
| 2340 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2341 | |
| 2342 | return WFA_SUCCESS; |
| 2343 | } |
| 2344 | |
| 2345 | #else |
| 2346 | |
| 2347 | int wfaStaTestBedCmd(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2348 | { |
| 2349 | dutCmdResponse_t *staCmdResp = &gGenericResp; |
| 2350 | |
| 2351 | wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf); |
| 2352 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2353 | |
| 2354 | return WFA_SUCCESS; |
| 2355 | } |
| 2356 | #endif |
| 2357 | |
| 2358 | /* |
| 2359 | * This is used to send a frame or action frame |
| 2360 | */ |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2361 | int wfaStaDevSendFrame(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2362 | { |
| 2363 | dutCommand_t *cmd = (dutCommand_t *)caCmdBuf; |
| 2364 | /* uncomment it if needed */ |
| 2365 | // char *ifname = cmd->intf; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2366 | dutCmdResponse_t *devSendResp = &gGenericResp; |
| 2367 | caStaDevSendFrame_t *sf = &cmd->cmdsu.sf; |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2368 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2369 | DPRINT_INFO(WFA_OUT, "Inside wfaStaDevSendFrame function ...\n"); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2370 | /* processing the frame */ |
| 2371 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2372 | switch(sf->program) |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2373 | { |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2374 | case PROG_TYPE_PMF: |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2375 | { |
| 2376 | pmfFrame_t *pmf = &sf->frameType.pmf; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2377 | switch(pmf->eFrameName) |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2378 | { |
| 2379 | case PMF_TYPE_DISASSOC: |
| 2380 | { |
| 2381 | /* use the protected to set what type of key to send */ |
| 2382 | |
| 2383 | } |
| 2384 | break; |
| 2385 | case PMF_TYPE_DEAUTH: |
| 2386 | { |
| 2387 | |
| 2388 | } |
| 2389 | break; |
| 2390 | case PMF_TYPE_SAQUERY: |
| 2391 | { |
| 2392 | |
| 2393 | } |
| 2394 | break; |
| 2395 | case PMF_TYPE_AUTH: |
| 2396 | { |
| 2397 | } |
| 2398 | break; |
| 2399 | case PMF_TYPE_ASSOCREQ: |
| 2400 | { |
| 2401 | } |
| 2402 | break; |
| 2403 | case PMF_TYPE_REASSOCREQ: |
| 2404 | { |
| 2405 | } |
| 2406 | break; |
| 2407 | } |
| 2408 | } |
| 2409 | break; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2410 | case PROG_TYPE_TDLS: |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2411 | { |
| 2412 | tdlsFrame_t *tdls = &sf->frameType.tdls; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2413 | switch(tdls->eFrameName) |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2414 | { |
| 2415 | case TDLS_TYPE_DISCOVERY: |
| 2416 | /* use the peer mac address to send the frame */ |
| 2417 | break; |
| 2418 | case TDLS_TYPE_SETUP: |
| 2419 | break; |
| 2420 | case TDLS_TYPE_TEARDOWN: |
| 2421 | break; |
| 2422 | case TDLS_TYPE_CHANNELSWITCH: |
| 2423 | break; |
| 2424 | case TDLS_TYPE_NULLFRAME: |
| 2425 | break; |
| 2426 | } |
| 2427 | } |
| 2428 | break; |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2429 | case PROG_TYPE_VENT: |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2430 | { |
| 2431 | ventFrame_t *vent = &sf->frameType.vent; |
| 2432 | switch(vent->type) |
| 2433 | { |
| 2434 | case VENT_TYPE_NEIGREQ: |
| 2435 | break; |
| 2436 | case VENT_TYPE_TRANSMGMT: |
| 2437 | break; |
| 2438 | } |
| 2439 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2440 | case PROG_TYPE_GEN: |
| 2441 | { |
| 2442 | /* General frames */ |
| 2443 | } |
| 2444 | |
| 2445 | |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2446 | } |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2447 | devSendResp->status = STATUS_COMPLETE; |
| 2448 | wfaEncodeTLV(WFA_STA_DEV_SEND_FRAME_RESP_TLV, 4, (BYTE *)devSendResp, respBuf); |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 2449 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2450 | |
| 2451 | return WFA_SUCCESS; |
| 2452 | } |
| 2453 | |
| 2454 | /* |
| 2455 | * This is used to set a temporary MAC address of an interface |
| 2456 | */ |
| 2457 | int wfaStaSetMacAddr(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2458 | { |
| 2459 | // Uncomment it if needed |
| 2460 | //dutCommand_t *cmd = (dutCommand_t *)caCmdBuf; |
| 2461 | // char *ifname = cmd->intf; |
| 2462 | dutCmdResponse_t *staCmdResp = &gGenericResp; |
| 2463 | // Uncomment it if needed |
| 2464 | //char *macaddr = &cmd->cmdsu.macaddr[0]; |
| 2465 | |
| 2466 | wfaEncodeTLV(WFA_STA_SET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf); |
| 2467 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2468 | |
| 2469 | return WFA_SUCCESS; |
| 2470 | } |
| 2471 | |
| 2472 | |
| 2473 | int wfaStaDisconnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2474 | { |
| 2475 | //dutCommand_t *disc = (dutCommand_t *)caCmdBuf; |
| 2476 | //char *intf = disc->intf; |
| 2477 | dutCmdResponse_t *staDiscResp = &gGenericResp; |
| 2478 | |
| 2479 | // stop the supplicant |
| 2480 | |
| 2481 | staDiscResp->status = STATUS_COMPLETE; |
| 2482 | |
| 2483 | wfaEncodeTLV(WFA_STA_DISCONNECT_RESP_TLV, 4, (BYTE *)staDiscResp, respBuf); |
| 2484 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 2485 | |
| 2486 | return WFA_SUCCESS; |
| 2487 | } |
| 2488 | |
| 2489 | /* Execute CLI, read the status from Environment variable */ |
| 2490 | int wfaExecuteCLI(char *CLI) |
| 2491 | { |
| 2492 | char *retstr; |
| 2493 | |
| 2494 | system(CLI); |
| 2495 | |
| 2496 | retstr = getenv("WFA_CLI_STATUS"); |
| 2497 | printf("cli status %s\n", retstr); |
| 2498 | return atoi(retstr); |
| 2499 | } |
| 2500 | |
| 2501 | /* Supporting Functions */ |
| 2502 | |
| 2503 | void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid) |
| 2504 | { |
| 2505 | int totalpkts; |
| 2506 | char cmdStr[128]; |
| 2507 | // char *addr = staPing->dipaddr; |
| 2508 | #ifdef WFA_PC_CONSOLE |
| 2509 | char addr[20]; |
| 2510 | char bflag[] = "-b"; |
| 2511 | char *tmpstr; |
| 2512 | int inum=0; |
| 2513 | #else |
| 2514 | char bflag[] = " "; |
| 2515 | #endif |
| 2516 | totalpkts = staPing->duration * staPing->frameRate; |
| 2517 | #ifdef WFA_PC_CONSOLE |
| 2518 | |
| 2519 | printf("\nCS : The Stream ID is %d",streamid); |
| 2520 | printf("\nCS :the addr is %s ",addr); |
| 2521 | strcpy(addr,staPing->dipaddr); |
| 2522 | printf("\nCS :Inside the WFA_PC_CONSLE BLOCK"); |
| 2523 | printf("\nCS :the addr is %s ",addr); |
| 2524 | tmpstr = strtok(addr, "."); |
| 2525 | |
| 2526 | inum = atoi(tmpstr); |
| 2527 | |
| 2528 | printf("interval %f\n", *interval); |
| 2529 | |
| 2530 | if(inum >= 224 && inum <= 239) // multicast |
| 2531 | { |
| 2532 | } |
| 2533 | else // if not MC, check if it is BC address |
| 2534 | { |
| 2535 | printf("\nCS :Inside the BC address BLOCK"); |
| 2536 | printf("\nCS :the inum %d",inum); |
| 2537 | strtok(NULL, "."); |
| 2538 | //strtok(NULL, "."); |
| 2539 | tmpstr = strtok(NULL, "."); |
| 2540 | printf("tmpstr %s\n", tmpstr); |
| 2541 | inum = atoi(tmpstr); |
| 2542 | printf("\nCS : The string is %s",tmpstr); |
| 2543 | if(inum != 255) |
| 2544 | memset(bflag, 0, strlen(bflag)); |
| 2545 | } |
| 2546 | #endif |
| 2547 | printf("\nCS : The Stream ID is %d",streamid); |
| 2548 | |
| 2549 | 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", |
| 2550 | streamid,streamid,bflag, staPing->dipaddr, *interval, totalpkts, staPing->frameSize,streamid); |
| 2551 | system(cmdStr); |
| 2552 | printf("\nCS : The command string is %s",cmdStr); |
| 2553 | |
| 2554 | sprintf(cmdStr, "updatepid.sh /tmp/spout_%d.txt",streamid); |
| 2555 | system(cmdStr); |
| 2556 | printf("\nCS : The command string is %s",cmdStr); |
| 2557 | |
| 2558 | } |
| 2559 | |
| 2560 | int wfaStopPing(dutCmdResponse_t *stpResp, int streamid) |
| 2561 | { |
| 2562 | char strout[256]; |
| 2563 | FILE *tmpfile = NULL; |
| 2564 | char cmdStr[128]; |
| 2565 | printf("Ping stop id %d\n", streamid); |
| 2566 | sprintf(cmdStr, "getpid.sh /tmp/spout_%d.txt /tmp/pid.txt",streamid); |
| 2567 | system(cmdStr); |
| 2568 | |
| 2569 | printf("\nCS : The command string is %s",cmdStr); |
| 2570 | |
| 2571 | system("stoping.sh /tmp/pid.txt ; sleep 2"); |
| 2572 | |
| 2573 | sprintf(cmdStr, "getpstats.sh /tmp/spout_%d.txt",streamid); |
| 2574 | system(cmdStr); |
| 2575 | |
| 2576 | printf("\nCS : The command string is %s",cmdStr); |
| 2577 | |
| 2578 | tmpfile = fopen("/tmp/stpsta.txt", "r+"); |
| 2579 | |
| 2580 | if(tmpfile == NULL) |
| 2581 | { |
| 2582 | return WFA_FAILURE; |
| 2583 | } |
| 2584 | |
| 2585 | if(fscanf(tmpfile, "%s", strout) != EOF) |
| 2586 | { |
| 2587 | if(*strout == '\0') |
| 2588 | { |
| 2589 | stpResp->cmdru.pingStp.sendCnt = 0; |
| 2590 | } |
| 2591 | |
| 2592 | else |
| 2593 | stpResp->cmdru.pingStp.sendCnt = atoi(strout); |
| 2594 | } |
| 2595 | |
| 2596 | printf("after scan sent count %i\n", stpResp->cmdru.pingStp.sendCnt); |
| 2597 | |
| 2598 | |
| 2599 | if(fscanf(tmpfile, "%s", strout) != EOF) |
| 2600 | { |
| 2601 | if(*strout == '\0') |
| 2602 | { |
| 2603 | stpResp->cmdru.pingStp.repliedCnt = 0; |
| 2604 | } |
| 2605 | else |
| 2606 | stpResp->cmdru.pingStp.repliedCnt = atoi(strout); |
| 2607 | } |
| 2608 | printf("after scan replied count %i\n", stpResp->cmdru.pingStp.repliedCnt); |
| 2609 | |
| 2610 | fclose(tmpfile); |
| 2611 | |
| 2612 | return WFA_SUCCESS; |
| 2613 | } |
| 2614 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 2615 | /* |
| 2616 | * wfaStaGetP2pDevAddress(): |
| 2617 | */ |
| 2618 | int wfaStaGetP2pDevAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2619 | { |
| 2620 | dutCmdResponse_t infoResp; |
| 2621 | /* dutCommand_t *getInfo = (dutCommand_t *)caCmdBuf; */ |
| 2622 | |
| 2623 | printf("\n Entry wfaStaGetP2pDevAddress... "); |
| 2624 | |
| 2625 | // Fetch the device ID and store into infoResp->cmdru.devid |
| 2626 | //strcpy(infoResp->cmdru.devid, str); |
| 2627 | strcpy(&infoResp.cmdru.devid[0], "ABCDEFGH"); |
| 2628 | |
| 2629 | |
| 2630 | infoResp.status = STATUS_COMPLETE; |
| 2631 | wfaEncodeTLV(WFA_STA_P2P_GET_DEV_ADDRESS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2632 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2633 | |
| 2634 | return WFA_SUCCESS; |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | |
| 2639 | /* |
| 2640 | * wfaStaSetP2p(): |
| 2641 | */ |
| 2642 | int wfaStaSetP2p(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2643 | { |
| 2644 | dutCmdResponse_t infoResp; |
| 2645 | /* caStaSetP2p_t *getStaSetP2p = (caStaSetP2p_t *)caCmdBuf; uncomment and use it*/ |
| 2646 | |
| 2647 | printf("\n Entry wfaStaSetP2p... "); |
| 2648 | |
| 2649 | // Implement the function and this does not return any thing back. |
| 2650 | |
| 2651 | infoResp.status = STATUS_COMPLETE; |
| 2652 | wfaEncodeTLV(WFA_STA_P2P_SETP2P_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2653 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2654 | |
| 2655 | return WFA_SUCCESS; |
| 2656 | } |
| 2657 | /* |
| 2658 | * wfaStaP2pConnect(): |
| 2659 | */ |
| 2660 | int wfaStaP2pConnect(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2661 | { |
| 2662 | dutCmdResponse_t infoResp; |
| 2663 | /* caStaP2pConnect_t *getStaP2pConnect = (caStaP2pConnect_t *)caCmdBuf; uncomment and use it */ |
| 2664 | |
| 2665 | printf("\n Entry wfaStaP2pConnect... "); |
| 2666 | |
| 2667 | // Implement the function and does not return anything. |
| 2668 | |
| 2669 | |
| 2670 | infoResp.status = STATUS_COMPLETE; |
| 2671 | wfaEncodeTLV(WFA_STA_P2P_CONNECT_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2672 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2673 | |
| 2674 | return WFA_SUCCESS; |
| 2675 | } |
| 2676 | |
| 2677 | /* |
| 2678 | * wfaStaStartAutoGo(): |
| 2679 | */ |
| 2680 | int wfaStaStartAutoGo(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2681 | { |
| 2682 | dutCmdResponse_t infoResp; |
| 2683 | //caStaStartAutoGo_t *getStaStartAutoGo = (caStaStartAutoGo_t *)caCmdBuf; |
| 2684 | |
| 2685 | printf("\n Entry wfaStaStartAutoGo... "); |
| 2686 | |
| 2687 | // Fetch the group ID and store into infoResp->cmdru.grpid |
| 2688 | strcpy(&infoResp.cmdru.grpid[0], "ABCDEFGH"); |
| 2689 | |
| 2690 | infoResp.status = STATUS_COMPLETE; |
| 2691 | wfaEncodeTLV(WFA_STA_P2P_START_AUTO_GO_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2692 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2693 | |
| 2694 | return WFA_SUCCESS; |
| 2695 | } |
| 2696 | |
| 2697 | |
| 2698 | |
| 2699 | |
| 2700 | /* |
| 2701 | * wfaStaP2pStartGrpFormation(): |
| 2702 | */ |
| 2703 | int wfaStaP2pStartGrpFormation(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2704 | { |
| 2705 | dutCmdResponse_t infoResp; |
| 2706 | //caStaP2pStartGrpForm_t *getStaP2pStartGrpForm = (caStaP2pStartGrpForm_t *)caCmdBuf; |
| 2707 | |
| 2708 | printf("\n Entry wfaStaP2pStartGrpFormation... "); |
| 2709 | |
| 2710 | // Fetch the device mode and put in infoResp->cmdru.p2presult |
| 2711 | //strcpy(infoResp->cmdru.p2presult, "GO"); |
| 2712 | |
| 2713 | // Fetch the device grp id and put in infoResp->cmdru.grpid |
| 2714 | //strcpy(infoResp->cmdru.grpid, "AA:BB:CC:DD:EE:FF_DIRECT-SSID"); |
| 2715 | |
| 2716 | strcpy(infoResp.cmdru.grpFormInfo.result, "CLIENT"); |
| 2717 | strcpy(infoResp.cmdru.grpFormInfo.grpId, "AA:BB:CC:DD:EE:FF_DIRECT-SSID"); |
| 2718 | |
| 2719 | |
| 2720 | infoResp.status = STATUS_COMPLETE; |
| 2721 | wfaEncodeTLV(WFA_STA_P2P_START_GRP_FORMATION_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2722 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2723 | |
| 2724 | return WFA_SUCCESS; |
| 2725 | } |
| 2726 | |
| 2727 | |
| 2728 | /* |
| 2729 | * wfaStaP2pDissolve(): |
| 2730 | */ |
| 2731 | int wfaStaP2pDissolve(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2732 | { |
| 2733 | dutCmdResponse_t infoResp; |
| 2734 | //caStaP2pDissolve_t *getStap2pDissolve= (caStaP2pDissolve_t *)caCmdBuf; |
| 2735 | |
| 2736 | printf("\n Entry wfaStaP2pDissolve... "); |
| 2737 | |
| 2738 | // Implement the function and this does not return any thing back. |
| 2739 | |
| 2740 | infoResp.status = STATUS_COMPLETE; |
| 2741 | wfaEncodeTLV(WFA_STA_P2P_DISSOLVE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2742 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2743 | |
| 2744 | return WFA_SUCCESS; |
| 2745 | } |
| 2746 | |
| 2747 | /* |
| 2748 | * wfaStaSendP2pInvReq(): |
| 2749 | */ |
| 2750 | int wfaStaSendP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2751 | { |
| 2752 | dutCmdResponse_t infoResp; |
| 2753 | /* caStaSendP2pInvReq_t *getStaP2pInvReq= (caStaSendP2pInvReq_t *)caCmdBuf; */ |
| 2754 | |
| 2755 | printf("\n Entry wfaStaSendP2pInvReq... "); |
| 2756 | |
| 2757 | // Implement the function and this does not return any thing back. |
| 2758 | |
| 2759 | infoResp.status = STATUS_COMPLETE; |
| 2760 | wfaEncodeTLV(WFA_STA_P2P_SEND_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2761 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2762 | |
| 2763 | return WFA_SUCCESS; |
| 2764 | } |
| 2765 | |
| 2766 | |
| 2767 | /* |
| 2768 | * wfaStaAcceptP2pInvReq(): |
| 2769 | */ |
| 2770 | int wfaStaAcceptP2pInvReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2771 | { |
| 2772 | dutCmdResponse_t infoResp; |
| 2773 | /* uncomment and use it |
| 2774 | * caStaAcceptP2pInvReq_t *getStaP2pInvReq= (caStaAcceptP2pInvReq_t *)caCmdBuf; |
| 2775 | */ |
| 2776 | |
| 2777 | printf("\n Entry wfaStaAcceptP2pInvReq... "); |
| 2778 | |
| 2779 | // Implement the function and this does not return any thing back. |
| 2780 | |
| 2781 | infoResp.status = STATUS_COMPLETE; |
| 2782 | wfaEncodeTLV(WFA_STA_P2P_ACCEPT_INV_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2783 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2784 | |
| 2785 | return WFA_SUCCESS; |
| 2786 | } |
| 2787 | |
| 2788 | |
| 2789 | /* |
| 2790 | * wfaStaSendP2pProvDisReq(): |
| 2791 | */ |
| 2792 | int wfaStaSendP2pProvDisReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2793 | { |
| 2794 | dutCmdResponse_t infoResp; |
| 2795 | /* uncomment and use it |
| 2796 | * caStaSendP2pProvDisReq_t *getStaP2pProvDisReq= (caStaSendP2pProvDisReq_t *)caCmdBuf; |
| 2797 | */ |
| 2798 | |
| 2799 | printf("\n Entry wfaStaSendP2pProvDisReq... "); |
| 2800 | |
| 2801 | // Implement the function and this does not return any thing back. |
| 2802 | |
| 2803 | infoResp.status = STATUS_COMPLETE; |
| 2804 | wfaEncodeTLV(WFA_STA_P2P_SEND_PROV_DIS_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2805 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2806 | |
| 2807 | return WFA_SUCCESS; |
| 2808 | } |
| 2809 | |
| 2810 | /* |
| 2811 | * wfaStaSetWpsPbc(): |
| 2812 | */ |
| 2813 | int wfaStaSetWpsPbc(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2814 | { |
| 2815 | dutCmdResponse_t infoResp; |
| 2816 | /* uncomment and use it |
| 2817 | * caStaSetWpsPbc_t *getStaSetWpsPbc= (caStaSetWpsPbc_t *)caCmdBuf; |
| 2818 | */ |
| 2819 | |
| 2820 | printf("\n Entry wfaStaSetWpsPbc... "); |
| 2821 | |
| 2822 | // Implement the function and this does not return any thing back. |
| 2823 | |
| 2824 | infoResp.status = STATUS_COMPLETE; |
| 2825 | wfaEncodeTLV(WFA_STA_WPS_SETWPS_PBC_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2826 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2827 | |
| 2828 | return WFA_SUCCESS; |
| 2829 | } |
| 2830 | |
| 2831 | /* |
| 2832 | * wfaStaWpsReadPin(): |
| 2833 | */ |
| 2834 | int wfaStaWpsReadPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2835 | { |
| 2836 | dutCmdResponse_t infoResp; |
| 2837 | /* uncomment and use it |
| 2838 | * caStaWpsReadPin_t *getStaWpsReadPin= (caStaWpsReadPin_t *)caCmdBuf; |
| 2839 | */ |
| 2840 | |
| 2841 | printf("\n Entry wfaStaWpsReadPin... "); |
| 2842 | |
| 2843 | // Fetch the device PIN and put in infoResp->cmdru.wpsPin |
| 2844 | //strcpy(infoResp->cmdru.wpsPin, "12345678"); |
| 2845 | strcpy(&infoResp.cmdru.wpsPin[0], "1234456"); |
| 2846 | |
| 2847 | |
| 2848 | infoResp.status = STATUS_COMPLETE; |
| 2849 | wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2850 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2851 | |
| 2852 | return WFA_SUCCESS; |
| 2853 | } |
| 2854 | |
| 2855 | |
| 2856 | |
| 2857 | /* |
| 2858 | * wfaStaWpsReadLabel(): |
| 2859 | */ |
| 2860 | int wfaStaWpsReadLabel(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2861 | { |
| 2862 | dutCmdResponse_t infoResp; |
| 2863 | /* uncomment and use it |
| 2864 | * caStaWpsReadLabel_t *getStaWpsReadLabel= (caStaWpsReadLabel_t *)caCmdBuf; |
| 2865 | */ |
| 2866 | |
| 2867 | printf("\n Entry wfaStaWpsReadLabel... "); |
| 2868 | |
| 2869 | // Fetch the device Label and put in infoResp->cmdru.wpsPin |
| 2870 | //strcpy(infoResp->cmdru.wpsPin, "12345678"); |
| 2871 | strcpy(&infoResp.cmdru.wpsPin[0], "1234456"); |
| 2872 | |
| 2873 | |
| 2874 | infoResp.status = STATUS_COMPLETE; |
| 2875 | wfaEncodeTLV(WFA_STA_WPS_READ_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2876 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2877 | |
| 2878 | return WFA_SUCCESS; |
| 2879 | } |
| 2880 | |
| 2881 | |
| 2882 | /* |
| 2883 | * wfaStaWpsEnterPin(): |
| 2884 | */ |
| 2885 | int wfaStaWpsEnterPin(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2886 | { |
| 2887 | dutCmdResponse_t infoResp; |
| 2888 | /* uncomment and use it |
| 2889 | * caStaWpsEnterPin_t *getStaWpsEnterPin= (caStaWpsEnterPin_t *)caCmdBuf; |
| 2890 | */ |
| 2891 | |
| 2892 | printf("\n Entry wfaStaWpsEnterPin... "); |
| 2893 | |
| 2894 | // Implement the function and this does not return any thing back. |
| 2895 | |
| 2896 | |
| 2897 | infoResp.status = STATUS_COMPLETE; |
| 2898 | wfaEncodeTLV(WFA_STA_WPS_ENTER_PIN_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2899 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2900 | |
| 2901 | return WFA_SUCCESS; |
| 2902 | } |
| 2903 | |
| 2904 | |
| 2905 | /* |
| 2906 | * wfaStaGetPsk(): |
| 2907 | */ |
| 2908 | int wfaStaGetPsk(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2909 | { |
| 2910 | dutCmdResponse_t infoResp; |
| 2911 | /* caStaGetPsk_t *getStaGetPsk= (caStaGetPsk_t *)caCmdBuf; uncomment and use it */ |
| 2912 | |
| 2913 | printf("\n Entry wfaStaGetPsk... "); |
| 2914 | |
| 2915 | |
| 2916 | // Fetch the device PP and SSID and put in infoResp->cmdru.pskInfo |
| 2917 | //strcpy(infoResp->cmdru.wpsPin, "12345678"); |
| 2918 | strcpy(&infoResp.cmdru.pskInfo.passPhrase[0], "1234456"); |
| 2919 | strcpy(&infoResp.cmdru.pskInfo.ssid[0], "WIFI_DIRECT"); |
| 2920 | |
| 2921 | |
| 2922 | infoResp.status = STATUS_COMPLETE; |
| 2923 | wfaEncodeTLV(WFA_STA_P2P_GET_PSK_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2924 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2925 | |
| 2926 | return WFA_SUCCESS; |
| 2927 | } |
| 2928 | |
| 2929 | /* |
| 2930 | * wfaStaP2pReset(): |
| 2931 | */ |
| 2932 | int wfaStaP2pReset(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2933 | { |
| 2934 | dutCmdResponse_t infoResp; |
| 2935 | /* dutCommand_t *getStaP2pReset= (dutCommand_t *)caCmdBuf; */ |
| 2936 | |
| 2937 | printf("\n Entry wfaStaP2pReset... "); |
| 2938 | // Implement the function and this does not return any thing back. |
| 2939 | |
| 2940 | |
| 2941 | |
| 2942 | infoResp.status = STATUS_COMPLETE; |
| 2943 | wfaEncodeTLV(WFA_STA_P2P_RESET_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2944 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2945 | |
| 2946 | return WFA_SUCCESS; |
| 2947 | } |
| 2948 | |
| 2949 | |
| 2950 | |
| 2951 | /* |
| 2952 | * wfaStaGetP2pIpConfig(): |
| 2953 | */ |
| 2954 | int wfaStaGetP2pIpConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2955 | { |
| 2956 | dutCmdResponse_t infoResp; |
| 2957 | /* caStaGetP2pIpConfig_t *staGetP2pIpConfig= (caStaGetP2pIpConfig_t *)caCmdBuf; */ |
| 2958 | |
| 2959 | caStaGetIpConfigResp_t *ifinfo = &(infoResp.cmdru.getIfconfig); |
| 2960 | |
| 2961 | printf("\n Entry wfaStaGetP2pIpConfig... "); |
| 2962 | |
| 2963 | |
| 2964 | // Fetch the device IP config and put in infoResp->cmdru |
| 2965 | //strcpy(infoResp->cmdru.wpsPin, "12345678"); |
| 2966 | ifinfo->isDhcp =0; |
| 2967 | strcpy(&(ifinfo->ipaddr[0]), "192.165.100.111"); |
| 2968 | strcpy(&(ifinfo->mask[0]), "255.255.255.0"); |
| 2969 | strcpy(&(ifinfo->dns[0][0]), "192.165.100.1"); |
| 2970 | strcpy(&(ifinfo->mac[0]), "ba:ba:ba:ba:ba:ba"); |
| 2971 | |
| 2972 | |
| 2973 | infoResp.status = STATUS_COMPLETE; |
| 2974 | wfaEncodeTLV(WFA_STA_P2P_GET_IP_CONFIG_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2975 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2976 | |
| 2977 | return WFA_SUCCESS; |
| 2978 | } |
| 2979 | |
| 2980 | |
| 2981 | |
| 2982 | |
| 2983 | /* |
| 2984 | * wfaStaSendServiceDiscoveryReq(): |
| 2985 | */ |
| 2986 | int wfaStaSendServiceDiscoveryReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 2987 | { |
| 2988 | dutCmdResponse_t infoResp; |
| 2989 | /* caStaSendServiceDiscoveryReq_t *staSendServiceDiscoveryReq= (caStaSendServiceDiscoveryReq_t *)caCmdBuf; uncomment and use it */ |
| 2990 | |
| 2991 | printf("\n Entry wfaStaSendServiceDiscoveryReq... "); |
| 2992 | // Implement the function and this does not return any thing back. |
| 2993 | |
| 2994 | |
| 2995 | |
| 2996 | infoResp.status = STATUS_COMPLETE; |
| 2997 | wfaEncodeTLV(WFA_STA_P2P_SEND_SERVICE_DISCOVERY_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 2998 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 2999 | |
| 3000 | return WFA_SUCCESS; |
| 3001 | } |
| 3002 | |
| 3003 | |
| 3004 | |
| 3005 | /* |
| 3006 | * wfaStaSendP2pPresenceReq(): |
| 3007 | */ |
| 3008 | int wfaStaSendP2pPresenceReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3009 | { |
| 3010 | dutCmdResponse_t infoResp; |
| 3011 | caStaSendP2pPresenceReq_t *staSendP2pPresenceReq= (caStaSendP2pPresenceReq_t *)caCmdBuf; |
| 3012 | |
| 3013 | printf("\n Entry wfaStaSendP2pPresenceReq... "); |
| 3014 | // Implement the function and this does not return any thing back. |
| 3015 | printf("\n The long long Duration: %lld... ",staSendP2pPresenceReq->duration); |
| 3016 | printf("\n The long long interval : %lld.. ",staSendP2pPresenceReq->interval); |
| 3017 | |
| 3018 | |
| 3019 | |
| 3020 | infoResp.status = STATUS_COMPLETE; |
| 3021 | wfaEncodeTLV(WFA_STA_P2P_SEND_PRESENCE_REQ_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 3022 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 3023 | |
| 3024 | return WFA_SUCCESS; |
| 3025 | } |
| 3026 | |
| 3027 | /* |
| 3028 | * wfaStaSetSleepReq(): |
| 3029 | */ |
| 3030 | int wfaStaSetSleepReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3031 | { |
| 3032 | dutCmdResponse_t infoResp; |
| 3033 | /* caStaSetSleep_t *staSetSleepReq= (caStaSetSleep_t *)caCmdBuf; */ |
| 3034 | |
| 3035 | printf("\n Entry wfaStaSetSleepReq... "); |
| 3036 | // Implement the function and this does not return any thing back. |
| 3037 | |
| 3038 | |
| 3039 | infoResp.status = STATUS_COMPLETE; |
| 3040 | wfaEncodeTLV(WFA_STA_P2P_SET_SLEEP_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 3041 | *respLen = WFA_TLV_HDR_LEN +4; |
| 3042 | |
| 3043 | return WFA_SUCCESS; |
| 3044 | } |
| 3045 | |
| 3046 | /* |
| 3047 | * wfaStaSetOpportunisticPsReq(): |
| 3048 | */ |
| 3049 | int wfaStaSetOpportunisticPsReq(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3050 | { |
| 3051 | dutCmdResponse_t infoResp; |
| 3052 | /* caStaSetOpprPs_t *staSetOpperPsReq= (caStaSetOpprPs_t *)caCmdBuf; uncomment and use it */ |
| 3053 | |
| 3054 | printf("\n Entry wfaStaSetOpportunisticPsReq... "); |
| 3055 | // Implement the function and this does not return any thing back. |
| 3056 | |
| 3057 | |
| 3058 | infoResp.status = STATUS_COMPLETE; |
| 3059 | wfaEncodeTLV(WFA_STA_P2P_SET_OPPORTUNISTIC_PS_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 3060 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3061 | |
| 3062 | return WFA_SUCCESS; |
| 3063 | } |
| 3064 | #ifndef WFA_STA_TB |
| 3065 | /* |
| 3066 | * wfaStaPresetParams(): |
| 3067 | */ |
| 3068 | |
| 3069 | int wfaStaPresetParams(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3070 | { |
| 3071 | dutCmdResponse_t infoResp; |
| 3072 | |
| 3073 | caStaPresetParameters_t *presetParams = (caStaPresetParameters_t *)caCmdBuf; |
| 3074 | |
| 3075 | |
| 3076 | DPRINT_INFO(WFA_OUT, "Inside wfaStaPresetParameters function ...\n"); |
| 3077 | |
| 3078 | // Implement the function and its sub commands |
| 3079 | infoResp.status = STATUS_COMPLETE; |
| 3080 | |
| 3081 | wfaEncodeTLV(WFA_STA_PRESET_PARAMETERS_RESP_TLV, 4, (BYTE *)&infoResp, respBuf); |
| 3082 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3083 | |
| 3084 | return WFA_SUCCESS; |
| 3085 | } |
| 3086 | int wfaStaSet11n(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3087 | { |
| 3088 | |
| 3089 | caSta11n_t * v11nParams = (caSta11n_t *)caCmdBuf; |
| 3090 | dutCmdResponse_t infoResp; |
| 3091 | dutCmdResponse_t *v11nParamsResp = &infoResp; |
| 3092 | |
| 3093 | |
| 3094 | |
| 3095 | int st =0; // SUCCESS |
| 3096 | |
| 3097 | DPRINT_INFO(WFA_OUT, "Inside wfaStaSet11n function....\n"); |
| 3098 | |
| 3099 | |
| 3100 | if(v11nParams->addba_reject != 0xFF && v11nParams->addba_reject < 2) |
| 3101 | { |
| 3102 | // implement the funciton |
| 3103 | //st = wfaExecuteCLI(gCmdStr); |
| 3104 | if(st != 0) |
| 3105 | { |
| 3106 | v11nParamsResp->status = STATUS_ERROR; |
| 3107 | strcpy(v11nParamsResp->cmdru.info, "set_addba_reject failed"); |
| 3108 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3109 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3110 | return FALSE; |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | if(v11nParams->ampdu != 0xFF && v11nParams->ampdu < 2) |
| 3115 | { |
| 3116 | // implement the funciton |
| 3117 | //st = wfaExecuteCLI(gCmdStr); |
| 3118 | |
| 3119 | if(st != 0) |
| 3120 | { |
| 3121 | v11nParamsResp->status = STATUS_ERROR; |
| 3122 | strcpy(v11nParamsResp->cmdru.info, "set_ampdu failed"); |
| 3123 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3124 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3125 | return FALSE; |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | if(v11nParams->amsdu != 0xFF && v11nParams->amsdu < 2) |
| 3130 | { |
| 3131 | // implement the funciton |
| 3132 | //st = wfaExecuteCLI(gCmdStr); |
| 3133 | if(st != 0) |
| 3134 | { |
| 3135 | v11nParamsResp->status = STATUS_ERROR; |
| 3136 | strcpy(v11nParamsResp->cmdru.info, "set_amsdu failed"); |
| 3137 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3138 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3139 | return FALSE; |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | if(v11nParams->greenfield != 0xFF && v11nParams->greenfield < 2) |
| 3144 | { |
| 3145 | // implement the funciton |
| 3146 | //st = wfaExecuteCLI(gCmdStr); |
| 3147 | if(st != 0) |
| 3148 | { |
| 3149 | v11nParamsResp->status = STATUS_ERROR; |
| 3150 | strcpy(v11nParamsResp->cmdru.info, "_set_greenfield failed"); |
| 3151 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3152 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3153 | return FALSE; |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | if(v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] != '\0') |
| 3158 | { |
| 3159 | // implement the funciton |
| 3160 | //st = wfaExecuteCLI(gCmdStr); |
| 3161 | if(st != 0) |
| 3162 | { |
| 3163 | v11nParamsResp->status = STATUS_ERROR; |
| 3164 | strcpy(v11nParamsResp->cmdru.info, "set_mcs failed"); |
| 3165 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3166 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3167 | return FALSE; |
| 3168 | } |
| 3169 | } |
| 3170 | else if (v11nParams->mcs32!= 0xFF && v11nParams->mcs32 < 2 && v11nParams->mcs_fixedrate[0] == '\0') |
| 3171 | { |
| 3172 | // implement the funciton |
| 3173 | //st = wfaExecuteCLI(gCmdStr); |
| 3174 | if(st != 0) |
| 3175 | { |
| 3176 | v11nParamsResp->status = STATUS_ERROR; |
| 3177 | strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed"); |
| 3178 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3179 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3180 | return FALSE; |
| 3181 | } |
| 3182 | |
| 3183 | } |
| 3184 | else if (v11nParams->mcs32 == 0xFF && v11nParams->mcs_fixedrate[0] != '\0') |
| 3185 | { |
| 3186 | // implement the funciton |
| 3187 | //st = wfaExecuteCLI(gCmdStr); |
| 3188 | if(st != 0) |
| 3189 | { |
| 3190 | v11nParamsResp->status = STATUS_ERROR; |
| 3191 | strcpy(v11nParamsResp->cmdru.info, "set_mcs32 failed"); |
| 3192 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3193 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3194 | return FALSE; |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | if(v11nParams->rifs_test != 0xFF && v11nParams->rifs_test < 2) |
| 3199 | { |
| 3200 | // implement the funciton |
| 3201 | //st = wfaExecuteCLI(gCmdStr); |
| 3202 | if(st != 0) |
| 3203 | { |
| 3204 | v11nParamsResp->status = STATUS_ERROR; |
| 3205 | strcpy(v11nParamsResp->cmdru.info, "set_rifs_test failed"); |
| 3206 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3207 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3208 | return FALSE; |
| 3209 | } |
| 3210 | } |
| 3211 | |
| 3212 | if(v11nParams->sgi20 != 0xFF && v11nParams->sgi20 < 2) |
| 3213 | { |
| 3214 | // implement the funciton |
| 3215 | //st = wfaExecuteCLI(gCmdStr); |
| 3216 | if(st != 0) |
| 3217 | { |
| 3218 | v11nParamsResp->status = STATUS_ERROR; |
| 3219 | strcpy(v11nParamsResp->cmdru.info, "set_sgi20 failed"); |
| 3220 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3221 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3222 | return FALSE; |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | if(v11nParams->smps != 0xFFFF) |
| 3227 | { |
| 3228 | if(v11nParams->smps == 0) |
| 3229 | { |
| 3230 | // implement the funciton |
| 3231 | //st = wfaExecuteCLI(gCmdStr); |
| 3232 | ; |
| 3233 | |
| 3234 | } |
| 3235 | else if(v11nParams->smps == 1) |
| 3236 | { |
| 3237 | // implement the funciton |
| 3238 | //st = wfaExecuteCLI(gCmdStr); |
| 3239 | ; |
| 3240 | } |
| 3241 | else if(v11nParams->smps == 2) |
| 3242 | { |
| 3243 | // implement the funciton |
| 3244 | //st = wfaExecuteCLI(gCmdStr); |
| 3245 | ; |
| 3246 | } |
| 3247 | if(st != 0) |
| 3248 | { |
| 3249 | v11nParamsResp->status = STATUS_ERROR; |
| 3250 | strcpy(v11nParamsResp->cmdru.info, "set_smps failed"); |
| 3251 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3252 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3253 | return FALSE; |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | if(v11nParams->stbc_rx != 0xFFFF) |
| 3258 | { |
| 3259 | // implement the funciton |
| 3260 | //st = wfaExecuteCLI(gCmdStr); |
| 3261 | if(st != 0) |
| 3262 | { |
| 3263 | v11nParamsResp->status = STATUS_ERROR; |
| 3264 | strcpy(v11nParamsResp->cmdru.info, "set_stbc_rx failed"); |
| 3265 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3266 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3267 | return FALSE; |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | if(v11nParams->width[0] != '\0') |
| 3272 | { |
| 3273 | // implement the funciton |
| 3274 | //st = wfaExecuteCLI(gCmdStr); |
| 3275 | if(st != 0) |
| 3276 | { |
| 3277 | v11nParamsResp->status = STATUS_ERROR; |
| 3278 | strcpy(v11nParamsResp->cmdru.info, "set_11n_channel_width failed"); |
| 3279 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3280 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3281 | return FALSE; |
| 3282 | } |
| 3283 | |
| 3284 | } |
| 3285 | |
| 3286 | if(v11nParams->_40_intolerant != 0xFF && v11nParams->_40_intolerant < 2) |
| 3287 | { |
| 3288 | // implement the funciton |
| 3289 | //st = wfaExecuteCLI(gCmdStr); |
| 3290 | if(st != 0) |
| 3291 | { |
| 3292 | v11nParamsResp->status = STATUS_ERROR; |
| 3293 | strcpy(v11nParamsResp->cmdru.info, "set_40_intolerant failed"); |
| 3294 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3295 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3296 | return FALSE; |
| 3297 | } |
| 3298 | |
| 3299 | } |
| 3300 | |
| 3301 | if(v11nParams->txsp_stream != 0 && v11nParams->txsp_stream <4) |
| 3302 | { |
| 3303 | // implement the funciton |
| 3304 | //st = wfaExecuteCLI(gCmdStr); |
| 3305 | if(st != 0) |
| 3306 | { |
| 3307 | v11nParamsResp->status = STATUS_ERROR; |
| 3308 | strcpy(v11nParamsResp->cmdru.info, "set_txsp_stream 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 | } |
| 3315 | |
| 3316 | if(v11nParams->rxsp_stream != 0 && v11nParams->rxsp_stream < 4) |
| 3317 | { |
| 3318 | // implement the funciton |
| 3319 | //st = wfaExecuteCLI(gCmdStr); |
| 3320 | if(st != 0) |
| 3321 | { |
| 3322 | v11nParamsResp->status = STATUS_ERROR; |
| 3323 | strcpy(v11nParamsResp->cmdru.info, "set_rxsp_stream failed"); |
| 3324 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)v11nParamsResp, respBuf); |
| 3325 | *respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t); |
| 3326 | return FALSE; |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | v11nParamsResp->status = STATUS_COMPLETE; |
| 3331 | wfaEncodeTLV(WFA_STA_SET_11N_RESP_TLV, 4, (BYTE *)v11nParamsResp, respBuf); |
| 3332 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3333 | return WFA_SUCCESS; |
| 3334 | } |
| 3335 | #endif |
| 3336 | /* |
| 3337 | * wfaStaAddArpTableEntry(): |
| 3338 | */ |
| 3339 | int wfaStaAddArpTableEntry(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3340 | { |
| 3341 | dutCmdResponse_t infoResp; |
| 3342 | /* caStaAddARPTableEntry_t *staAddARPTableEntry= (caStaAddARPTableEntry_t *)caCmdBuf; uncomment and use it */ |
| 3343 | |
| 3344 | printf("\n Entry wfastaAddARPTableEntry... "); |
| 3345 | // Implement the function and this does not return any thing back. |
| 3346 | |
| 3347 | infoResp.status = STATUS_COMPLETE; |
| 3348 | wfaEncodeTLV(WFA_STA_P2P_ADD_ARP_TABLE_ENTRY_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 3349 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 3350 | |
| 3351 | return WFA_SUCCESS; |
| 3352 | } |
| 3353 | |
| 3354 | /* |
| 3355 | * wfaStaBlockICMPResponse(): |
| 3356 | */ |
| 3357 | int wfaStaBlockICMPResponse(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3358 | { |
| 3359 | dutCmdResponse_t infoResp; |
| 3360 | /* caStaBlockICMPResponse_t *staAddARPTableEntry= (caStaBlockICMPResponse_t *)caCmdBuf; uncomment and use it */ |
| 3361 | |
| 3362 | printf("\n Entry wfaStaBlockICMPResponse... "); |
| 3363 | // Implement the function and this does not return any thing back. |
| 3364 | |
| 3365 | infoResp.status = STATUS_COMPLETE; |
| 3366 | wfaEncodeTLV(WFA_STA_P2P_BLOCK_ICMP_RESPONSE_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 3367 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 3368 | |
| 3369 | return WFA_SUCCESS; |
| 3370 | } |
Ankur Vachhani | e1b4fbc | 2011-12-26 09:40:02 +0000 | [diff] [blame] | 3371 | int wfaStaSetRadio(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3372 | { |
| 3373 | dutCommand_t *setRadio = (dutCommand_t *)caCmdBuf; |
| 3374 | dutCmdResponse_t *staCmdResp = &gGenericResp; |
| 3375 | char *str; |
| 3376 | caStaSetRadio_t *sr = &setRadio->cmdsu.sr; |
| 3377 | |
| 3378 | if(sr->mode == WFA_OFF) |
| 3379 | { |
| 3380 | // turn radio off |
| 3381 | } |
| 3382 | else |
| 3383 | { |
| 3384 | // always turn the radio on |
| 3385 | } |
| 3386 | |
| 3387 | staCmdResp->status = STATUS_COMPLETE; |
| 3388 | wfaEncodeTLV(WFA_STA_SET_RADIO_RESP_TLV, 4, (BYTE *)staCmdResp, respBuf); |
| 3389 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3390 | |
| 3391 | return WFA_SUCCESS; |
| 3392 | } |
| 3393 | |
| 3394 | int wfaStaSetRFeature(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3395 | { |
| 3396 | dutCommand_t *dutCmd = (dutCommand_t *)caCmdBuf; |
| 3397 | caStaRFeat_t *rfeat = &dutCmd->cmdsu.rfeat; |
| 3398 | dutCmdResponse_t *caResp = &gGenericResp; |
| 3399 | char *intf = dutCmd->intf; |
| 3400 | |
| 3401 | if(strcasecmp(rfeat->prog, "tdls") == 0) |
| 3402 | { |
| 3403 | |
| 3404 | |
| 3405 | } |
| 3406 | |
| 3407 | caResp->status = STATUS_COMPLETE; |
| 3408 | wfaEncodeTLV(WFA_STA_SET_RFEATURE_RESP_TLV, 4, (BYTE *)caResp, respBuf); |
| 3409 | *respLen = WFA_TLV_HDR_LEN + 4; |
| 3410 | |
| 3411 | return WFA_SUCCESS; |
| 3412 | } |
| 3413 | |
| 3414 | |
Ankur Vachhani | c485b71 | 2012-02-15 23:29:49 +0000 | [diff] [blame^] | 3415 | int wfaStaCliCommand(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf) |
| 3416 | { |
| 3417 | |
| 3418 | char cmdName[32]; |
| 3419 | char * pcmdStr,*str; |
| 3420 | int st,tmp_val; |
| 3421 | char CmdStr[WFA_CMD_STR_SZ]; |
| 3422 | FILE *wfaCliFd; |
| 3423 | char wfaCliBuff[64]; |
| 3424 | char retstr[256]; |
| 3425 | int CmdReturnFlag; |
| 3426 | char tmp[256]; |
| 3427 | FILE * sh_pipe; |
| 3428 | |
| 3429 | caStaCliCmdResp_t infoResp; |
| 3430 | |
| 3431 | printf("\n Entry wfaStaCliCommand... "); |
| 3432 | |
| 3433 | printf("The command Received: %s",caCmdBuf); |
| 3434 | |
| 3435 | memcpy(cmdName, strtok_r((char *)caCmdBuf, ",", (char **)&pcmdStr), 32); |
| 3436 | |
| 3437 | sprintf(CmdStr, "%s",cmdName); |
| 3438 | |
| 3439 | |
| 3440 | |
| 3441 | |
| 3442 | for(;;) |
| 3443 | { |
| 3444 | str = strtok_r(NULL, ",", &pcmdStr); |
| 3445 | if(str == NULL || str[0] == '\0') |
| 3446 | break; |
| 3447 | else |
| 3448 | { |
| 3449 | sprintf(CmdStr, "%s /%s",CmdStr,str); |
| 3450 | str = strtok_r(NULL, ",", &pcmdStr); |
| 3451 | sprintf(CmdStr, "%s %s",CmdStr,str); |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | CmdReturnFlag =0; |
| 3456 | // check the return process |
| 3457 | wfaCliFd=fopen("/etc/WfaEndpoint/wfa_cli.txt","r"); |
| 3458 | if(wfaCliFd!= NULL) |
| 3459 | { |
| 3460 | while(fgets(wfaCliBuff, 64, wfaCliFd) != NULL) |
| 3461 | { |
| 3462 | //printf("\nLine read from CLI file : %s",wfaCliBuff); |
| 3463 | if(ferror(wfaCliFd)) |
| 3464 | break; |
| 3465 | str=strtok(wfaCliBuff,"-"); |
| 3466 | if(strcmp(str,cmdName) == 0) |
| 3467 | { |
| 3468 | str=strtok(NULL,","); |
| 3469 | //printf("\n The str: %s Check\n",str); |
| 3470 | if(strcmp(str,"TRUE") == 0) |
| 3471 | CmdReturnFlag =1; |
| 3472 | break; |
| 3473 | } |
| 3474 | } |
| 3475 | fclose(wfaCliFd); |
| 3476 | |
| 3477 | } |
| 3478 | |
| 3479 | |
| 3480 | //printf("\n Command Return Flag : %d",CmdReturnFlag); |
| 3481 | st = 1; |
| 3482 | memset(&retstr[0],'\0',255); |
| 3483 | memset(&tmp[0],'\0',255); |
| 3484 | |
| 3485 | sprintf(gCmdStr, "%s", CmdStr); |
| 3486 | printf("\nCLI Command -- %s\n", gCmdStr); |
| 3487 | |
| 3488 | sh_pipe = popen(gCmdStr,"r"); |
| 3489 | |
| 3490 | if(!sh_pipe) |
| 3491 | { |
| 3492 | printf ("Error in opening pipe"); |
| 3493 | } |
| 3494 | |
| 3495 | |
| 3496 | //tmp_val=getdelim(&retstr,255,"\n",sh_pipe); |
| 3497 | fgets(&retstr,255,sh_pipe); |
| 3498 | |
| 3499 | if(pclose(sh_pipe) != 0) |
| 3500 | { |
| 3501 | printf("Error in closing shell cmd pipe"); |
| 3502 | } |
| 3503 | sleep(2); |
| 3504 | |
| 3505 | printf("CLI retun value- %s\n",retstr); |
| 3506 | |
| 3507 | memcpy(tmp, strtok_r((char *)retstr, "-", (char **)&pcmdStr), 2); |
| 3508 | printf("\ncli status - %s",tmp); |
| 3509 | if(strlen(tmp) > 0) |
| 3510 | st = atoi(tmp); |
| 3511 | |
| 3512 | infoResp.resFlag=CmdReturnFlag; |
| 3513 | |
| 3514 | switch(st) |
| 3515 | { |
| 3516 | case 0: |
| 3517 | infoResp.status = STATUS_COMPLETE; |
| 3518 | if (CmdReturnFlag) |
| 3519 | { |
| 3520 | str=strtok_r(NULL, "\n", (char **)&pcmdStr); |
| 3521 | strncpy(tmp,str, 255); |
| 3522 | printf("\nresult - %s",tmp); |
| 3523 | if(tmp != NULL) |
| 3524 | { |
| 3525 | memset(&infoResp.result[0],'\0',WFA_CLI_CMD_RESP_LEN-1); |
| 3526 | strncpy(&infoResp.result[0], tmp,(strlen(tmp) < WFA_CLI_CMD_RESP_LEN ) ? strlen(tmp) : (WFA_CLI_CMD_RESP_LEN-1) ); |
| 3527 | printf("Return CLI result to CA: %s****\n", &infoResp.result[0]); |
| 3528 | } |
| 3529 | else |
| 3530 | strcpy(&infoResp.result[0], "ENV_VAR_NOT_DEFINED"); |
| 3531 | |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | break; |
| 3536 | case 1: |
| 3537 | infoResp.status = STATUS_ERROR; |
| 3538 | break; |
| 3539 | case 2: |
| 3540 | infoResp.status = STATUS_INVALID; |
| 3541 | break; |
| 3542 | } |
| 3543 | |
| 3544 | wfaEncodeTLV(WFA_STA_CLI_CMD_RESP_TLV, sizeof(infoResp), (BYTE *)&infoResp, respBuf); |
| 3545 | *respLen = WFA_TLV_HDR_LEN + sizeof(infoResp); |
| 3546 | |
| 3547 | printf("\nExit from CLI function\n"); |
| 3548 | return TRUE; |
| 3549 | |
| 3550 | |
| 3551 | } |
| 3552 | |