~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-resource-generic/src/80211_resource.c

  • Committer: Sylvain Pineau
  • Date: 2014-07-29 16:05:54 UTC
  • mto: This revision was merged to the branch mainline in revision 3149.
  • Revision ID: sylvain.pineau@canonical.com-20140729160554-qev8887xbunn9tmi
checkbox-ng:launchers:checkbox-cli: The checkbox-cli launcher

Running the default whitelist (with the suite selection screen skipped)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
25
 */
26
26
 
27
 
#include <stdlib.h>
28
 
#include <stdio.h>
29
 
#include <string.h>
30
27
#include <errno.h>
31
28
#include <stdbool.h>
32
29
 
42
39
        int nl80211_id;
43
40
};
44
41
 
45
 
struct wireless_capabilities {
46
 
  unsigned int ac_support : 1;
47
 
  unsigned int n_support : 1;
48
 
  unsigned int bg_support : 1;
49
 
  unsigned int band_5GHz_support : 1;
50
 
};
51
 
 
52
42
static const char *ifmodes[] = {
53
43
        "unspecified",
54
44
        "IBSS",
117
107
        return NL_SKIP;
118
108
}
119
109
 
120
 
/* Search for a specific pattern inside the given file handle.
121
 
 * @arg fp         a FILE pointer
122
 
 * @arg pattern    the search pattern
123
 
 *
124
 
 * @return 0 on success 1 otherwise.
125
 
 */
126
 
static int heuristic_test(FILE *fp, const char *pattern)
127
 
{
128
 
    char *line = NULL;
129
 
    size_t len = 0;
130
 
    ssize_t read;
131
 
    char *p;
132
 
 
133
 
    while ((read = getline(&line, &len, fp)) != -1) {
134
 
        if ((p = strstr(line, pattern)) != NULL) {
135
 
            return 0;
136
 
        }
137
 
    }
138
 
    free(line);
139
 
    return 1;
140
 
}
141
 
 
142
110
static int print_phy_handler(struct nl_msg *msg, void *arg)
143
111
{
144
112
        struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
148
116
        struct nlattr *nl_band;
149
117
        struct nlattr *nl_freq;
150
118
        struct nlattr *nl_mode;
151
 
        struct wireless_capabilities *cap = arg;
152
119
        int rem_band, rem_freq, rem_mode;
 
120
    bool ac_support = false;
 
121
    bool n_support = false;
 
122
    bool bg_support = false;
 
123
    bool band_5GHz_support = false;
153
124
 
154
125
        nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
155
126
                  genlmsg_attrlen(gnlh, 0), NULL);
162
133
#if HAVE_NL80211_BAND_ATTR_VHT_CAPA && HAVE_NL80211_BAND_ATTR_VHT_MCS_SET
163
134
            if (tb_band[NL80211_BAND_ATTR_VHT_CAPA] &&
164
135
                            tb_band[NL80211_BAND_ATTR_VHT_MCS_SET])
165
 
                                cap->ac_support = true;
 
136
                                ac_support = true;
166
137
#endif
167
138
#if HAVE_NL80211_BAND_ATTR_HT_CAPA
168
139
            /* 802.11n can use a new set of rates designed specifically for high throughput (HT) */
169
140
            if (tb_band[NL80211_BAND_ATTR_HT_CAPA])
170
 
                                cap->n_support = true;
 
141
                                n_support = true;
171
142
#endif
172
143
            /* Always assume 802.11b/g support */
173
 
            cap->bg_support = true;
 
144
            bg_support = true;
174
145
 
175
146
                        if (tb_band[NL80211_BAND_ATTR_FREQS]) {
176
147
                                nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
185
156
                                        freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
186
157
                    /* http://en.wikipedia.org/wiki/List_of_WLAN_channels */
187
158
                    if (freq >= 4915 && freq <= 5825) 
188
 
                                                cap->band_5GHz_support = true;
 
159
                        band_5GHz_support = true;
189
160
                                }
190
161
                        }
191
162
                }
199
170
        }
200
171
        }
201
172
 
 
173
    if (ac_support)
 
174
        printf("ac: supported\n");
 
175
    if (n_support)
 
176
        printf("n: supported\n");
 
177
    if (bg_support)
 
178
        printf("bg: supported\n");
 
179
    if (band_5GHz_support) 
 
180
        printf("band_5GHz: supported\n");
 
181
 
202
182
    return 0;
203
183
}
204
184
 
205
185
int main(int argc, char **argv)
206
186
{
207
187
        struct nl80211_state nlstate;
208
 
        struct wireless_capabilities cap;
209
188
        int err;
210
 
        FILE *pci_fp;
211
189
 
212
190
        err = nl80211_init(&nlstate);
213
191
        if (err)
241
219
                goto out;
242
220
 
243
221
        err = 1;
244
 
        cap.ac_support = 0;
245
 
        cap.n_support = 0;
246
 
        cap.bg_support = 0;
247
 
        cap.band_5GHz_support = 0;
248
222
 
249
223
        nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
250
224
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
251
 
    nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, &cap);
 
225
    nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, &err);
252
226
 
253
227
        while (err > 0)
254
228
                nl_recvmsgs(nlstate.nl_sock, cb);
262
236
 
263
237
        nl80211_cleanup(&nlstate);
264
238
 
265
 
    /* Try to guess the ac capabilities using heuristics (sometimes required
266
 
       as some drivers don't expose all their wireless properties to libnl */
267
 
    if (!cap.ac_support) {
268
 
        pci_fp = popen("lspci -nnv", "r");
269
 
        if (!pci_fp) {
270
 
            perror("Something is wrong with lspci");
271
 
            exit(1);
272
 
        }
273
 
        if (heuristic_test(pci_fp, "802.11ac") == 0)
274
 
            cap.ac_support = true;
275
 
        pclose(pci_fp);
276
 
    }
277
 
    if (cap.ac_support)
278
 
        printf("ac: supported\n");
279
 
    if (cap.n_support)
280
 
        printf("n: supported\n");
281
 
    if (cap.bg_support)
282
 
        printf("bg: supported\n");
283
 
    if (cap.band_5GHz_support)
284
 
        printf("band_5GHz: supported\n");
285
 
 
286
239
        return err;
287
240
}