source: rtems-libbsd/freebsd/lib/lib80211/lib80211_ioctl.c @ 2389539

55-freebsd-126-freebsd-12
Last change on this file since 2389539 was 2389539, checked in by Christian Mauderer <Christian.Mauderer@…>, on 11/16/16 at 14:02:20

ifconfig/wlan, expat, lib80211: Import from FreeBSD.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright 2001 The Aerospace Corporation.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of The Aerospace Corporation may not be used to endorse or
15 *    promote products derived from this software.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD$
30 */
31
32/*-
33 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
34 * All rights reserved.
35 *
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
38 * NASA Ames Research Center.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 *    notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 *    notice, this list of conditions and the following disclaimer in the
47 *    documentation and/or other materials provided with the distribution.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGE.
60 */
61
62#include <rtems/bsd/sys/param.h>
63#include <sys/ioctl.h>
64#include <sys/socket.h>
65#include <sys/sysctl.h>
66#include <sys/time.h>
67
68#include <net/ethernet.h>
69#include <net/if.h>
70#include <net/if_dl.h>
71#include <net/if_types.h>
72#include <net/if_media.h>
73#include <net/route.h>
74
75#include <net80211/ieee80211_ioctl.h>
76#include <net80211/ieee80211_freebsd.h>
77#include <net80211/ieee80211_superg.h>
78#include <net80211/ieee80211_tdma.h>
79#include <net80211/ieee80211_mesh.h>
80
81#include <assert.h>
82#include <ctype.h>
83#include <err.h>
84#include <errno.h>
85#include <fcntl.h>
86#include <inttypes.h>
87#include <stdio.h>
88#include <stdlib.h>
89#include <string.h>
90#include <unistd.h>
91#include <stdarg.h>
92#include <stddef.h>             /* NB: for offsetof */
93
94#include "lib80211_ioctl.h"
95
96/*
97 * These implement basic net80211 accessor methods to wrap the IOCTL
98 * calls.
99 */
100
101int
102lib80211_get80211(int s, const char *name, int type, void *data, int len)
103{
104        struct ieee80211req ireq;
105
106        (void) memset(&ireq, 0, sizeof(ireq));
107        (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
108        ireq.i_type = type;
109        ireq.i_data = data;
110        ireq.i_len = len;
111        return ioctl(s, SIOCG80211, &ireq);
112}
113
114int
115lib80211_get80211len(int s, const char *name, int type, void *data, int len, int *plen)
116{
117        struct ieee80211req ireq;
118
119        (void) memset(&ireq, 0, sizeof(ireq));
120        (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
121        ireq.i_type = type;
122        ireq.i_len = len;
123        assert(ireq.i_len == len);      /* NB: check for 16-bit truncation */
124        ireq.i_data = data;
125        if (ioctl(s, SIOCG80211, &ireq) < 0)
126                return -1;
127        *plen = ireq.i_len;
128        return 0;
129}
130
131int
132lib80211_get80211val(int s, const char *name, int type, int *val)
133{
134        struct ieee80211req ireq;
135
136        (void) memset(&ireq, 0, sizeof(ireq));
137        (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
138        ireq.i_type = type;
139        if (ioctl(s, SIOCG80211, &ireq) < 0)
140                return -1;
141        *val = ireq.i_val;
142        return 0;
143}
144
145int
146lib80211_set80211(int s, const char *name, int type, int val, int len, void *data)
147{
148        struct ieee80211req     ireq;
149
150        (void) memset(&ireq, 0, sizeof(ireq));
151        (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
152        ireq.i_type = type;
153        ireq.i_val = val;
154        ireq.i_len = len;
155        assert(ireq.i_len == len);      /* NB: check for 16-bit truncation */
156        ireq.i_data = data;
157        if (ioctl(s, SIOCS80211, &ireq) < 0)
158                return (-1);
159        return (0);
160}
161
Note: See TracBrowser for help on using the repository browser.