Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (station/AP) |
| 3 | * Copyright (c) 2014-2015, Qualcomm Atheros, Inc. |
| 4 | * All Rights Reserved. |
| 5 | * Licensed under the Clear BSD license. See README for more details. |
| 6 | */ |
| 7 | |
| 8 | #include "sigma_dut.h" |
| 9 | #include <sys/stat.h> |
| 10 | #include "wpa_helpers.h" |
| 11 | |
| 12 | enum driver_type wifi_chip_type = DRIVER_NOT_SET; |
| 13 | enum openwrt_driver_type openwrt_chip_type = OPENWRT_DRIVER_NOT_SET; |
| 14 | |
| 15 | |
| 16 | int file_exists(const char *fname) |
| 17 | { |
| 18 | struct stat s; |
| 19 | return stat(fname, &s) == 0; |
| 20 | } |
| 21 | |
| 22 | |
| 23 | int set_wifi_chip(const char *chip_type) |
| 24 | { |
| 25 | if (!strncmp(chip_type, "WCN", strlen("WCN"))) |
| 26 | wifi_chip_type = DRIVER_WCN; |
| 27 | else if (!strncmp(chip_type, "ATHEROS", strlen("ATHEROS"))) |
| 28 | wifi_chip_type = DRIVER_ATHEROS; |
| 29 | else if (!strncmp(chip_type, "AR6003", strlen("AR6003"))) |
| 30 | wifi_chip_type = DRIVER_AR6003; |
| 31 | else if (strcmp(chip_type, "MAC80211") == 0) |
| 32 | wifi_chip_type = DRIVER_MAC80211; |
| 33 | else if (strcmp(chip_type, "QNXNTO") == 0) |
| 34 | wifi_chip_type = DRIVER_QNXNTO; |
| 35 | else if (strcmp(chip_type, "OPENWRT") == 0) |
| 36 | wifi_chip_type = DRIVER_OPENWRT; |
Sreelakshmi Konamki | b692f10 | 2016-04-26 19:47:00 +0530 | [diff] [blame] | 37 | else if (!strncmp(chip_type, "LINUX-WCN", strlen("LINUX-WCN"))) |
| 38 | wifi_chip_type = DRIVER_LINUX_WCN; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 39 | else |
| 40 | return -1; |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | enum driver_type get_driver_type(void) |
| 47 | { |
| 48 | struct stat s; |
| 49 | if (wifi_chip_type == DRIVER_NOT_SET) { |
| 50 | /* Check for 60G driver */ |
| 51 | ssize_t len; |
| 52 | char link[256]; |
| 53 | char buf[256]; |
| 54 | char *ifname = get_station_ifname(); |
| 55 | |
| 56 | snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/driver", |
| 57 | ifname); |
| 58 | len = readlink(buf, link, sizeof(link) - 1); |
| 59 | if (len >= 0) { |
| 60 | link[len] = '\0'; |
| 61 | if (strstr(link, DRIVER_NAME_60G)) |
| 62 | return DRIVER_WIL6210; |
| 63 | } |
| 64 | |
| 65 | if (stat("/sys/module/mac80211", &s) == 0) |
| 66 | return DRIVER_MAC80211; |
| 67 | return DRIVER_ATHEROS; |
| 68 | } |
| 69 | return wifi_chip_type; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | enum openwrt_driver_type get_openwrt_driver_type(void) |
| 74 | { |
| 75 | struct stat s; |
| 76 | |
| 77 | if (openwrt_chip_type == OPENWRT_DRIVER_NOT_SET) { |
Sarvepalli, Rajesh Babu | a62e20a | 2016-07-08 18:10:30 +0530 | [diff] [blame^] | 78 | if (stat("/sys/module/umac", &s) == 0) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 79 | openwrt_chip_type = OPENWRT_DRIVER_ATHEROS; |
| 80 | } |
| 81 | |
| 82 | return openwrt_chip_type; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | enum sigma_program sigma_program_to_enum(const char *prog) |
| 87 | { |
| 88 | if (prog == NULL) |
| 89 | return PROGRAM_UNKNOWN; |
| 90 | |
| 91 | if (strcasecmp(prog, "TDLS") == 0) |
| 92 | return PROGRAM_TDLS; |
| 93 | if (strcasecmp(prog, "HS2") == 0) |
| 94 | return PROGRAM_HS2; |
| 95 | if (strcasecmp(prog, "HS2_R2") == 0 || |
| 96 | strcasecmp(prog, "HS2-R2") == 0) |
| 97 | return PROGRAM_HS2_R2; |
| 98 | if (strcasecmp(prog, "WFD") == 0) |
| 99 | return PROGRAM_WFD; |
| 100 | if (strcasecmp(prog, "PMF") == 0) |
| 101 | return PROGRAM_PMF; |
| 102 | if (strcasecmp(prog, "WPS") == 0) |
| 103 | return PROGRAM_WPS; |
| 104 | if (strcasecmp(prog, "11n") == 0) |
| 105 | return PROGRAM_HT; |
| 106 | if (strcasecmp(prog, "VHT") == 0) |
| 107 | return PROGRAM_VHT; |
| 108 | if (strcasecmp(prog, "60GHZ") == 0) |
| 109 | return PROGRAM_60GHZ; |
| 110 | if (strcasecmp(prog, "NAN") == 0) |
| 111 | return PROGRAM_NAN; |
| 112 | |
| 113 | return PROGRAM_UNKNOWN; |
| 114 | } |