/*1* Copyright 2001 The Aerospace Corporation. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11* 3. The name of The Aerospace Corporation may not be used to endorse or12* promote products derived from this software.13*14* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627/*-28* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.29* All rights reserved.30*31* This code is derived from software contributed to The NetBSD Foundation32* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,33* NASA Ames Research Center.34*35* Redistribution and use in source and binary forms, with or without36* modification, are permitted provided that the following conditions37* are met:38* 1. Redistributions of source code must retain the above copyright39* notice, this list of conditions and the following disclaimer.40* 2. Redistributions in binary form must reproduce the above copyright41* notice, this list of conditions and the following disclaimer in the42* documentation and/or other materials provided with the distribution.43*44* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS45* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED46* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR47* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS48* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR49* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF50* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS51* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN52* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)53* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE54* POSSIBILITY OF SUCH DAMAGE.55*/5657#include <sys/param.h>58#include <sys/ioctl.h>59#include <sys/socket.h>60#include <sys/sysctl.h>61#include <sys/time.h>6263#include <net/ethernet.h>64#include <net/if.h>65#include <net/if_dl.h>66#include <net/if_types.h>67#include <net/if_media.h>68#include <net/route.h>6970#include <net80211/ieee80211_ioctl.h>71#include <net80211/ieee80211_freebsd.h>72#include <net80211/ieee80211_superg.h>73#include <net80211/ieee80211_tdma.h>74#include <net80211/ieee80211_mesh.h>7576#include <assert.h>77#include <ctype.h>78#include <err.h>79#include <errno.h>80#include <fcntl.h>81#include <inttypes.h>82#include <stdio.h>83#include <stdlib.h>84#include <string.h>85#include <unistd.h>86#include <stdarg.h>87#include <stddef.h> /* NB: for offsetof */8889#include "lib80211_ioctl.h"9091/*92* These implement basic net80211 accessor methods to wrap the IOCTL93* calls.94*/9596int97lib80211_get80211(int s, const char *name, int type, void *data, int len)98{99struct ieee80211req ireq;100101(void) memset(&ireq, 0, sizeof(ireq));102(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));103ireq.i_type = type;104ireq.i_data = data;105ireq.i_len = len;106return ioctl(s, SIOCG80211, &ireq);107}108109int110lib80211_get80211len(int s, const char *name, int type, void *data, int len, int *plen)111{112struct ieee80211req ireq;113114(void) memset(&ireq, 0, sizeof(ireq));115(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));116ireq.i_type = type;117ireq.i_len = len;118assert(ireq.i_len == len); /* NB: check for 16-bit truncation */119ireq.i_data = data;120if (ioctl(s, SIOCG80211, &ireq) < 0)121return -1;122*plen = ireq.i_len;123return 0;124}125126int127lib80211_get80211val(int s, const char *name, int type, int *val)128{129struct ieee80211req ireq;130131(void) memset(&ireq, 0, sizeof(ireq));132(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));133ireq.i_type = type;134if (ioctl(s, SIOCG80211, &ireq) < 0)135return -1;136*val = ireq.i_val;137return 0;138}139140int141lib80211_set80211(int s, const char *name, int type, int val, int len, void *data)142{143struct ieee80211req ireq;144145(void) memset(&ireq, 0, sizeof(ireq));146(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));147ireq.i_type = type;148ireq.i_val = val;149ireq.i_len = len;150assert(ireq.i_len == len); /* NB: check for 16-bit truncation */151ireq.i_data = data;152if (ioctl(s, SIOCS80211, &ireq) < 0)153return (-1);154return (0);155}156157158159