127be1a706
routines to interface with net80211. This is all from the ifconfig program; the duplicate code from ifconfig will be removed when it starts using this API. Differential Revision: https://reviews.freebsd.org/D4290
160 lines
5.3 KiB
C
160 lines
5.3 KiB
C
/*
|
|
* Copyright 2001 The Aerospace Corporation. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of The Aerospace Corporation may not be used to endorse or
|
|
* promote products derived from this software.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
/*-
|
|
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
* NASA Ames Research Center.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/sysctl.h>
|
|
#include <sys/time.h>
|
|
|
|
#include <net/ethernet.h>
|
|
#include <net/if.h>
|
|
#include <net/if_dl.h>
|
|
#include <net/if_types.h>
|
|
#include <net/if_media.h>
|
|
#include <net/route.h>
|
|
|
|
#include <net80211/ieee80211_ioctl.h>
|
|
#include <net80211/ieee80211_freebsd.h>
|
|
#include <net80211/ieee80211_superg.h>
|
|
#include <net80211/ieee80211_tdma.h>
|
|
#include <net80211/ieee80211_mesh.h>
|
|
|
|
#include <assert.h>
|
|
#include <ctype.h>
|
|
#include <err.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <stdarg.h>
|
|
#include <stddef.h> /* NB: for offsetof */
|
|
|
|
#include "lib80211_ioctl.h"
|
|
|
|
/*
|
|
* These implement basic net80211 accessor methods to wrap the IOCTL
|
|
* calls.
|
|
*/
|
|
|
|
int
|
|
lib80211_get80211(int s, const char *name, int type, void *data, int len)
|
|
{
|
|
struct ieee80211req ireq;
|
|
|
|
(void) memset(&ireq, 0, sizeof(ireq));
|
|
(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
|
|
ireq.i_type = type;
|
|
ireq.i_data = data;
|
|
ireq.i_len = len;
|
|
return ioctl(s, SIOCG80211, &ireq);
|
|
}
|
|
|
|
int
|
|
lib80211_get80211len(int s, const char *name, int type, void *data, int len, int *plen)
|
|
{
|
|
struct ieee80211req ireq;
|
|
|
|
(void) memset(&ireq, 0, sizeof(ireq));
|
|
(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
|
|
ireq.i_type = type;
|
|
ireq.i_len = len;
|
|
assert(ireq.i_len == len); /* NB: check for 16-bit truncation */
|
|
ireq.i_data = data;
|
|
if (ioctl(s, SIOCG80211, &ireq) < 0)
|
|
return -1;
|
|
*plen = ireq.i_len;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
lib80211_get80211val(int s, const char *name, int type, int *val)
|
|
{
|
|
struct ieee80211req ireq;
|
|
|
|
(void) memset(&ireq, 0, sizeof(ireq));
|
|
(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
|
|
ireq.i_type = type;
|
|
if (ioctl(s, SIOCG80211, &ireq) < 0)
|
|
return -1;
|
|
*val = ireq.i_val;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
lib80211_set80211(int s, const char *name, int type, int val, int len, void *data)
|
|
{
|
|
struct ieee80211req ireq;
|
|
|
|
(void) memset(&ireq, 0, sizeof(ireq));
|
|
(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
|
|
ireq.i_type = type;
|
|
ireq.i_val = val;
|
|
ireq.i_len = len;
|
|
assert(ireq.i_len == len); /* NB: check for 16-bit truncation */
|
|
ireq.i_data = data;
|
|
if (ioctl(s, SIOCS80211, &ireq) < 0)
|
|
return (-1);
|
|
return (0);
|
|
}
|
|
|