blob: e2fcb85e803b6adf742ee6f9eedd6bd85d31b816 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
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
12enum driver_type wifi_chip_type = DRIVER_NOT_SET;
13enum openwrt_driver_type openwrt_chip_type = OPENWRT_DRIVER_NOT_SET;
14
15
16int file_exists(const char *fname)
17{
18 struct stat s;
19 return stat(fname, &s) == 0;
20}
21
22
23int 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;
37 else
38 return -1;
39
40 return 0;
41}
42
43
44enum driver_type get_driver_type(void)
45{
46 struct stat s;
47 if (wifi_chip_type == DRIVER_NOT_SET) {
48 /* Check for 60G driver */
49 ssize_t len;
50 char link[256];
51 char buf[256];
52 char *ifname = get_station_ifname();
53
54 snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/driver",
55 ifname);
56 len = readlink(buf, link, sizeof(link) - 1);
57 if (len >= 0) {
58 link[len] = '\0';
59 if (strstr(link, DRIVER_NAME_60G))
60 return DRIVER_WIL6210;
61 }
62
63 if (stat("/sys/module/mac80211", &s) == 0)
64 return DRIVER_MAC80211;
65 return DRIVER_ATHEROS;
66 }
67 return wifi_chip_type;
68}
69
70
71enum openwrt_driver_type get_openwrt_driver_type(void)
72{
73 struct stat s;
74
75 if (openwrt_chip_type == OPENWRT_DRIVER_NOT_SET) {
76 if (stat("/sys/module/ath_hal", &s) == 0)
77 openwrt_chip_type = OPENWRT_DRIVER_ATHEROS;
78 }
79
80 return openwrt_chip_type;
81}
82
83
84enum sigma_program sigma_program_to_enum(const char *prog)
85{
86 if (prog == NULL)
87 return PROGRAM_UNKNOWN;
88
89 if (strcasecmp(prog, "TDLS") == 0)
90 return PROGRAM_TDLS;
91 if (strcasecmp(prog, "HS2") == 0)
92 return PROGRAM_HS2;
93 if (strcasecmp(prog, "HS2_R2") == 0 ||
94 strcasecmp(prog, "HS2-R2") == 0)
95 return PROGRAM_HS2_R2;
96 if (strcasecmp(prog, "WFD") == 0)
97 return PROGRAM_WFD;
98 if (strcasecmp(prog, "PMF") == 0)
99 return PROGRAM_PMF;
100 if (strcasecmp(prog, "WPS") == 0)
101 return PROGRAM_WPS;
102 if (strcasecmp(prog, "11n") == 0)
103 return PROGRAM_HT;
104 if (strcasecmp(prog, "VHT") == 0)
105 return PROGRAM_VHT;
106 if (strcasecmp(prog, "60GHZ") == 0)
107 return PROGRAM_60GHZ;
108 if (strcasecmp(prog, "NAN") == 0)
109 return PROGRAM_NAN;
110
111 return PROGRAM_UNKNOWN;
112}