diff --git a/src/libs/compat/freebsd_network/Condvar.cpp b/src/libs/compat/freebsd_network/Condvar.cpp new file mode 100644 index 0000000000..28c7b29fc3 --- /dev/null +++ b/src/libs/compat/freebsd_network/Condvar.cpp @@ -0,0 +1,84 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All Rights Reserved. Distributed under the terms of the MIT License. + */ + + +#include "condvar.h" + +extern "C" { +#include +#include +} + +#include + +#include + +#include "device.h" + + +#define ticks_to_usecs(t) (1000000*(t) / hz) + + +extern "C" { +static object_cache* sConditionVariableCache; + + +status_t +init_condition_variables() +{ + sConditionVariableCache = create_object_cache("condition variables", + sizeof (ConditionVariable), 0, NULL, NULL, NULL); + if (sConditionVariableCache == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + +void +uninit_condition_variables() +{ + delete_object_cache(sConditionVariableCache); +} + +} /* extern "C" */ + + +void +_cv_init(struct cv* conditionVariable, const char* description) +{ + conditionVariable->condVar = + (ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0); + conditionVariable->condVar->Init(NULL, description); +} + + +void +_cv_wait_unlocked(struct cv* conditionVariable) +{ + conditionVariable->condVar->Wait(); +} + + +int +_cv_timedwait_unlocked(struct cv* conditionVariable, int timeout) +{ + status_t status; + + status = conditionVariable->condVar->Wait(B_ABSOLUTE_TIMEOUT, + ticks_to_usecs(timeout)); + + if (status == B_OK) + return ENOERR; + else + return EWOULDBLOCK; +} + + +void +_cv_signal(struct cv* conditionVariable) +{ + conditionVariable->condVar->NotifyOne(); +} diff --git a/src/libs/compat/freebsd_network/Jamfile b/src/libs/compat/freebsd_network/Jamfile index 53fb8ad4e1..e5e92dac2a 100644 --- a/src/libs/compat/freebsd_network/Jamfile +++ b/src/libs/compat/freebsd_network/Jamfile @@ -1,6 +1,5 @@ SubDir HAIKU_TOP src libs compat freebsd_network ; - UseHeaders [ FDirName $(SUBDIR) ] : true ; UseHeaders [ FDirName $(SUBDIR) compat ] : true ; UsePrivateHeaders net ; @@ -12,7 +11,10 @@ SubDirCcFlags [ FDefines _KERNEL=1 ] ; KernelStaticLibrary libfreebsd_network.a : bus.c callout.c + clock.c compat.c + condvar.c + Condvar.cpp device.c driver.c eventhandler.c @@ -20,13 +22,23 @@ KernelStaticLibrary libfreebsd_network.a : fbsd_ether.c fbsd_if_media.c fbsd_mbuf.c + fbsd_mbuf2.c fbsd_mii.c fbsd_mii_physubr.c + fbsd_time.c + firmware.c if.c + libkern.c mbuf.c mii.c mutex.c + priv.c + sleepqueue.c + synch.c taskqueue.c + timeout.c + unit.c + Unit.cpp ; rule MIIHeaderGen @@ -46,4 +58,3 @@ actions MIIHeaderGen1 } MIIHeaderGen [ FGristFiles miidevs.h ] : miidevs : miidevs2h.awk ; - diff --git a/src/libs/compat/freebsd_network/Unit.cpp b/src/libs/compat/freebsd_network/Unit.cpp new file mode 100644 index 0000000000..9099918c07 --- /dev/null +++ b/src/libs/compat/freebsd_network/Unit.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All Rights Reserved. Distributed under the terms of the MIT License. + * + */ + + +/*! Wrapper functions for accessing the number buffer.*/ + + +#include "unit.h" + +// TODO Update Headercomment about count of code users +#include + + +#define ID_STORE_FULL -1 + + +status_t +_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) { + + status_t status = B_OK; + + idStore->idBuffer = radix_bitmap_create(maxIdCount); + if (idStore->idBuffer == NULL) + status = B_NO_MEMORY; + + return status; +} + + +void +_delete_unrhdr_buffer_locked(struct unrhdr* idStore) { + + radix_bitmap_destroy(idStore->idBuffer); +} + + +int +_alloc_unr_locked(struct unrhdr* idStore) { + swap_addr_t slotIndex; + int id = ID_STORE_FULL; + + slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1); + if (slotIndex != SWAP_SLOT_NONE) { + id = slotIndex + idStore->idBias; + } + + return id; +} + + +void +_free_unr_locked(struct unrhdr* idStore, u_int identity) { + uint32 slotIndex = (int32)identity - idStore->idBias; + + radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1); +} diff --git a/src/libs/compat/freebsd_network/bus.c b/src/libs/compat/freebsd_network/bus.c index ecccfdba75..eca9da6b53 100644 --- a/src/libs/compat/freebsd_network/bus.c +++ b/src/libs/compat/freebsd_network/bus.c @@ -1,10 +1,10 @@ /* * Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2004, Marcus Overhagen. All Rights Reserved. - * * Distributed under the terms of the MIT License. */ + #include "device.h" #include @@ -14,12 +14,15 @@ #include #include #include -#include +#include +#include #include +#include // private kernel header to get B_NO_HANDLED_INFO #include + //#define DEBUG_BUS_SPACE_RW #ifdef DEBUG_BUS_SPACE_RW # define TRACE_BUS_SPACE_RW(x) driver_printf x @@ -37,9 +40,6 @@ #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1)) -// TODO: x86 specific! -#define I386_BUS_SPACE_IO 0 -#define I386_BUS_SPACE_MEM 1 struct internal_intr { device_t dev; @@ -54,7 +54,6 @@ struct internal_intr { int32 handling; }; - static int32 intr_wrapper(void *data); @@ -457,6 +456,15 @@ BUS_SPACE_WRITE(1, uint8_t, out8) BUS_SPACE_WRITE(2, uint16_t, out16) BUS_SPACE_WRITE(4, uint32_t, out32) +int +bus_child_present(device_t child) +{ + device_t parent = device_get_parent(child); + if (parent == NULL) + return 0; + + return bus_child_present(parent); +} // #pragma mark - PCI functions diff --git a/src/libs/compat/freebsd_network/callout.c b/src/libs/compat/freebsd_network/callout.c index f9374392f7..007435e66b 100644 --- a/src/libs/compat/freebsd_network/callout.c +++ b/src/libs/compat/freebsd_network/callout.c @@ -1,8 +1,10 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ + #include "device.h" #include @@ -33,11 +35,7 @@ handle_callout(struct net_timer *timer, void *data) void callout_init_mtx(struct callout *c, struct mtx *mtx, int flags) { - // we must manually initialize the timer, since the networking - // stack might not be loaded yet - c->c_timer.hook = handle_callout; - c->c_timer.data = c; - c->c_timer.due = 0; + gStack->init_timer(&c->c_timer, handle_callout, c); c->c_arg = NULL; c->c_func = NULL; diff --git a/src/libs/compat/freebsd_network/clock.c b/src/libs/compat/freebsd_network/clock.c new file mode 100644 index 0000000000..1b11b03dc4 --- /dev/null +++ b/src/libs/compat/freebsd_network/clock.c @@ -0,0 +1,40 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include "device.h" + + +int ticks; +struct net_timer hardclockTimer; + + +void hardclock(struct net_timer*, void*); + + +// TODO use the hardclock function in the compat layer actually. +status_t +init_clock() +{ + gStack->init_timer(&hardclockTimer, &hardclock, NULL); + gStack->set_timer(&hardclockTimer, hz); + + return B_OK; +} + + +void +uninit_clock() +{ + gStack->cancel_timer(&hardclockTimer); +} + + +void +hardclock(struct net_timer* timer, void* argument) +{ + atomic_add((vint32*)&ticks, 1); + gStack->set_timer(&hardclockTimer, hz); +} diff --git a/src/libs/compat/freebsd_network/compat.c b/src/libs/compat/freebsd_network/compat.c index f29f16b3db..118b94562e 100644 --- a/src/libs/compat/freebsd_network/compat.c +++ b/src/libs/compat/freebsd_network/compat.c @@ -6,6 +6,7 @@ * Distributed under the terms of the MIT License. */ + #include "device.h" #include @@ -16,6 +17,8 @@ #include #include #include +#include +#include #include @@ -28,7 +31,6 @@ pci_module_info *gPci; static struct list sRootDevices; static int sNextUnit; - // #pragma mark - private functions @@ -71,7 +73,7 @@ find_own_image() while (get_next_image_info(B_SYSTEM_TEAM, &cookie, &info) == B_OK) { if (((uint32)info.text <= (uint32)find_own_image && (uint32)info.text + (uint32)info.text_size - > (uint32)find_own_image)) { + > (uint32)find_own_image)) { // found our own image return info.id; } @@ -373,9 +375,18 @@ device_attach(device_t device) || device->methods.attach == NULL) return B_ERROR; + if (get_module(NET_STACK_MODULE_NAME, (module_info **)&gStack) != B_OK) + return B_ERROR; + result = device->methods.attach(device); - if (result == 0) + + if (result == 0) { atomic_or(&device->flags, DEVICE_ATTACHED); + } + + if (result == 0) { + result = start_wlan(device); + } return result; } @@ -389,7 +400,15 @@ device_detach(device_t device) if ((atomic_and(&device->flags, ~DEVICE_ATTACHED) & DEVICE_ATTACHED) != 0 && device->methods.detach != NULL) { - int result = device->methods.detach(device); + int result = B_OK; + + result = stop_wlan(device); + if (result != 0) { + atomic_or(&device->flags, DEVICE_ATTACHED); + return result; + } + + result = device->methods.detach(device); if (result != 0) { atomic_or(&device->flags, DEVICE_ATTACHED); return result; @@ -523,7 +542,8 @@ ffs(int value) } -int resource_int_value(const char *name, int unit, const char *resname, +int +resource_int_value(const char *name, int unit, const char *resname, int *result) { /* no support for hints */ @@ -599,4 +619,3 @@ pmap_kextract(vm_offset_t virtualAddress) return (vm_paddr_t)entry.address; } - diff --git a/src/libs/compat/freebsd_network/compat/altq/if_altq.h b/src/libs/compat/freebsd_network/compat/altq/if_altq.h index ba77f41b7d..5b0a815011 100644 --- a/src/libs/compat/freebsd_network/compat/altq/if_altq.h +++ b/src/libs/compat/freebsd_network/compat/altq/if_altq.h @@ -1,29 +1,36 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_ALTQ_IF_ALTQ_H_ #define _FBSD_COMPAT_ALTQ_IF_ALTQ_H_ + #include #include + struct ifaltq { - struct mbuf * ifq_head; - struct mbuf * ifq_tail; + struct mbuf* ifq_head; + struct mbuf* ifq_tail; int ifq_len; int ifq_maxlen; int ifq_drops; struct mtx ifq_mtx; - struct mbuf * ifq_drv_head; - struct mbuf * ifq_drv_tail; + struct mbuf* ifq_drv_head; + struct mbuf* ifq_drv_tail; int ifq_drv_len; int ifq_drv_maxlen; int altq_flags; }; + #define ALTQF_READY 0x1 -#define ALTDQ_REMOVE 1 +#define ALTDQ_REMOVE 1 #define ALTQ_IS_ENABLED(ifq) 0 #define ALTQ_ENQUEUE(ifr, m, foo, error) \ diff --git a/src/libs/compat/freebsd_network/compat/dev/mii/miidevs b/src/libs/compat/freebsd_network/compat/dev/mii/miidevs index 3b62654b68..325107005c 100644 --- a/src/libs/compat/freebsd_network/compat/dev/mii/miidevs +++ b/src/libs/compat/freebsd_network/compat/dev/mii/miidevs @@ -49,6 +49,7 @@ $FreeBSD$ * mangled accordingly to compensate. */ + oui AGERE 0x00a0bc Agere Systems oui ALTIMA 0x0010a9 Altima Communications oui AMD 0x00001a Advanced Micro Devices diff --git a/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h b/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h index 9b8a5d0a41..27e83a2fcd 100644 --- a/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h +++ b/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h @@ -589,6 +589,12 @@ #define PCIM_EXP_TYPE_PCI_BRIDGE 0x0070 #define PCIM_EXP_FLAGS_SLOT 0x0100 #define PCIM_EXP_FLAGS_IRQ 0x3e00 +#define PCIR_EXPRESS_DEVICE_CTL 0x8 +#define PCIM_EXP_CTL_MAX_PAYLOAD 0x00e0 +#define PCIM_EXP_CTL_MAX_READ_REQUEST 0x7000 +#define PCIR_EXPRESS_LINK_CAP 0xc +#define PCIM_LINK_CAP_ASPM 0x00000c00 +#define PCIR_EXPRESS_LINK_CTL 0x10 /* MSI-X definitions */ #define PCIR_MSIX_CTRL 0x2 diff --git a/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h b/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h index 8dde0ba799..994a226fed 100644 --- a/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h +++ b/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -12,6 +13,12 @@ #define PCI_RF_DENSE 0x10000 // ignored on x86 +#define PCI_POWERSTATE_D0 0 +#define PCI_POWERSTATE_D1 1 +#define PCI_POWERSTATE_D2 2 +#define PCI_POWERSTATE_D3 3 +#define PCI_POWERSTATE_UNKNOWN -1 + int pci_enable_busmaster(device_t dev); int pci_enable_io(device_t dev, int reg); @@ -44,10 +51,25 @@ int pci_release_msi(device_t dev); int pci_msix_count(device_t dev); int pci_alloc_msix(device_t dev, int *count); + static inline int pci_get_vpd_ident(device_t dev, const char **identptr) { return -1; } + +static inline int +pci_set_powerstate(device_t dev, int state) +{ + return PCI_POWERSTATE_UNKNOWN; +} + + +static inline int +pci_get_powerstate(device_t dev) +{ + return PCI_POWERSTATE_D0; +} + #endif /* _FBSD_COMPAT_DEV_PCI_PCIVAR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/machine/_bus.h b/src/libs/compat/freebsd_network/compat/machine/_bus.h new file mode 100644 index 0000000000..c3f3220e66 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/machine/_bus.h @@ -0,0 +1,16 @@ +/* + * Copyright 2009, Colin Günther. All Rights Reserved. + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_MACHINE__BUS_H_ +#define _FBSD_COMPAT_MACHINE__BUS_H_ + + +typedef uint32_t bus_addr_t; +typedef uint32_t bus_size_t; + +typedef int bus_space_tag_t; +typedef unsigned int bus_space_handle_t; + +#endif /* _FBSD_COMPAT_MACHINE__BUS_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/machine/bus.h b/src/libs/compat/freebsd_network/compat/machine/bus.h index e69de29bb2..41ca5f3f6d 100644 --- a/src/libs/compat/freebsd_network/compat/machine/bus.h +++ b/src/libs/compat/freebsd_network/compat/machine/bus.h @@ -0,0 +1,108 @@ +/* + * Copyright 2009, Colin Günther. All Rights Reserved. + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_MACHINE_BUS_H_ +#define _FBSD_COMPAT_MACHINE_BUS_H_ + + +#include + + +// TODO: x86 specific! +#define I386_BUS_SPACE_IO 0 +#define I386_BUS_SPACE_MEM 1 + +#define BUS_SPACE_MAXADDR_32BIT 0xffffffff +#define BUS_SPACE_MAXADDR 0xffffffff + +#define BUS_SPACE_MAXSIZE_32BIT 0xffffffff +#define BUS_SPACE_MAXSIZE 0xffffffff + +#define BUS_SPACE_UNRESTRICTED (~0) + +#define BUS_SPACE_BARRIER_READ 1 +#define BUS_SPACE_BARRIER_WRITE 2 + + +uint8_t bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset); +uint16_t bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset); +uint32_t bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset); +void bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint8_t value); +void bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint16_t value); +void bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint32_t value); + +void bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count); + + +static __inline void +bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ + + if (tag == I386_BUS_SPACE_IO) { + int _port_ = bsh + offset; + __asm __volatile(" \n\ + cld \n\ + 1: inl %w2,%%eax \n\ + stosl \n\ + addl $4,%2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); + } else { + void* _port_ = (void*) (bsh + offset); + memcpy(addr, _port_, count); + } +} + + +static __inline void +bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + if (tag == I386_BUS_SPACE_IO) { + int _port_ = bsh + offset; + __asm __volatile(" \n\ + cld \n\ + 1: lodsb \n\ + outb %%al,%w0 \n\ + incl %0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); + } else { + void* _port_ = (void*) (bsh + offset); + memcpy(_port_, addr, count); + } +} + + +static inline void +bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, bus_size_t len, int flags) +{ + if (flags & BUS_SPACE_BARRIER_READ) + __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory"); + else + __asm__ __volatile__ ("" : : : "memory"); +} + + +#include + + +#define bus_space_write_stream_4(t, h, o, v) \ + bus_space_write_4((t), (h), (o), (v)) + +#endif /* _FBSD_COMPAT_MACHINE_BUS_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/machine/bus_dma.h b/src/libs/compat/freebsd_network/compat/machine/bus_dma.h new file mode 100644 index 0000000000..8520e43496 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/machine/bus_dma.h @@ -0,0 +1,11 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All Rights Reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_MACHINE_BUS_DMA_H_ +#define _FBSD_COMPAT_MACHINE_BUS_DMA_H_ + + +#include + +#endif /* _FBSD_COMPAT_MACHINE_BUS_DMA_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/machine/clock.h b/src/libs/compat/freebsd_network/compat/machine/clock.h index e69de29bb2..e458d01a13 100644 --- a/src/libs/compat/freebsd_network/compat/machine/clock.h +++ b/src/libs/compat/freebsd_network/compat/machine/clock.h @@ -0,0 +1,9 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_CLOCK_H_ +#define _FBSD_COMPAT_SYS_CLOCK_H_ + + +#endif /* _FBSD_COMPAT_SYS_CLOCK_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/machine/endian.h b/src/libs/compat/freebsd_network/compat/machine/endian.h index 1be0a6875b..52861ac4bd 100644 --- a/src/libs/compat/freebsd_network/compat/machine/endian.h +++ b/src/libs/compat/freebsd_network/compat/machine/endian.h @@ -1,4 +1,12 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_MACHINE_ENDIAN_H_ #define _FBSD_COMPAT_MACHINE_ENDIAN_H_ + +#include +#include + #endif diff --git a/src/libs/compat/freebsd_network/compat/machine/in_cksum.h b/src/libs/compat/freebsd_network/compat/machine/in_cksum.h index bef3234e13..f174d3021e 100644 --- a/src/libs/compat/freebsd_network/compat/machine/in_cksum.h +++ b/src/libs/compat/freebsd_network/compat/machine/in_cksum.h @@ -9,6 +9,9 @@ #include +#define in_cksum(m, len) in_cksum_skip(m, len, 0) + + static inline u_short in_pseudo(u_int sum, u_int b, u_int c) { @@ -17,7 +20,6 @@ in_pseudo(u_int sum, u_int b, u_int c) return 0; } -#define in_cksum(m, len) in_cksum_skip(m, len, 0) static inline u_short in_cksum_skip(struct mbuf* m, int len, int skip) diff --git a/src/libs/compat/freebsd_network/compat/machine/resource.h b/src/libs/compat/freebsd_network/compat/machine/resource.h index 8b8192646c..f9d9d43b4e 100644 --- a/src/libs/compat/freebsd_network/compat/machine/resource.h +++ b/src/libs/compat/freebsd_network/compat/machine/resource.h @@ -1,6 +1,11 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_MACHINE_RESOURCE_H_ #define _FBSD_COMPAT_MACHINE_RESOURCE_H_ + #define SYS_RES_IRQ 0x1 #define SYS_RES_DRQ 0x2 #define SYS_RES_MEMORY 0x3 diff --git a/src/libs/compat/freebsd_network/compat/machine/stdarg.h b/src/libs/compat/freebsd_network/compat/machine/stdarg.h new file mode 100644 index 0000000000..75961678b4 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/machine/stdarg.h @@ -0,0 +1,12 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_MACHINE_STDARG_H_ +#define _FBSD_COMPAT_MACHINE_STDARG_H_ + + +#include +#include + +#endif /* _FBSD_COMPAT_MACHINE_STDARG_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net/bpf.h b/src/libs/compat/freebsd_network/compat/net/bpf.h index 2e962b520a..4c9dbd8183 100644 --- a/src/libs/compat/freebsd_network/compat/net/bpf.h +++ b/src/libs/compat/freebsd_network/compat/net/bpf.h @@ -1,12 +1,20 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FBSD_COMPAT_NET_BPF_H_ #define _FBSD_COMPAT_NET_BPF_H_ + +struct bpf_if; + + #define bpf_mtap(bpf_if, mbuf) do { } while (0) #define BPF_MTAP(ifp, m) do { } while (0) +#define bpf_mtap2(bpf_if, data, dlen, mbuf) do { } while (0) +#define bpfattach2(ifnet, dlt, hdrlen, bpf_if) do { } while (0) + static inline int bpf_peers_present(struct bpf_if *bpf) diff --git a/src/libs/compat/freebsd_network/compat/net/ethernet.h b/src/libs/compat/freebsd_network/compat/net/ethernet.h index 6df08aab65..e112c1ebd9 100644 --- a/src/libs/compat/freebsd_network/compat/net/ethernet.h +++ b/src/libs/compat/freebsd_network/compat/net/ethernet.h @@ -4,11 +4,9 @@ * $FreeBSD: src/sys/net/ethernet.h,v 1.32 2007/05/29 12:40:45 yar Exp $ * */ - #ifndef _FBSD_COMPAT_NET_ETHERNET_H_ #define _FBSD_COMPAT_NET_ETHERNET_H_ -#include /* * Somce basic Ethernet constants. @@ -56,6 +54,9 @@ #define ETHER_IS_VALID_LEN(foo) \ ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) +static const u_char etherbroadcastaddr[ETHER_ADDR_LEN] = + { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + /* * Structure of a 10Mb/s Ethernet header. */ @@ -365,7 +366,7 @@ CTASSERT(sizeof (struct ether_addr) == ETHER_ADDR_LEN); struct ifnet; struct mbuf; -struct rtentry; +struct route; struct sockaddr; struct bpf_if; @@ -376,7 +377,7 @@ extern void ether_ifattach(struct ifnet *, const u_int8_t *); extern void ether_ifdetach(struct ifnet *); extern int ether_ioctl(struct ifnet *, u_long, caddr_t); extern int ether_output(struct ifnet *, - struct mbuf *, struct sockaddr *, struct rtentry *); + struct mbuf *, struct sockaddr *, struct route *); extern int ether_output_frame(struct ifnet *, struct mbuf *); extern char *ether_sprintf(const u_int8_t *); void ether_vlan_mtap(struct bpf_if *, struct mbuf *, diff --git a/src/libs/compat/freebsd_network/compat/net/if.h b/src/libs/compat/freebsd_network/compat/net/if.h index 1b473098a4..48f0fb6b98 100644 --- a/src/libs/compat/freebsd_network/compat/net/if.h +++ b/src/libs/compat/freebsd_network/compat/net/if.h @@ -6,8 +6,14 @@ #define _FBSD_COMPAT_NET_IF_H_ +// Rename the ifreq structure provided by posix/net/if.h +// so that we can add FreeBSD based ifreq parts. +#define ifreq ifreq_haiku_unused #include +#undef ifreq +#include +#include #include @@ -15,7 +21,6 @@ #define IF_Mbps(x) (IF_Kbps((x) * 1000)) #define IF_Gbps(x) (IF_Mbps((x) * 1000)) - /* Capabilities that interfaces can advertise. */ #define IFCAP_RXCSUM 0x0001 /* can offload checksum on RX */ #define IFCAP_TXCSUM 0x0002 /* can offload checksum on TX */ @@ -26,25 +31,53 @@ #define IFCAP_POLLING 0x0040 /* driver supports polling */ #define IFCAP_VLAN_HWCSUM 0x0080 #define IFCAP_TSO4 0x0100 /* supports TCP segmentation offload */ +#define IFCAP_WOL_UCAST 0x00800 /* wake on any unicast frame */ +#define IFCAP_WOL_MCAST 0x01000 /* wake on any multicast frame */ +#define IFCAP_WOL_MAGIC 0x02000 /* wake on any Magic Packet */ #define IFCAP_VLAN_HWFILTER 0x10000 /* interface hw can filter vlan tag */ #define IFCAP_HWCSUM (IFCAP_RXCSUM | IFCAP_TXCSUM) +#define IFCAP_WOL (IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC) -#define IFF_DRV_RUNNING 0x10000 -#define IFF_DRV_OACTIVE 0x20000 -#define IFF_LINK0 0x40000 -#define IFF_DEBUG 0x80000 - +#define IFF_DRV_RUNNING 0x00010000 +#define IFF_DRV_OACTIVE 0x00020000 +#define IFF_LINK0 0x00040000 /* per link layer defined bit */ +#define IFF_LINK1 0x00080000 /* per link layer defined bit */ +#define IFF_LINK2 0x00100000 /* per link layer defined bit */ +#define IFF_DEBUG 0x00200000 +#define IFF_MONITOR 0x00400000 /* (n) user-requested monitor mode */ #define LINK_STATE_UNKNOWN 0 #define LINK_STATE_DOWN 1 #define LINK_STATE_UP 2 - #define IFQ_MAXLEN 50 +struct ifreq { + char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + union { + struct sockaddr ifr_addr; + struct sockaddr ifr_dstaddr; + struct sockaddr ifr_broadaddr; + struct sockaddr ifr_mask; + struct ifreq_parameter ifr_parameter; + struct ifreq_stats ifr_stats; + struct route_entry ifr_route; + int ifr_flags; + int ifr_index; + int ifr_metric; + int ifr_mtu; + int ifr_media; + int ifr_type; + int ifr_reqcap; + + // FreeBSD specific Part + caddr_t ifr_data; + }; +}; + struct ifmediareq { char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ int ifm_current; /* current media options */ @@ -92,4 +125,16 @@ struct if_data { struct timeval ifi_lastchange; /* time of last administrative change */ }; +struct ifdrv { + char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + unsigned long ifd_cmd; + size_t ifd_len; + void *ifd_data; +}; + +#ifdef _KERNEL +/* XXX - this should go away soon. */ +#include +#endif + #endif diff --git a/src/libs/compat/freebsd_network/compat/net/if_arp.h b/src/libs/compat/freebsd_network/compat/net/if_arp.h index 2cfdf7ef82..2be137aebb 100644 --- a/src/libs/compat/freebsd_network/compat/net/if_arp.h +++ b/src/libs/compat/freebsd_network/compat/net/if_arp.h @@ -30,8 +30,8 @@ * $FreeBSD: src/sys/net/if_arp.h,v 1.22 2005/06/10 16:49:18 brooks Exp $ */ -#ifndef _NET_IF_ARP_H_ -#define _NET_IF_ARP_H_ +#ifndef _FBSD_COMPAT_NET_IF_ARP_H_ +#define _FBSD_COMPAT_NET_IF_ARP_H_ /* * Address Resolution Protocol. @@ -112,4 +112,4 @@ struct arpcom { #endif -#endif /* !_NET_IF_ARP_H_ */ +#endif /* _FBSD_COMPAT_NET_IF_ARP_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net/if_media.h b/src/libs/compat/freebsd_network/compat/net/if_media.h index ddbdf13df2..e22134ad31 100644 --- a/src/libs/compat/freebsd_network/compat/net/if_media.h +++ b/src/libs/compat/freebsd_network/compat/net/if_media.h @@ -35,8 +35,8 @@ * SUCH DAMAGE. */ -#ifndef _NET_IF_MEDIA_H_ -#define _NET_IF_MEDIA_H_ +#ifndef _FBSD_COMPAT_NET_IF_MEDIA_H_ +#define _FBSD_COMPAT_NET_IF_MEDIA_H_ /* * Prototypes and definitions for BSD/OS-compatible network interface @@ -211,6 +211,7 @@ uint64_t ifmedia_baudrate(int); #define IFM_IEEE80211_WDS 0x00000800 /* Operate in WDS mode */ #define IFM_IEEE80211_TURBO 0x00001000 /* Operate in turbo mode */ #define IFM_IEEE80211_MONITOR 0x00002000 /* Operate in monitor mode */ +#define IFM_IEEE80211_MBSS 0x00004000 /* Operate in MBSS mode */ /* operating mode for multi-mode devices */ #define IFM_IEEE80211_11A 0x00010000 /* 5Ghz, OFDM mode */ @@ -662,4 +663,4 @@ struct ifmedia_status_description { { 0, 0, 0, \ { NULL, NULL } } \ } -#endif /* _NET_IF_MEDIA_H_ */ +#endif /* _FBSD_COMPAT_NET_IF_MEDIA_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net/if_types.h b/src/libs/compat/freebsd_network/compat/net/if_types.h new file mode 100644 index 0000000000..25766e4b1a --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net/if_types.h @@ -0,0 +1,14 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_NET_IF_TYPES_H_ +#define _FBSD_COMPAT_NET_IF_TYPES_H_ + + +#include + + +#define IFT_IEEE80211 0x47 + +#endif /* _FBSD_COMPAT_NET_IF_TYPES_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net/if_var.h b/src/libs/compat/freebsd_network/compat/net/if_var.h index 067b84b8a0..e26198c460 100644 --- a/src/libs/compat/freebsd_network/compat/net/if_var.h +++ b/src/libs/compat/freebsd_network/compat/net/if_var.h @@ -30,8 +30,8 @@ * $FreeBSD: src/sys/net/if_var.h,v 1.98.2.6 2006/10/06 20:26:05 andre Exp $ */ -#ifndef _NET_IF_VAR_H_ -#define _NET_IF_VAR_H_ +#ifndef _FBSD_COMPAT_NET_IF_VAR_H_ +#define _FBSD_COMPAT_NET_IF_VAR_H_ /* * Structures defining a network interface, providing a packet @@ -69,8 +69,11 @@ struct rt_addrinfo; struct socket; struct ether_header; struct carp_if; +struct route; #endif +#include + #include /* get TAILQ macros */ #ifdef _KERNEL @@ -86,8 +89,6 @@ struct carp_if; #include -#include /* for sockaddr_dl */ - TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ TAILQ_HEAD(ifprefixhead, ifprefix); @@ -149,7 +150,7 @@ struct ifnet { /* procedure handles */ int (*if_output) /* output routine (enqueue) */ (struct ifnet *, struct mbuf *, struct sockaddr *, - struct rtentry *); + struct route *); void (*if_input) /* input routine (from h/w driver) */ (struct ifnet *, struct mbuf *); void (*if_start) /* initiate output routine */ @@ -162,6 +163,8 @@ struct ifnet { (void *); int (*if_resolvemulti) /* validate/resolve multicast */ (struct ifnet *, struct sockaddr **, struct sockaddr *); + int (*if_transmit) /* initiate output routine */ + (struct ifnet *, struct mbuf *); void *if_spare1; /* spare pointer 1 */ void *if_spare2; /* spare pointer 2 */ void *if_spare3; /* spare pointer 3 */ @@ -194,6 +197,9 @@ struct ifnet { sem_id link_state_sem; int32 open_count; int32 flags; + + /* WLAN specific additions */ + sem_id scan_done_sem; }; typedef void if_init_f_t(void *); @@ -225,7 +231,7 @@ typedef void if_init_f_t(void *); #define if_lastchange if_data.ifi_lastchange #define if_recvquota if_data.ifi_recvquota #define if_xmitquota if_data.ifi_xmitquota -#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)NULL) +#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct route *)NULL) /* for compatibility with other BSDs */ #define if_addrlist if_addrhead @@ -239,17 +245,12 @@ typedef void if_init_f_t(void *); #define IF_ADDR_LOCK_DESTROY(if) mtx_destroy(&(if)->if_addr_mtx) #define IF_ADDR_LOCK(if) mtx_lock(&(if)->if_addr_mtx) #define IF_ADDR_UNLOCK(if) mtx_unlock(&(if)->if_addr_mtx) +#define IF_ADDR_LOCK_ASSERT(if) mtx_assert(&(if)->if_addr_mtx, MA_OWNED) -/* - * Function variations on locking macros intended to be used by loadable - * kernel modules in order to divorce them from the internals of address list - * locking. - */ void if_addr_rlock(struct ifnet *ifp); /* if_addrhead */ void if_addr_runlock(struct ifnet *ifp); /* if_addrhead */ void if_maddr_rlock(struct ifnet *ifp); /* if_multiaddrs */ void if_maddr_runlock(struct ifnet *ifp); /* if_multiaddrs */ -#define IF_ADDR_LOCK_ASSERT(if) mtx_assert(&(if)->if_addr_mtx, MA_OWNED) /* * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) @@ -602,50 +603,26 @@ struct ifmultiaddr { }; #ifdef _KERNEL -#define IFAFREE(ifa) \ - do { \ - IFA_LOCK(ifa); \ - KASSERT((ifa)->ifa_refcnt > 0, \ - ("ifa %p !(ifa_refcnt > 0)", ifa)); \ - if (--(ifa)->ifa_refcnt == 0) { \ - IFA_DESTROY(ifa); \ - free(ifa, M_IFADDR); \ - } else \ - IFA_UNLOCK(ifa); \ - } while (0) +#define IFA_LOCK(ifa) mtx_lock(&(ifa)->ifa_mtx) +#define IFA_UNLOCK(ifa) mtx_unlock(&(ifa)->ifa_mtx) -#define IFAREF(ifa) \ - do { \ - IFA_LOCK(ifa); \ - ++(ifa)->ifa_refcnt; \ - IFA_UNLOCK(ifa); \ - } while (0) +__unused static void ifa_free(struct ifaddr *ifa) {} +__unused static void ifa_init(struct ifaddr *ifa) {} +__unused static void ifa_ref(struct ifaddr *ifa) {} extern struct mtx ifnet_lock; -#define IFNET_LOCK_INIT() \ - mtx_init(&ifnet_lock, "ifnet", NULL, MTX_DEF | MTX_RECURSE) -#define IFNET_WLOCK() mtx_lock(&ifnet_lock) -#define IFNET_WUNLOCK() mtx_unlock(&ifnet_lock) -#define IFNET_RLOCK() IFNET_WLOCK() -#define IFNET_RUNLOCK() IFNET_WUNLOCK() +#define IFNET_LOCK_INIT() +#define IFNET_WLOCK() mtx_lock(&ifnet_lock) +#define IFNET_WUNLOCK() mtx_unlock(&ifnet_lock) +#define IFNET_RLOCK() IFNET_WLOCK() +#define IFNET_RLOCK_NOSLEEP() IFNET_WLOCK() +#define IFNET_RUNLOCK() IFNET_WUNLOCK() +#define IFNET_RUNLOCK_NOSLEEP() IFNET_WUNLOCK() -struct ifindex_entry { - struct ifnet *ife_ifnet; - struct ifaddr *ife_ifnet_addr; - struct cdev *ife_dev; -}; - -#define ifnet_byindex(idx) ifindex_table[(idx)].ife_ifnet -/* - * Given the index, ifaddr_byindex() returns the one and only - * link-level ifaddr for the interface. You are not supposed to use - * it to traverse the list of addresses associated to the interface. - */ -#define ifaddr_byindex(idx) ifindex_table[(idx)].ife_ifnet_addr -#define ifdev_byindex(idx) ifindex_table[(idx)].ife_dev +struct ifnet *ifnet_byindex(u_short idx); +struct ifnet *ifnet_byindex_locked(u_short idx); extern struct ifnethead ifnet; -extern struct ifindex_entry *ifindex_table; extern int ifqmaxlen; extern struct ifnet *loif; /* first loopback interface */ extern int if_index; @@ -657,6 +634,7 @@ void if_attach(struct ifnet *); int if_delmulti(struct ifnet *, struct sockaddr *); void if_detach(struct ifnet *); void if_purgeaddrs(struct ifnet *); +void if_purgemaddrs(struct ifnet *); void if_down(struct ifnet *); void if_free(struct ifnet *); void if_free_type(struct ifnet *, u_char); @@ -696,4 +674,4 @@ int ether_poll_deregister(struct ifnet *ifp); #endif /* _KERNEL */ -#endif /* !_NET_IF_VAR_H_ */ +#endif /* _FBSD_COMPAT_NET_IF_VAR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h b/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h index 4061d01dbc..fc3b44be7a 100644 --- a/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h +++ b/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h @@ -29,8 +29,8 @@ * $FreeBSD: src/sys/net/if_vlan_var.h,v 1.26 2007/02/28 22:05:30 bms Exp $ */ -#ifndef _NET_IF_VLAN_VAR_H_ -#define _NET_IF_VLAN_VAR_H_ 1 +#ifndef _FBSD_COMPAT_NET_IF_VLAN_VAR_H_ +#define _FBSD_COMPAT_NET_IF_VLAN_VAR_H_ 1 struct ether_vlan_header { u_char evl_dhost[ETHER_ADDR_LEN]; @@ -132,4 +132,4 @@ struct vlanreq { extern void (*vlan_trunk_cap_p)(struct ifnet *); #endif /* _KERNEL */ -#endif /* _NET_IF_VLAN_VAR_H_ */ +#endif /* _FBSD_COMPAT_NET_IF_VLAN_VAR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net/route.h b/src/libs/compat/freebsd_network/compat/net/route.h new file mode 100644 index 0000000000..4109ead3f3 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net/route.h @@ -0,0 +1,24 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_NET_ROUTE_H_ +#define _FBSD_COMPAT_NET_ROUTE_H_ + + +#include + + +/* + * A route consists of a destination address, a reference + * to a routing entry, and a reference to an llentry. + * These are often held by protocols in their control + * blocks, e.g. inpcb. + */ +struct route { + struct rtentry *ro_rt; + struct llentry *ro_lle; + struct sockaddr ro_dst; +}; + +#endif /* _FBSD_COMPAT_NET_ROUTE_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/_ieee80211.h b/src/libs/compat/freebsd_network/compat/net80211/_ieee80211.h new file mode 100644 index 0000000000..0e78e10959 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/_ieee80211.h @@ -0,0 +1,396 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211__IEEE80211_H_ +#define _FBSD_COMPAT_NET80211__IEEE80211_H_ + +/* + * 802.11 implementation definitions. + * + * NB: this file is used by applications. + */ + +/* + * PHY type; mostly used to identify FH phys. + */ +enum ieee80211_phytype { + IEEE80211_T_DS, /* direct sequence spread spectrum */ + IEEE80211_T_FH, /* frequency hopping */ + IEEE80211_T_OFDM, /* frequency division multiplexing */ + IEEE80211_T_TURBO, /* high rate OFDM, aka turbo mode */ + IEEE80211_T_HT, /* high throughput */ + IEEE80211_T_OFDM_HALF, /* 1/2 rate OFDM */ + IEEE80211_T_OFDM_QUARTER, /* 1/4 rate OFDM */ +}; +#define IEEE80211_T_CCK IEEE80211_T_DS /* more common nomenclature */ + +/* + * PHY mode; this is not really a mode as multi-mode devices + * have multiple PHY's. Mode is mostly used as a shorthand + * for constraining which channels to consider in setting up + * operation. Modes used to be used more extensively when + * channels were identified as IEEE channel numbers. + */ +enum ieee80211_phymode { + IEEE80211_MODE_AUTO = 0, /* autoselect */ + IEEE80211_MODE_11A = 1, /* 5GHz, OFDM */ + IEEE80211_MODE_11B = 2, /* 2GHz, CCK */ + IEEE80211_MODE_11G = 3, /* 2GHz, OFDM */ + IEEE80211_MODE_FH = 4, /* 2GHz, GFSK */ + IEEE80211_MODE_TURBO_A = 5, /* 5GHz, OFDM, 2x clock */ + IEEE80211_MODE_TURBO_G = 6, /* 2GHz, OFDM, 2x clock */ + IEEE80211_MODE_STURBO_A = 7, /* 5GHz, OFDM, 2x clock, static */ + IEEE80211_MODE_11NA = 8, /* 5GHz, w/ HT */ + IEEE80211_MODE_11NG = 9, /* 2GHz, w/ HT */ + IEEE80211_MODE_HALF = 10, /* OFDM, 1/2x clock */ + IEEE80211_MODE_QUARTER = 11, /* OFDM, 1/4x clock */ +}; +#define IEEE80211_MODE_MAX (IEEE80211_MODE_QUARTER+1) + +/* + * Operating mode. Devices do not necessarily support + * all modes; they indicate which are supported in their + * capabilities. + */ +enum ieee80211_opmode { + IEEE80211_M_IBSS = 0, /* IBSS (adhoc) station */ + IEEE80211_M_STA = 1, /* infrastructure station */ + IEEE80211_M_WDS = 2, /* WDS link */ + IEEE80211_M_AHDEMO = 3, /* Old lucent compatible adhoc demo */ + IEEE80211_M_HOSTAP = 4, /* Software Access Point */ + IEEE80211_M_MONITOR = 5, /* Monitor mode */ + IEEE80211_M_MBSS = 6, /* MBSS (Mesh Point) link */ +}; +#define IEEE80211_OPMODE_MAX (IEEE80211_M_MBSS+1) + +/* + * 802.11g/802.11n protection mode. + */ +enum ieee80211_protmode { + IEEE80211_PROT_NONE = 0, /* no protection */ + IEEE80211_PROT_CTSONLY = 1, /* CTS to self */ + IEEE80211_PROT_RTSCTS = 2, /* RTS-CTS */ +}; + +/* + * Authentication mode. The open and shared key authentication + * modes are implemented within the 802.11 layer. 802.1x and + * WPA/802.11i are implemented in user mode by setting the + * 802.11 layer into IEEE80211_AUTH_8021X and deferring + * authentication to user space programs. + */ +enum ieee80211_authmode { + IEEE80211_AUTH_NONE = 0, + IEEE80211_AUTH_OPEN = 1, /* open */ + IEEE80211_AUTH_SHARED = 2, /* shared-key */ + IEEE80211_AUTH_8021X = 3, /* 802.1x */ + IEEE80211_AUTH_AUTO = 4, /* auto-select/accept */ + /* NB: these are used only for ioctls */ + IEEE80211_AUTH_WPA = 5, /* WPA/RSN w/ 802.1x/PSK */ +}; + +/* + * Roaming mode is effectively who controls the operation + * of the 802.11 state machine when operating as a station. + * State transitions are controlled either by the driver + * (typically when management frames are processed by the + * hardware/firmware), the host (auto/normal operation of + * the 802.11 layer), or explicitly through ioctl requests + * when applications like wpa_supplicant want control. + */ +enum ieee80211_roamingmode { + IEEE80211_ROAMING_DEVICE= 0, /* driver/hardware control */ + IEEE80211_ROAMING_AUTO = 1, /* 802.11 layer control */ + IEEE80211_ROAMING_MANUAL= 2, /* application control */ +}; + +/* + * Channels are specified by frequency and attributes. + */ +struct ieee80211_channel { + uint32_t ic_flags; /* see below */ + uint16_t ic_freq; /* setting in Mhz */ + uint8_t ic_ieee; /* IEEE channel number */ + int8_t ic_maxregpower; /* maximum regulatory tx power in dBm */ + int8_t ic_maxpower; /* maximum tx power in .5 dBm */ + int8_t ic_minpower; /* minimum tx power in .5 dBm */ + uint8_t ic_state; /* dynamic state */ + uint8_t ic_extieee; /* HT40 extension channel number */ + int8_t ic_maxantgain; /* maximum antenna gain in .5 dBm */ + uint8_t ic_pad; + uint16_t ic_devdata; /* opaque device/driver data */ +}; + +#define IEEE80211_CHAN_MAX 256 +#define IEEE80211_CHAN_BYTES 32 /* howmany(IEEE80211_CHAN_MAX, NBBY) */ +#define IEEE80211_CHAN_ANY 0xffff /* token for ``any channel'' */ +#define IEEE80211_CHAN_ANYC \ + ((struct ieee80211_channel *) IEEE80211_CHAN_ANY) + +/* channel attributes */ +#define IEEE80211_CHAN_PRIV0 0x00000001 /* driver private bit 0 */ +#define IEEE80211_CHAN_PRIV1 0x00000002 /* driver private bit 1 */ +#define IEEE80211_CHAN_PRIV2 0x00000004 /* driver private bit 2 */ +#define IEEE80211_CHAN_PRIV3 0x00000008 /* driver private bit 3 */ +#define IEEE80211_CHAN_TURBO 0x00000010 /* Turbo channel */ +#define IEEE80211_CHAN_CCK 0x00000020 /* CCK channel */ +#define IEEE80211_CHAN_OFDM 0x00000040 /* OFDM channel */ +#define IEEE80211_CHAN_2GHZ 0x00000080 /* 2 GHz spectrum channel. */ +#define IEEE80211_CHAN_5GHZ 0x00000100 /* 5 GHz spectrum channel */ +#define IEEE80211_CHAN_PASSIVE 0x00000200 /* Only passive scan allowed */ +#define IEEE80211_CHAN_DYN 0x00000400 /* Dynamic CCK-OFDM channel */ +#define IEEE80211_CHAN_GFSK 0x00000800 /* GFSK channel (FHSS PHY) */ +#define IEEE80211_CHAN_GSM 0x00001000 /* 900 MHz spectrum channel */ +#define IEEE80211_CHAN_STURBO 0x00002000 /* 11a static turbo channel only */ +#define IEEE80211_CHAN_HALF 0x00004000 /* Half rate channel */ +#define IEEE80211_CHAN_QUARTER 0x00008000 /* Quarter rate channel */ +#define IEEE80211_CHAN_HT20 0x00010000 /* HT 20 channel */ +#define IEEE80211_CHAN_HT40U 0x00020000 /* HT 40 channel w/ ext above */ +#define IEEE80211_CHAN_HT40D 0x00040000 /* HT 40 channel w/ ext below */ +#define IEEE80211_CHAN_DFS 0x00080000 /* DFS required */ +#define IEEE80211_CHAN_4MSXMIT 0x00100000 /* 4ms limit on frame length */ +#define IEEE80211_CHAN_NOADHOC 0x00200000 /* adhoc mode not allowed */ +#define IEEE80211_CHAN_NOHOSTAP 0x00400000 /* hostap mode not allowed */ +#define IEEE80211_CHAN_11D 0x00800000 /* 802.11d required */ + +#define IEEE80211_CHAN_HT40 (IEEE80211_CHAN_HT40U | IEEE80211_CHAN_HT40D) +#define IEEE80211_CHAN_HT (IEEE80211_CHAN_HT20 | IEEE80211_CHAN_HT40) + +#define IEEE80211_CHAN_BITS \ + "\20\1PRIV0\2PRIV2\3PRIV3\4PRIV4\5TURBO\6CCK\7OFDM\0102GHZ\0115GHZ" \ + "\12PASSIVE\13DYN\14GFSK\15GSM\16STURBO\17HALF\20QUARTER\21HT20" \ + "\22HT40U\23HT40D\24DFS\0254MSXMIT\26NOADHOC\27NOHOSTAP\03011D" + +/* + * Useful combinations of channel characteristics. + */ +#define IEEE80211_CHAN_FHSS \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK) +#define IEEE80211_CHAN_A \ + (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) +#define IEEE80211_CHAN_B \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) +#define IEEE80211_CHAN_PUREG \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM) +#define IEEE80211_CHAN_G \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN) +#define IEEE80211_CHAN_108A \ + (IEEE80211_CHAN_A | IEEE80211_CHAN_TURBO) +#define IEEE80211_CHAN_108G \ + (IEEE80211_CHAN_PUREG | IEEE80211_CHAN_TURBO) +#define IEEE80211_CHAN_ST \ + (IEEE80211_CHAN_108A | IEEE80211_CHAN_STURBO) + +#define IEEE80211_CHAN_ALL \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_GFSK | \ + IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_DYN | \ + IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER | \ + IEEE80211_CHAN_HT) +#define IEEE80211_CHAN_ALLTURBO \ + (IEEE80211_CHAN_ALL | IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO) + +#define IEEE80211_IS_CHAN_FHSS(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS) +#define IEEE80211_IS_CHAN_A(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) +#define IEEE80211_IS_CHAN_B(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) +#define IEEE80211_IS_CHAN_PUREG(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG) +#define IEEE80211_IS_CHAN_G(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) +#define IEEE80211_IS_CHAN_ANYG(_c) \ + (IEEE80211_IS_CHAN_PUREG(_c) || IEEE80211_IS_CHAN_G(_c)) +#define IEEE80211_IS_CHAN_ST(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) +#define IEEE80211_IS_CHAN_108A(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) +#define IEEE80211_IS_CHAN_108G(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) + +#define IEEE80211_IS_CHAN_2GHZ(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_2GHZ) != 0) +#define IEEE80211_IS_CHAN_5GHZ(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_5GHZ) != 0) +#define IEEE80211_IS_CHAN_PASSIVE(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_PASSIVE) != 0) +#define IEEE80211_IS_CHAN_OFDM(_c) \ + (((_c)->ic_flags & (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_DYN)) != 0) +#define IEEE80211_IS_CHAN_CCK(_c) \ + (((_c)->ic_flags & (IEEE80211_CHAN_CCK | IEEE80211_CHAN_DYN)) != 0) +#define IEEE80211_IS_CHAN_GFSK(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_GFSK) != 0) +#define IEEE80211_IS_CHAN_TURBO(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_TURBO) != 0) +#define IEEE80211_IS_CHAN_STURBO(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_STURBO) != 0) +#define IEEE80211_IS_CHAN_DTURBO(_c) \ + (((_c)->ic_flags & \ + (IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO)) == IEEE80211_CHAN_TURBO) +#define IEEE80211_IS_CHAN_HALF(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HALF) != 0) +#define IEEE80211_IS_CHAN_QUARTER(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_QUARTER) != 0) +#define IEEE80211_IS_CHAN_FULL(_c) \ + (((_c)->ic_flags & (IEEE80211_CHAN_QUARTER | IEEE80211_CHAN_HALF)) == 0) +#define IEEE80211_IS_CHAN_GSM(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_GSM) != 0) +#define IEEE80211_IS_CHAN_HT(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HT) != 0) +#define IEEE80211_IS_CHAN_HT20(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HT20) != 0) +#define IEEE80211_IS_CHAN_HT40(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HT40) != 0) +#define IEEE80211_IS_CHAN_HT40U(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HT40U) != 0) +#define IEEE80211_IS_CHAN_HT40D(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HT40D) != 0) +#define IEEE80211_IS_CHAN_HTA(_c) \ + (IEEE80211_IS_CHAN_5GHZ(_c) && \ + ((_c)->ic_flags & IEEE80211_CHAN_HT) != 0) +#define IEEE80211_IS_CHAN_HTG(_c) \ + (IEEE80211_IS_CHAN_2GHZ(_c) && \ + ((_c)->ic_flags & IEEE80211_CHAN_HT) != 0) +#define IEEE80211_IS_CHAN_DFS(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_DFS) != 0) +#define IEEE80211_IS_CHAN_NOADHOC(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_NOADHOC) != 0) +#define IEEE80211_IS_CHAN_NOHOSTAP(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_NOHOSTAP) != 0) +#define IEEE80211_IS_CHAN_11D(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_11D) != 0) + +#define IEEE80211_CHAN2IEEE(_c) (_c)->ic_ieee + +/* dynamic state */ +#define IEEE80211_CHANSTATE_RADAR 0x01 /* radar detected */ +#define IEEE80211_CHANSTATE_CACDONE 0x02 /* CAC completed */ +#define IEEE80211_CHANSTATE_CWINT 0x04 /* interference detected */ +#define IEEE80211_CHANSTATE_NORADAR 0x10 /* post notify on radar clear */ + +#define IEEE80211_IS_CHAN_RADAR(_c) \ + (((_c)->ic_state & IEEE80211_CHANSTATE_RADAR) != 0) +#define IEEE80211_IS_CHAN_CACDONE(_c) \ + (((_c)->ic_state & IEEE80211_CHANSTATE_CACDONE) != 0) +#define IEEE80211_IS_CHAN_CWINT(_c) \ + (((_c)->ic_state & IEEE80211_CHANSTATE_CWINT) != 0) + +/* ni_chan encoding for FH phy */ +#define IEEE80211_FH_CHANMOD 80 +#define IEEE80211_FH_CHAN(set,pat) (((set)-1)*IEEE80211_FH_CHANMOD+(pat)) +#define IEEE80211_FH_CHANSET(chan) ((chan)/IEEE80211_FH_CHANMOD+1) +#define IEEE80211_FH_CHANPAT(chan) ((chan)%IEEE80211_FH_CHANMOD) + +#define IEEE80211_TID_SIZE (WME_NUM_TID+1) /* WME TID's +1 for non-QoS */ +#define IEEE80211_NONQOS_TID WME_NUM_TID /* index for non-QoS sta */ + +/* + * The 802.11 spec says at most 2007 stations may be + * associated at once. For most AP's this is way more + * than is feasible so we use a default of 128. This + * number may be overridden by the driver and/or by + * user configuration but may not be less than IEEE80211_AID_MIN. + */ +#define IEEE80211_AID_DEF 128 +#define IEEE80211_AID_MIN 16 + +/* + * 802.11 rate set. + */ +#define IEEE80211_RATE_SIZE 8 /* 802.11 standard */ +#define IEEE80211_RATE_MAXSIZE 15 /* max rates we'll handle */ + +struct ieee80211_rateset { + uint8_t rs_nrates; + uint8_t rs_rates[IEEE80211_RATE_MAXSIZE]; +}; + +/* + * 802.11n variant of ieee80211_rateset. Instead of + * legacy rates the entries are MCS rates. We define + * the structure such that it can be used interchangeably + * with an ieee80211_rateset (modulo structure size). + */ +#define IEEE80211_HTRATE_MAXSIZE 127 + +struct ieee80211_htrateset { + uint8_t rs_nrates; + uint8_t rs_rates[IEEE80211_HTRATE_MAXSIZE]; +}; + +#define IEEE80211_RATE_MCS 0x80 + +/* + * Per-mode transmit parameters/controls visible to user space. + * These can be used to set fixed transmit rate for all operating + * modes or on a per-client basis according to the capabilities + * of the client (e.g. an 11b client associated to an 11g ap). + * + * MCS are distinguished from legacy rates by or'ing in 0x80. + */ +struct ieee80211_txparam { + uint8_t ucastrate; /* ucast data rate (legacy/MCS|0x80) */ + uint8_t mgmtrate; /* mgmt frame rate (legacy/MCS|0x80) */ + uint8_t mcastrate; /* multicast rate (legacy/MCS|0x80) */ + uint8_t maxretry; /* max unicast data retry count */ +}; + +/* + * Per-mode roaming state visible to user space. There are two + * thresholds that control whether roaming is considered; when + * either is exceeded the 802.11 layer will check the scan cache + * for another AP. If the cache is stale then a scan may be + * triggered. + */ +struct ieee80211_roamparam { + int8_t rssi; /* rssi thresh (.5 dBm) */ + uint8_t rate; /* tx rate thresh (.5 Mb/s or MCS) */ + uint16_t pad; /* reserve */ +}; + +/* + * Regulatory Information. + */ +struct ieee80211_regdomain { + uint16_t regdomain; /* SKU */ + uint16_t country; /* ISO country code */ + uint8_t location; /* I (indoor), O (outdoor), other */ + uint8_t ecm; /* Extended Channel Mode */ + char isocc[2]; /* country code string */ + short pad[2]; +}; + +/* + * MIMO antenna/radio state. + */ +struct ieee80211_mimo_info { + int8_t rssi[3]; /* per-antenna rssi */ + int8_t noise[3]; /* per-antenna noise floor */ + uint8_t pad[2]; + uint32_t evm[3]; /* EVM data */ +}; +#endif /* _FBSD_COMPAT_NET80211__IEEE80211_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211.h new file mode 100644 index 0000000000..2e4700b2e7 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211.h @@ -0,0 +1,1085 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_H_ + +/* + * 802.11 protocol definitions. + */ + +#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ +/* is 802.11 address multicast/broadcast? */ +#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01) + +typedef uint16_t ieee80211_seq; + +/* IEEE 802.11 PLCP header */ +struct ieee80211_plcp_hdr { + uint16_t i_sfd; + uint8_t i_signal; + uint8_t i_service; + uint16_t i_length; + uint16_t i_crc; +} __packed; + +#define IEEE80211_PLCP_SFD 0xF3A0 +#define IEEE80211_PLCP_SERVICE 0x00 +#define IEEE80211_PLCP_SERVICE_LOCKED 0x04 +#define IEEE80211_PLCL_SERVICE_PBCC 0x08 +#define IEEE80211_PLCP_SERVICE_LENEXT5 0x20 +#define IEEE80211_PLCP_SERVICE_LENEXT6 0x40 +#define IEEE80211_PLCP_SERVICE_LENEXT7 0x80 + +/* + * generic definitions for IEEE 802.11 frames + */ +struct ieee80211_frame { + uint8_t i_fc[2]; + uint8_t i_dur[2]; + uint8_t i_addr1[IEEE80211_ADDR_LEN]; + uint8_t i_addr2[IEEE80211_ADDR_LEN]; + uint8_t i_addr3[IEEE80211_ADDR_LEN]; + uint8_t i_seq[2]; + /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ + /* see below */ +} __packed; + +struct ieee80211_qosframe { + uint8_t i_fc[2]; + uint8_t i_dur[2]; + uint8_t i_addr1[IEEE80211_ADDR_LEN]; + uint8_t i_addr2[IEEE80211_ADDR_LEN]; + uint8_t i_addr3[IEEE80211_ADDR_LEN]; + uint8_t i_seq[2]; + uint8_t i_qos[2]; + /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ + /* see below */ +} __packed; + +struct ieee80211_qoscntl { + uint8_t i_qos[2]; +}; + +struct ieee80211_frame_addr4 { + uint8_t i_fc[2]; + uint8_t i_dur[2]; + uint8_t i_addr1[IEEE80211_ADDR_LEN]; + uint8_t i_addr2[IEEE80211_ADDR_LEN]; + uint8_t i_addr3[IEEE80211_ADDR_LEN]; + uint8_t i_seq[2]; + uint8_t i_addr4[IEEE80211_ADDR_LEN]; +} __packed; + + +struct ieee80211_qosframe_addr4 { + uint8_t i_fc[2]; + uint8_t i_dur[2]; + uint8_t i_addr1[IEEE80211_ADDR_LEN]; + uint8_t i_addr2[IEEE80211_ADDR_LEN]; + uint8_t i_addr3[IEEE80211_ADDR_LEN]; + uint8_t i_seq[2]; + uint8_t i_addr4[IEEE80211_ADDR_LEN]; + uint8_t i_qos[2]; +} __packed; + +#define IEEE80211_FC0_VERSION_MASK 0x03 +#define IEEE80211_FC0_VERSION_SHIFT 0 +#define IEEE80211_FC0_VERSION_0 0x00 +#define IEEE80211_FC0_TYPE_MASK 0x0c +#define IEEE80211_FC0_TYPE_SHIFT 2 +#define IEEE80211_FC0_TYPE_MGT 0x00 +#define IEEE80211_FC0_TYPE_CTL 0x04 +#define IEEE80211_FC0_TYPE_DATA 0x08 + +#define IEEE80211_FC0_SUBTYPE_MASK 0xf0 +#define IEEE80211_FC0_SUBTYPE_SHIFT 4 +/* for TYPE_MGT */ +#define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00 +#define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10 +#define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20 +#define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30 +#define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40 +#define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50 +#define IEEE80211_FC0_SUBTYPE_BEACON 0x80 +#define IEEE80211_FC0_SUBTYPE_ATIM 0x90 +#define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0 +#define IEEE80211_FC0_SUBTYPE_AUTH 0xb0 +#define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0 +#define IEEE80211_FC0_SUBTYPE_ACTION 0xd0 +/* for TYPE_CTL */ +#define IEEE80211_FC0_SUBTYPE_BAR 0x80 +#define IEEE80211_FC0_SUBTYPE_BA 0x90 +#define IEEE80211_FC0_SUBTYPE_PS_POLL 0xa0 +#define IEEE80211_FC0_SUBTYPE_RTS 0xb0 +#define IEEE80211_FC0_SUBTYPE_CTS 0xc0 +#define IEEE80211_FC0_SUBTYPE_ACK 0xd0 +#define IEEE80211_FC0_SUBTYPE_CF_END 0xe0 +#define IEEE80211_FC0_SUBTYPE_CF_END_ACK 0xf0 +/* for TYPE_DATA (bit combination) */ +#define IEEE80211_FC0_SUBTYPE_DATA 0x00 +#define IEEE80211_FC0_SUBTYPE_CF_ACK 0x10 +#define IEEE80211_FC0_SUBTYPE_CF_POLL 0x20 +#define IEEE80211_FC0_SUBTYPE_CF_ACPL 0x30 +#define IEEE80211_FC0_SUBTYPE_NODATA 0x40 +#define IEEE80211_FC0_SUBTYPE_CFACK 0x50 +#define IEEE80211_FC0_SUBTYPE_CFPOLL 0x60 +#define IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK 0x70 +#define IEEE80211_FC0_SUBTYPE_QOS 0x80 +#define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0 + +#define IEEE80211_FC1_DIR_MASK 0x03 +#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */ +#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */ +#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */ +#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */ + +#define IEEE80211_IS_DSTODS(wh) \ + (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) + +#define IEEE80211_FC1_MORE_FRAG 0x04 +#define IEEE80211_FC1_RETRY 0x08 +#define IEEE80211_FC1_PWR_MGT 0x10 +#define IEEE80211_FC1_MORE_DATA 0x20 +#define IEEE80211_FC1_WEP 0x40 +#define IEEE80211_FC1_ORDER 0x80 + +#define IEEE80211_SEQ_FRAG_MASK 0x000f +#define IEEE80211_SEQ_FRAG_SHIFT 0 +#define IEEE80211_SEQ_SEQ_MASK 0xfff0 +#define IEEE80211_SEQ_SEQ_SHIFT 4 +#define IEEE80211_SEQ_RANGE 4096 + +#define IEEE80211_SEQ_ADD(seq, incr) \ + (((seq) + (incr)) & (IEEE80211_SEQ_RANGE-1)) +#define IEEE80211_SEQ_INC(seq) IEEE80211_SEQ_ADD(seq,1) +#define IEEE80211_SEQ_SUB(a, b) \ + (((a) + IEEE80211_SEQ_RANGE - (b)) & (IEEE80211_SEQ_RANGE-1)) + +#define IEEE80211_SEQ_BA_RANGE 2048 /* 2^11 */ +#define IEEE80211_SEQ_BA_BEFORE(a, b) \ + (IEEE80211_SEQ_SUB(b, a+1) < IEEE80211_SEQ_BA_RANGE-1) + +#define IEEE80211_NWID_LEN 32 +#define IEEE80211_MESHID_LEN 32 + +#define IEEE80211_QOS_TXOP 0x00ff +/* bit 8 is reserved */ +#define IEEE80211_QOS_AMSDU 0x80 +#define IEEE80211_QOS_AMSDU_S 7 +#define IEEE80211_QOS_ACKPOLICY 0x60 +#define IEEE80211_QOS_ACKPOLICY_S 5 +#define IEEE80211_QOS_ACKPOLICY_NOACK 0x20 /* No ACK required */ +#define IEEE80211_QOS_ACKPOLICY_BA 0x60 /* Block ACK */ +#define IEEE80211_QOS_EOSP 0x10 /* EndOfService Period*/ +#define IEEE80211_QOS_EOSP_S 4 +#define IEEE80211_QOS_TID 0x0f + +/* does frame have QoS sequence control data */ +#define IEEE80211_QOS_HAS_SEQ(wh) \ + (((wh)->i_fc[0] & \ + (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \ + (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS)) + +/* + * WME/802.11e information element. + */ +struct ieee80211_wme_info { + uint8_t wme_id; /* IEEE80211_ELEMID_VENDOR */ + uint8_t wme_len; /* length in bytes */ + uint8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */ + uint8_t wme_type; /* OUI type */ + uint8_t wme_subtype; /* OUI subtype */ + uint8_t wme_version; /* spec revision */ + uint8_t wme_info; /* QoS info */ +} __packed; + +/* + * WME/802.11e Tspec Element + */ +struct ieee80211_wme_tspec { + uint8_t ts_id; + uint8_t ts_len; + uint8_t ts_oui[3]; + uint8_t ts_oui_type; + uint8_t ts_oui_subtype; + uint8_t ts_version; + uint8_t ts_tsinfo[3]; + uint8_t ts_nom_msdu[2]; + uint8_t ts_max_msdu[2]; + uint8_t ts_min_svc[4]; + uint8_t ts_max_svc[4]; + uint8_t ts_inactv_intv[4]; + uint8_t ts_susp_intv[4]; + uint8_t ts_start_svc[4]; + uint8_t ts_min_rate[4]; + uint8_t ts_mean_rate[4]; + uint8_t ts_max_burst[4]; + uint8_t ts_min_phy[4]; + uint8_t ts_peak_rate[4]; + uint8_t ts_delay[4]; + uint8_t ts_surplus[2]; + uint8_t ts_medium_time[2]; +} __packed; + +/* + * WME AC parameter field + */ +struct ieee80211_wme_acparams { + uint8_t acp_aci_aifsn; + uint8_t acp_logcwminmax; + uint16_t acp_txop; +} __packed; + +#define WME_NUM_AC 4 /* 4 AC categories */ +#define WME_NUM_TID 16 /* 16 tids */ + +#define WME_PARAM_ACI 0x60 /* Mask for ACI field */ +#define WME_PARAM_ACI_S 5 /* Shift for ACI field */ +#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */ +#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */ +#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */ +#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */ +#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */ +#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */ +#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */ +#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */ + +#define WME_AC_TO_TID(_ac) ( \ + ((_ac) == WME_AC_VO) ? 6 : \ + ((_ac) == WME_AC_VI) ? 5 : \ + ((_ac) == WME_AC_BK) ? 1 : \ + 0) + +#define TID_TO_WME_AC(_tid) ( \ + ((_tid) == 0 || (_tid) == 3) ? WME_AC_BE : \ + ((_tid) < 3) ? WME_AC_BK : \ + ((_tid) < 6) ? WME_AC_VI : \ + WME_AC_VO) + +/* + * WME Parameter Element + */ +struct ieee80211_wme_param { + uint8_t param_id; + uint8_t param_len; + uint8_t param_oui[3]; + uint8_t param_oui_type; + uint8_t param_oui_subtype; + uint8_t param_version; + uint8_t param_qosInfo; +#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */ + uint8_t param_reserved; + struct ieee80211_wme_acparams params_acParams[WME_NUM_AC]; +} __packed; + +/* + * Management Notification Frame + */ +struct ieee80211_mnf { + uint8_t mnf_category; + uint8_t mnf_action; + uint8_t mnf_dialog; + uint8_t mnf_status; +} __packed; +#define MNF_SETUP_REQ 0 +#define MNF_SETUP_RESP 1 +#define MNF_TEARDOWN 2 + +/* + * 802.11n Management Action Frames + */ +/* generic frame format */ +struct ieee80211_action { + uint8_t ia_category; + uint8_t ia_action; +} __packed; + +#define IEEE80211_ACTION_CAT_SM 0 /* Spectrum Management */ +#define IEEE80211_ACTION_CAT_QOS 1 /* QoS */ +#define IEEE80211_ACTION_CAT_DLS 2 /* DLS */ +#define IEEE80211_ACTION_CAT_BA 3 /* BA */ +#define IEEE80211_ACTION_CAT_HT 7 /* HT */ +#define IEEE80211_ACTION_CAT_VENDOR 127 /* Vendor Specific */ + +#define IEEE80211_ACTION_HT_TXCHWIDTH 0 /* recommended xmit chan width*/ +#define IEEE80211_ACTION_HT_MIMOPWRSAVE 1 /* MIMO power save */ + +/* HT - recommended transmission channel width */ +struct ieee80211_action_ht_txchwidth { + struct ieee80211_action at_header; + uint8_t at_chwidth; +} __packed; + +#define IEEE80211_A_HT_TXCHWIDTH_20 0 +#define IEEE80211_A_HT_TXCHWIDTH_2040 1 + +/* HT - MIMO Power Save (NB: D2.04) */ +struct ieee80211_action_ht_mimopowersave { + struct ieee80211_action am_header; + uint8_t am_control; +} __packed; + +#define IEEE80211_A_HT_MIMOPWRSAVE_ENA 0x01 /* PS enabled */ +#define IEEE80211_A_HT_MIMOPWRSAVE_MODE 0x02 +#define IEEE80211_A_HT_MIMOPWRSAVE_MODE_S 1 +#define IEEE80211_A_HT_MIMOPWRSAVE_DYNAMIC 0x02 /* Dynamic Mode */ +#define IEEE80211_A_HT_MIMOPWRSAVE_STATIC 0x00 /* no SM packets */ +/* bits 2-7 reserved */ + +/* Block Ack actions */ +#define IEEE80211_ACTION_BA_ADDBA_REQUEST 0 /* ADDBA request */ +#define IEEE80211_ACTION_BA_ADDBA_RESPONSE 1 /* ADDBA response */ +#define IEEE80211_ACTION_BA_DELBA 2 /* DELBA */ + +/* Block Ack Parameter Set */ +#define IEEE80211_BAPS_BUFSIZ 0xffc0 /* buffer size */ +#define IEEE80211_BAPS_BUFSIZ_S 6 +#define IEEE80211_BAPS_TID 0x003c /* TID */ +#define IEEE80211_BAPS_TID_S 2 +#define IEEE80211_BAPS_POLICY 0x0002 /* block ack policy */ +#define IEEE80211_BAPS_POLICY_S 1 + +#define IEEE80211_BAPS_POLICY_DELAYED (0< IEEE80211_MIN_LEN. The default + * mtu is Ethernet-compatible; it's set by ether_ifattach. + */ +#define IEEE80211_MTU_MAX 2290 +#define IEEE80211_MTU_MIN 32 + +#define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \ + (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN)) +#define IEEE80211_ACK_LEN \ + (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN) +#define IEEE80211_MIN_LEN \ + (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN) + +/* + * The 802.11 spec says at most 2007 stations may be + * associated at once. For most AP's this is way more + * than is feasible so we use a default of IEEE80211_AID_DEF. + * This number may be overridden by the driver and/or by + * user configuration but may not be less than IEEE80211_AID_MIN + * (see _ieee80211.h for implementation-specific settings). + */ +#define IEEE80211_AID_MAX 2007 + +#define IEEE80211_AID(b) ((b) &~ 0xc000) + +/* + * RTS frame length parameters. The default is specified in + * the 802.11 spec as 512; we treat it as implementation-dependent + * so it's defined in ieee80211_var.h. The max may be wrong + * for jumbo frames. + */ +#define IEEE80211_RTS_MIN 1 +#define IEEE80211_RTS_MAX 2346 + +/* + * TX fragmentation parameters. As above for RTS, we treat + * default as implementation-dependent so define it elsewhere. + */ +#define IEEE80211_FRAG_MIN 256 +#define IEEE80211_FRAG_MAX 2346 + +/* + * Beacon interval (TU's). Min+max come from WiFi requirements. + * As above, we treat default as implementation-dependent so + * define it elsewhere. + */ +#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */ +#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */ + +/* + * DTIM period (beacons). Min+max are not really defined + * by the protocol but we want them publicly visible so + * define them here. + */ +#define IEEE80211_DTIM_MAX 15 /* max DTIM period */ +#define IEEE80211_DTIM_MIN 1 /* min DTIM period */ + +/* + * Beacon miss threshold (beacons). As for DTIM, we define + * them here to be publicly visible. Note the max may be + * clamped depending on device capabilities. + */ +#define IEEE80211_HWBMISS_MIN 1 +#define IEEE80211_HWBMISS_MAX 255 + +/* + * 802.11 frame duration definitions. + */ + +struct ieee80211_duration { + uint16_t d_rts_dur; + uint16_t d_data_dur; + uint16_t d_plcp_len; + uint8_t d_residue; /* unused octets in time slot */ +}; + +/* One Time Unit (TU) is 1Kus = 1024 microseconds. */ +#define IEEE80211_DUR_TU 1024 + +/* IEEE 802.11b durations for DSSS PHY in microseconds */ +#define IEEE80211_DUR_DS_LONG_PREAMBLE 144 +#define IEEE80211_DUR_DS_SHORT_PREAMBLE 72 + +#define IEEE80211_DUR_DS_SLOW_PLCPHDR 48 +#define IEEE80211_DUR_DS_FAST_PLCPHDR 24 +#define IEEE80211_DUR_DS_SLOW_ACK 112 +#define IEEE80211_DUR_DS_FAST_ACK 56 +#define IEEE80211_DUR_DS_SLOW_CTS 112 +#define IEEE80211_DUR_DS_FAST_CTS 56 + +#define IEEE80211_DUR_DS_SLOT 20 +#define IEEE80211_DUR_DS_SIFS 10 +#define IEEE80211_DUR_DS_PIFS (IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT) +#define IEEE80211_DUR_DS_DIFS (IEEE80211_DUR_DS_SIFS + \ + 2 * IEEE80211_DUR_DS_SLOT) +#define IEEE80211_DUR_DS_EIFS (IEEE80211_DUR_DS_SIFS + \ + IEEE80211_DUR_DS_SLOW_ACK + \ + IEEE80211_DUR_DS_LONG_PREAMBLE + \ + IEEE80211_DUR_DS_SLOW_PLCPHDR + \ + IEEE80211_DUR_DIFS) + +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_action.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_action.h new file mode 100644 index 0000000000..9be0aba821 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_action.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_ACTION_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_ACTION_H_ + +/* + * 802.11 send/recv action frame support. + */ + +struct ieee80211_node; +struct ieee80211_frame; + +typedef int ieee80211_send_action_func(struct ieee80211_node *, + int, int, void *); +int ieee80211_send_action_register(int cat, int act, + ieee80211_send_action_func *f); +void ieee80211_send_action_unregister(int cat, int act); +int ieee80211_send_action(struct ieee80211_node *, int, int, void *); + +typedef int ieee80211_recv_action_func(struct ieee80211_node *, + const struct ieee80211_frame *, const uint8_t *, const uint8_t *); +int ieee80211_recv_action_register(int cat, int act, + ieee80211_recv_action_func *); +void ieee80211_recv_action_unregister(int cat, int act); +int ieee80211_recv_action(struct ieee80211_node *, + const struct ieee80211_frame *, + const uint8_t *, const uint8_t *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_ACTION_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_adhoc.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_adhoc.h new file mode 100644 index 0000000000..461c938976 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_adhoc.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_ADHOC_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_ADHOC_H_ + +/* + * Adhoc-mode (ibss+ahdemo) implementation definitions. + */ +void ieee80211_adhoc_attach(struct ieee80211com *); +void ieee80211_adhoc_detach(struct ieee80211com *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_STA_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ageq.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ageq.h new file mode 100644 index 0000000000..a187f41ac5 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ageq.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_STAGEQ_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_STAGEQ_H_ + +struct ieee80211_node; +struct mbuf; + +struct ieee80211_ageq { + ieee80211_ageq_lock_t aq_lock; + int aq_len; /* # items on queue */ + int aq_maxlen; /* max queue length */ + int aq_drops; /* frames dropped */ + struct mbuf *aq_head; /* frames linked w/ m_nextpkt */ + struct mbuf *aq_tail; /* last frame in queue */ +}; + +void ieee80211_ageq_init(struct ieee80211_ageq *, int maxlen, + const char *name); +void ieee80211_ageq_cleanup(struct ieee80211_ageq *); +void ieee80211_ageq_mfree(struct mbuf *); +int ieee80211_ageq_append(struct ieee80211_ageq *, struct mbuf *, + int age); +void ieee80211_ageq_drain(struct ieee80211_ageq *); +void ieee80211_ageq_drain_node(struct ieee80211_ageq *, + struct ieee80211_node *); +struct mbuf *ieee80211_ageq_age(struct ieee80211_ageq *, int quanta); +struct mbuf *ieee80211_ageq_remove(struct ieee80211_ageq *, + struct ieee80211_node *match); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_STAGEQ_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_amrr.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_amrr.h new file mode 100644 index 0000000000..fe4b224cf4 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_amrr.h @@ -0,0 +1,101 @@ +/* $FreeBSD$ */ +/* $OpenBSD: ieee80211_amrr.h,v 1.3 2006/06/17 19:34:31 damien Exp $ */ + +/*- + * Copyright (c) 2006 + * Damien Bergamini + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_AMRR_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_AMRR_H_ + +/*- + * Naive implementation of the Adaptive Multi Rate Retry algorithm: + * + * "IEEE 802.11 Rate Adaptation: A Practical Approach" + * Mathieu Lacage, Hossein Manshaei, Thierry Turletti + * INRIA Sophia - Projet Planete + * http://www-sop.inria.fr/rapports/sophia/RR-5208.html + */ + +/* + * Rate control settings. + */ +struct ieee80211vap; + +struct ieee80211_amrr { + u_int amrr_min_success_threshold; + u_int amrr_max_success_threshold; + int amrr_interval; /* update interval (ticks) */ +}; + +#define IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD 1 +#define IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD 15 + +/* + * Rate control state for a given node. + */ +struct ieee80211_amrr_node { + struct ieee80211_amrr *amn_amrr;/* backpointer */ + int amn_rix; /* current rate index */ + int amn_ticks; /* time of last update */ + /* statistics */ + u_int amn_txcnt; + u_int amn_success; + u_int amn_success_threshold; + u_int amn_recovery; + u_int amn_retrycnt; +}; + +void ieee80211_amrr_init(struct ieee80211_amrr *, struct ieee80211vap *, + int, int, int); +void ieee80211_amrr_cleanup(struct ieee80211_amrr *); +void ieee80211_amrr_setinterval(struct ieee80211_amrr *, int); +void ieee80211_amrr_node_init(struct ieee80211_amrr *, + struct ieee80211_amrr_node *, struct ieee80211_node *); +int ieee80211_amrr_choose(struct ieee80211_node *, + struct ieee80211_amrr_node *); + +#define IEEE80211_AMRR_SUCCESS 1 +#define IEEE80211_AMRR_FAILURE 0 + +/* + * Update statistics with tx complete status. Ok is non-zero + * if the packet is known to be ACK'd. Retries has the number + * retransmissions (i.e. xmit attempts - 1). + */ +static __inline void +ieee80211_amrr_tx_complete(struct ieee80211_amrr_node *amn, + int ok, int retries) +{ + amn->amn_txcnt++; + if (ok) + amn->amn_success++; + amn->amn_retrycnt += retries; +} + +/* + * Set tx count/retry statistics explicitly. Intended for + * drivers that poll the device for statistics maintained + * in the device. + */ +static __inline void +ieee80211_amrr_tx_update(struct ieee80211_amrr_node *amn, + int txcnt, int success, int retrycnt) +{ + amn->amn_txcnt = txcnt; + amn->amn_success = success; + amn->amn_retrycnt = retrycnt; +} +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_AMRR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_crypto.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_crypto.h new file mode 100644 index 0000000000..26f373bbce --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_crypto.h @@ -0,0 +1,243 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_CRYPTO_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_CRYPTO_H_ + +/* + * 802.11 protocol crypto-related definitions. + */ +#define IEEE80211_KEYBUF_SIZE 16 +#define IEEE80211_MICBUF_SIZE (8+8) /* space for both tx+rx keys */ + +/* + * Old WEP-style key. Deprecated. + */ +struct ieee80211_wepkey { + u_int wk_len; /* key length in bytes */ + uint8_t wk_key[IEEE80211_KEYBUF_SIZE]; +}; + +struct ieee80211_rsnparms { + uint8_t rsn_mcastcipher; /* mcast/group cipher */ + uint8_t rsn_mcastkeylen; /* mcast key length */ + uint8_t rsn_ucastcipher; /* selected unicast cipher */ + uint8_t rsn_ucastkeylen; /* unicast key length */ + uint8_t rsn_keymgmt; /* selected key mgmt algo */ + uint16_t rsn_caps; /* capabilities */ +}; + +struct ieee80211_cipher; + +/* + * Crypto key state. There is sufficient room for all supported + * ciphers (see below). The underlying ciphers are handled + * separately through loadable cipher modules that register with + * the generic crypto support. A key has a reference to an instance + * of the cipher; any per-key state is hung off wk_private by the + * cipher when it is attached. Ciphers are automatically called + * to detach and cleanup any such state when the key is deleted. + * + * The generic crypto support handles encap/decap of cipher-related + * frame contents for both hardware- and software-based implementations. + * A key requiring software crypto support is automatically flagged and + * the cipher is expected to honor this and do the necessary work. + * Ciphers such as TKIP may also support mixed hardware/software + * encrypt/decrypt and MIC processing. + */ +typedef uint16_t ieee80211_keyix; /* h/w key index */ + +struct ieee80211_key { + uint8_t wk_keylen; /* key length in bytes */ + uint8_t wk_pad; + uint16_t wk_flags; +#define IEEE80211_KEY_XMIT 0x0001 /* key used for xmit */ +#define IEEE80211_KEY_RECV 0x0002 /* key used for recv */ +#define IEEE80211_KEY_GROUP 0x0004 /* key used for WPA group operation */ +#define IEEE80211_KEY_SWENCRYPT 0x0010 /* host-based encrypt */ +#define IEEE80211_KEY_SWDECRYPT 0x0020 /* host-based decrypt */ +#define IEEE80211_KEY_SWENMIC 0x0040 /* host-based enmic */ +#define IEEE80211_KEY_SWDEMIC 0x0080 /* host-based demic */ +#define IEEE80211_KEY_DEVKEY 0x0100 /* device key request completed */ +#define IEEE80211_KEY_CIPHER0 0x1000 /* cipher-specific action 0 */ +#define IEEE80211_KEY_CIPHER1 0x2000 /* cipher-specific action 1 */ + ieee80211_keyix wk_keyix; /* h/w key index */ + ieee80211_keyix wk_rxkeyix; /* optional h/w rx key index */ + uint8_t wk_key[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE]; +#define wk_txmic wk_key+IEEE80211_KEYBUF_SIZE+0 /* XXX can't () right */ +#define wk_rxmic wk_key+IEEE80211_KEYBUF_SIZE+8 /* XXX can't () right */ + /* key receive sequence counter */ + uint64_t wk_keyrsc[IEEE80211_TID_SIZE]; + uint64_t wk_keytsc; /* key transmit sequence counter */ + const struct ieee80211_cipher *wk_cipher; + void *wk_private; /* private cipher state */ + uint8_t wk_macaddr[IEEE80211_ADDR_LEN]; +}; +#define IEEE80211_KEY_COMMON /* common flags passed in by apps */\ + (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV | IEEE80211_KEY_GROUP) +#define IEEE80211_KEY_DEVICE /* flags owned by device driver */\ + (IEEE80211_KEY_DEVKEY|IEEE80211_KEY_CIPHER0|IEEE80211_KEY_CIPHER1) + +#define IEEE80211_KEY_SWCRYPT \ + (IEEE80211_KEY_SWENCRYPT | IEEE80211_KEY_SWDECRYPT) +#define IEEE80211_KEY_SWMIC (IEEE80211_KEY_SWENMIC | IEEE80211_KEY_SWDEMIC) + +#define IEEE80211_KEY_BITS \ + "\20\1XMIT\2RECV\3GROUP\4SWENCRYPT\5SWDECRYPT\6SWENMIC\7SWDEMIC" \ + "\10DEVKEY\11CIPHER0\12CIPHER1" + +#define IEEE80211_KEYIX_NONE ((ieee80211_keyix) -1) + +/* + * NB: these values are ordered carefully; there are lots of + * of implications in any reordering. Beware that 4 is used + * only to indicate h/w TKIP MIC support in driver capabilities; + * there is no separate cipher support (it's rolled into the + * TKIP cipher support). + */ +#define IEEE80211_CIPHER_WEP 0 +#define IEEE80211_CIPHER_TKIP 1 +#define IEEE80211_CIPHER_AES_OCB 2 +#define IEEE80211_CIPHER_AES_CCM 3 +#define IEEE80211_CIPHER_TKIPMIC 4 /* TKIP MIC capability */ +#define IEEE80211_CIPHER_CKIP 5 +#define IEEE80211_CIPHER_NONE 6 /* pseudo value */ + +#define IEEE80211_CIPHER_MAX (IEEE80211_CIPHER_NONE+1) + +/* capability bits in ic_cryptocaps/iv_cryptocaps */ +#define IEEE80211_CRYPTO_WEP (1<wk_cipher == &ieee80211_cipher_none) + +void ieee80211_crypto_register(const struct ieee80211_cipher *); +void ieee80211_crypto_unregister(const struct ieee80211_cipher *); +int ieee80211_crypto_available(u_int cipher); + +struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211_node *, + struct mbuf *); +struct ieee80211_key *ieee80211_crypto_decap(struct ieee80211_node *, + struct mbuf *, int); + +/* + * Check and remove any MIC. + */ +static __inline int +ieee80211_crypto_demic(struct ieee80211vap *vap, struct ieee80211_key *k, + struct mbuf *m, int force) +{ + const struct ieee80211_cipher *cip = k->wk_cipher; + return (cip->ic_miclen > 0 ? cip->ic_demic(k, m, force) : 1); +} + +/* + * Add any MIC. + */ +static __inline int +ieee80211_crypto_enmic(struct ieee80211vap *vap, + struct ieee80211_key *k, struct mbuf *m, int force) +{ + const struct ieee80211_cipher *cip = k->wk_cipher; + return (cip->ic_miclen > 0 ? cip->ic_enmic(k, m, force) : 1); +} + +/* + * Reset key state to an unused state. The crypto + * key allocation mechanism insures other state (e.g. + * key data) is properly setup before a key is used. + */ +static __inline void +ieee80211_crypto_resetkey(struct ieee80211vap *vap, + struct ieee80211_key *k, ieee80211_keyix ix) +{ + k->wk_cipher = &ieee80211_cipher_none; + k->wk_private = k->wk_cipher->ic_attach(vap, k); + k->wk_keyix = k->wk_rxkeyix = ix; + k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV; +} + +/* + * Crypt-related notification methods. + */ +void ieee80211_notify_replay_failure(struct ieee80211vap *, + const struct ieee80211_frame *, const struct ieee80211_key *, + uint64_t rsc, int tid); +void ieee80211_notify_michael_failure(struct ieee80211vap *, + const struct ieee80211_frame *, u_int keyix); +#endif /* defined(__KERNEL__) || defined(_KERNEL) */ +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_CRYPTO_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_dfs.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_dfs.h new file mode 100644 index 0000000000..e448cc5ceb --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_dfs.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_DFS_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_DFS_H_ + +/* + * 802.11h/DFS definitions. + */ + +struct ieee80211_dfs_state { + int nol_event[IEEE80211_CHAN_MAX]; + struct callout nol_timer; /* NOL list processing */ + struct callout cac_timer; /* CAC timer */ + struct timeval lastevent; /* time of last radar event */ + int cureps; /* current events/second */ + const struct ieee80211_channel *lastchan;/* chan w/ last radar event */ + struct ieee80211_channel *newchan; /* chan selected next */ +}; + +void ieee80211_dfs_attach(struct ieee80211com *); +void ieee80211_dfs_detach(struct ieee80211com *); + +void ieee80211_dfs_reset(struct ieee80211com *); + +void ieee80211_dfs_cac_start(struct ieee80211vap *); +void ieee80211_dfs_cac_stop(struct ieee80211vap *); +void ieee80211_dfs_cac_clear(struct ieee80211com *, + const struct ieee80211_channel *); + +void ieee80211_dfs_notify_radar(struct ieee80211com *, + struct ieee80211_channel *); +struct ieee80211_channel *ieee80211_dfs_pickchannel(struct ieee80211com *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_DFS_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_haiku.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_haiku.h new file mode 100644 index 0000000000..7136575c8e --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_haiku.h @@ -0,0 +1,301 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_ + +#ifdef _KERNEL + +#include +#include +#include + + +/* + * Common state locking definitions. + */ +typedef struct { + char name[16]; /* e.g. "ath0_com_lock" */ + struct mtx mtx; +} ieee80211_com_lock_t; +#define IEEE80211_LOCK_INIT(_ic, _name) do { \ + ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \ + snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \ + mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF | MTX_RECURSE); \ +} while (0) +#define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.mtx) +#define IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_LOCK_OBJ(_ic)) +#define IEEE80211_LOCK(_ic) mtx_lock(IEEE80211_LOCK_OBJ(_ic)) +#define IEEE80211_UNLOCK(_ic) mtx_unlock(IEEE80211_LOCK_OBJ(_ic)) +#define IEEE80211_LOCK_ASSERT(_ic) \ + mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_OWNED) + +/* + * Node locking definitions. + */ +typedef struct { + char name[16]; /* e.g. "ath0_node_lock" */ + struct mtx mtx; +} ieee80211_node_lock_t; +#define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \ + ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \ + snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \ + mtx_init(&nl->mtx, nl->name, NULL, MTX_DEF | MTX_RECURSE); \ +} while (0) +#define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.mtx) +#define IEEE80211_NODE_LOCK_DESTROY(_nt) \ + mtx_destroy(IEEE80211_NODE_LOCK_OBJ(_nt)) +#define IEEE80211_NODE_LOCK(_nt) \ + mtx_lock(IEEE80211_NODE_LOCK_OBJ(_nt)) +#define IEEE80211_NODE_IS_LOCKED(_nt) \ + mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt)) +#define IEEE80211_NODE_UNLOCK(_nt) \ + mtx_unlock(IEEE80211_NODE_LOCK_OBJ(_nt)) +#define IEEE80211_NODE_LOCK_ASSERT(_nt) \ + mtx_assert(IEEE80211_NODE_LOCK_OBJ(_nt), MA_OWNED) + +/* + * Node table iteration locking definitions; this protects the + * scan generation # used to iterate over the station table + * while grabbing+releasing the node lock. + */ +typedef struct { + char name[16]; /* e.g. "ath0_scan_lock" */ + struct mtx mtx; +} ieee80211_scan_lock_t; +#define IEEE80211_NODE_ITERATE_LOCK_INIT(_nt, _name) do { \ + ieee80211_scan_lock_t *sl = &(_nt)->nt_scanlock; \ + snprintf(sl->name, sizeof(sl->name), "%s_scan_lock", _name); \ + mtx_init(&sl->mtx, sl->name, NULL, MTX_DEF); \ +} while (0) +#define IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt) (&(_nt)->nt_scanlock.mtx) +#define IEEE80211_NODE_ITERATE_LOCK_DESTROY(_nt) \ + mtx_destroy(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)) +#define IEEE80211_NODE_ITERATE_LOCK(_nt) \ + mtx_lock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)) +#define IEEE80211_NODE_ITERATE_UNLOCK(_nt) \ + mtx_unlock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)) + +/* + * Power-save queue definitions. + */ +typedef struct mtx ieee80211_psq_lock_t; +#define IEEE80211_PSQ_INIT(_psq, _name) \ + mtx_init(&(_psq)->psq_lock, _name, "802.11 ps q", MTX_DEF) +#define IEEE80211_PSQ_DESTROY(_psq) mtx_destroy(&(_psq)->psq_lock) +#define IEEE80211_PSQ_LOCK(_psq) mtx_lock(&(_psq)->psq_lock) +#define IEEE80211_PSQ_UNLOCK(_psq) mtx_unlock(&(_psq)->psq_lock) + +#ifndef IF_PREPEND_LIST +#define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ + (mtail)->m_nextpkt = (ifq)->ifq_head; \ + if ((ifq)->ifq_tail == NULL) \ + (ifq)->ifq_tail = (mtail); \ + (ifq)->ifq_head = (mhead); \ + (ifq)->ifq_len += (mcount); \ +} while (0) +#define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ + IF_LOCK(ifq); \ + _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \ + IF_UNLOCK(ifq); \ +} while (0) +#endif /* IF_PREPEND_LIST */ + +/* + * Age queue definitions. + */ +typedef struct mtx ieee80211_ageq_lock_t; +#define IEEE80211_AGEQ_INIT(_aq, _name) \ + mtx_init(&(_aq)->aq_lock, _name, "802.11 age q", MTX_DEF) +#define IEEE80211_AGEQ_DESTROY(_aq) mtx_destroy(&(_aq)->aq_lock) +#define IEEE80211_AGEQ_LOCK(_aq) mtx_lock(&(_aq)->aq_lock) +#define IEEE80211_AGEQ_UNLOCK(_aq) mtx_unlock(&(_aq)->aq_lock) + +/* + * Node reference counting definitions. + * + * ieee80211_node_initref initialize the reference count to 1 + * ieee80211_node_incref add a reference + * ieee80211_node_decref remove a reference + * ieee80211_node_dectestref remove a reference and return 1 if this + * is the last reference, otherwise 0 + * ieee80211_node_refcnt reference count for printing (only) + */ +#include + +#define ieee80211_node_initref(_ni) \ + do { ((_ni)->ni_refcnt = 1); } while (0) +#define ieee80211_node_incref(_ni) \ + atomic_add_int(&(_ni)->ni_refcnt, 1) +#define ieee80211_node_decref(_ni) \ + atomic_subtract_int(&(_ni)->ni_refcnt, 1) +struct ieee80211_node; +int ieee80211_node_dectestref(struct ieee80211_node *ni); +#define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt + +struct ifqueue; +struct ieee80211vap; +void ieee80211_drain_ifq(struct ifqueue *); +void ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *); + +void ieee80211_vap_destroy(struct ieee80211vap *); + +#define IFNET_IS_UP_RUNNING(_ifp) \ + (((_ifp)->if_flags & IFF_UP) && \ + ((_ifp)->if_drv_flags & IFF_DRV_RUNNING)) + +#define msecs_to_ticks(ms) (((ms)*hz)/1000) +#define ticks_to_msecs(t) (1000*(t) / hz) +#define ticks_to_secs(t) ((t) / hz) +#define time_after(a,b) ((long long)(b) - (long long)(a) < 0) +#define time_before(a,b) time_after(b,a) +#define time_after_eq(a,b) ((long long)(a) - (long long)(b) >= 0) +#define time_before_eq(a,b) time_after_eq(b,a) + +struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); + +/* tx path usage */ +#define M_ENCAP M_PROTO1 /* 802.11 encap done */ +#define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */ +#define M_PWR_SAV M_PROTO4 /* bypass PS handling */ +#define M_MORE_DATA M_PROTO5 /* more data frames to follow */ +#define M_FF M_PROTO6 /* fast frame */ +#define M_TXCB M_PROTO7 /* do tx complete callback */ +#define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */ +#define M_80211_TX \ + (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\ + M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU) + +/* rx path usage */ +#define M_AMPDU M_PROTO1 /* A-MPDU subframe */ +#define M_WEP M_PROTO2 /* WEP done by hardware */ +#if 0 +#define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */ +#endif +#define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU) + +/* + * Store WME access control bits in the vlan tag. + * This is safe since it's done after the packet is classified + * (where we use any previous tag) and because it's passed + * directly in to the driver and there's no chance someone + * else will clobber them on us. + */ +#define M_WME_SETAC(m, ac) \ + ((m)->m_pkthdr.ether_vtag = (ac)) +#define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vtag) + +/* + * Mbufs on the power save queue are tagged with an age and + * timed out. We reuse the hardware checksum field in the + * mbuf packet header to store this data. + */ +#define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) +#define M_AGE_GET(m) (m->m_pkthdr.csum_data) +#define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) + +/* + * Store the sequence number. + */ +#define M_SEQNO_SET(m, seqno) \ + ((m)->m_pkthdr.tso_segsz = (seqno)) +#define M_SEQNO_GET(m) ((m)->m_pkthdr.tso_segsz) + +#define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */ + +struct ieee80211_cb { + void (*func)(struct ieee80211_node *, void *, int status); + void *arg; +}; +#define NET80211_TAG_CALLBACK 0 /* xmit complete callback */ + +int ieee80211_add_callback(struct mbuf *m, + void (*func)(struct ieee80211_node *, void *, int), void *arg); +void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int); + +void get_random_bytes(void *, size_t); + +struct ieee80211com; + +void ieee80211_sysctl_attach(struct ieee80211com *); +void ieee80211_sysctl_detach(struct ieee80211com *); +void ieee80211_sysctl_vattach(struct ieee80211vap *); +void ieee80211_sysctl_vdetach(struct ieee80211vap *); + +void ieee80211_load_module(const char *); + +/* + * A "policy module" is an adjunct module to net80211 that provides + * functionality that typically includes policy decisions. This + * modularity enables extensibility and vendor-supplied functionality. + */ +#define _IEEE80211_POLICY_MODULE(policy, name, version) \ +typedef void (*policy##_setup)(int); \ +SET_DECLARE(policy##_set, policy##_setup); \ + +// l338 +/* + * Scanner modules provide scanning policy. + */ +#define IEEE80211_SCANNER_MODULE(name, version) \ + _IEEE80211_POLICY_MODULE(scanner, name, version) + +#define IEEE80211_SCANNER_ALG(name, alg, v) \ +static void \ +name##_modevent(int type) \ +{ \ + if (type == MOD_LOAD) \ + ieee80211_scanner_register(alg, &v); \ + else \ + ieee80211_scanner_unregister(alg, &v); \ +} \ +TEXT_SET(scanner_set, name##_modevent); \ + +struct ieee80211req; +typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, + struct ieee80211req *); +SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc); +#define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get) + +typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, + struct ieee80211req *); +SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc); +#define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set) +#endif /* _KERNEL */ + +/* + * Structure prepended to raw packets sent through the bpf + * interface when set to DLT_IEEE802_11_RADIO. This allows + * user applications to specify pretty much everything in + * an Atheros tx descriptor. XXX need to generalize. + * + * XXX cannot be more than 14 bytes as it is copied to a sockaddr's + * XXX sa_data area. + */ +struct ieee80211_bpf_params { + uint8_t ibp_vers; /* version */ +#define IEEE80211_BPF_VERSION 0 + uint8_t ibp_len; /* header length in bytes */ + uint8_t ibp_flags; +#define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ +#define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ +#define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ +#define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ +#define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ +#define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ +#define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ + uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ + uint8_t ibp_try0; /* series 1 try count */ + uint8_t ibp_rate0; /* series 1 IEEE tx rate */ + uint8_t ibp_power; /* tx power (device units) */ + uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ + uint8_t ibp_try1; /* series 2 try count */ + uint8_t ibp_rate1; /* series 2 IEEE tx rate */ + uint8_t ibp_try2; /* series 3 try count */ + uint8_t ibp_rate2; /* series 3 IEEE tx rate */ + uint8_t ibp_try3; /* series 4 try count */ + uint8_t ibp_rate3; /* series 4 IEEE tx rate */ +}; + +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_hostap.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_hostap.h new file mode 100644 index 0000000000..f3ecd69704 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_hostap.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_HOSTAP_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_HOSTAP_H_ + +/* + * Hostap implementation definitions. + */ +void ieee80211_hostap_attach(struct ieee80211com *); +void ieee80211_hostap_detach(struct ieee80211com *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_HOSTAP_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ht.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ht.h new file mode 100644 index 0000000000..4d81893918 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ht.h @@ -0,0 +1,204 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_HT_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_HT_H_ + +/* + * 802.11n protocol implementation definitions. + */ + +void ieee80211_ht_init(void); + +#define IEEE80211_AGGR_BAWMAX 64 /* max block ack window size */ +/* threshold for aging overlapping non-HT bss */ +#define IEEE80211_NONHT_PRESENT_AGE msecs_to_ticks(60*1000) + +struct ieee80211_tx_ampdu { + struct ieee80211_node *txa_ni; /* back pointer */ + u_short txa_flags; +#define IEEE80211_AGGR_IMMEDIATE 0x0001 /* BA policy */ +#define IEEE80211_AGGR_XCHGPEND 0x0002 /* ADDBA response pending */ +#define IEEE80211_AGGR_RUNNING 0x0004 /* ADDBA response received */ +#define IEEE80211_AGGR_SETUP 0x0008 /* deferred state setup */ +#define IEEE80211_AGGR_NAK 0x0010 /* peer NAK'd ADDBA request */ +#define IEEE80211_AGGR_BARPEND 0x0020 /* BAR response pending */ + uint8_t txa_ac; + uint8_t txa_token; /* dialog token */ + int txa_lastsample; /* ticks @ last traffic sample */ + int txa_pkts; /* packets over last sample interval */ + int txa_avgpps; /* filtered traffic over window */ + int txa_qbytes; /* data queued (bytes) */ + short txa_qframes; /* data queued (frames) */ + ieee80211_seq txa_start; /* BA window left edge */ + ieee80211_seq txa_seqpending; /* new txa_start pending BAR response */ + uint16_t txa_wnd; /* BA window size */ + uint8_t txa_attempts; /* # ADDBA/BAR requests w/o a response*/ + int txa_nextrequest;/* soonest to make next request */ + struct callout txa_timer; + void *txa_private; /* driver-private storage */ + uint64_t txa_pad[4]; +}; + +/* return non-zero if AMPDU tx for the TID is running */ +#define IEEE80211_AMPDU_RUNNING(tap) \ + (((tap)->txa_flags & IEEE80211_AGGR_RUNNING) != 0) + +/* return non-zero if AMPDU tx for the TID is running or started */ +#define IEEE80211_AMPDU_REQUESTED(tap) \ + (((tap)->txa_flags & \ + (IEEE80211_AGGR_RUNNING|IEEE80211_AGGR_XCHGPEND|IEEE80211_AGGR_NAK)) != 0) + +#define IEEE80211_AGGR_BITS \ + "\20\1IMMEDIATE\2XCHGPEND\3RUNNING\4SETUP\5NAK" + +/* + * Traffic estimator support. We estimate packets/sec for + * each AC that is setup for AMPDU or will potentially be + * setup for AMPDU. The traffic rate can be used to decide + * when AMPDU should be setup (according to a threshold) + * and is available for drivers to do things like cache + * eviction when only a limited number of BA streams are + * available and more streams are requested than available. + */ + +static __inline void +ieee80211_txampdu_update_pps(struct ieee80211_tx_ampdu *tap) +{ + /* NB: scale factor of 2 was picked heuristically */ + tap->txa_avgpps = ((tap->txa_avgpps << 2) - + tap->txa_avgpps + tap->txa_pkts) >> 2; +} + +/* + * Count a packet towards the pps estimate. + */ +static __inline void +ieee80211_txampdu_count_packet(struct ieee80211_tx_ampdu *tap) +{ + /* XXX bound loop/do more crude estimate? */ + while (ticks - tap->txa_lastsample >= hz) { + ieee80211_txampdu_update_pps(tap); + /* reset to start new sample interval */ + tap->txa_pkts = 0; + if (tap->txa_avgpps == 0) { + tap->txa_lastsample = ticks; + break; + } + tap->txa_lastsample += hz; + } + tap->txa_pkts++; +} + +/* + * Get the current pps estimate. If the average is out of + * date due to lack of traffic then we decay the estimate + * to account for the idle time. + */ +static __inline int +ieee80211_txampdu_getpps(struct ieee80211_tx_ampdu *tap) +{ + /* XXX bound loop/do more crude estimate? */ + while (ticks - tap->txa_lastsample >= hz) { + ieee80211_txampdu_update_pps(tap); + tap->txa_pkts = 0; + if (tap->txa_avgpps == 0) { + tap->txa_lastsample = ticks; + break; + } + tap->txa_lastsample += hz; + } + return tap->txa_avgpps; +} + +struct ieee80211_rx_ampdu { + int rxa_flags; + int rxa_qbytes; /* data queued (bytes) */ + short rxa_qframes; /* data queued (frames) */ + ieee80211_seq rxa_seqstart; + ieee80211_seq rxa_start; /* start of current BA window */ + uint16_t rxa_wnd; /* BA window size */ + int rxa_age; /* age of oldest frame in window */ + int rxa_nframes; /* frames since ADDBA */ + struct mbuf *rxa_m[IEEE80211_AGGR_BAWMAX]; + uint64_t rxa_pad[4]; +}; + +void ieee80211_ht_attach(struct ieee80211com *); +void ieee80211_ht_detach(struct ieee80211com *); +void ieee80211_ht_vattach(struct ieee80211vap *); +void ieee80211_ht_vdetach(struct ieee80211vap *); + +void ieee80211_ht_announce(struct ieee80211com *); + +struct ieee80211_mcs_rates { + uint16_t ht20_rate_800ns; + uint16_t ht20_rate_400ns; + uint16_t ht40_rate_800ns; + uint16_t ht40_rate_400ns; +}; +extern const struct ieee80211_mcs_rates ieee80211_htrates[16]; +const struct ieee80211_htrateset *ieee80211_get_suphtrates( + struct ieee80211com *, const struct ieee80211_channel *); + +struct ieee80211_node; +int ieee80211_setup_htrates(struct ieee80211_node *, + const uint8_t *htcap, int flags); +void ieee80211_setup_basic_htrates(struct ieee80211_node *, + const uint8_t *htinfo); +struct mbuf *ieee80211_decap_amsdu(struct ieee80211_node *, struct mbuf *); +int ieee80211_ampdu_reorder(struct ieee80211_node *, struct mbuf *); +void ieee80211_recv_bar(struct ieee80211_node *, struct mbuf *); +void ieee80211_ht_node_init(struct ieee80211_node *); +void ieee80211_ht_node_cleanup(struct ieee80211_node *); +void ieee80211_ht_node_age(struct ieee80211_node *); + +struct ieee80211_channel *ieee80211_ht_adjust_channel(struct ieee80211com *, + struct ieee80211_channel *, int); +void ieee80211_ht_wds_init(struct ieee80211_node *); +void ieee80211_ht_node_join(struct ieee80211_node *); +void ieee80211_ht_node_leave(struct ieee80211_node *); +void ieee80211_htprot_update(struct ieee80211com *, int protmode); +void ieee80211_ht_timeout(struct ieee80211com *); +void ieee80211_parse_htcap(struct ieee80211_node *, const uint8_t *); +void ieee80211_parse_htinfo(struct ieee80211_node *, const uint8_t *); +void ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *, + const uint8_t *); +void ieee80211_ht_updatehtcap(struct ieee80211_node *, const uint8_t *); +int ieee80211_ampdu_request(struct ieee80211_node *, + struct ieee80211_tx_ampdu *); +void ieee80211_ampdu_stop(struct ieee80211_node *, + struct ieee80211_tx_ampdu *, int); +int ieee80211_send_bar(struct ieee80211_node *, struct ieee80211_tx_ampdu *, + ieee80211_seq); +uint8_t *ieee80211_add_htcap(uint8_t *, struct ieee80211_node *); +uint8_t *ieee80211_add_htcap_vendor(uint8_t *, struct ieee80211_node *); +uint8_t *ieee80211_add_htinfo(uint8_t *, struct ieee80211_node *); +uint8_t *ieee80211_add_htinfo_vendor(uint8_t *, struct ieee80211_node *); +struct ieee80211_beacon_offsets; +void ieee80211_ht_update_beacon(struct ieee80211vap *, + struct ieee80211_beacon_offsets *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_HT_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_input.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_input.h new file mode 100644 index 0000000000..921d07c238 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_input.h @@ -0,0 +1,160 @@ +/*- + * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_INPUT_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_INPUT_H_ + +/* Verify the existence and length of __elem or get out. */ +#define IEEE80211_VERIFY_ELEMENT(__elem, __maxlen, _action) do { \ + if ((__elem) == NULL) { \ + IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID, \ + wh, NULL, "%s", "no " #__elem ); \ + vap->iv_stats.is_rx_elem_missing++; \ + _action; \ + } else if ((__elem)[1] > (__maxlen)) { \ + IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID, \ + wh, NULL, "bad " #__elem " len %d", (__elem)[1]); \ + vap->iv_stats.is_rx_elem_toobig++; \ + _action; \ + } \ +} while (0) + +#define IEEE80211_VERIFY_LENGTH(_len, _minlen, _action) do { \ + if ((_len) < (_minlen)) { \ + IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID, \ + wh, NULL, "ie too short, got %d, expected %d", \ + (_len), (_minlen)); \ + vap->iv_stats.is_rx_elem_toosmall++; \ + _action; \ + } \ +} while (0) + +#ifdef IEEE80211_DEBUG +void ieee80211_ssid_mismatch(struct ieee80211vap *, const char *tag, + uint8_t mac[IEEE80211_ADDR_LEN], uint8_t *ssid); + +#define IEEE80211_VERIFY_SSID(_ni, _ssid, _action) do { \ + if ((_ssid)[1] != 0 && \ + ((_ssid)[1] != (_ni)->ni_esslen || \ + memcmp((_ssid) + 2, (_ni)->ni_essid, (_ssid)[1]) != 0)) { \ + if (ieee80211_msg_input(vap)) \ + ieee80211_ssid_mismatch(vap, \ + ieee80211_mgt_subtype_name[subtype >> \ + IEEE80211_FC0_SUBTYPE_SHIFT], \ + wh->i_addr2, _ssid); \ + vap->iv_stats.is_rx_ssidmismatch++; \ + _action; \ + } \ +} while (0) +#else /* !IEEE80211_DEBUG */ +#define IEEE80211_VERIFY_SSID(_ni, _ssid, _action) do { \ + if ((_ssid)[1] != 0 && \ + ((_ssid)[1] != (_ni)->ni_esslen || \ + memcmp((_ssid) + 2, (_ni)->ni_essid, (_ssid)[1]) != 0)) { \ + vap->iv_stats.is_rx_ssidmismatch++; \ + _action; \ + } \ +} while (0) +#endif /* !IEEE80211_DEBUG */ + +/* unalligned little endian access */ +#define LE_READ_2(p) \ + ((uint16_t) \ + ((((const uint8_t *)(p))[0] ) | \ + (((const uint8_t *)(p))[1] << 8))) +#define LE_READ_4(p) \ + ((uint32_t) \ + ((((const uint8_t *)(p))[0] ) | \ + (((const uint8_t *)(p))[1] << 8) | \ + (((const uint8_t *)(p))[2] << 16) | \ + (((const uint8_t *)(p))[3] << 24))) + +static __inline int +iswpaoui(const uint8_t *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI); +} + +static __inline int +iswmeoui(const uint8_t *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI); +} + +static __inline int +iswmeparam(const uint8_t *frm) +{ + return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && + frm[6] == WME_PARAM_OUI_SUBTYPE; +} + +static __inline int +iswmeinfo(const uint8_t *frm) +{ + return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && + frm[6] == WME_INFO_OUI_SUBTYPE; +} + +static __inline int +isatherosoui(const uint8_t *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI); +} + +static __inline int +istdmaoui(const uint8_t *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI); +} + +static __inline int +ishtcapoui(const uint8_t *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTCAP<<24)|BCM_OUI); +} + +static __inline int +ishtinfooui(const uint8_t *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTINFO<<24)|BCM_OUI); +} + +void ieee80211_deliver_data(struct ieee80211vap *, + struct ieee80211_node *, struct mbuf *); +struct mbuf *ieee80211_defrag(struct ieee80211_node *, + struct mbuf *, int); +struct mbuf *ieee80211_realign(struct ieee80211vap *, struct mbuf *, size_t); +struct mbuf *ieee80211_decap(struct ieee80211vap *, struct mbuf *, int); +struct mbuf *ieee80211_decap1(struct mbuf *, int *); +int ieee80211_setup_rates(struct ieee80211_node *ni, + const uint8_t *rates, const uint8_t *xrates, int flags); +void ieee80211_send_error(struct ieee80211_node *, + const uint8_t mac[IEEE80211_ADDR_LEN], int subtype, int arg); +int ieee80211_alloc_challenge(struct ieee80211_node *); +int ieee80211_parse_beacon(struct ieee80211_node *, struct mbuf *, + struct ieee80211_scanparams *); +int ieee80211_parse_action(struct ieee80211_node *, struct mbuf *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_INPUT_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ioctl.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ioctl.h new file mode 100644 index 0000000000..73c6aeefaa --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_ioctl.h @@ -0,0 +1,848 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_IOCTL_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_IOCTL_H_ + +/* + * IEEE 802.11 ioctls. + */ +#include +#include +#include + +/* + * Per/node (station) statistics. + */ +struct ieee80211_nodestats { + uint32_t ns_rx_data; /* rx data frames */ + uint32_t ns_rx_mgmt; /* rx management frames */ + uint32_t ns_rx_ctrl; /* rx control frames */ + uint32_t ns_rx_ucast; /* rx unicast frames */ + uint32_t ns_rx_mcast; /* rx multi/broadcast frames */ + uint64_t ns_rx_bytes; /* rx data count (bytes) */ + uint64_t ns_rx_beacons; /* rx beacon frames */ + uint32_t ns_rx_proberesp; /* rx probe response frames */ + + uint32_t ns_rx_dup; /* rx discard 'cuz dup */ + uint32_t ns_rx_noprivacy; /* rx w/ wep but privacy off */ + uint32_t ns_rx_wepfail; /* rx wep processing failed */ + uint32_t ns_rx_demicfail; /* rx demic failed */ + uint32_t ns_rx_decap; /* rx decapsulation failed */ + uint32_t ns_rx_defrag; /* rx defragmentation failed */ + uint32_t ns_rx_disassoc; /* rx disassociation */ + uint32_t ns_rx_deauth; /* rx deauthentication */ + uint32_t ns_rx_action; /* rx action */ + uint32_t ns_rx_decryptcrc; /* rx decrypt failed on crc */ + uint32_t ns_rx_unauth; /* rx on unauthorized port */ + uint32_t ns_rx_unencrypted; /* rx unecrypted w/ privacy */ + uint32_t ns_rx_drop; /* rx discard other reason */ + + uint32_t ns_tx_data; /* tx data frames */ + uint32_t ns_tx_mgmt; /* tx management frames */ + uint32_t ns_tx_ctrl; /* tx control frames */ + uint32_t ns_tx_ucast; /* tx unicast frames */ + uint32_t ns_tx_mcast; /* tx multi/broadcast frames */ + uint64_t ns_tx_bytes; /* tx data count (bytes) */ + uint32_t ns_tx_probereq; /* tx probe request frames */ + + uint32_t ns_tx_novlantag; /* tx discard 'cuz no tag */ + uint32_t ns_tx_vlanmismatch; /* tx discard 'cuz bad tag */ + + uint32_t ns_ps_discard; /* ps discard 'cuz of age */ + + /* MIB-related state */ + uint32_t ns_tx_assoc; /* [re]associations */ + uint32_t ns_tx_assoc_fail; /* [re]association failures */ + uint32_t ns_tx_auth; /* [re]authentications */ + uint32_t ns_tx_auth_fail; /* [re]authentication failures*/ + uint32_t ns_tx_deauth; /* deauthentications */ + uint32_t ns_tx_deauth_code; /* last deauth reason */ + uint32_t ns_tx_disassoc; /* disassociations */ + uint32_t ns_tx_disassoc_code; /* last disassociation reason */ + uint32_t ns_spare[8]; +}; + +/* + * Summary statistics. + */ +struct ieee80211_stats { + uint32_t is_rx_badversion; /* rx frame with bad version */ + uint32_t is_rx_tooshort; /* rx frame too short */ + uint32_t is_rx_wrongbss; /* rx from wrong bssid */ + uint32_t is_rx_dup; /* rx discard 'cuz dup */ + uint32_t is_rx_wrongdir; /* rx w/ wrong direction */ + uint32_t is_rx_mcastecho; /* rx discard 'cuz mcast echo */ + uint32_t is_rx_notassoc; /* rx discard 'cuz sta !assoc */ + uint32_t is_rx_noprivacy; /* rx w/ wep but privacy off */ + uint32_t is_rx_unencrypted; /* rx w/o wep and privacy on */ + uint32_t is_rx_wepfail; /* rx wep processing failed */ + uint32_t is_rx_decap; /* rx decapsulation failed */ + uint32_t is_rx_mgtdiscard; /* rx discard mgt frames */ + uint32_t is_rx_ctl; /* rx ctrl frames */ + uint32_t is_rx_beacon; /* rx beacon frames */ + uint32_t is_rx_rstoobig; /* rx rate set truncated */ + uint32_t is_rx_elem_missing; /* rx required element missing*/ + uint32_t is_rx_elem_toobig; /* rx element too big */ + uint32_t is_rx_elem_toosmall; /* rx element too small */ + uint32_t is_rx_elem_unknown; /* rx element unknown */ + uint32_t is_rx_badchan; /* rx frame w/ invalid chan */ + uint32_t is_rx_chanmismatch; /* rx frame chan mismatch */ + uint32_t is_rx_nodealloc; /* rx frame dropped */ + uint32_t is_rx_ssidmismatch; /* rx frame ssid mismatch */ + uint32_t is_rx_auth_unsupported; /* rx w/ unsupported auth alg */ + uint32_t is_rx_auth_fail; /* rx sta auth failure */ + uint32_t is_rx_auth_countermeasures;/* rx auth discard 'cuz CM */ + uint32_t is_rx_assoc_bss; /* rx assoc from wrong bssid */ + uint32_t is_rx_assoc_notauth; /* rx assoc w/o auth */ + uint32_t is_rx_assoc_capmismatch;/* rx assoc w/ cap mismatch */ + uint32_t is_rx_assoc_norate; /* rx assoc w/ no rate match */ + uint32_t is_rx_assoc_badwpaie; /* rx assoc w/ bad WPA IE */ + uint32_t is_rx_deauth; /* rx deauthentication */ + uint32_t is_rx_disassoc; /* rx disassociation */ + uint32_t is_rx_badsubtype; /* rx frame w/ unknown subtype*/ + uint32_t is_rx_nobuf; /* rx failed for lack of buf */ + uint32_t is_rx_decryptcrc; /* rx decrypt failed on crc */ + uint32_t is_rx_ahdemo_mgt; /* rx discard ahdemo mgt frame*/ + uint32_t is_rx_bad_auth; /* rx bad auth request */ + uint32_t is_rx_unauth; /* rx on unauthorized port */ + uint32_t is_rx_badkeyid; /* rx w/ incorrect keyid */ + uint32_t is_rx_ccmpreplay; /* rx seq# violation (CCMP) */ + uint32_t is_rx_ccmpformat; /* rx format bad (CCMP) */ + uint32_t is_rx_ccmpmic; /* rx MIC check failed (CCMP) */ + uint32_t is_rx_tkipreplay; /* rx seq# violation (TKIP) */ + uint32_t is_rx_tkipformat; /* rx format bad (TKIP) */ + uint32_t is_rx_tkipmic; /* rx MIC check failed (TKIP) */ + uint32_t is_rx_tkipicv; /* rx ICV check failed (TKIP) */ + uint32_t is_rx_badcipher; /* rx failed 'cuz key type */ + uint32_t is_rx_nocipherctx; /* rx failed 'cuz key !setup */ + uint32_t is_rx_acl; /* rx discard 'cuz acl policy */ + uint32_t is_tx_nobuf; /* tx failed for lack of buf */ + uint32_t is_tx_nonode; /* tx failed for no node */ + uint32_t is_tx_unknownmgt; /* tx of unknown mgt frame */ + uint32_t is_tx_badcipher; /* tx failed 'cuz key type */ + uint32_t is_tx_nodefkey; /* tx failed 'cuz no defkey */ + uint32_t is_tx_noheadroom; /* tx failed 'cuz no space */ + uint32_t is_tx_fragframes; /* tx frames fragmented */ + uint32_t is_tx_frags; /* tx fragments created */ + uint32_t is_scan_active; /* active scans started */ + uint32_t is_scan_passive; /* passive scans started */ + uint32_t is_node_timeout; /* nodes timed out inactivity */ + uint32_t is_crypto_nomem; /* no memory for crypto ctx */ + uint32_t is_crypto_tkip; /* tkip crypto done in s/w */ + uint32_t is_crypto_tkipenmic; /* tkip en-MIC done in s/w */ + uint32_t is_crypto_tkipdemic; /* tkip de-MIC done in s/w */ + uint32_t is_crypto_tkipcm; /* tkip counter measures */ + uint32_t is_crypto_ccmp; /* ccmp crypto done in s/w */ + uint32_t is_crypto_wep; /* wep crypto done in s/w */ + uint32_t is_crypto_setkey_cipher;/* cipher rejected key */ + uint32_t is_crypto_setkey_nokey; /* no key index for setkey */ + uint32_t is_crypto_delkey; /* driver key delete failed */ + uint32_t is_crypto_badcipher; /* unknown cipher */ + uint32_t is_crypto_nocipher; /* cipher not available */ + uint32_t is_crypto_attachfail; /* cipher attach failed */ + uint32_t is_crypto_swfallback; /* cipher fallback to s/w */ + uint32_t is_crypto_keyfail; /* driver key alloc failed */ + uint32_t is_crypto_enmicfail; /* en-MIC failed */ + uint32_t is_ibss_capmismatch; /* merge failed-cap mismatch */ + uint32_t is_ibss_norate; /* merge failed-rate mismatch */ + uint32_t is_ps_unassoc; /* ps-poll for unassoc. sta */ + uint32_t is_ps_badaid; /* ps-poll w/ incorrect aid */ + uint32_t is_ps_qempty; /* ps-poll w/ nothing to send */ + uint32_t is_ff_badhdr; /* fast frame rx'd w/ bad hdr */ + uint32_t is_ff_tooshort; /* fast frame rx decap error */ + uint32_t is_ff_split; /* fast frame rx split error */ + uint32_t is_ff_decap; /* fast frames decap'd */ + uint32_t is_ff_encap; /* fast frames encap'd for tx */ + uint32_t is_rx_badbintval; /* rx frame w/ bogus bintval */ + uint32_t is_rx_demicfail; /* rx demic failed */ + uint32_t is_rx_defrag; /* rx defragmentation failed */ + uint32_t is_rx_mgmt; /* rx management frames */ + uint32_t is_rx_action; /* rx action mgt frames */ + uint32_t is_amsdu_tooshort; /* A-MSDU rx decap error */ + uint32_t is_amsdu_split; /* A-MSDU rx split error */ + uint32_t is_amsdu_decap; /* A-MSDU decap'd */ + uint32_t is_amsdu_encap; /* A-MSDU encap'd for tx */ + uint32_t is_ampdu_bar_bad; /* A-MPDU BAR out of window */ + uint32_t is_ampdu_bar_oow; /* A-MPDU BAR before ADDBA */ + uint32_t is_ampdu_bar_move; /* A-MPDU BAR moved window */ + uint32_t is_ampdu_bar_rx; /* A-MPDU BAR frames handled */ + uint32_t is_ampdu_rx_flush; /* A-MPDU frames flushed */ + uint32_t is_ampdu_rx_oor; /* A-MPDU frames out-of-order */ + uint32_t is_ampdu_rx_copy; /* A-MPDU frames copied down */ + uint32_t is_ampdu_rx_drop; /* A-MPDU frames dropped */ + uint32_t is_tx_badstate; /* tx discard state != RUN */ + uint32_t is_tx_notassoc; /* tx failed, sta not assoc */ + uint32_t is_tx_classify; /* tx classification failed */ + uint32_t is_dwds_mcast; /* discard mcast over dwds */ + uint32_t is_dwds_qdrop; /* dwds pending frame q full */ + uint32_t is_ht_assoc_nohtcap; /* non-HT sta rejected */ + uint32_t is_ht_assoc_downgrade; /* HT sta forced to legacy */ + uint32_t is_ht_assoc_norate; /* HT assoc w/ rate mismatch */ + uint32_t is_ampdu_rx_age; /* A-MPDU sent up 'cuz of age */ + uint32_t is_ampdu_rx_move; /* A-MPDU MSDU moved window */ + uint32_t is_addba_reject; /* ADDBA reject 'cuz disabled */ + uint32_t is_addba_norequest; /* ADDBA response w/o ADDBA */ + uint32_t is_addba_badtoken; /* ADDBA response w/ wrong + dialogtoken */ + uint32_t is_addba_badpolicy; /* ADDBA resp w/ wrong policy */ + uint32_t is_ampdu_stop; /* A-MPDU stream stopped */ + uint32_t is_ampdu_stop_failed; /* A-MPDU stream not running */ + uint32_t is_ampdu_rx_reorder; /* A-MPDU held for rx reorder */ + uint32_t is_scan_bg; /* background scans started */ + uint8_t is_rx_deauth_code; /* last rx'd deauth reason */ + uint8_t is_rx_disassoc_code; /* last rx'd disassoc reason */ + uint8_t is_rx_authfail_code; /* last rx'd auth fail reason */ + uint32_t is_beacon_miss; /* beacon miss notification */ + uint32_t is_rx_badstate; /* rx discard state != RUN */ + uint32_t is_ff_flush; /* ff's flush'd from stageq */ + uint32_t is_tx_ctl; /* tx ctrl frames */ + uint32_t is_ampdu_rexmt; /* A-MPDU frames rexmt ok */ + uint32_t is_ampdu_rexmt_fail; /* A-MPDU frames rexmt fail */ + + uint32_t is_mesh_wrongmesh; /* dropped 'cuz not mesh sta*/ + uint32_t is_mesh_nolink; /* dropped 'cuz link not estab*/ + uint32_t is_mesh_fwd_ttl; /* mesh not fwd'd 'cuz ttl 0 */ + uint32_t is_mesh_fwd_nobuf; /* mesh not fwd'd 'cuz no mbuf*/ + uint32_t is_mesh_fwd_tooshort; /* mesh not fwd'd 'cuz no hdr */ + uint32_t is_mesh_fwd_disabled; /* mesh not fwd'd 'cuz disabled */ + uint32_t is_mesh_fwd_nopath; /* mesh not fwd'd 'cuz path unknown */ + + uint32_t is_hwmp_wrongseq; /* wrong hwmp seq no. */ + uint32_t is_hwmp_rootreqs; /* root PREQs sent */ + uint32_t is_hwmp_rootrann; /* root RANNs sent */ + + uint32_t is_mesh_badae; /* dropped 'cuz invalid AE */ + uint32_t is_mesh_rtaddfailed; /* route add failed */ + uint32_t is_mesh_notproxy; /* dropped 'cuz not proxying */ + uint32_t is_rx_badalign; /* dropped 'cuz misaligned */ + uint32_t is_hwmp_proxy; /* PREP for proxy route */ + + uint32_t is_spare[11]; +}; + +/* + * Max size of optional information elements. We artificially + * constrain this; it's limited only by the max frame size (and + * the max parameter size of the wireless extensions). + */ +#define IEEE80211_MAX_OPT_IE 256 + +/* + * WPA/RSN get/set key request. Specify the key/cipher + * type and whether the key is to be used for sending and/or + * receiving. The key index should be set only when working + * with global keys (use IEEE80211_KEYIX_NONE for ``no index''). + * Otherwise a unicast/pairwise key is specified by the bssid + * (on a station) or mac address (on an ap). They key length + * must include any MIC key data; otherwise it should be no + * more than IEEE80211_KEYBUF_SIZE. + */ +struct ieee80211req_key { + uint8_t ik_type; /* key/cipher type */ + uint8_t ik_pad; + uint16_t ik_keyix; /* key index */ + uint8_t ik_keylen; /* key length in bytes */ + uint8_t ik_flags; +/* NB: IEEE80211_KEY_XMIT and IEEE80211_KEY_RECV defined elsewhere */ +#define IEEE80211_KEY_DEFAULT 0x80 /* default xmit key */ + uint8_t ik_macaddr[IEEE80211_ADDR_LEN]; + uint64_t ik_keyrsc; /* key receive sequence counter */ + uint64_t ik_keytsc; /* key transmit sequence counter */ + uint8_t ik_keydata[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE]; +}; + +/* + * Delete a key either by index or address. Set the index + * to IEEE80211_KEYIX_NONE when deleting a unicast key. + */ +struct ieee80211req_del_key { + uint8_t idk_keyix; /* key index */ + uint8_t idk_macaddr[IEEE80211_ADDR_LEN]; +}; + +/* + * MLME state manipulation request. IEEE80211_MLME_ASSOC + * only makes sense when operating as a station. The other + * requests can be used when operating as a station or an + * ap (to effect a station). + */ +struct ieee80211req_mlme { + uint8_t im_op; /* operation to perform */ +#define IEEE80211_MLME_ASSOC 1 /* associate station */ +#define IEEE80211_MLME_DISASSOC 2 /* disassociate station */ +#define IEEE80211_MLME_DEAUTH 3 /* deauthenticate station */ +#define IEEE80211_MLME_AUTHORIZE 4 /* authorize station */ +#define IEEE80211_MLME_UNAUTHORIZE 5 /* unauthorize station */ +#define IEEE80211_MLME_AUTH 6 /* authenticate station */ + uint8_t im_ssid_len; /* length of optional ssid */ + uint16_t im_reason; /* 802.11 reason code */ + uint8_t im_macaddr[IEEE80211_ADDR_LEN]; + uint8_t im_ssid[IEEE80211_NWID_LEN]; +}; + +/* + * MAC ACL operations. + */ +enum { + IEEE80211_MACCMD_POLICY_OPEN = 0, /* set policy: no ACL's */ + IEEE80211_MACCMD_POLICY_ALLOW = 1, /* set policy: allow traffic */ + IEEE80211_MACCMD_POLICY_DENY = 2, /* set policy: deny traffic */ + IEEE80211_MACCMD_FLUSH = 3, /* flush ACL database */ + IEEE80211_MACCMD_DETACH = 4, /* detach ACL policy */ + IEEE80211_MACCMD_POLICY = 5, /* get ACL policy */ + IEEE80211_MACCMD_LIST = 6, /* get ACL database */ + IEEE80211_MACCMD_POLICY_RADIUS = 7, /* set policy: RADIUS managed */ +}; + +struct ieee80211req_maclist { + uint8_t ml_macaddr[IEEE80211_ADDR_LEN]; +} __packed; + +/* + * Mesh Routing Table Operations. + */ +enum { + IEEE80211_MESH_RTCMD_LIST = 0, /* list HWMP routing table */ + IEEE80211_MESH_RTCMD_FLUSH = 1, /* flush HWMP routing table */ + IEEE80211_MESH_RTCMD_ADD = 2, /* add entry to the table */ + IEEE80211_MESH_RTCMD_DELETE = 3, /* delete an entry from the table */ +}; + +struct ieee80211req_mesh_route { + uint8_t imr_flags; +#define IEEE80211_MESHRT_FLAGS_VALID 0x01 +#define IEEE80211_MESHRT_FLAGS_PROXY 0x02 + uint8_t imr_dest[IEEE80211_ADDR_LEN]; + uint8_t imr_nexthop[IEEE80211_ADDR_LEN]; + uint16_t imr_nhops; + uint8_t imr_pad; + uint32_t imr_metric; + uint32_t imr_lifetime; + uint32_t imr_lastmseq; +}; + +/* + * HWMP root modes + */ +enum { + IEEE80211_HWMP_ROOTMODE_DISABLED = 0, /* disabled */ + IEEE80211_HWMP_ROOTMODE_NORMAL = 1, /* normal PREPs */ + IEEE80211_HWMP_ROOTMODE_PROACTIVE = 2, /* proactive PREPS */ + IEEE80211_HWMP_ROOTMODE_RANN = 3, /* use RANN elemid */ +}; + + +/* + * Set the active channel list by IEEE channel #: each channel + * to be marked active is set in a bit vector. Note this list is + * intersected with the available channel list in calculating + * the set of channels actually used in scanning. + */ +struct ieee80211req_chanlist { + uint8_t ic_channels[32]; /* NB: can be variable length */ +}; + +/* + * Get the active channel list info. + */ +struct ieee80211req_chaninfo { + u_int ic_nchans; + struct ieee80211_channel ic_chans[1]; /* NB: variable length */ +}; +#define IEEE80211_CHANINFO_SIZE(_nchan) \ + (sizeof(struct ieee80211req_chaninfo) + \ + (((_nchan)-1) * sizeof(struct ieee80211_channel))) +#define IEEE80211_CHANINFO_SPACE(_ci) \ + IEEE80211_CHANINFO_SIZE((_ci)->ic_nchans) + +/* + * Retrieve the WPA/RSN information element for an associated station. + */ +struct ieee80211req_wpaie { /* old version w/ only one ie */ + uint8_t wpa_macaddr[IEEE80211_ADDR_LEN]; + uint8_t wpa_ie[IEEE80211_MAX_OPT_IE]; +}; +struct ieee80211req_wpaie2 { + uint8_t wpa_macaddr[IEEE80211_ADDR_LEN]; + uint8_t wpa_ie[IEEE80211_MAX_OPT_IE]; + uint8_t rsn_ie[IEEE80211_MAX_OPT_IE]; +}; + +/* + * Retrieve per-node statistics. + */ +struct ieee80211req_sta_stats { + union { + /* NB: explicitly force 64-bit alignment */ + uint8_t macaddr[IEEE80211_ADDR_LEN]; + uint64_t pad; + } is_u; + struct ieee80211_nodestats is_stats; +}; + +/* + * Station information block; the mac address is used + * to retrieve other data like stats, unicast key, etc. + */ +struct ieee80211req_sta_info { + uint16_t isi_len; /* total length (mult of 4) */ + uint16_t isi_ie_off; /* offset to IE data */ + uint16_t isi_ie_len; /* IE length */ + uint16_t isi_freq; /* MHz */ + uint32_t isi_flags; /* channel flags */ + uint32_t isi_state; /* state flags */ + uint8_t isi_authmode; /* authentication algorithm */ + int8_t isi_rssi; /* receive signal strength */ + int8_t isi_noise; /* noise floor */ + uint8_t isi_capinfo; /* capabilities */ + uint8_t isi_erp; /* ERP element */ + uint8_t isi_macaddr[IEEE80211_ADDR_LEN]; + uint8_t isi_nrates; + /* negotiated rates */ + uint8_t isi_rates[IEEE80211_RATE_MAXSIZE]; + uint8_t isi_txrate; /* legacy/IEEE rate or MCS */ + uint16_t isi_associd; /* assoc response */ + uint16_t isi_txpower; /* current tx power */ + uint16_t isi_vlan; /* vlan tag */ + /* NB: [IEEE80211_NONQOS_TID] holds seq#'s for non-QoS stations */ + uint16_t isi_txseqs[IEEE80211_TID_SIZE];/* tx seq #/TID */ + uint16_t isi_rxseqs[IEEE80211_TID_SIZE];/* rx seq#/TID */ + uint16_t isi_inact; /* inactivity timer */ + uint16_t isi_txmbps; /* current tx rate in .5 Mb/s */ + uint16_t isi_pad; + uint32_t isi_jointime; /* time of assoc/join */ + struct ieee80211_mimo_info isi_mimo; /* MIMO info for 11n sta's */ + /* 11s info */ + uint16_t isi_peerid; + uint16_t isi_localid; + uint8_t isi_peerstate; + /* XXX frag state? */ + /* variable length IE data */ +}; + +/* + * Retrieve per-station information; to retrieve all + * specify a mac address of ff:ff:ff:ff:ff:ff. + */ +struct ieee80211req_sta_req { + union { + /* NB: explicitly force 64-bit alignment */ + uint8_t macaddr[IEEE80211_ADDR_LEN]; + uint64_t pad; + } is_u; + struct ieee80211req_sta_info info[1]; /* variable length */ +}; + +/* + * Get/set per-station tx power cap. + */ +struct ieee80211req_sta_txpow { + uint8_t it_macaddr[IEEE80211_ADDR_LEN]; + uint8_t it_txpow; +}; + +/* + * WME parameters manipulated with IEEE80211_IOC_WME_CWMIN + * through IEEE80211_IOC_WME_ACKPOLICY are set and return + * using i_val and i_len. i_val holds the value itself. + * i_len specifies the AC and, as appropriate, then high bit + * specifies whether the operation is to be applied to the + * BSS or ourself. + */ +#define IEEE80211_WMEPARAM_SELF 0x0000 /* parameter applies to self */ +#define IEEE80211_WMEPARAM_BSS 0x8000 /* parameter applies to BSS */ +#define IEEE80211_WMEPARAM_VAL 0x7fff /* parameter value */ + +/* + * Application Information Elements can be appended to a variety + * of frames with the IEE80211_IOC_APPIE request. This request + * piggybacks on a normal ieee80211req; the frame type is passed + * in i_val as the 802.11 FC0 bytes and the length of the IE data + * is passed in i_len. The data is referenced in i_data. If i_len + * is zero then any previously configured IE data is removed. At + * most IEEE80211_MAX_APPIE data be appened. Note that multiple + * IE's can be supplied; the data is treated opaquely. + */ +#define IEEE80211_MAX_APPIE 1024 /* max app IE data */ +/* + * Hack: the WPA authenticator uses this mechanism to specify WPA + * ie's that are used instead of the ones normally constructed using + * the cipher state setup with separate ioctls. This avoids issues + * like the authenticator ordering ie data differently than the + * net80211 layer and needing to keep separate state for WPA and RSN. + */ +#define IEEE80211_APPIE_WPA \ + (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_BEACON | \ + IEEE80211_FC0_SUBTYPE_PROBE_RESP) + +/* + * Station mode roaming parameters. These are maintained + * per band/mode and control the roaming algorithm. + */ +struct ieee80211_roamparams_req { + struct ieee80211_roamparam params[IEEE80211_MODE_MAX]; +}; + +/* + * Transmit parameters. These can be used to set fixed transmit + * rate for each operating mode when operating as client or on a + * per-client basis according to the capabilities of the client + * (e.g. an 11b client associated to an 11g ap) when operating as + * an ap. + * + * MCS are distinguished from legacy rates by or'ing in 0x80. + */ +struct ieee80211_txparams_req { + struct ieee80211_txparam params[IEEE80211_MODE_MAX]; +}; + +/* + * Set regulatory domain state with IEEE80211_IOC_REGDOMAIN. + * Note this is both the regulatory description and the channel + * list. The get request for IEEE80211_IOC_REGDOMAIN returns + * only the regdomain info; the channel list is obtained + * separately with IEEE80211_IOC_CHANINFO. + */ +struct ieee80211_regdomain_req { + struct ieee80211_regdomain rd; + struct ieee80211req_chaninfo chaninfo; +}; +#define IEEE80211_REGDOMAIN_SIZE(_nchan) \ + (sizeof(struct ieee80211_regdomain_req) + \ + (((_nchan)-1) * sizeof(struct ieee80211_channel))) +#define IEEE80211_REGDOMAIN_SPACE(_req) \ + IEEE80211_REGDOMAIN_SIZE((_req)->chaninfo.ic_nchans) + +/* + * Get driver capabilities. Driver, hardware crypto, and + * HT/802.11n capabilities, and a table that describes what + * the radio can do. + */ +struct ieee80211_devcaps_req { + uint32_t dc_drivercaps; /* general driver caps */ + uint32_t dc_cryptocaps; /* hardware crypto support */ + uint32_t dc_htcaps; /* HT/802.11n support */ + struct ieee80211req_chaninfo dc_chaninfo; +}; +#define IEEE80211_DEVCAPS_SIZE(_nchan) \ + (sizeof(struct ieee80211_devcaps_req) + \ + (((_nchan)-1) * sizeof(struct ieee80211_channel))) +#define IEEE80211_DEVCAPS_SPACE(_dc) \ + IEEE80211_DEVCAPS_SIZE((_dc)->dc_chaninfo.ic_nchans) + +struct ieee80211_chanswitch_req { + struct ieee80211_channel csa_chan; /* new channel */ + int csa_mode; /* CSA mode */ + int csa_count; /* beacon count to switch */ +}; + +/* + * Get/set per-station vlan tag. + */ +struct ieee80211req_sta_vlan { + uint8_t sv_macaddr[IEEE80211_ADDR_LEN]; + uint16_t sv_vlan; +}; + +#if defined(__FreeBSD__) || defined(__HAIKU__) +/* + * FreeBSD-style ioctls. + */ +/* the first member must be matched with struct ifreq */ +struct ieee80211req { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + uint16_t i_type; /* req type */ + int16_t i_val; /* Index or simple value */ + int16_t i_len; /* Index or simple value */ + void *i_data; /* Extra data */ +}; +#define SIOCS80211 _IOW('i', 234, struct ieee80211req) +#define SIOCG80211 _IOWR('i', 235, struct ieee80211req) +#define SIOCG80211STATS _IOWR('i', 236, struct ifreq) + +#define IEEE80211_IOC_SSID 1 +#define IEEE80211_IOC_NUMSSIDS 2 +#define IEEE80211_IOC_WEP 3 +#define IEEE80211_WEP_NOSUP -1 +#define IEEE80211_WEP_OFF 0 +#define IEEE80211_WEP_ON 1 +#define IEEE80211_WEP_MIXED 2 +#define IEEE80211_IOC_WEPKEY 4 +#define IEEE80211_IOC_NUMWEPKEYS 5 +#define IEEE80211_IOC_WEPTXKEY 6 +#define IEEE80211_IOC_AUTHMODE 7 +#define IEEE80211_IOC_STATIONNAME 8 +#define IEEE80211_IOC_CHANNEL 9 +#define IEEE80211_IOC_POWERSAVE 10 +#define IEEE80211_POWERSAVE_NOSUP -1 +#define IEEE80211_POWERSAVE_OFF 0 +#define IEEE80211_POWERSAVE_CAM 1 +#define IEEE80211_POWERSAVE_PSP 2 +#define IEEE80211_POWERSAVE_PSP_CAM 3 +#define IEEE80211_POWERSAVE_ON IEEE80211_POWERSAVE_CAM +#define IEEE80211_IOC_POWERSAVESLEEP 11 +#define IEEE80211_IOC_RTSTHRESHOLD 12 +#define IEEE80211_IOC_PROTMODE 13 +#define IEEE80211_PROTMODE_OFF 0 +#define IEEE80211_PROTMODE_CTS 1 +#define IEEE80211_PROTMODE_RTSCTS 2 +#define IEEE80211_IOC_TXPOWER 14 /* global tx power limit */ +#define IEEE80211_IOC_BSSID 15 +#define IEEE80211_IOC_ROAMING 16 /* roaming mode */ +#define IEEE80211_IOC_PRIVACY 17 /* privacy invoked */ +#define IEEE80211_IOC_DROPUNENCRYPTED 18 /* discard unencrypted frames */ +#define IEEE80211_IOC_WPAKEY 19 +#define IEEE80211_IOC_DELKEY 20 +#define IEEE80211_IOC_MLME 21 +/* 22 was IEEE80211_IOC_OPTIE, replaced by IEEE80211_IOC_APPIE */ +/* 23 was IEEE80211_IOC_SCAN_REQ */ +/* 24 was IEEE80211_IOC_SCAN_RESULTS */ +#define IEEE80211_IOC_COUNTERMEASURES 25 /* WPA/TKIP countermeasures */ +#define IEEE80211_IOC_WPA 26 /* WPA mode (0,1,2) */ +#define IEEE80211_IOC_CHANLIST 27 /* channel list */ +#define IEEE80211_IOC_WME 28 /* WME mode (on, off) */ +#define IEEE80211_IOC_HIDESSID 29 /* hide SSID mode (on, off) */ +#define IEEE80211_IOC_APBRIDGE 30 /* AP inter-sta bridging */ +/* 31-35,37-38 were for WPA authenticator settings */ +/* 36 was IEEE80211_IOC_DRIVER_CAPS */ +#define IEEE80211_IOC_WPAIE 39 /* WPA information element */ +#define IEEE80211_IOC_STA_STATS 40 /* per-station statistics */ +#define IEEE80211_IOC_MACCMD 41 /* MAC ACL operation */ +#define IEEE80211_IOC_CHANINFO 42 /* channel info list */ +#define IEEE80211_IOC_TXPOWMAX 43 /* max tx power for channel */ +#define IEEE80211_IOC_STA_TXPOW 44 /* per-station tx power limit */ +/* 45 was IEEE80211_IOC_STA_INFO */ +#define IEEE80211_IOC_WME_CWMIN 46 /* WME: ECWmin */ +#define IEEE80211_IOC_WME_CWMAX 47 /* WME: ECWmax */ +#define IEEE80211_IOC_WME_AIFS 48 /* WME: AIFSN */ +#define IEEE80211_IOC_WME_TXOPLIMIT 49 /* WME: txops limit */ +#define IEEE80211_IOC_WME_ACM 50 /* WME: ACM (bss only) */ +#define IEEE80211_IOC_WME_ACKPOLICY 51 /* WME: ACK policy (!bss only)*/ +#define IEEE80211_IOC_DTIM_PERIOD 52 /* DTIM period (beacons) */ +#define IEEE80211_IOC_BEACON_INTERVAL 53 /* beacon interval (ms) */ +#define IEEE80211_IOC_ADDMAC 54 /* add sta to MAC ACL table */ +#define IEEE80211_IOC_DELMAC 55 /* del sta from MAC ACL table */ +#define IEEE80211_IOC_PUREG 56 /* pure 11g (no 11b stations) */ +#define IEEE80211_IOC_FF 57 /* ATH fast frames (on, off) */ +#define IEEE80211_IOC_TURBOP 58 /* ATH turbo' (on, off) */ +#define IEEE80211_IOC_BGSCAN 59 /* bg scanning (on, off) */ +#define IEEE80211_IOC_BGSCAN_IDLE 60 /* bg scan idle threshold */ +#define IEEE80211_IOC_BGSCAN_INTERVAL 61 /* bg scan interval */ +#define IEEE80211_IOC_SCANVALID 65 /* scan cache valid threshold */ +/* 66-72 were IEEE80211_IOC_ROAM_* and IEEE80211_IOC_MCAST_RATE */ +#define IEEE80211_IOC_FRAGTHRESHOLD 73 /* tx fragmentation threshold */ +#define IEEE80211_IOC_BURST 75 /* packet bursting */ +#define IEEE80211_IOC_SCAN_RESULTS 76 /* get scan results */ +#define IEEE80211_IOC_BMISSTHRESHOLD 77 /* beacon miss threshold */ +#define IEEE80211_IOC_STA_INFO 78 /* station/neighbor info */ +#define IEEE80211_IOC_WPAIE2 79 /* WPA+RSN info elements */ +#define IEEE80211_IOC_CURCHAN 80 /* current channel */ +#define IEEE80211_IOC_SHORTGI 81 /* 802.11n half GI */ +#define IEEE80211_IOC_AMPDU 82 /* 802.11n A-MPDU (on, off) */ +#define IEEE80211_IOC_AMPDU_LIMIT 83 /* A-MPDU length limit */ +#define IEEE80211_IOC_AMPDU_DENSITY 84 /* A-MPDU density */ +#define IEEE80211_IOC_AMSDU 85 /* 802.11n A-MSDU (on, off) */ +#define IEEE80211_IOC_AMSDU_LIMIT 86 /* A-MSDU length limit */ +#define IEEE80211_IOC_PUREN 87 /* pure 11n (no legacy sta's) */ +#define IEEE80211_IOC_DOTH 88 /* 802.11h (on, off) */ +/* 89-91 were regulatory items */ +#define IEEE80211_IOC_HTCOMPAT 92 /* support pre-D1.10 HT ie's */ +#define IEEE80211_IOC_DWDS 93 /* DWDS/4-address handling */ +#define IEEE80211_IOC_INACTIVITY 94 /* sta inactivity handling */ +#define IEEE80211_IOC_APPIE 95 /* application IE's */ +#define IEEE80211_IOC_WPS 96 /* WPS operation */ +#define IEEE80211_IOC_TSN 97 /* TSN operation */ +#define IEEE80211_IOC_DEVCAPS 98 /* driver+device capabilities */ +#define IEEE80211_IOC_CHANSWITCH 99 /* start 11h channel switch */ +#define IEEE80211_IOC_DFS 100 /* DFS (on, off) */ +#define IEEE80211_IOC_DOTD 101 /* 802.11d (on, off) */ +#define IEEE80211_IOC_HTPROTMODE 102 /* HT protection (off, rts) */ +#define IEEE80211_IOC_SCAN_REQ 103 /* scan w/ specified params */ +#define IEEE80211_IOC_SCAN_CANCEL 104 /* cancel ongoing scan */ +#define IEEE80211_IOC_HTCONF 105 /* HT config (off, HT20, HT40)*/ +#define IEEE80211_IOC_REGDOMAIN 106 /* regulatory domain info */ +#define IEEE80211_IOC_ROAM 107 /* roaming params en masse */ +#define IEEE80211_IOC_TXPARAMS 108 /* tx parameters */ +#define IEEE80211_IOC_STA_VLAN 109 /* per-station vlan tag */ +#define IEEE80211_IOC_SMPS 110 /* MIMO power save */ +#define IEEE80211_IOC_RIFS 111 /* RIFS config (on, off) */ +#define IEEE80211_IOC_GREENFIELD 112 /* Greenfield (on, off) */ +#define IEEE80211_IOC_STBC 113 /* STBC Tx/RX (on, off) */ + +#define IEEE80211_IOC_MESH_ID 170 /* mesh identifier */ +#define IEEE80211_IOC_MESH_AP 171 /* accepting peerings */ +#define IEEE80211_IOC_MESH_FWRD 172 /* forward frames */ +#define IEEE80211_IOC_MESH_PROTO 173 /* mesh protocols */ +#define IEEE80211_IOC_MESH_TTL 174 /* mesh TTL */ +#define IEEE80211_IOC_MESH_RTCMD 175 /* mesh routing table commands*/ +#define IEEE80211_IOC_MESH_PR_METRIC 176 /* mesh metric protocol */ +#define IEEE80211_IOC_MESH_PR_PATH 177 /* mesh path protocol */ +#define IEEE80211_IOC_MESH_PR_SIG 178 /* mesh sig protocol */ +#define IEEE80211_IOC_MESH_PR_CC 179 /* mesh congestion protocol */ +#define IEEE80211_IOC_MESH_PR_AUTH 180 /* mesh auth protocol */ + +#define IEEE80211_IOC_HWMP_ROOTMODE 190 /* HWMP root mode */ +#define IEEE80211_IOC_HWMP_MAXHOPS 191 /* number of hops before drop */ +#define IEEE80211_IOC_HWMP_TTL 192 /* HWMP TTL */ + +#define IEEE80211_IOC_TDMA_SLOT 201 /* TDMA: assigned slot */ +#define IEEE80211_IOC_TDMA_SLOTCNT 202 /* TDMA: slots in bss */ +#define IEEE80211_IOC_TDMA_SLOTLEN 203 /* TDMA: slot length (usecs) */ +#define IEEE80211_IOC_TDMA_BINTERVAL 204 /* TDMA: beacon intvl (slots) */ + +/* + * Parameters for controlling a scan requested with + * IEEE80211_IOC_SCAN_REQ. + * + * Active scans cause ProbeRequest frames to be issued for each + * specified ssid and, by default, a broadcast ProbeRequest frame. + * The set of ssid's is specified in the request. + * + * By default the scan will cause a BSS to be joined (in station/adhoc + * mode) or a channel to be selected for operation (hostap mode). + * To disable that specify IEEE80211_IOC_SCAN_NOPICK and if the + * + * If the station is currently associated to an AP then a scan request + * will cause the station to leave the current channel and potentially + * miss frames from the AP. Alternatively the station may notify the + * AP that it is going into power save mode before it leaves the channel. + * This ensures frames for the station are buffered by the AP. This is + * termed a ``bg scan'' and is requested with the IEEE80211_IOC_SCAN_BGSCAN + * flag. Background scans may take longer than foreground scans and may + * be preempted by traffic. If a station is not associated to an AP + * then a request for a background scan is automatically done in the + * foreground. + * + * The results of the scan request are cached by the system. This + * information is aged out and/or invalidated based on events like not + * being able to associated to an AP. To flush the current cache + * contents before doing a scan the IEEE80211_IOC_SCAN_FLUSH flag may + * be specified. + * + * By default the scan will be done until a suitable AP is located + * or a channel is found for use. A scan can also be constrained + * to be done once (IEEE80211_IOC_SCAN_ONCE) or to last for no more + * than a specified duration. + */ +struct ieee80211_scan_req { + int sr_flags; +#define IEEE80211_IOC_SCAN_NOPICK 0x00001 /* scan only, no selection */ +#define IEEE80211_IOC_SCAN_ACTIVE 0x00002 /* active scan (probe req) */ +#define IEEE80211_IOC_SCAN_PICK1ST 0x00004 /* ``hey sailor'' mode */ +#define IEEE80211_IOC_SCAN_BGSCAN 0x00008 /* bg scan, exit ps at end */ +#define IEEE80211_IOC_SCAN_ONCE 0x00010 /* do one complete pass */ +#define IEEE80211_IOC_SCAN_NOBCAST 0x00020 /* don't send bcast probe req */ +#define IEEE80211_IOC_SCAN_NOJOIN 0x00040 /* no auto-sequencing */ +#define IEEE80211_IOC_SCAN_FLUSH 0x10000 /* flush scan cache first */ +#define IEEE80211_IOC_SCAN_CHECK 0x20000 /* check scan cache first */ + u_int sr_duration; /* duration (ms) */ +#define IEEE80211_IOC_SCAN_DURATION_MIN 1 +#define IEEE80211_IOC_SCAN_DURATION_MAX 0x7fffffff +#define IEEE80211_IOC_SCAN_FOREVER IEEE80211_IOC_SCAN_DURATION_MAX + u_int sr_mindwell; /* min channel dwelltime (ms) */ + u_int sr_maxdwell; /* max channel dwelltime (ms) */ + int sr_nssid; +#define IEEE80211_IOC_SCAN_MAX_SSID 3 + struct { + int len; /* length in bytes */ + uint8_t ssid[IEEE80211_NWID_LEN]; /* ssid contents */ + } sr_ssid[IEEE80211_IOC_SCAN_MAX_SSID]; +}; + +/* + * Scan result data returned for IEEE80211_IOC_SCAN_RESULTS. + * Each result is a fixed size structure followed by a variable + * length SSID and one or more variable length information elements. + * The size of each variable length item is found in the fixed + * size structure and the entire length of the record is specified + * in isr_len. Result records are rounded to a multiple of 4 bytes. + */ +struct ieee80211req_scan_result { + uint16_t isr_len; /* total length (mult of 4) */ + uint16_t isr_ie_off; /* offset to SSID+IE data */ + uint16_t isr_ie_len; /* IE length */ + struct ieee80211_channel isr_chan; /* Handing out the conmplete channel info */ + int8_t isr_noise; + int8_t isr_rssi; + uint8_t isr_intval; /* beacon interval */ + uint8_t isr_capinfo; /* capabilities */ + uint8_t isr_erp; /* ERP element */ + uint8_t isr_bssid[IEEE80211_ADDR_LEN]; + uint8_t isr_nrates; + uint8_t isr_rates[IEEE80211_RATE_MAXSIZE]; + uint8_t isr_ssid_len; /* SSID length */ + uint8_t isr_meshid_len; /* MESH ID length */ + /* variable length SSID, followed by variable length MESH ID, + followed by IE data */ +}; + +/* + * Virtual AP cloning parameters. The parent device must + * be a vap-capable device. All parameters specified with + * the clone request are fixed for the lifetime of the vap. + * + * There are two flavors of WDS vaps: legacy and dynamic. + * Legacy WDS operation implements a static binding between + * two stations encapsulating traffic in 4-address frames. + * Dynamic WDS vaps are created when a station associates to + * an AP and sends a 4-address frame. If the AP vap is + * configured to support WDS then this will generate an + * event to user programs listening on the routing socket + * and a Dynamic WDS vap will be created to handle traffic + * to/from that station. In both cases the bssid of the + * peer must be specified when creating the vap. + * + * By default a vap will inherit the mac address/bssid of + * the underlying device. To request a unique address the + * IEEE80211_CLONE_BSSID flag should be supplied. This is + * meaningless for WDS vaps as they share the bssid of an + * AP vap that must otherwise exist. Note that some devices + * may not be able to support multiple addresses. + * + * Station mode vap's normally depend on the device to notice + * when the AP stops sending beacon frames. If IEEE80211_CLONE_NOBEACONS + * is specified the net80211 layer will do this in s/w. This + * is mostly useful when setting up a WDS repeater/extender where + * an AP vap is combined with a sta vap and the device isn't able + * to track beacon frames in hardware. + */ +struct ieee80211_clone_params { + char icp_parent[IFNAMSIZ]; /* parent device */ + uint16_t icp_opmode; /* operating mode */ + uint16_t icp_flags; /* see below */ + uint8_t icp_bssid[IEEE80211_ADDR_LEN]; /* for WDS links */ + uint8_t icp_macaddr[IEEE80211_ADDR_LEN];/* local address */ +}; +#define IEEE80211_CLONE_BSSID 0x0001 /* allocate unique mac/bssid */ +#define IEEE80211_CLONE_NOBEACONS 0x0002 /* don't setup beacon timers */ +#define IEEE80211_CLONE_WDSLEGACY 0x0004 /* legacy WDS processing */ +#define IEEE80211_CLONE_MACADDR 0x0008 /* use specified mac addr */ +#define IEEE80211_CLONE_TDMA 0x0010 /* operate in TDMA mode */ +#endif /* __FreeBSD__ */ + +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_IOCTL_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_mesh.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_mesh.h new file mode 100644 index 0000000000..b543831c13 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_mesh.h @@ -0,0 +1,525 @@ +/*- + * Copyright (c) 2009 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Rui Paulo under sponsorship from the + * FreeBSD Foundation. + * + * 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 AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_MESH_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_MESH_H_ + +#define IEEE80211_MESH_DEFAULT_TTL 31 + +/* + * NB: all structures are__packed so sizeof works on arm, et. al. + */ +/* + * 802.11s Information Elements. +*/ +/* Mesh Configuration */ +struct ieee80211_meshconf_ie { + uint8_t conf_ie; /* IEEE80211_ELEMID_MESHCONF */ + uint8_t conf_len; + uint8_t conf_ver; + uint8_t conf_pselid[4]; /* Active Path Sel. Proto. ID */ + uint8_t conf_pmetid[4]; /* APS Metric Identifier */ + uint8_t conf_ccid[4]; /* Congestion Control Mode ID */ + uint8_t conf_syncid[4]; /* Sync. Protocol ID */ + uint8_t conf_authid[4]; /* Auth. Protocol ID */ + uint8_t conf_form; /* Formation Information */ + uint8_t conf_cap; +} __packed; + +#define IEEE80211_MESHCONF_VERSION 1 +/* Null Protocol */ +#define IEEE80211_MESHCONF_NULL_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHCONF_NULL_VALUE 0xff +#define IEEE80211_MESHCONF_NULL { IEEE80211_MESHCONF_NULL_OUI, \ + IEEE80211_MESHCONF_NULL_VALUE } +/* Hybrid Wireless Mesh Protocol */ +#define IEEE80211_MESHCONF_HWMP_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHCONF_HWMP_VALUE 0x00 +#define IEEE80211_MESHCONF_HWMP { IEEE80211_MESHCONF_HWMP_OUI, \ + IEEE80211_MESHCONF_HWMP_VALUE } +/* Airtime Link Metric */ +#define IEEE80211_MESHCONF_AIRTIME_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHCONF_AIRTIME_VALUE 0x00 +#define IEEE80211_MESHCONF_AIRTIME { IEEE80211_MESHCONF_AIRTIME_OUI, \ + IEEE80211_MESHCONF_AIRTIME_VALUE } +/* Congestion Control Signaling */ +#define IEEE80211_MESHCONF_CCSIG_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHCONF_CCSIG_VALUE 0x00 +#define IEEE80211_MESHCONF_CCSIG { IEEE80211_MESHCONF_CCSIG_OUI,\ + IEEE80211_MESHCONF_CCSIG_VALUE } +/* Neighbour Offset */ +#define IEEE80211_MESHCONF_NEIGHOFF_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHCONF_NEIGHOFF_VALUE 0x00 +#define IEEE80211_MESHCONF_NEIGHOFF { IEEE80211_MESHCONF_NEIGHOFF_OUI, \ + IEEE80211_MESHCONF_NEIGHOFF_VALUE } +/* Simultaneous Authenticaction of Equals */ +#define IEEE80211_MESHCONF_SAE_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHCONF_SAE_VALUE 0x01 +#define IEEE80211_MESHCONF_SAE { IEEE80211_MESHCONF_SAE_OUI, \ + IEEE80211_MESHCONF_SAE_VALUE } +#define IEEE80211_MESHCONF_FORM_MP 0x01 /* Connected to Portal */ +#define IEEE80211_MESHCONF_FORM_NNEIGH_MASK 0x04 /* Number of Neighbours */ +#define IEEE80211_MESHCONF_CAP_AP 0x01 /* Accepting Peers */ +#define IEEE80211_MESHCONF_CAP_MCCAS 0x02 /* MCCA supported */ +#define IEEE80211_MESHCONF_CAP_MCCAE 0x04 /* MCCA enabled */ +#define IEEE80211_MESHCONF_CAP_FWRD 0x08 /* forwarding enabled */ +#define IEEE80211_MESHCONF_CAP_BTR 0x10 /* Beacon Timing Report Enab */ +#define IEEE80211_MESHCONF_CAP_TBTTA 0x20 /* TBTT Adj. Enabled */ +#define IEEE80211_MESHCONF_CAP_PSL 0x40 /* Power Save Level */ + +/* Mesh Identifier */ +struct ieee80211_meshid_ie { + uint8_t id_ie; /* IEEE80211_ELEMID_MESHID */ + uint8_t id_len; +} __packed; + +/* Link Metric Report */ +struct ieee80211_meshlmetric_ie { + uint8_t lm_ie; /* IEEE80211_ELEMID_MESHLINK */ + uint8_t lm_len; + uint32_t lm_metric; +#define IEEE80211_MESHLMETRIC_INITIALVAL 0 +} __packed; + +/* Congestion Notification */ +struct ieee80211_meshcngst_ie { + uint8_t cngst_ie; /* IEEE80211_ELEMID_MESHCNGST */ + uint8_t cngst_len; + uint16_t cngst_timer[4]; /* Expiration Timers: AC_BK, + AC_BE, AC_VI, AC_VO */ +} __packed; + +/* Peer Version */ +struct ieee80211_meshpeerver_ie { + uint8_t peerver_ie; /* IEEE80211_ELEMID_MESHPEERVER */ + uint8_t peerver_len; + uint8_t peerver_proto[4]; +} __packed; +/* Mesh Peering Management Protocol */ +#define IEEE80211_MESHPEERVER_PEER_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHPEERVER_PEER_VALUE 0x2a +#define IEEE80211_MESHPEERVER_PEER { IEEE80211_MESHPEERVER_PEER_OUI, \ + IEEE80211_MESHPEERVER_PEER_VALUE } +/* Abbreviated Handshake Protocol */ +#define IEEE80211_MESHPEERVER_AH_OUI 0x00, 0x0f, 0xac +#define IEEE80211_MESHPEERVER_AH_VALUE 0x2b +#define IEEE80211_MESHPEERVER_AH { IEEE80211_MESHPEERVER_AH_OUI, \ + IEEE80211_MESHPEERVER_AH_VALUE } + +/* Peer Link Management */ +struct ieee80211_meshpeer_ie { + uint8_t peer_ie; /* IEEE80211_ELEMID_MESHPEER */ + uint8_t peer_len; + uint8_t peer_subtype; + uint16_t peer_llinkid; /* Local Link ID */ + uint16_t peer_linkid; /* Peer Link ID */ + uint16_t peer_rcode; +} __packed; + +enum { + IEEE80211_MESH_PEER_LINK_OPEN = 0, + IEEE80211_MESH_PEER_LINK_CONFIRM = 1, + IEEE80211_MESH_PEER_LINK_CLOSE = 2, + /* values 3-255 are reserved */ +}; + +#ifdef notyet +/* Mesh Channel Switch Annoucement */ +struct ieee80211_meshcsa_ie { + uint8_t csa_ie; /* IEEE80211_ELEMID_MESHCSA */ + uint8_t csa_len; + uint8_t csa_mode; + uint8_t csa_newclass; /* New Regulatory Class */ + uint8_t csa_newchan; + uint8_t csa_precvalue; /* Precedence Value */ + uint8_t csa_count; +} __packed; + +/* Mesh TIM */ +/* Equal to the non Mesh version */ + +/* Mesh Awake Window */ +struct ieee80211_meshawakew_ie { + uint8_t awakew_ie; /* IEEE80211_ELEMID_MESHAWAKEW */ + uint8_t awakew_len; + uint8_t awakew_windowlen; /* in TUs */ +} __packed; + +/* Mesh Beacon Timing */ +struct ieee80211_meshbeacont_ie { + uint8_t beacont_ie; /* IEEE80211_ELEMID_MESHBEACONT */ + uint8_t beacont_len; + struct { + uint8_t mp_aid; /* Least Octet of AID */ + uint16_t mp_btime; /* Beacon Time */ + uint16_t mp_bint; /* Beacon Interval */ + } __packed mp[1]; /* NB: variable size */ +} __packed; +#endif + +/* Portal (MP) Annoucement */ +struct ieee80211_meshpann_ie { + uint8_t pann_ie; /* IEEE80211_ELEMID_MESHPANN */ + uint8_t pann_len; + uint8_t pann_flags; + uint8_t pann_hopcount; + uint8_t pann_ttl; + uint8_t pann_addr[IEEE80211_ADDR_LEN]; + uint8_t pann_seq; /* PANN Sequence Number */ +} __packed; + +/* Root (MP) Annoucement */ +struct ieee80211_meshrann_ie { + uint8_t rann_ie; /* IEEE80211_ELEMID_MESHRANN */ + uint8_t rann_len; + uint8_t rann_flags; +#define IEEE80211_MESHRANN_FLAGS_PR 0x01 /* Portal Role */ + uint8_t rann_hopcount; + uint8_t rann_ttl; + uint8_t rann_addr[IEEE80211_ADDR_LEN]; + uint32_t rann_seq; /* HWMP Sequence Number */ + uint32_t rann_metric; +} __packed; + +/* Mesh Path Request */ +struct ieee80211_meshpreq_ie { + uint8_t preq_ie; /* IEEE80211_ELEMID_MESHPREQ */ + uint8_t preq_len; + uint8_t preq_flags; +#define IEEE80211_MESHPREQ_FLAGS_PR 0x01 /* Portal Role */ +#define IEEE80211_MESHPREQ_FLAGS_AM 0x02 /* 0 = ucast / 1 = bcast */ +#define IEEE80211_MESHPREQ_FLAGS_PP 0x04 /* Proactive PREP */ +#define IEEE80211_MESHPREQ_FLAGS_AE 0x40 /* Address Extension */ + uint8_t preq_hopcount; + uint8_t preq_ttl; + uint32_t preq_id; + uint8_t preq_origaddr[IEEE80211_ADDR_LEN]; + uint32_t preq_origseq; /* HWMP Sequence Number */ + /* NB: may have Originator Proxied Address */ + uint32_t preq_lifetime; + uint32_t preq_metric; + uint8_t preq_tcount; /* target count */ + struct { + uint8_t target_flags; +#define IEEE80211_MESHPREQ_TFLAGS_TO 0x01 /* Target Only */ +#define IEEE80211_MESHPREQ_TFLAGS_RF 0x02 /* Reply and Forward */ +#define IEEE80211_MESHPREQ_TFLAGS_USN 0x04 /* Unknown HWMP seq number */ + uint8_t target_addr[IEEE80211_ADDR_LEN]; + uint32_t target_seq; /* HWMP Sequence Number */ + } __packed preq_targets[1]; /* NB: variable size */ +} __packed; + +/* Mesh Path Reply */ +struct ieee80211_meshprep_ie { + uint8_t prep_ie; /* IEEE80211_ELEMID_MESHPREP */ + uint8_t prep_len; + uint8_t prep_flags; + uint8_t prep_hopcount; + uint8_t prep_ttl; + uint8_t prep_targetaddr[IEEE80211_ADDR_LEN]; + uint32_t prep_targetseq; + /* NB: May have Target Proxied Address */ + uint32_t prep_lifetime; + uint32_t prep_metric; + uint8_t prep_origaddr[IEEE80211_ADDR_LEN]; + uint32_t prep_origseq; /* HWMP Sequence Number */ +} __packed; + +/* Mesh Path Error */ +struct ieee80211_meshperr_ie { + uint8_t perr_ie; /* IEEE80211_ELEMID_MESHPERR */ + uint8_t perr_len; + uint8_t perr_mode; /* NB: reserved */ + uint8_t perr_ndests; /* Number of Destinations */ + struct { + uint8_t dest_addr[IEEE80211_ADDR_LEN]; + uint32_t dest_seq; /* HWMP Sequence Number */ + } __packed perr_dests[1]; /* NB: variable size */ +} __packed; + +#ifdef notyet +/* Mesh Proxy Update */ +struct ieee80211_meshpu_ie { + uint8_t pu_ie; /* IEEE80211_ELEMID_MESHPU */ + uint8_t pu_len; + uint8_t pu_flags; +#define IEEE80211_MESHPU_FLAGS_MASK 0x1 +#define IEEE80211_MESHPU_FLAGS_DEL 0x0 +#define IEEE80211_MESHPU_FLAGS_ADD 0x1 + uint8_t pu_seq; /* PU Sequence Number */ + uint8_t pu_addr[IEEE80211_ADDR_LEN]; + uint8_t pu_naddr; /* Number of Proxied Addresses */ + /* NB: proxied address follows */ +} __packed; + +/* Mesh Proxy Update Confirmation */ +struct ieee80211_meshpuc_ie { + uint8_t puc_ie; /* IEEE80211_ELEMID_MESHPUC */ + uint8_t puc_len; + uint8_t puc_flags; + uint8_t puc_seq; /* PU Sequence Number */ + uint8_t puc_daddr[IEEE80211_ADDR_LEN]; +} __packed; +#endif + +/* + * 802.11s Action Frames + */ +#define IEEE80211_ACTION_CAT_MESHPEERING 30 /* XXX Linux */ +#define IEEE80211_ACTION_CAT_MESHLMETRIC 13 +#define IEEE80211_ACTION_CAT_MESHPATH 32 /* XXX Linux */ +#define IEEE80211_ACTION_CAT_INTERWORK 15 +#define IEEE80211_ACTION_CAT_RESOURCE 16 +#define IEEE80211_ACTION_CAT_PROXY 17 + +/* + * Mesh Peering Action codes. + */ +enum { + IEEE80211_ACTION_MESHPEERING_OPEN = 0, + IEEE80211_ACTION_MESHPEERING_CONFIRM = 1, + IEEE80211_ACTION_MESHPEERING_CLOSE = 2, + /* 3-255 reserved */ +}; + +/* + * Mesh Path Selection Action codes. + */ +enum { + IEEE80211_ACTION_MESHPATH_REQ = 0, + IEEE80211_ACTION_MESHPATH_REP = 1, + IEEE80211_ACTION_MESHPATH_ERR = 2, + IEEE80211_ACTION_MESHPATH_RANN = 3, + /* 4-255 reserved */ +}; + +/* + * Mesh Link Metric Action codes. + */ +enum { + IEEE80211_ACTION_MESHLMETRIC_REQ = 0, /* Link Metric Request */ + IEEE80211_ACTION_MESHLMETRIC_REP = 1, /* Link Metric Report */ + /* 2-255 reserved */ +}; + +/* + * Mesh Portal Annoucement Action codes. + */ +enum { + IEEE80211_ACTION_MESHPANN = 0, + /* 1-255 reserved */ +}; + +/* + * Different mesh control structures based on the AE + * (Address Extension) bits. + */ +struct ieee80211_meshcntl { + uint8_t mc_flags; /* Address Extension 00 */ + uint8_t mc_ttl; /* TTL */ + uint8_t mc_seq[4]; /* Sequence No. */ + /* NB: more addresses may follow */ +} __packed; + +struct ieee80211_meshcntl_ae01 { + uint8_t mc_flags; /* Address Extension 01 */ + uint8_t mc_ttl; /* TTL */ + uint8_t mc_seq[4]; /* Sequence No. */ + uint8_t mc_addr4[IEEE80211_ADDR_LEN]; +} __packed; + +struct ieee80211_meshcntl_ae10 { + uint8_t mc_flags; /* Address Extension 10 */ + uint8_t mc_ttl; /* TTL */ + uint8_t mc_seq[4]; /* Sequence No. */ + uint8_t mc_addr4[IEEE80211_ADDR_LEN]; + uint8_t mc_addr5[IEEE80211_ADDR_LEN]; +} __packed; + +struct ieee80211_meshcntl_ae11 { + uint8_t mc_flags; /* Address Extension 11 */ + uint8_t mc_ttl; /* TTL */ + uint8_t mc_seq[4]; /* Sequence No. */ + uint8_t mc_addr4[IEEE80211_ADDR_LEN]; + uint8_t mc_addr5[IEEE80211_ADDR_LEN]; + uint8_t mc_addr6[IEEE80211_ADDR_LEN]; +} __packed; + +#ifdef _KERNEL +struct ieee80211_mesh_route { + TAILQ_ENTRY(ieee80211_mesh_route) rt_next; + int rt_crtime; /* creation time */ + uint8_t rt_dest[IEEE80211_ADDR_LEN]; + uint8_t rt_nexthop[IEEE80211_ADDR_LEN]; + uint32_t rt_metric; /* path metric */ + uint16_t rt_nhops; /* number of hops */ + uint16_t rt_flags; +#define IEEE80211_MESHRT_FLAGS_VALID 0x01 /* patch discovery complete */ +#define IEEE80211_MESHRT_FLAGS_PROXY 0x02 /* proxy entry */ + uint32_t rt_lifetime; + uint32_t rt_lastmseq; /* last seq# seen dest */ + void *rt_priv; /* private data */ +}; +#define IEEE80211_MESH_ROUTE_PRIV(rt, cast) ((cast *)rt->rt_priv) + +#define IEEE80211_MESH_PROTO_DSZ 12 /* description size */ +/* + * Mesh Path Selection Protocol. + */ +enum ieee80211_state; +struct ieee80211_mesh_proto_path { + char mpp_descr[IEEE80211_MESH_PROTO_DSZ]; + uint8_t mpp_ie[4]; + struct ieee80211_node * + (*mpp_discover)(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN], + struct mbuf *); + void (*mpp_peerdown)(struct ieee80211_node *); + void (*mpp_vattach)(struct ieee80211vap *); + void (*mpp_vdetach)(struct ieee80211vap *); + int (*mpp_newstate)(struct ieee80211vap *, + enum ieee80211_state, int); + const size_t mpp_privlen; /* size required in the routing table + for private data */ + int mpp_inact; /* inact. timeout for invalid routes + (ticks) */ +}; + +/* + * Mesh Link Metric Report Protocol. + */ +struct ieee80211_mesh_proto_metric { + char mpm_descr[IEEE80211_MESH_PROTO_DSZ]; + uint8_t mpm_ie[4]; + uint32_t (*mpm_metric)(struct ieee80211_node *); +}; + +#ifdef notyet +/* + * Mesh Authentication Protocol. + */ +struct ieee80211_mesh_proto_auth { + uint8_t mpa_ie[4]; +}; + +struct ieee80211_mesh_proto_congestion { +}; + +struct ieee80211_mesh_proto_sync { +}; +#endif + +typedef uint32_t ieee80211_mesh_seq; +#define IEEE80211_MESH_SEQ_LEQ(a, b) ((int32_t)((a)-(b)) <= 0) +#define IEEE80211_MESH_SEQ_GEQ(a, b) ((int32_t)((a)-(b)) >= 0) + +struct ieee80211_mesh_state { + int ms_idlen; + uint8_t ms_id[IEEE80211_MESHID_LEN]; + ieee80211_mesh_seq ms_seq; /* seq no for meshcntl */ + uint16_t ms_neighbors; + uint8_t ms_ttl; /* mesh ttl set in packets */ +#define IEEE80211_MESHFLAGS_AP 0x01 /* accept peers */ +#define IEEE80211_MESHFLAGS_PORTAL 0x02 /* mesh portal role */ +#define IEEE80211_MESHFLAGS_FWD 0x04 /* forward packets */ + uint8_t ms_flags; + struct mtx ms_rt_lock; + struct callout ms_cleantimer; + TAILQ_HEAD(, ieee80211_mesh_route) ms_routes; + struct ieee80211_mesh_proto_metric *ms_pmetric; + struct ieee80211_mesh_proto_path *ms_ppath; +}; +void ieee80211_mesh_attach(struct ieee80211com *); +void ieee80211_mesh_detach(struct ieee80211com *); + +struct ieee80211_mesh_route * + ieee80211_mesh_rt_find(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN]); +struct ieee80211_mesh_route * + ieee80211_mesh_rt_add(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN]); +void ieee80211_mesh_rt_del(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN]); +void ieee80211_mesh_rt_flush(struct ieee80211vap *); +void ieee80211_mesh_rt_flush_peer(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN]); +void ieee80211_mesh_proxy_check(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN]); + +int ieee80211_mesh_register_proto_path(const + struct ieee80211_mesh_proto_path *); +int ieee80211_mesh_register_proto_metric(const + struct ieee80211_mesh_proto_metric *); + +uint8_t * ieee80211_add_meshpeerver(uint8_t *, struct ieee80211vap *); +uint8_t * ieee80211_add_meshid(uint8_t *, struct ieee80211vap *); +uint8_t * ieee80211_add_meshconf(uint8_t *, struct ieee80211vap *); +uint8_t * ieee80211_add_meshpeer(uint8_t *, uint8_t, uint16_t, uint16_t, + uint16_t); +uint8_t * ieee80211_add_meshlmetric(uint8_t *, uint32_t); + +void ieee80211_mesh_node_init(struct ieee80211vap *, + struct ieee80211_node *); +void ieee80211_mesh_node_cleanup(struct ieee80211_node *); +void ieee80211_parse_meshid(struct ieee80211_node *, + const uint8_t *); +struct ieee80211_scanparams; +void ieee80211_mesh_init_neighbor(struct ieee80211_node *, + const struct ieee80211_frame *, + const struct ieee80211_scanparams *); + +/* + * Return non-zero if proxy operation is enabled. + */ +static __inline int +ieee80211_mesh_isproxyena(struct ieee80211vap *vap) +{ + struct ieee80211_mesh_state *ms = vap->iv_mesh; + return (ms->ms_flags & + (IEEE80211_MESHFLAGS_AP | IEEE80211_MESHFLAGS_PORTAL)) != 0; +} + +/* + * Process an outbound frame: if a path is known to the + * destination then return a reference to the next hop + * for immediate transmission. Otherwise initiate path + * discovery and, if possible queue the packet to be + * sent when path discovery completes. + */ +static __inline struct ieee80211_node * +ieee80211_mesh_discover(struct ieee80211vap *vap, + const uint8_t dest[IEEE80211_ADDR_LEN], struct mbuf *m) +{ + struct ieee80211_mesh_state *ms = vap->iv_mesh; + return ms->ms_ppath->mpp_discover(vap, dest, m); +} + +#endif /* _KERNEL */ +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_MESH_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_monitor.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_monitor.h new file mode 100644 index 0000000000..d62154342b --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_monitor.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_MONITOR_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_MONITOR_H_ + +/* + * Monitor implementation definitions. + */ +void ieee80211_monitor_attach(struct ieee80211com *); +void ieee80211_monitor_detach(struct ieee80211com *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_MONITOR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_node.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_node.h new file mode 100644 index 0000000000..0eeb46eed2 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_node.h @@ -0,0 +1,453 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_NODE_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_NODE_H_ + +#include /* for ieee80211_nodestats */ +#include /* for aggregation state */ + +/* + * Each ieee80211com instance has a single timer that fires every + * IEEE80211_INACT_WAIT seconds to handle "inactivity processing". + * This is used to do node inactivity processing when operating + * as an AP, adhoc or mesh mode. For inactivity processing each node + * has a timeout set in it's ni_inact field that is decremented + * on each timeout and the node is reclaimed when the counter goes + * to zero. We use different inactivity timeout values depending + * on whether the node is associated and authorized (either by + * 802.1x or open/shared key authentication) or associated but yet + * to be authorized. The latter timeout is shorter to more aggressively + * reclaim nodes that leave part way through the 802.1x exchange. + */ +#define IEEE80211_INACT_WAIT 15 /* inactivity interval (secs) */ +#define IEEE80211_INACT_INIT (30/IEEE80211_INACT_WAIT) /* initial */ +#define IEEE80211_INACT_AUTH (180/IEEE80211_INACT_WAIT) /* associated but not authorized */ +#define IEEE80211_INACT_RUN (300/IEEE80211_INACT_WAIT) /* authorized */ +#define IEEE80211_INACT_PROBE (30/IEEE80211_INACT_WAIT) /* probe */ +#define IEEE80211_INACT_SCAN (300/IEEE80211_INACT_WAIT) /* scanned */ + +#define IEEE80211_TRANS_WAIT 2 /* mgt frame tx timer (secs) */ + +/* threshold for aging overlapping non-ERP bss */ +#define IEEE80211_NONERP_PRESENT_AGE msecs_to_ticks(60*1000) + +#define IEEE80211_NODE_HASHSIZE 32 /* NB: hash size must be pow2 */ +/* simple hash is enough for variation of macaddr */ +#define IEEE80211_NODE_HASH(ic, addr) \ + (((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \ + IEEE80211_NODE_HASHSIZE) + +struct ieee80211_node_table; +struct ieee80211com; +struct ieee80211vap; + +/* + * Information element ``blob''. We use this structure + * to capture management frame payloads that need to be + * retained. Information elements within the payload that + * we need to consult have references recorded. + */ +struct ieee80211_ies { + /* the following are either NULL or point within data */ + uint8_t *wpa_ie; /* captured WPA ie */ + uint8_t *rsn_ie; /* captured RSN ie */ + uint8_t *wme_ie; /* captured WME ie */ + uint8_t *ath_ie; /* captured Atheros ie */ + uint8_t *htcap_ie; /* captured HTCAP ie */ + uint8_t *htinfo_ie; /* captured HTINFO ie */ + uint8_t *tdma_ie; /* captured TDMA ie */ + uint8_t *meshid_ie; /* captured MESH ID ie */ + uint8_t *spare[4]; + /* NB: these must be the last members of this structure */ + uint8_t *data; /* frame data > 802.11 header */ + int len; /* data size in bytes */ +}; + +/* + * 802.11s (Mesh) Peer Link FSM state. + */ +enum ieee80211_mesh_mlstate { + IEEE80211_NODE_MESH_IDLE = 0, + IEEE80211_NODE_MESH_OPENSNT = 1, /* open frame sent */ + IEEE80211_NODE_MESH_OPENRCV = 2, /* open frame received */ + IEEE80211_NODE_MESH_CONFIRMRCV = 3, /* confirm frame received */ + IEEE80211_NODE_MESH_ESTABLISHED = 4, /* link established */ + IEEE80211_NODE_MESH_HOLDING = 5, /* link closing */ +}; +#define IEEE80211_MESH_MLSTATE_BITS \ + "\20\1IDLE\2OPENSNT\2OPENRCV\3CONFIRMRCV\4ESTABLISHED\5HOLDING" + +/* + * Node specific information. Note that drivers are expected + * to derive from this structure to add device-specific per-node + * state. This is done by overriding the ic_node_* methods in + * the ieee80211com structure. + */ +struct ieee80211_node { + struct ieee80211vap *ni_vap; /* associated vap */ + struct ieee80211com *ni_ic; /* copy from vap to save deref*/ + struct ieee80211_node_table *ni_table; /* NB: may be NULL */ + TAILQ_ENTRY(ieee80211_node) ni_list; /* list of all nodes */ + LIST_ENTRY(ieee80211_node) ni_hash; /* hash collision list */ + u_int ni_refcnt; /* count of held references */ + u_int ni_scangen; /* gen# for timeout scan */ + u_int ni_flags; +#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */ +#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */ +#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */ +/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */ +#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */ +#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */ +#define IEEE80211_NODE_HT 0x000040 /* HT enabled */ +#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */ +#define IEEE80211_NODE_WPS 0x000100 /* WPS association */ +#define IEEE80211_NODE_TSN 0x000200 /* TSN association */ +#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */ +#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */ +#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */ +#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */ +#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */ +#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */ +#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */ +#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */ +#define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */ +#define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */ + uint16_t ni_associd; /* association ID */ + uint16_t ni_vlan; /* vlan tag */ + uint16_t ni_txpower; /* current transmit power */ + uint8_t ni_authmode; /* authentication algorithm */ + uint8_t ni_ath_flags; /* Atheros feature flags */ + /* NB: These must have the same values as IEEE80211_ATHC_* */ +#define IEEE80211_NODE_TURBOP 0x0001 /* Turbo prime enable */ +#define IEEE80211_NODE_COMP 0x0002 /* Compresssion enable */ +#define IEEE80211_NODE_FF 0x0004 /* Fast Frame capable */ +#define IEEE80211_NODE_XR 0x0008 /* Atheros WME enable */ +#define IEEE80211_NODE_AR 0x0010 /* AR capable */ +#define IEEE80211_NODE_BOOST 0x0080 /* Dynamic Turbo boosted */ + uint16_t ni_ath_defkeyix;/* Atheros def key index */ + const struct ieee80211_txparam *ni_txparms; + uint32_t ni_jointime; /* time of join (secs) */ + uint32_t *ni_challenge; /* shared-key challenge */ + struct ieee80211_ies ni_ies; /* captured ie's */ + /* tx seq per-tid */ + ieee80211_seq ni_txseqs[IEEE80211_TID_SIZE]; + /* rx seq previous per-tid*/ + ieee80211_seq ni_rxseqs[IEEE80211_TID_SIZE]; + uint32_t ni_rxfragstamp; /* time stamp of last rx frag */ + struct mbuf *ni_rxfrag[3]; /* rx frag reassembly */ + struct ieee80211_key ni_ucastkey; /* unicast key */ + + /* hardware */ + uint32_t ni_avgrssi; /* recv ssi state */ + int8_t ni_noise; /* noise floor */ + + /* header */ + uint8_t ni_macaddr[IEEE80211_ADDR_LEN]; + uint8_t ni_bssid[IEEE80211_ADDR_LEN]; + + /* beacon, probe response */ + union { + uint8_t data[8]; + u_int64_t tsf; + } ni_tstamp; /* from last rcv'd beacon */ + uint16_t ni_intval; /* beacon interval */ + uint16_t ni_capinfo; /* capabilities */ + uint8_t ni_esslen; + uint8_t ni_essid[IEEE80211_NWID_LEN]; + struct ieee80211_rateset ni_rates; /* negotiated rate set */ + struct ieee80211_channel *ni_chan; + uint16_t ni_fhdwell; /* FH only */ + uint8_t ni_fhindex; /* FH only */ + uint16_t ni_erp; /* ERP from beacon/probe resp */ + uint16_t ni_timoff; /* byte offset to TIM ie */ + uint8_t ni_dtim_period; /* DTIM period */ + uint8_t ni_dtim_count; /* DTIM count for last bcn */ + + /* 11s state */ + uint8_t ni_meshidlen; + uint8_t ni_meshid[IEEE80211_MESHID_LEN]; + enum ieee80211_mesh_mlstate ni_mlstate; /* peering management state */ + uint16_t ni_mllid; /* link local ID */ + uint16_t ni_mlpid; /* link peer ID */ + struct callout ni_mltimer; /* link mesh timer */ + uint8_t ni_mlrcnt; /* link mesh retry counter */ + uint8_t ni_mltval; /* link mesh timer value */ + + /* 11n state */ + uint16_t ni_htcap; /* HT capabilities */ + uint8_t ni_htparam; /* HT params */ + uint8_t ni_htctlchan; /* HT control channel */ + uint8_t ni_ht2ndchan; /* HT 2nd channel */ + uint8_t ni_htopmode; /* HT operating mode */ + uint8_t ni_htstbc; /* HT */ + uint8_t ni_chw; /* negotiated channel width */ + struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */ + struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_AC]; + struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID]; + + /* others */ + short ni_inact; /* inactivity mark count */ + short ni_inact_reload;/* inactivity reload value */ + int ni_txrate; /* legacy rate/MCS */ + struct ieee80211_psq ni_psq; /* power save queue */ + struct ieee80211_nodestats ni_stats; /* per-node statistics */ + + struct ieee80211vap *ni_wdsvap; /* associated WDS vap */ + uint64_t ni_spare[4]; +}; + +#define IEEE80211_NODE_ATH (IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP) +#define IEEE80211_NODE_AMPDU \ + (IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX) +#define IEEE80211_NODE_AMSDU \ + (IEEE80211_NODE_AMSDU_RX | IEEE80211_NODE_AMSDU_TX) +#define IEEE80211_NODE_HT_ALL \ + (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \ + IEEE80211_NODE_AMPDU | IEEE80211_NODE_AMSDU | \ + IEEE80211_NODE_MIMO_PS | IEEE80211_NODE_MIMO_RTS | \ + IEEE80211_NODE_RIFS | IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40) + +#define IEEE80211_NODE_BITS \ + "\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \ + "\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \ + "\22ASSOCID" + +#define IEEE80211_NODE_AID(ni) IEEE80211_AID(ni->ni_associd) + +#define IEEE80211_NODE_STAT(ni,stat) (ni->ni_stats.ns_##stat++) +#define IEEE80211_NODE_STAT_ADD(ni,stat,v) (ni->ni_stats.ns_##stat += v) +#define IEEE80211_NODE_STAT_SET(ni,stat,v) (ni->ni_stats.ns_##stat = v) + +/* + * Filtered rssi calculation support. The receive rssi is maintained + * as an average over the last 10 frames received using a low pass filter + * (all frames for now, possibly need to be more selective). Calculations + * are designed such that a good compiler can optimize them. The avg + * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and + * each sample incorporated with IEEE80211_RSSI_LPF. Use IEEE80211_RSSI_GET + * to extract the current value. + * + * Note that we assume rssi data are in the range [-127..127] and we + * discard values <-20. This is consistent with assumptions throughout + * net80211 that signal strength data are in .5 dBm units relative to + * the current noise floor (linear, not log). + */ +#define IEEE80211_RSSI_LPF_LEN 10 +#define IEEE80211_RSSI_DUMMY_MARKER 127 +/* NB: pow2 to optimize out * and / */ +#define IEEE80211_RSSI_EP_MULTIPLIER (1<<7) +#define IEEE80211_RSSI_IN(x) ((x) * IEEE80211_RSSI_EP_MULTIPLIER) +#define _IEEE80211_RSSI_LPF(x, y, len) \ + (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y)) +#define IEEE80211_RSSI_LPF(x, y) do { \ + if ((y) >= -20) { \ + x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), \ + IEEE80211_RSSI_LPF_LEN); \ + } \ +} while (0) +#define IEEE80211_RSSI_EP_RND(x, mul) \ + ((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul)) +#define IEEE80211_RSSI_GET(x) \ + IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER) + +static __inline struct ieee80211_node * +ieee80211_ref_node(struct ieee80211_node *ni) +{ + ieee80211_node_incref(ni); + return ni; +} + +static __inline void +ieee80211_unref_node(struct ieee80211_node **ni) +{ + ieee80211_node_decref(*ni); + *ni = NULL; /* guard against use */ +} + +struct ieee80211com; + +void ieee80211_node_attach(struct ieee80211com *); +void ieee80211_node_lateattach(struct ieee80211com *); +void ieee80211_node_detach(struct ieee80211com *); +void ieee80211_node_vattach(struct ieee80211vap *); +void ieee80211_node_latevattach(struct ieee80211vap *); +void ieee80211_node_vdetach(struct ieee80211vap *); + +static __inline int +ieee80211_node_is_authorized(const struct ieee80211_node *ni) +{ + return (ni->ni_flags & IEEE80211_NODE_AUTH); +} + +void ieee80211_node_authorize(struct ieee80211_node *); +void ieee80211_node_unauthorize(struct ieee80211_node *); + +void ieee80211_node_setuptxparms(struct ieee80211_node *); +void ieee80211_node_set_chan(struct ieee80211_node *, + struct ieee80211_channel *); +void ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *); +void ieee80211_reset_bss(struct ieee80211vap *); +void ieee80211_sync_curchan(struct ieee80211com *); +void ieee80211_setupcurchan(struct ieee80211com *, + struct ieee80211_channel *); +void ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *); +int ieee80211_ibss_merge(struct ieee80211_node *); +struct ieee80211_scan_entry; +int ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *, + const struct ieee80211_scan_entry *); +void ieee80211_sta_leave(struct ieee80211_node *); +void ieee80211_node_deauth(struct ieee80211_node *, int); + +int ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int); +void ieee80211_ies_cleanup(struct ieee80211_ies *); +void ieee80211_ies_expand(struct ieee80211_ies *); +#define ieee80211_ies_setie(_ies, _ie, _off) do { \ + (_ies)._ie = (_ies).data + (_off); \ +} while (0) + +/* + * Table of ieee80211_node instances. Each ieee80211com + * has one that holds association stations (when operating + * as an ap) or neighbors (in ibss mode). + * + * XXX embed this in ieee80211com instead of indirect? + */ +struct ieee80211_node_table { + struct ieee80211com *nt_ic; /* back reference */ + ieee80211_node_lock_t nt_nodelock; /* on node table */ + TAILQ_HEAD(, ieee80211_node) nt_node; /* information of all nodes */ + LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE]; + struct ieee80211_node **nt_keyixmap; /* key ix -> node map */ + int nt_keyixmax; /* keyixmap size */ + const char *nt_name; /* table name for debug msgs */ + ieee80211_scan_lock_t nt_scanlock; /* on nt_scangen */ + u_int nt_scangen; /* gen# for iterators */ + int nt_inact_init; /* initial node inact setting */ +}; + +struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *, + struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *, + const uint8_t bssid[IEEE80211_ADDR_LEN], + struct ieee80211_channel *); +#ifdef IEEE80211_DEBUG_REFCNT +void ieee80211_free_node_debug(struct ieee80211_node *, + const char *func, int line); +struct ieee80211_node *ieee80211_find_node_locked_debug( + struct ieee80211_node_table *, + const uint8_t macaddr[IEEE80211_ADDR_LEN], + const char *func, int line); +struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *, + const uint8_t macaddr[IEEE80211_ADDR_LEN], + const char *func, int line); +struct ieee80211_node *ieee80211_find_vap_node_locked_debug( + struct ieee80211_node_table *, + const struct ieee80211vap *vap, + const uint8_t macaddr[IEEE80211_ADDR_LEN], + const char *func, int line); +struct ieee80211_node *ieee80211_find_vap_node_debug( + struct ieee80211_node_table *, + const struct ieee80211vap *vap, + const uint8_t macaddr[IEEE80211_ADDR_LEN], + const char *func, int line); +struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *, + const struct ieee80211_frame_min *, + const char *func, int line); +struct ieee80211_node * ieee80211_find_rxnode_withkey_debug( + struct ieee80211com *, + const struct ieee80211_frame_min *, uint16_t keyix, + const char *func, int line); +struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *, + const uint8_t *, + const char *func, int line); +#define ieee80211_free_node(ni) \ + ieee80211_free_node_debug(ni, __func__, __LINE__) +#define ieee80211_find_node_locked(nt, mac) \ + ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__) +#define ieee80211_find_node(nt, mac) \ + ieee80211_find_node_debug(nt, mac, __func__, __LINE__) +#define ieee80211_find_vap_node_locked(nt, vap, mac) \ + ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__) +#define ieee80211_find_vap_node(nt, vap, mac) \ + ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__) +#define ieee80211_find_rxnode(ic, wh) \ + ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__) +#define ieee80211_find_rxnode_withkey(ic, wh, keyix) \ + ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__) +#define ieee80211_find_txnode(vap, mac) \ + ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__) +#else +void ieee80211_free_node(struct ieee80211_node *); +struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node *ieee80211_find_vap_node_locked( + struct ieee80211_node_table *, const struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node *ieee80211_find_vap_node( + struct ieee80211_node_table *, const struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *, + const struct ieee80211_frame_min *); +struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *, + const struct ieee80211_frame_min *, uint16_t keyix); +struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +#endif +int ieee80211_node_delucastkey(struct ieee80211_node *); +void ieee80211_node_timeout(void *arg); + +typedef void ieee80211_iter_func(void *, struct ieee80211_node *); +void ieee80211_iterate_nodes(struct ieee80211_node_table *, + ieee80211_iter_func *, void *); + +void ieee80211_notify_erp(struct ieee80211com *); +void ieee80211_dump_node(struct ieee80211_node_table *, + struct ieee80211_node *); +void ieee80211_dump_nodes(struct ieee80211_node_table *); + +struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +struct ieee80211_scanparams; +void ieee80211_init_neighbor(struct ieee80211_node *, + const struct ieee80211_frame *, + const struct ieee80211_scanparams *); +struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *, + const struct ieee80211_frame *, + const struct ieee80211_scanparams *); +void ieee80211_node_join(struct ieee80211_node *,int); +void ieee80211_node_leave(struct ieee80211_node *); +int8_t ieee80211_getrssi(struct ieee80211vap *); +void ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_NODE_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_phy.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_phy.h new file mode 100644 index 0000000000..69d7568219 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_phy.h @@ -0,0 +1,157 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ + +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_PHY_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_PHY_H_ + +#ifdef _KERNEL +/* + * IEEE 802.11 PHY-related definitions. + */ + +void ieee80211_phy_init(void); + +/* + * Contention window (slots). + */ +#define IEEE80211_CW_MAX 1023 /* aCWmax */ +#define IEEE80211_CW_MIN_0 31 /* DS/CCK aCWmin, ERP aCWmin(0) */ +#define IEEE80211_CW_MIN_1 15 /* OFDM aCWmin, ERP aCWmin(1) */ + +/* + * SIFS (microseconds). + */ +#define IEEE80211_DUR_SIFS 10 /* DS/CCK/ERP SIFS */ +#define IEEE80211_DUR_OFDM_SIFS 16 /* OFDM SIFS */ + +/* + * Slot time (microseconds). + */ +#define IEEE80211_DUR_SLOT 20 /* DS/CCK slottime, ERP long slottime */ +#define IEEE80211_DUR_SHSLOT 9 /* ERP short slottime */ +#define IEEE80211_DUR_OFDM_SLOT 9 /* OFDM slottime */ + +/* + * DIFS (microseconds). + */ +#define IEEE80211_DUR_DIFS(sifs, slot) ((sifs) + 2 * (slot)) + +struct ieee80211_channel; + +struct ieee80211_rate_table { + int rateCount; /* NB: for proper padding */ + uint8_t rateCodeToIndex[256]; /* back mapping */ + struct { + uint8_t phy; /* CCK/OFDM/TURBO */ + uint32_t rateKbps; /* transfer rate in kbs */ + uint8_t shortPreamble; /* mask for enabling short + * preamble in CCK rate code */ + uint8_t dot11Rate; /* value for supported rates + * info element of MLME */ + uint8_t ctlRateIndex; /* index of next lower basic + * rate; used for dur. calcs */ + uint16_t lpAckDuration; /* long preamble ACK dur. */ + uint16_t spAckDuration; /* short preamble ACK dur. */ + } info[32]; +}; + +const struct ieee80211_rate_table *ieee80211_get_ratetable( + struct ieee80211_channel *); + +static __inline__ uint8_t +ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate) +{ + uint8_t cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex; + KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate)); + return rt->info[cix].dot11Rate; +} + +static __inline__ uint8_t +ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, uint8_t rate) +{ + uint8_t cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex; + KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate)); + return rt->info[cix].dot11Rate; +} + +static __inline__ enum ieee80211_phytype +ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate) +{ + uint8_t rix = rt->rateCodeToIndex[rate]; + KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate)); + return rt->info[rix].phy; +} + +static __inline__ int +ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate) +{ + return rt->rateCodeToIndex[rate] != (uint8_t)-1; +} + +/* + * Calculate ACK field for + * o non-fragment data frames + * o management frames + * sent using rate, phy and short preamble setting. + */ +static __inline__ uint16_t +ieee80211_ack_duration(const struct ieee80211_rate_table *rt, + uint8_t rate, int isShortPreamble) +{ + uint8_t rix = rt->rateCodeToIndex[rate]; + + KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate)); + if (isShortPreamble) { + KASSERT(rt->info[rix].spAckDuration != 0, + ("shpreamble ack dur is not computed!\n")); + return rt->info[rix].spAckDuration; + } else { + KASSERT(rt->info[rix].lpAckDuration != 0, + ("lgpreamble ack dur is not computed!\n")); + return rt->info[rix].lpAckDuration; + } +} + +/* + * Compute the time to transmit a frame of length frameLen bytes + * using the specified 802.11 rate code, phy, and short preamble + * setting. + * + * NB: SIFS is included. + */ +uint16_t ieee80211_compute_duration(const struct ieee80211_rate_table *, + uint32_t frameLen, uint16_t rate, int isShortPreamble); +/* + * Convert PLCP signal/rate field to 802.11 rate code (.5Mbits/s) + */ +uint8_t ieee80211_plcp2rate(uint8_t, enum ieee80211_phytype); +/* + * Convert 802.11 rate code to PLCP signal. + */ +uint8_t ieee80211_rate2plcp(int, enum ieee80211_phytype); +#endif /* _KERNEL */ +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_PHY_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_power.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_power.h new file mode 100644 index 0000000000..29f04da473 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_power.h @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_POWER_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_POWER_H_ + +struct ieee80211com; +struct ieee80211vap; +struct ieee80211_node; +struct mbuf; + +/* + * Power save packet queues. There are two queues, one + * for frames coming from the net80211 layer and the other + * for frames that come from the driver. Frames from the + * driver are expected to have M_ENCAP marked to indicate + * they have already been encapsulated and are treated as + * higher priority: they are sent first when flushing the + * queue on a power save state change or in response to a + * ps-poll frame. + * + * Note that frames sent from the high priority queue are + * fed directly to the driver without going through + * ieee80211_start again; drivers that send up encap'd + * frames are required to handle them when they come back. + */ +struct ieee80211_psq { + ieee80211_psq_lock_t psq_lock; + int psq_len; + int psq_maxlen; + int psq_drops; + struct ieee80211_psq_head { + struct mbuf *head; + struct mbuf *tail; + int len; + } psq_head[2]; /* 2 priorities */ +}; + +void ieee80211_psq_init(struct ieee80211_psq *, const char *); +void ieee80211_psq_cleanup(struct ieee80211_psq *); + +void ieee80211_power_attach(struct ieee80211com *); +void ieee80211_power_detach(struct ieee80211com *); +void ieee80211_power_vattach(struct ieee80211vap *); +void ieee80211_power_vdetach(struct ieee80211vap *); +void ieee80211_power_latevattach(struct ieee80211vap *); + +struct mbuf *ieee80211_node_psq_dequeue(struct ieee80211_node *ni, int *qlen); +int ieee80211_node_psq_drain(struct ieee80211_node *); +int ieee80211_node_psq_age(struct ieee80211_node *); +int ieee80211_pwrsave(struct ieee80211_node *, struct mbuf *); +void ieee80211_node_pwrsave(struct ieee80211_node *, int enable); +void ieee80211_sta_pwrsave(struct ieee80211vap *, int enable); + +void ieee80211_power_poll(struct ieee80211com *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_POWER_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_proto.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_proto.h new file mode 100644 index 0000000000..1f9feb6a01 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_proto.h @@ -0,0 +1,387 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_PROTO_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_PROTO_H_ + +/* + * 802.11 protocol implementation definitions. + */ + +void ieee80211_auth_setup(void); + +enum ieee80211_state { + IEEE80211_S_INIT = 0, /* default state */ + IEEE80211_S_SCAN = 1, /* scanning */ + IEEE80211_S_AUTH = 2, /* try to authenticate */ + IEEE80211_S_ASSOC = 3, /* try to assoc */ + IEEE80211_S_CAC = 4, /* doing channel availability check */ + IEEE80211_S_RUN = 5, /* operational (e.g. associated) */ + IEEE80211_S_CSA = 6, /* channel switch announce pending */ + IEEE80211_S_SLEEP = 7, /* power save */ +}; +#define IEEE80211_S_MAX (IEEE80211_S_SLEEP+1) + +#define IEEE80211_SEND_MGMT(_ni,_type,_arg) \ + ((*(_ni)->ni_ic->ic_send_mgmt)(_ni, _type, _arg)) + +extern const char *ieee80211_mgt_subtype_name[]; +extern const char *ieee80211_phymode_name[IEEE80211_MODE_MAX]; +extern const int ieee80211_opcap[IEEE80211_OPMODE_MAX]; + +void ieee80211_proto_attach(struct ieee80211com *); +void ieee80211_proto_detach(struct ieee80211com *); +void ieee80211_proto_vattach(struct ieee80211vap *); +void ieee80211_proto_vdetach(struct ieee80211vap *); + +void ieee80211_syncifflag_locked(struct ieee80211com *, int flag); +void ieee80211_syncflag(struct ieee80211vap *, int flag); +void ieee80211_syncflag_ht(struct ieee80211vap *, int flag); +void ieee80211_syncflag_ext(struct ieee80211vap *, int flag); + +#define ieee80211_input(ni, m, rssi, nf) \ + ((ni)->ni_vap->iv_input(ni, m, rssi, nf)) +int ieee80211_input_all(struct ieee80211com *, struct mbuf *, int, int); +struct ieee80211_bpf_params; +int ieee80211_mgmt_output(struct ieee80211_node *, struct mbuf *, int, + struct ieee80211_bpf_params *); +int ieee80211_raw_xmit(struct ieee80211_node *, struct mbuf *, + const struct ieee80211_bpf_params *); +int ieee80211_output(struct ifnet *, struct mbuf *, + struct sockaddr *, struct route *ro); +void ieee80211_send_setup(struct ieee80211_node *, struct mbuf *, int, int, + const uint8_t [IEEE80211_ADDR_LEN], const uint8_t [IEEE80211_ADDR_LEN], + const uint8_t [IEEE80211_ADDR_LEN]); +void ieee80211_start(struct ifnet *); +int ieee80211_send_nulldata(struct ieee80211_node *); +int ieee80211_classify(struct ieee80211_node *, struct mbuf *m); +struct mbuf *ieee80211_mbuf_adjust(struct ieee80211vap *, int, + struct ieee80211_key *, struct mbuf *); +struct mbuf *ieee80211_encap(struct ieee80211vap *, struct ieee80211_node *, + struct mbuf *); +int ieee80211_send_mgmt(struct ieee80211_node *, int, int); +struct ieee80211_appie; +int ieee80211_send_probereq(struct ieee80211_node *ni, + const uint8_t sa[IEEE80211_ADDR_LEN], + const uint8_t da[IEEE80211_ADDR_LEN], + const uint8_t bssid[IEEE80211_ADDR_LEN], + const uint8_t *ssid, size_t ssidlen); +/* + * The formation of ProbeResponse frames requires guidance to + * deal with legacy clients. When the client is identified as + * "legacy 11b" ieee80211_send_proberesp is passed this token. + */ +#define IEEE80211_SEND_LEGACY_11B 0x1 /* legacy 11b client */ +#define IEEE80211_SEND_LEGACY_11 0x2 /* other legacy client */ +#define IEEE80211_SEND_LEGACY 0x3 /* any legacy client */ +struct mbuf *ieee80211_alloc_proberesp(struct ieee80211_node *, int); +int ieee80211_send_proberesp(struct ieee80211vap *, + const uint8_t da[IEEE80211_ADDR_LEN], int); +struct mbuf *ieee80211_alloc_rts(struct ieee80211com *ic, + const uint8_t [IEEE80211_ADDR_LEN], + const uint8_t [IEEE80211_ADDR_LEN], uint16_t); +struct mbuf *ieee80211_alloc_cts(struct ieee80211com *, + const uint8_t [IEEE80211_ADDR_LEN], uint16_t); + +uint8_t *ieee80211_add_rates(uint8_t *, const struct ieee80211_rateset *); +uint8_t *ieee80211_add_xrates(uint8_t *, const struct ieee80211_rateset *); +uint16_t ieee80211_getcapinfo(struct ieee80211vap *, + struct ieee80211_channel *); + +void ieee80211_reset_erp(struct ieee80211com *); +void ieee80211_set_shortslottime(struct ieee80211com *, int onoff); +int ieee80211_iserp_rateset(const struct ieee80211_rateset *); +void ieee80211_setbasicrates(struct ieee80211_rateset *, + enum ieee80211_phymode); +void ieee80211_addbasicrates(struct ieee80211_rateset *, + enum ieee80211_phymode); + +/* + * Return the size of the 802.11 header for a management or data frame. + */ +static __inline int +ieee80211_hdrsize(const void *data) +{ + const struct ieee80211_frame *wh = data; + int size = sizeof(struct ieee80211_frame); + + /* NB: we don't handle control frames */ + KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL, + ("%s: control frame", __func__)); + if (IEEE80211_IS_DSTODS(wh)) + size += IEEE80211_ADDR_LEN; + if (IEEE80211_QOS_HAS_SEQ(wh)) + size += sizeof(uint16_t); + return size; +} + +/* + * Like ieee80211_hdrsize, but handles any type of frame. + */ +static __inline int +ieee80211_anyhdrsize(const void *data) +{ + const struct ieee80211_frame *wh = data; + + if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) { + switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) { + case IEEE80211_FC0_SUBTYPE_CTS: + case IEEE80211_FC0_SUBTYPE_ACK: + return sizeof(struct ieee80211_frame_ack); + case IEEE80211_FC0_SUBTYPE_BAR: + return sizeof(struct ieee80211_frame_bar); + } + return sizeof(struct ieee80211_frame_min); + } else + return ieee80211_hdrsize(data); +} + +/* + * Template for an in-kernel authenticator. Authenticators + * register with the protocol code and are typically loaded + * as separate modules as needed. One special authenticator + * is xauth; it intercepts requests so that protocols like + * WPA can be handled in user space. + */ +struct ieee80211_authenticator { + const char *ia_name; /* printable name */ + int (*ia_attach)(struct ieee80211vap *); + void (*ia_detach)(struct ieee80211vap *); + void (*ia_node_join)(struct ieee80211_node *); + void (*ia_node_leave)(struct ieee80211_node *); +}; +void ieee80211_authenticator_register(int type, + const struct ieee80211_authenticator *); +void ieee80211_authenticator_unregister(int type); +const struct ieee80211_authenticator *ieee80211_authenticator_get(int auth); + +struct ieee80211req; +/* + * Template for an MAC ACL policy module. Such modules + * register with the protocol code and are passed the sender's + * address of each received auth frame for validation. + */ +struct ieee80211_aclator { + const char *iac_name; /* printable name */ + int (*iac_attach)(struct ieee80211vap *); + void (*iac_detach)(struct ieee80211vap *); + int (*iac_check)(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN]); + int (*iac_add)(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN]); + int (*iac_remove)(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN]); + int (*iac_flush)(struct ieee80211vap *); + int (*iac_setpolicy)(struct ieee80211vap *, int); + int (*iac_getpolicy)(struct ieee80211vap *); + int (*iac_setioctl)(struct ieee80211vap *, struct ieee80211req *); + int (*iac_getioctl)(struct ieee80211vap *, struct ieee80211req *); +}; +void ieee80211_aclator_register(const struct ieee80211_aclator *); +void ieee80211_aclator_unregister(const struct ieee80211_aclator *); +const struct ieee80211_aclator *ieee80211_aclator_get(const char *name); + +/* flags for ieee80211_fix_rate() */ +#define IEEE80211_F_DOSORT 0x00000001 /* sort rate list */ +#define IEEE80211_F_DOFRATE 0x00000002 /* use fixed legacy rate */ +#define IEEE80211_F_DONEGO 0x00000004 /* calc negotiated rate */ +#define IEEE80211_F_DODEL 0x00000008 /* delete ignore rate */ +#define IEEE80211_F_DOBRS 0x00000010 /* check basic rate set */ +#define IEEE80211_F_JOIN 0x00000020 /* sta joining our bss */ +#define IEEE80211_F_DOFMCS 0x00000040 /* use fixed HT rate */ +int ieee80211_fix_rate(struct ieee80211_node *, + struct ieee80211_rateset *, int); + +/* + * WME/WMM support. + */ +struct wmeParams { + uint8_t wmep_acm; + uint8_t wmep_aifsn; + uint8_t wmep_logcwmin; /* log2(cwmin) */ + uint8_t wmep_logcwmax; /* log2(cwmax) */ + uint8_t wmep_txopLimit; + uint8_t wmep_noackPolicy; /* 0 (ack), 1 (no ack) */ +}; +#define IEEE80211_TXOP_TO_US(_txop) ((_txop)<<5) +#define IEEE80211_US_TO_TXOP(_us) ((_us)>>5) + +struct chanAccParams { + uint8_t cap_info; /* version of the current set */ + struct wmeParams cap_wmeParams[WME_NUM_AC]; +}; + +struct ieee80211_wme_state { + u_int wme_flags; +#define WME_F_AGGRMODE 0x00000001 /* STATUS: WME agressive mode */ + u_int wme_hipri_traffic; /* VI/VO frames in beacon interval */ + u_int wme_hipri_switch_thresh;/* agressive mode switch thresh */ + u_int wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */ + + struct wmeParams wme_params[4]; /* from assoc resp for each AC*/ + struct chanAccParams wme_wmeChanParams; /* WME params applied to self */ + struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */ + struct chanAccParams wme_chanParams; /* params applied to self */ + struct chanAccParams wme_bssChanParams; /* params bcast to stations */ + + int (*wme_update)(struct ieee80211com *); +}; + +void ieee80211_wme_initparams(struct ieee80211vap *); +void ieee80211_wme_updateparams(struct ieee80211vap *); +void ieee80211_wme_updateparams_locked(struct ieee80211vap *); + +/* + * Return the WME TID from a QoS frame. If no TID + * is present return the index for the "non-QoS" entry. + */ +static __inline uint8_t +ieee80211_gettid(const struct ieee80211_frame *wh) +{ + uint8_t tid; + + if (IEEE80211_QOS_HAS_SEQ(wh)) { + if (IEEE80211_IS_DSTODS(wh)) + tid = ((const struct ieee80211_qosframe_addr4 *)wh)-> + i_qos[0]; + else + tid = ((const struct ieee80211_qosframe *)wh)->i_qos[0]; + tid &= IEEE80211_QOS_TID; + } else + tid = IEEE80211_NONQOS_TID; + return tid; +} + +void ieee80211_waitfor_parent(struct ieee80211com *); +void ieee80211_start_locked(struct ieee80211vap *); +void ieee80211_init(void *); +void ieee80211_start_all(struct ieee80211com *); +void ieee80211_stop_locked(struct ieee80211vap *); +void ieee80211_stop(struct ieee80211vap *); +void ieee80211_stop_all(struct ieee80211com *); +void ieee80211_suspend_all(struct ieee80211com *); +void ieee80211_resume_all(struct ieee80211com *); +void ieee80211_dturbo_switch(struct ieee80211vap *, int newflags); +void ieee80211_swbmiss(void *arg); +void ieee80211_beacon_miss(struct ieee80211com *); +int ieee80211_new_state(struct ieee80211vap *, enum ieee80211_state, int); +void ieee80211_print_essid(const uint8_t *, int); +void ieee80211_dump_pkt(struct ieee80211com *, + const uint8_t *, int, int, int); + +extern const char *ieee80211_opmode_name[]; +extern const char *ieee80211_state_name[IEEE80211_S_MAX]; +extern const char *ieee80211_wme_acnames[]; + +/* + * Beacon frames constructed by ieee80211_beacon_alloc + * have the following structure filled in so drivers + * can update the frame later w/ minimal overhead. + */ +struct ieee80211_beacon_offsets { + uint8_t bo_flags[4]; /* update/state flags */ + uint16_t *bo_caps; /* capabilities */ + uint8_t *bo_cfp; /* start of CFParms element */ + uint8_t *bo_tim; /* start of atim/dtim */ + uint8_t *bo_wme; /* start of WME parameters */ + uint8_t *bo_tdma; /* start of TDMA parameters */ + uint8_t *bo_tim_trailer;/* start of fixed-size trailer */ + uint16_t bo_tim_len; /* atim/dtim length in bytes */ + uint16_t bo_tim_trailer_len;/* tim trailer length in bytes */ + uint8_t *bo_erp; /* start of ERP element */ + uint8_t *bo_htinfo; /* start of HT info element */ + uint8_t *bo_ath; /* start of ATH parameters */ + uint8_t *bo_appie; /* start of AppIE element */ + uint16_t bo_appie_len; /* AppIE length in bytes */ + uint16_t bo_csa_trailer_len;; + uint8_t *bo_csa; /* start of CSA element */ + uint8_t *bo_spare[4]; +}; +struct mbuf *ieee80211_beacon_alloc(struct ieee80211_node *, + struct ieee80211_beacon_offsets *); + +/* + * Beacon frame updates are signaled through calls to iv_update_beacon + * with one of the IEEE80211_BEACON_* tokens defined below. For devices + * that construct beacon frames on the host this can trigger a rebuild + * or defer the processing. For devices that offload beacon frame + * handling this callback can be used to signal a rebuild. The bo_flags + * array in the ieee80211_beacon_offsets structure is intended to record + * deferred processing requirements; ieee80211_beacon_update uses the + * state to optimize work. Since this structure is owned by the driver + * and not visible to the 802.11 layer drivers must supply an iv_update_beacon + * callback that marks the flag bits and schedules (as necessary) an update. + */ +enum { + IEEE80211_BEACON_CAPS = 0, /* capabilities */ + IEEE80211_BEACON_TIM = 1, /* DTIM/ATIM */ + IEEE80211_BEACON_WME = 2, + IEEE80211_BEACON_ERP = 3, /* Extended Rate Phy */ + IEEE80211_BEACON_HTINFO = 4, /* HT Information */ + IEEE80211_BEACON_APPIE = 5, /* Application IE's */ + IEEE80211_BEACON_CFP = 6, /* CFParms */ + IEEE80211_BEACON_CSA = 7, /* Channel Switch Announcement */ + IEEE80211_BEACON_TDMA = 9, /* TDMA Info */ + IEEE80211_BEACON_ATH = 10, /* ATH parameters */ +}; +int ieee80211_beacon_update(struct ieee80211_node *, + struct ieee80211_beacon_offsets *, struct mbuf *, int mcast); + +void ieee80211_csa_startswitch(struct ieee80211com *, + struct ieee80211_channel *, int mode, int count); +void ieee80211_csa_completeswitch(struct ieee80211com *); +void ieee80211_csa_cancelswitch(struct ieee80211com *); +void ieee80211_cac_completeswitch(struct ieee80211vap *); + +/* + * Notification methods called from the 802.11 state machine. + * Note that while these are defined here, their implementation + * is OS-specific. + */ +void ieee80211_notify_node_join(struct ieee80211_node *, int newassoc); +void ieee80211_notify_node_leave(struct ieee80211_node *); +void ieee80211_notify_scan_done(struct ieee80211vap *); +void ieee80211_notify_wds_discover(struct ieee80211_node *); +void ieee80211_notify_csa(struct ieee80211com *, + const struct ieee80211_channel *, int mode, int count); +void ieee80211_notify_radar(struct ieee80211com *, + const struct ieee80211_channel *); +enum ieee80211_notify_cac_event { + IEEE80211_NOTIFY_CAC_START = 0, /* CAC timer started */ + IEEE80211_NOTIFY_CAC_STOP = 1, /* CAC intentionally stopped */ + IEEE80211_NOTIFY_CAC_RADAR = 2, /* CAC stopped due to radar detectio */ + IEEE80211_NOTIFY_CAC_EXPIRE = 3, /* CAC expired w/o radar */ +}; +void ieee80211_notify_cac(struct ieee80211com *, + const struct ieee80211_channel *, + enum ieee80211_notify_cac_event); +void ieee80211_notify_node_deauth(struct ieee80211_node *); +void ieee80211_notify_node_auth(struct ieee80211_node *); +void ieee80211_notify_country(struct ieee80211vap *, const uint8_t [], + const uint8_t cc[2]); +void ieee80211_notify_radio(struct ieee80211com *, int); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_PROTO_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_radiotap.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_radiotap.h new file mode 100644 index 0000000000..f7ef147c77 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_radiotap.h @@ -0,0 +1,234 @@ +/* $FreeBSD$ */ +/* $NetBSD: ieee80211_radiotap.h,v 1.16 2007/01/06 05:51:15 dyoung Exp $ */ + +/*- + * Copyright (c) 2003, 2004 David Young. 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 David Young may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``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 DAVID + * YOUNG 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. + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_RADIOTAP_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_RADIOTAP_H_ + +/* A generic radio capture format is desirable. It must be + * rigidly defined (e.g., units for fields should be given), + * and easily extensible. + * + * The following is an extensible radio capture format. It is + * based on a bitmap indicating which fields are present. + * + * I am trying to describe precisely what the application programmer + * should expect in the following, and for that reason I tell the + * units and origin of each measurement (where it applies), or else I + * use sufficiently weaselly language ("is a monotonically nondecreasing + * function of...") that I cannot set false expectations for lawyerly + * readers. + */ +#if defined(__KERNEL__) || defined(_KERNEL) +#ifndef DLT_IEEE802_11_RADIO +#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus WLAN header */ +#endif +#endif /* defined(__KERNEL__) || defined(_KERNEL) */ + +#define IEEE80211_RADIOTAP_HDRLEN 64 /* XXX deprecated */ + +/* + * The radio capture header precedes the 802.11 header. + * + * Note well: all radiotap fields are little-endian. + */ +struct ieee80211_radiotap_header { + uint8_t it_version; /* Version 0. Only increases + * for drastic changes, + * introduction of compatible + * new fields does not count. + */ + uint8_t it_pad; + uint16_t it_len; /* length of the whole + * header in bytes, including + * it_version, it_pad, + * it_len, and data fields. + */ + uint32_t it_present; /* A bitmap telling which + * fields are present. Set bit 31 + * (0x80000000) to extend the + * bitmap by another 32 bits. + * Additional extensions are made + * by setting bit 31. + */ +} __packed; + +/* + * Name Data type Units + * ---- --------- ----- + * + * IEEE80211_RADIOTAP_TSFT uint64_t microseconds + * + * Value in microseconds of the MAC's 64-bit 802.11 Time + * Synchronization Function timer when the first bit of the + * MPDU arrived at the MAC. For received frames, only. + * + * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap + * + * Tx/Rx frequency in MHz, followed by flags (see below). + * + * IEEE80211_RADIOTAP_FHSS uint16_t see below + * + * For frequency-hopping radios, the hop set (first byte) + * and pattern (second byte). + * + * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s or index + * + * Tx/Rx data rate. If bit 0x80 is set then it represents an + * an MCS index and not an IEEE rate. + * + * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from + * one milliwatt (dBm) + * + * RF signal power at the antenna, decibel difference from + * one milliwatt. + * + * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from + * one milliwatt (dBm) + * + * RF noise power at the antenna, decibel difference from one + * milliwatt. + * + * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB) + * + * RF signal power at the antenna, decibel difference from an + * arbitrary, fixed reference. + * + * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB) + * + * RF noise power at the antenna, decibel difference from an + * arbitrary, fixed reference point. + * + * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless + * + * Quality of Barker code lock. Unitless. Monotonically + * nondecreasing with "better" lock strength. Called "Signal + * Quality" in datasheets. (Is there a standard way to measure + * this?) + * + * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless + * + * Transmit power expressed as unitless distance from max + * power set at factory calibration. 0 is max power. + * Monotonically nondecreasing with lower power levels. + * + * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB) + * + * Transmit power expressed as decibel distance from max power + * set at factory calibration. 0 is max power. Monotonically + * nondecreasing with lower power levels. + * + * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from + * one milliwatt (dBm) + * + * Transmit power expressed as dBm (decibels from a 1 milliwatt + * reference). This is the absolute power level measured at + * the antenna port. + * + * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap + * + * Properties of transmitted and received frames. See flags + * defined below. + * + * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index + * + * Unitless indication of the Rx/Tx antenna for this packet. + * The first antenna is antenna 0. + * + * IEEE80211_RADIOTAP_XCHANNEL uint32_t bitmap + * uint16_t MHz + * uint8_t channel number + * int8_t .5 dBm + * + * Extended channel specification: flags (see below) followed by + * frequency in MHz, the corresponding IEEE channel number, and + * finally the maximum regulatory transmit power cap in .5 dBm + * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL + * and only one of the two should be present. + */ +enum ieee80211_radiotap_type { + IEEE80211_RADIOTAP_TSFT = 0, + IEEE80211_RADIOTAP_FLAGS = 1, + IEEE80211_RADIOTAP_RATE = 2, + IEEE80211_RADIOTAP_CHANNEL = 3, + IEEE80211_RADIOTAP_FHSS = 4, + IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, + IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, + IEEE80211_RADIOTAP_LOCK_QUALITY = 7, + IEEE80211_RADIOTAP_TX_ATTENUATION = 8, + IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, + IEEE80211_RADIOTAP_DBM_TX_POWER = 10, + IEEE80211_RADIOTAP_ANTENNA = 11, + IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, + IEEE80211_RADIOTAP_DB_ANTNOISE = 13, + /* NB: gap for netbsd definitions */ + IEEE80211_RADIOTAP_XCHANNEL = 18, + IEEE80211_RADIOTAP_EXT = 31, +}; + +#ifndef _KERNEL +/* channel attributes */ +#define IEEE80211_CHAN_TURBO 0x00000010 /* Turbo channel */ +#define IEEE80211_CHAN_CCK 0x00000020 /* CCK channel */ +#define IEEE80211_CHAN_OFDM 0x00000040 /* OFDM channel */ +#define IEEE80211_CHAN_2GHZ 0x00000080 /* 2 GHz spectrum channel. */ +#define IEEE80211_CHAN_5GHZ 0x00000100 /* 5 GHz spectrum channel */ +#define IEEE80211_CHAN_PASSIVE 0x00000200 /* Only passive scan allowed */ +#define IEEE80211_CHAN_DYN 0x00000400 /* Dynamic CCK-OFDM channel */ +#define IEEE80211_CHAN_GFSK 0x00000800 /* GFSK channel (FHSS PHY) */ +#define IEEE80211_CHAN_GSM 0x00001000 /* 900 MHz spectrum channel */ +#define IEEE80211_CHAN_STURBO 0x00002000 /* 11a static turbo channel only */ +#define IEEE80211_CHAN_HALF 0x00004000 /* Half rate channel */ +#define IEEE80211_CHAN_QUARTER 0x00008000 /* Quarter rate channel */ +#endif /* !_KERNEL */ + +/* For IEEE80211_RADIOTAP_FLAGS */ +#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received + * during CFP + */ +#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received + * with short + * preamble + */ +#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received + * with WEP encryption + */ +#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received + * with fragmentation + */ +#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ +#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between + * 802.11 header and payload + * (to 32-bit boundary) + */ +#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */ +#define IEEE80211_RADIOTAP_F_SHORTGI 0x80 /* HT short GI */ + +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_RADIOTAP_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_regdomain.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_regdomain.h new file mode 100644 index 0000000000..93f228af03 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_regdomain.h @@ -0,0 +1,282 @@ +/*- + * Copyright (c) 2005-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_REGDOMAIN_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_REGDOMAIN_H_ + +/* + * 802.11 regulatory domain definitions. + */ + +/* + * ISO 3166 Country/Region Codes + * http://ftp.ics.uci.edu/pub/ietf/http/related/iso3166.txt + */ +enum ISOCountryCode { + CTRY_AFGHANISTAN = 4, + CTRY_ALBANIA = 8, /* Albania */ + CTRY_ALGERIA = 12, /* Algeria */ + CTRY_AMERICAN_SAMOA = 16, + CTRY_ANDORRA = 20, + CTRY_ANGOLA = 24, + CTRY_ANGUILLA = 660, + CTRY_ANTARTICA = 10, + CTRY_ANTIGUA = 28, /* Antigua and Barbuda */ + CTRY_ARGENTINA = 32, /* Argentina */ + CTRY_ARMENIA = 51, /* Armenia */ + CTRY_ARUBA = 533, /* Aruba */ + CTRY_AUSTRALIA = 36, /* Australia */ + CTRY_AUSTRIA = 40, /* Austria */ + CTRY_AZERBAIJAN = 31, /* Azerbaijan */ + CTRY_BAHAMAS = 44, /* Bahamas */ + CTRY_BAHRAIN = 48, /* Bahrain */ + CTRY_BANGLADESH = 50, /* Bangladesh */ + CTRY_BARBADOS = 52, + CTRY_BELARUS = 112, /* Belarus */ + CTRY_BELGIUM = 56, /* Belgium */ + CTRY_BELIZE = 84, + CTRY_BENIN = 204, + CTRY_BERMUDA = 60, + CTRY_BHUTAN = 64, + CTRY_BOLIVIA = 68, /* Bolivia */ + CTRY_BOSNIA_AND_HERZEGOWINA = 70, + CTRY_BOTSWANA = 72, + CTRY_BOUVET_ISLAND = 74, + CTRY_BRAZIL = 76, /* Brazil */ + CTRY_BRITISH_INDIAN_OCEAN_TERRITORY = 86, + CTRY_BRUNEI_DARUSSALAM = 96, /* Brunei Darussalam */ + CTRY_BULGARIA = 100, /* Bulgaria */ + CTRY_BURKINA_FASO = 854, + CTRY_BURUNDI = 108, + CTRY_CAMBODIA = 116, + CTRY_CAMEROON = 120, + CTRY_CANADA = 124, /* Canada */ + CTRY_CAPE_VERDE = 132, + CTRY_CAYMAN_ISLANDS = 136, + CTRY_CENTRAL_AFRICAN_REPUBLIC = 140, + CTRY_CHAD = 148, + CTRY_CHILE = 152, /* Chile */ + CTRY_CHINA = 156, /* People's Republic of China */ + CTRY_CHRISTMAS_ISLAND = 162, + CTRY_COCOS_ISLANDS = 166, + CTRY_COLOMBIA = 170, /* Colombia */ + CTRY_COMOROS = 174, + CTRY_CONGO = 178, + CTRY_COOK_ISLANDS = 184, + CTRY_COSTA_RICA = 188, /* Costa Rica */ + CTRY_COTE_DIVOIRE = 384, + CTRY_CROATIA = 191, /* Croatia (local name: Hrvatska) */ + CTRY_CYPRUS = 196, /* Cyprus */ + CTRY_CZECH = 203, /* Czech Republic */ + CTRY_DENMARK = 208, /* Denmark */ + CTRY_DJIBOUTI = 262, + CTRY_DOMINICA = 212, + CTRY_DOMINICAN_REPUBLIC = 214, /* Dominican Republic */ + CTRY_EAST_TIMOR = 626, + CTRY_ECUADOR = 218, /* Ecuador */ + CTRY_EGYPT = 818, /* Egypt */ + CTRY_EL_SALVADOR = 222, /* El Salvador */ + CTRY_EQUATORIAL_GUINEA = 226, + CTRY_ERITREA = 232, + CTRY_ESTONIA = 233, /* Estonia */ + CTRY_ETHIOPIA = 210, + CTRY_FALKLAND_ISLANDS = 238, /* (Malvinas) */ + CTRY_FAEROE_ISLANDS = 234, /* Faeroe Islands */ + CTRY_FIJI = 242, + CTRY_FINLAND = 246, /* Finland */ + CTRY_FRANCE = 250, /* France */ + CTRY_FRANCE2 = 255, /* France (Metropolitan) */ + CTRY_FRENCH_GUIANA = 254, + CTRY_FRENCH_POLYNESIA = 258, + CTRY_FRENCH_SOUTHERN_TERRITORIES = 260, + CTRY_GABON = 266, + CTRY_GAMBIA = 270, + CTRY_GEORGIA = 268, /* Georgia */ + CTRY_GERMANY = 276, /* Germany */ + CTRY_GHANA = 288, + CTRY_GIBRALTAR = 292, + CTRY_GREECE = 300, /* Greece */ + CTRY_GREENLAND = 304, + CTRY_GRENADA = 308, + CTRY_GUADELOUPE = 312, + CTRY_GUAM = 316, + CTRY_GUATEMALA = 320, /* Guatemala */ + CTRY_GUINEA = 324, + CTRY_GUINEA_BISSAU = 624, + CTRY_GUYANA = 328, + /* XXX correct remainder */ + CTRY_HAITI = 332, + CTRY_HONDURAS = 340, /* Honduras */ + CTRY_HONG_KONG = 344, /* Hong Kong S.A.R., P.R.C. */ + CTRY_HUNGARY = 348, /* Hungary */ + CTRY_ICELAND = 352, /* Iceland */ + CTRY_INDIA = 356, /* India */ + CTRY_INDONESIA = 360, /* Indonesia */ + CTRY_IRAN = 364, /* Iran */ + CTRY_IRAQ = 368, /* Iraq */ + CTRY_IRELAND = 372, /* Ireland */ + CTRY_ISRAEL = 376, /* Israel */ + CTRY_ITALY = 380, /* Italy */ + CTRY_JAMAICA = 388, /* Jamaica */ + CTRY_JAPAN = 392, /* Japan */ + CTRY_JORDAN = 400, /* Jordan */ + CTRY_KAZAKHSTAN = 398, /* Kazakhstan */ + CTRY_KENYA = 404, /* Kenya */ + CTRY_KOREA_NORTH = 408, /* North Korea */ + CTRY_KOREA_ROC = 410, /* South Korea */ + CTRY_KOREA_ROC2 = 411, /* South Korea */ + CTRY_KUWAIT = 414, /* Kuwait */ + CTRY_LATVIA = 428, /* Latvia */ + CTRY_LEBANON = 422, /* Lebanon */ + CTRY_LIBYA = 434, /* Libya */ + CTRY_LIECHTENSTEIN = 438, /* Liechtenstein */ + CTRY_LITHUANIA = 440, /* Lithuania */ + CTRY_LUXEMBOURG = 442, /* Luxembourg */ + CTRY_MACAU = 446, /* Macau */ + CTRY_MACEDONIA = 807, /* the Former Yugoslav Republic of Macedonia */ + CTRY_MALAYSIA = 458, /* Malaysia */ + CTRY_MALTA = 470, /* Malta */ + CTRY_MEXICO = 484, /* Mexico */ + CTRY_MONACO = 492, /* Principality of Monaco */ + CTRY_MOROCCO = 504, /* Morocco */ + CTRY_NEPAL = 524, /* Nepal */ + CTRY_NETHERLANDS = 528, /* Netherlands */ + CTRY_NEW_ZEALAND = 554, /* New Zealand */ + CTRY_NICARAGUA = 558, /* Nicaragua */ + CTRY_NORWAY = 578, /* Norway */ + CTRY_OMAN = 512, /* Oman */ + CTRY_PAKISTAN = 586, /* Islamic Republic of Pakistan */ + CTRY_PANAMA = 591, /* Panama */ + CTRY_PARAGUAY = 600, /* Paraguay */ + CTRY_PERU = 604, /* Peru */ + CTRY_PHILIPPINES = 608, /* Republic of the Philippines */ + CTRY_POLAND = 616, /* Poland */ + CTRY_PORTUGAL = 620, /* Portugal */ + CTRY_PUERTO_RICO = 630, /* Puerto Rico */ + CTRY_QATAR = 634, /* Qatar */ + CTRY_ROMANIA = 642, /* Romania */ + CTRY_RUSSIA = 643, /* Russia */ + CTRY_SAUDI_ARABIA = 682, /* Saudi Arabia */ + CTRY_SINGAPORE = 702, /* Singapore */ + CTRY_SLOVAKIA = 703, /* Slovak Republic */ + CTRY_SLOVENIA = 705, /* Slovenia */ + CTRY_SOUTH_AFRICA = 710, /* South Africa */ + CTRY_SPAIN = 724, /* Spain */ + CTRY_SRILANKA = 144, /* Sri Lanka */ + CTRY_SWEDEN = 752, /* Sweden */ + CTRY_SWITZERLAND = 756, /* Switzerland */ + CTRY_SYRIA = 760, /* Syria */ + CTRY_TAIWAN = 158, /* Taiwan */ + CTRY_THAILAND = 764, /* Thailand */ + CTRY_TRINIDAD_Y_TOBAGO = 780, /* Trinidad y Tobago */ + CTRY_TUNISIA = 788, /* Tunisia */ + CTRY_TURKEY = 792, /* Turkey */ + CTRY_UAE = 784, /* U.A.E. */ + CTRY_UKRAINE = 804, /* Ukraine */ + CTRY_UNITED_KINGDOM = 826, /* United Kingdom */ + CTRY_UNITED_STATES = 840, /* United States */ + CTRY_URUGUAY = 858, /* Uruguay */ + CTRY_UZBEKISTAN = 860, /* Uzbekistan */ + CTRY_VENEZUELA = 862, /* Venezuela */ + CTRY_VIET_NAM = 704, /* Viet Nam */ + CTRY_YEMEN = 887, /* Yemen */ + CTRY_ZIMBABWE = 716, /* Zimbabwe */ + + /* NB: from here down not listed in 3166; they come from Atheros */ + CTRY_DEBUG = 0x1ff, /* debug */ + CTRY_DEFAULT = 0, /* default */ + + CTRY_UNITED_STATES_FCC49 = 842, /* United States (Public Safety)*/ + CTRY_KOREA_ROC3 = 412, /* South Korea */ + + CTRY_JAPAN1 = 393, /* Japan (JP1) */ + CTRY_JAPAN2 = 394, /* Japan (JP0) */ + CTRY_JAPAN3 = 395, /* Japan (JP1-1) */ + CTRY_JAPAN4 = 396, /* Japan (JE1) */ + CTRY_JAPAN5 = 397, /* Japan (JE2) */ + CTRY_JAPAN6 = 399, /* Japan (JP6) */ + CTRY_JAPAN7 = 4007, /* Japan (J7) */ + CTRY_JAPAN8 = 4008, /* Japan (J8) */ + CTRY_JAPAN9 = 4009, /* Japan (J9) */ + CTRY_JAPAN10 = 4010, /* Japan (J10) */ + CTRY_JAPAN11 = 4011, /* Japan (J11) */ + CTRY_JAPAN12 = 4012, /* Japan (J12) */ + CTRY_JAPAN13 = 4013, /* Japan (J13) */ + CTRY_JAPAN14 = 4014, /* Japan (J14) */ + CTRY_JAPAN15 = 4015, /* Japan (J15) */ + CTRY_JAPAN16 = 4016, /* Japan (J16) */ + CTRY_JAPAN17 = 4017, /* Japan (J17) */ + CTRY_JAPAN18 = 4018, /* Japan (J18) */ + CTRY_JAPAN19 = 4019, /* Japan (J19) */ + CTRY_JAPAN20 = 4020, /* Japan (J20) */ + CTRY_JAPAN21 = 4021, /* Japan (J21) */ + CTRY_JAPAN22 = 4022, /* Japan (J22) */ + CTRY_JAPAN23 = 4023, /* Japan (J23) */ + CTRY_JAPAN24 = 4024, /* Japan (J24) */ +}; + +enum RegdomainCode { + SKU_FCC = 0x10, /* FCC, aka United States */ + SKU_CA = 0x20, /* North America, aka Canada */ + SKU_ETSI = 0x30, /* Europe */ + SKU_ETSI2 = 0x32, /* Europe w/o HT40 in 5GHz */ + SKU_ETSI3 = 0x33, /* Europe - channel 36 */ + SKU_FCC3 = 0x3a, /* FCC w/5470 band, 11h, DFS */ + SKU_JAPAN = 0x40, + SKU_KOREA = 0x45, + SKU_APAC = 0x50, /* Asia Pacific */ + SKU_APAC2 = 0x51, /* Asia Pacific w/ DFS on mid-band */ + SKU_APAC3 = 0x5d, /* Asia Pacific w/o ISM band */ + SKU_ROW = 0x81, /* China/Taiwan/Rest of World */ + SKU_NONE = 0xf0, /* "Region Free" */ + SKU_DEBUG = 0x1ff, + + /* NB: from here down private */ + SKU_SR9 = 0x0298, /* Ubiquiti SR9 (900MHz/GSM) */ + SKU_XR9 = 0x0299, /* Ubiquiti XR9 (900MHz/GSM) */ + SKU_GZ901 = 0x029a, /* Zcomax GZ-901 (900MHz/GSM) */ +}; + +#if defined(__KERNEL__) || defined(_KERNEL) +struct ieee80211com; +void ieee80211_regdomain_attach(struct ieee80211com *); +void ieee80211_regdomain_detach(struct ieee80211com *); +struct ieee80211vap; +void ieee80211_regdomain_vattach(struct ieee80211vap *); +void ieee80211_regdomain_vdetach(struct ieee80211vap *); + +struct ieee80211_regdomain; +int ieee80211_init_channels(struct ieee80211com *, + const struct ieee80211_regdomain *, const uint8_t bands[]); +struct ieee80211_channel; +void ieee80211_sort_channels(struct ieee80211_channel *chans, int nchans); +struct ieee80211_appie; +struct ieee80211_appie *ieee80211_alloc_countryie(struct ieee80211com *); +struct ieee80211_regdomain_req; +int ieee80211_setregdomain(struct ieee80211vap *, + struct ieee80211_regdomain_req *); +#endif /* defined(__KERNEL__) || defined(_KERNEL) */ +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_REGDOMAIN_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_rssadapt.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_rssadapt.h new file mode 100644 index 0000000000..a88e9b2ce5 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_rssadapt.h @@ -0,0 +1,101 @@ +/* $FreeBSD$ */ +/* $NetBSD: ieee80211_rssadapt.h,v 1.4 2005/02/26 22:45:09 perry Exp $ */ +/*- + * Copyright (c) 2003, 2004 David Young. 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 David Young may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY David Young ``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 David + * Young 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. + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_RSSADAPT_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_RSSADAPT_H_ + +/* Data-rate adaptation loosely based on "Link Adaptation Strategy + * for IEEE 802.11 WLAN via Received Signal Strength Measurement" + * by Javier del Prado Pavon and Sunghyun Choi. + */ + +/* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */ +#define IEEE80211_RSSADAPT_BKTS 3 +#define IEEE80211_RSSADAPT_BKT0 128 +#define IEEE80211_RSSADAPT_BKTPOWER 3 /* 2**_BKTPOWER */ + +struct ieee80211_rssadapt { + struct ieee80211vap *vap; + int interval; /* update interval (ticks) */ +}; + +struct ieee80211_rssadapt_node { + struct ieee80211_rssadapt *ra_rs; /* backpointer */ + struct ieee80211_rateset ra_rates; /* negotiated rates */ + int ra_rix; /* current rate index */ + int ra_ticks; /* time of last update */ + int ra_last_raise; /* time of last rate raise */ + int ra_raise_interval; /* rate raise time threshold */ + + /* Tx failures in this update interval */ + uint32_t ra_nfail; + /* Tx successes in this update interval */ + uint32_t ra_nok; + /* exponential average packets/second */ + uint32_t ra_pktrate; + /* RSSI threshold for each Tx rate */ + uint16_t ra_rate_thresh[IEEE80211_RSSADAPT_BKTS] + [IEEE80211_RATE_SIZE]; +}; + +void ieee80211_rssadapt_init(struct ieee80211_rssadapt *, + struct ieee80211vap *, int); +void ieee80211_rssadapt_cleanup(struct ieee80211_rssadapt *); +void ieee80211_rssadapt_setinterval(struct ieee80211_rssadapt *, int); +void ieee80211_rssadapt_node_init(struct ieee80211_rssadapt *, + struct ieee80211_rssadapt_node *, struct ieee80211_node *); +int ieee80211_rssadapt_choose(struct ieee80211_node *, + struct ieee80211_rssadapt_node *, u_int); + +/* NB: these are public only for the inline below */ +void ieee80211_rssadapt_raise_rate(struct ieee80211_rssadapt_node *, + int pktlen, int rssi); +void ieee80211_rssadapt_lower_rate(struct ieee80211_rssadapt_node *, + int pktlen, int rssi); + +#define IEEE80211_RSSADAPT_SUCCESS 1 +#define IEEE80211_RSSADAPT_FAILURE 0 + +static __inline void +ieee80211_rssadapt_tx_complete(struct ieee80211_rssadapt_node *ra, + int success, int pktlen, int rssi) +{ + if (success) { + ra->ra_nok++; + if ((ra->ra_rix + 1) < ra->ra_rates.rs_nrates && + (ticks - ra->ra_last_raise) >= ra->ra_raise_interval) + ieee80211_rssadapt_raise_rate(ra, pktlen, rssi); + } else { + ra->ra_nfail++; + ieee80211_rssadapt_lower_rate(ra, pktlen, rssi); + } +} +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_RSSADAPT_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_scan.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_scan.h new file mode 100644 index 0000000000..9b5ecf7ad4 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_scan.h @@ -0,0 +1,301 @@ +/*- + * Copyright (c) 2005-2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_SCAN_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_SCAN_H_ + +/* + * 802.11 scanning support. + * + * Scanning is the procedure by which a station locates a bss to join + * (infrastructure/ibss mode), or a channel to use (when operating as + * an ap or ibss master). Scans are either "active" or "passive". An + * active scan causes one or more probe request frames to be sent on + * visiting each channel. A passive request causes each channel in the + * scan set to be visited but no frames to be transmitted; the station + * only listens for traffic. Note that active scanning may still need + * to listen for traffic before sending probe request frames depending + * on regulatory constraints; the 802.11 layer handles this by generating + * a callback when scanning on a ``passive channel'' when the + * IEEE80211_FEXT_PROBECHAN flag is set. + * + * A scan operation involves constructing a set of channels to inspect + * (the scan set), visiting each channel and collecting information + * (e.g. what bss are present), and then analyzing the results to make + * decisions like which bss to join. This process needs to be as fast + * as possible so we do things like intelligently construct scan sets + * and dwell on a channel only as long as necessary. The scan code also + * maintains a cache of recent scan results and uses it to bypass scanning + * whenever possible. The scan cache is also used to enable roaming + * between access points when operating in infrastructure mode. + * + * Scanning is handled with pluggable modules that implement "policy" + * per-operating mode. The core scanning support provides an + * instrastructure to support these modules and exports a common api + * to the rest of the 802.11 layer. Policy modules decide what + * channels to visit, what state to record to make decisions (e.g. ap + * mode scanning for auto channel selection keeps significantly less + * state than sta mode scanning for an ap to associate to), and selects + * the final station/channel to return as the result of a scan. + * + * Scanning is done synchronously when initially bringing a vap to an + * operational state and optionally in the background to maintain the + * scan cache for doing roaming and rogue ap monitoring. Scanning is + * not tied to the 802.11 state machine that governs vaps though there + * is linkage to the IEEE80211_SCAN state. Only one vap at a time may + * be scanning; this scheduling policy is handled in ieee80211_new_state + * and is invisible to the scanning code. +*/ +#define IEEE80211_SCAN_MAX IEEE80211_CHAN_MAX + +struct ieee80211_scanner; /* scan policy state */ + +struct ieee80211_scan_ssid { + int len; /* length in bytes */ + uint8_t ssid[IEEE80211_NWID_LEN]; /* ssid contents */ +}; +#define IEEE80211_SCAN_MAX_SSID 1 /* max # ssid's to probe */ + +/* + * Scan state visible to the 802.11 layer. Scan parameters and + * results are stored in this data structure. The ieee80211_scan_state + * structure is extended with space that is maintained private to + * the core scanning support. We allocate one instance and link it + * to the ieee80211com structure; then share it between all associated + * vaps. We could allocate multiple of these, e.g. to hold multiple + * scan results, but this is sufficient for current needs. + */ +struct ieee80211_scan_state { + struct ieee80211vap *ss_vap; + struct ieee80211com *ss_ic; + const struct ieee80211_scanner *ss_ops; /* policy hookup, see below */ + void *ss_priv; /* scanner private state */ + uint16_t ss_flags; +#define IEEE80211_SCAN_NOPICK 0x0001 /* scan only, no selection */ +#define IEEE80211_SCAN_ACTIVE 0x0002 /* active scan (probe req) */ +#define IEEE80211_SCAN_PICK1ST 0x0004 /* ``hey sailor'' mode */ +#define IEEE80211_SCAN_BGSCAN 0x0008 /* bg scan, exit ps at end */ +#define IEEE80211_SCAN_ONCE 0x0010 /* do one complete pass */ +#define IEEE80211_SCAN_NOBCAST 0x0020 /* no broadcast probe req */ +#define IEEE80211_SCAN_NOJOIN 0x0040 /* no auto-sequencing */ +#define IEEE80211_SCAN_GOTPICK 0x1000 /* got candidate, can stop */ + uint8_t ss_nssid; /* # ssid's to probe/match */ + struct ieee80211_scan_ssid ss_ssid[IEEE80211_SCAN_MAX_SSID]; + /* ssid's to probe/match */ + /* ordered channel set */ + struct ieee80211_channel *ss_chans[IEEE80211_SCAN_MAX]; + uint16_t ss_next; /* ix of next chan to scan */ + uint16_t ss_last; /* ix+1 of last chan to scan */ + unsigned long ss_mindwell; /* min dwell on channel */ + unsigned long ss_maxdwell; /* max dwell on channel */ +}; + +/* + * The upper 16 bits of the flags word is used to communicate + * information to the scanning code that is NOT recorded in + * ss_flags. It might be better to split this stuff out into + * a separate variable to avoid confusion. + */ +#define IEEE80211_SCAN_FLUSH 0x00010000 /* flush candidate table */ +#define IEEE80211_SCAN_NOSSID 0x80000000 /* don't update ssid list */ + +struct ieee80211com; +void ieee80211_scan_sta_init(void); +void ieee80211_scan_attach(struct ieee80211com *); +void ieee80211_scan_detach(struct ieee80211com *); +void ieee80211_scan_vattach(struct ieee80211vap *); +void ieee80211_scan_vdetach(struct ieee80211vap *); + +void ieee80211_scan_dump_channels(const struct ieee80211_scan_state *); + +#define IEEE80211_SCAN_FOREVER 0x7fffffff +int ieee80211_start_scan(struct ieee80211vap *, int flags, + u_int duration, u_int mindwell, u_int maxdwell, + u_int nssid, const struct ieee80211_scan_ssid ssids[]); +int ieee80211_check_scan(struct ieee80211vap *, int flags, + u_int duration, u_int mindwell, u_int maxdwell, + u_int nssid, const struct ieee80211_scan_ssid ssids[]); +int ieee80211_check_scan_current(struct ieee80211vap *); +int ieee80211_bg_scan(struct ieee80211vap *, int); +void ieee80211_cancel_scan(struct ieee80211vap *); +void ieee80211_cancel_anyscan(struct ieee80211vap *); +void ieee80211_scan_next(struct ieee80211vap *); +void ieee80211_scan_done(struct ieee80211vap *); +void ieee80211_probe_curchan(struct ieee80211vap *, int); +struct ieee80211_channel *ieee80211_scan_pickchannel(struct ieee80211com *, int); + +struct ieee80211_scanparams; +void ieee80211_add_scan(struct ieee80211vap *, + const struct ieee80211_scanparams *, + const struct ieee80211_frame *, + int subtype, int rssi, int noise); +void ieee80211_scan_timeout(struct ieee80211com *); + +void ieee80211_scan_assoc_success(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN]); +enum { + IEEE80211_SCAN_FAIL_TIMEOUT = 1, /* no response to mgmt frame */ + IEEE80211_SCAN_FAIL_STATUS = 2 /* negative response to " " */ +}; +void ieee80211_scan_assoc_fail(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN], int reason); +void ieee80211_scan_flush(struct ieee80211vap *); + +struct ieee80211_scan_entry; +typedef void ieee80211_scan_iter_func(void *, + const struct ieee80211_scan_entry *); +void ieee80211_scan_iterate(struct ieee80211vap *, + ieee80211_scan_iter_func, void *); +enum { + IEEE80211_BPARSE_BADIELEN = 0x01, /* ie len past end of frame */ + IEEE80211_BPARSE_RATES_INVALID = 0x02, /* invalid RATES ie */ + IEEE80211_BPARSE_XRATES_INVALID = 0x04, /* invalid XRATES ie */ + IEEE80211_BPARSE_SSID_INVALID = 0x08, /* invalid SSID ie */ + IEEE80211_BPARSE_CHAN_INVALID = 0x10, /* invalid FH/DSPARMS chan */ + IEEE80211_BPARSE_OFFCHAN = 0x20, /* DSPARMS chan != curchan */ + IEEE80211_BPARSE_BINTVAL_INVALID= 0x40, /* invalid beacon interval */ + IEEE80211_BPARSE_CSA_INVALID = 0x80, /* invalid CSA ie */ +}; + +/* + * Parameters supplied when adding/updating an entry in a + * scan cache. Pointer variables should be set to NULL + * if no data is available. Pointer references can be to + * local data; any information that is saved will be copied. + * All multi-byte values must be in host byte order. + */ +struct ieee80211_scanparams { + uint8_t status; /* bitmask of IEEE80211_BPARSE_* */ + uint8_t chan; /* channel # from FH/DSPARMS */ + uint8_t bchan; /* curchan's channel # */ + uint8_t fhindex; + uint16_t fhdwell; /* FHSS dwell interval */ + uint16_t capinfo; /* 802.11 capabilities */ + uint16_t erp; /* NB: 0x100 indicates ie present */ + uint16_t bintval; + uint8_t timoff; + uint8_t *ies; /* all captured ies */ + size_t ies_len; /* length of all captured ies */ + uint8_t *tim; + uint8_t *tstamp; + uint8_t *country; + uint8_t *ssid; + uint8_t *rates; + uint8_t *xrates; + uint8_t *doth; + uint8_t *wpa; + uint8_t *rsn; + uint8_t *wme; + uint8_t *htcap; + uint8_t *htinfo; + uint8_t *ath; + uint8_t *tdma; + uint8_t *csa; + uint8_t *meshid; + uint8_t *meshconf; + uint8_t *spare[3]; +}; + +/* + * Scan cache entry format used when exporting data from a policy + * module; this data may be represented some other way internally. + */ +struct ieee80211_scan_entry { + uint8_t se_macaddr[IEEE80211_ADDR_LEN]; + uint8_t se_bssid[IEEE80211_ADDR_LEN]; + /* XXX can point inside se_ies */ + uint8_t se_ssid[2+IEEE80211_NWID_LEN]; + uint8_t se_rates[2+IEEE80211_RATE_MAXSIZE]; + uint8_t se_xrates[2+IEEE80211_RATE_MAXSIZE]; + union { + uint8_t data[8]; + u_int64_t tsf; + } se_tstamp; /* from last rcv'd beacon */ + uint16_t se_intval; /* beacon interval (host byte order) */ + uint16_t se_capinfo; /* capabilities (host byte order) */ + struct ieee80211_channel *se_chan;/* channel where sta found */ + uint16_t se_timoff; /* byte offset to TIM ie */ + uint16_t se_fhdwell; /* FH only (host byte order) */ + uint8_t se_fhindex; /* FH only */ + uint8_t se_dtimperiod; /* DTIM period */ + uint16_t se_erp; /* ERP from beacon/probe resp */ + int8_t se_rssi; /* avg'd recv ssi */ + int8_t se_noise; /* noise floor */ + uint8_t se_cc[2]; /* captured country code */ + uint8_t se_meshid[2+IEEE80211_MESHID_LEN]; + struct ieee80211_ies se_ies; /* captured ie's */ + u_int se_age; /* age of entry (0 on create) */ +}; + +/* + * Template for an in-kernel scan policy module. + * Modules register with the scanning code and are + * typically loaded as needed. + */ +struct ieee80211_scanner { + const char *scan_name; /* printable name */ + int (*scan_attach)(struct ieee80211_scan_state *); + int (*scan_detach)(struct ieee80211_scan_state *); + int (*scan_start)(struct ieee80211_scan_state *, + struct ieee80211vap *); + int (*scan_restart)(struct ieee80211_scan_state *, + struct ieee80211vap *); + int (*scan_cancel)(struct ieee80211_scan_state *, + struct ieee80211vap *); + int (*scan_end)(struct ieee80211_scan_state *, + struct ieee80211vap *); + int (*scan_flush)(struct ieee80211_scan_state *); + struct ieee80211_channel *(*scan_pickchan)( + struct ieee80211_scan_state *, int); + /* add an entry to the cache */ + int (*scan_add)(struct ieee80211_scan_state *, + const struct ieee80211_scanparams *, + const struct ieee80211_frame *, + int subtype, int rssi, int noise); + /* age and/or purge entries in the cache */ + void (*scan_age)(struct ieee80211_scan_state *); + /* note that association failed for an entry */ + void (*scan_assoc_fail)(struct ieee80211_scan_state *, + const uint8_t macaddr[IEEE80211_ADDR_LEN], + int reason); + /* note that association succeed for an entry */ + void (*scan_assoc_success)(struct ieee80211_scan_state *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); + /* iterate over entries in the scan cache */ + void (*scan_iterate)(struct ieee80211_scan_state *, + ieee80211_scan_iter_func *, void *); + void (*scan_spare0)(void); + void (*scan_spare1)(void); + void (*scan_spare2)(void); + void (*scan_spare4)(void); +}; +void ieee80211_scanner_register(enum ieee80211_opmode, + const struct ieee80211_scanner *); +void ieee80211_scanner_unregister(enum ieee80211_opmode, + const struct ieee80211_scanner *); +void ieee80211_scanner_unregister_all(const struct ieee80211_scanner *); +const struct ieee80211_scanner *ieee80211_scanner_get(enum ieee80211_opmode); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_SCAN_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_sta.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_sta.h new file mode 100644 index 0000000000..d701600ad9 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_sta.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_STA_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_STA_H_ + +/* + * Station-mode implementation definitions. + */ +void ieee80211_sta_attach(struct ieee80211com *); +void ieee80211_sta_detach(struct ieee80211com *); +void ieee80211_sta_vattach(struct ieee80211vap *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_STA_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_superg.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_superg.h new file mode 100644 index 0000000000..7872da80ee --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_superg.h @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 2009 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_SUPERG_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_SUPERG_H_ + +/* + * Atheros' 802.11 SuperG protocol support. + */ + +/* + * Atheros advanced capability information element. + */ +struct ieee80211_ath_ie { + uint8_t ath_id; /* IEEE80211_ELEMID_VENDOR */ + uint8_t ath_len; /* length in bytes */ + uint8_t ath_oui[3]; /* ATH_OUI */ + uint8_t ath_oui_type; /* ATH_OUI_TYPE */ + uint8_t ath_oui_subtype; /* ATH_OUI_SUBTYPE */ + uint8_t ath_version; /* spec revision */ + uint8_t ath_capability; /* capability info */ +#define ATHEROS_CAP_TURBO_PRIME 0x01 /* dynamic turbo--aka Turbo' */ +#define ATHEROS_CAP_COMPRESSION 0x02 /* data compression */ +#define ATHEROS_CAP_FAST_FRAME 0x04 /* fast (jumbo) frames */ +#define ATHEROS_CAP_XR 0x08 /* Xtended Range support */ +#define ATHEROS_CAP_AR 0x10 /* Advanded Radar support */ +#define ATHEROS_CAP_BURST 0x20 /* Bursting - not negotiated */ +#define ATHEROS_CAP_WME 0x40 /* CWMin tuning */ +#define ATHEROS_CAP_BOOST 0x80 /* use turbo/!turbo mode */ + uint8_t ath_defkeyix[2]; +} __packed; + +#define ATH_OUI_VERSION 0x00 +#define ATH_OUI_SUBTYPE 0x01 + +#ifdef _KERNEL +struct ieee80211_stageq { + struct mbuf *head; /* frames linked w/ m_nextpkt */ + struct mbuf *tail; /* last frame in queue */ + int depth; /* # items on head */ +}; + +struct ieee80211_superg { + /* fast-frames staging q */ + struct ieee80211_stageq ff_stageq[WME_NUM_AC]; + int ff_stageqdepth; /* cumulative depth */ +}; + +void ieee80211_superg_attach(struct ieee80211com *); +void ieee80211_superg_detach(struct ieee80211com *); +void ieee80211_superg_vattach(struct ieee80211vap *); +void ieee80211_superg_vdetach(struct ieee80211vap *); + +uint8_t *ieee80211_add_ath(uint8_t *, uint8_t, ieee80211_keyix); +uint8_t *ieee80211_add_athcaps(uint8_t *, const struct ieee80211_node *); +void ieee80211_parse_ath(struct ieee80211_node *, uint8_t *); +int ieee80211_parse_athparams(struct ieee80211_node *, uint8_t *, + const struct ieee80211_frame *); + +void ieee80211_ff_node_init(struct ieee80211_node *); +void ieee80211_ff_node_cleanup(struct ieee80211_node *); + +struct mbuf *ieee80211_ff_check(struct ieee80211_node *, struct mbuf *); +void ieee80211_ff_age(struct ieee80211com *, struct ieee80211_stageq *, + int quanta); + +static __inline void +ieee80211_ff_flush(struct ieee80211com *ic, int ac) +{ + struct ieee80211_superg *sg = ic->ic_superg; + + if (sg != NULL && sg->ff_stageq[ac].depth) + ieee80211_ff_age(ic, &sg->ff_stageq[ac], 0x7fffffff); +} + +static __inline void +ieee80211_ff_age_all(struct ieee80211com *ic, int quanta) +{ + struct ieee80211_superg *sg = ic->ic_superg; + + if (sg != NULL && sg->ff_stageqdepth) { + if (sg->ff_stageq[WME_AC_VO].depth) + ieee80211_ff_age(ic, &sg->ff_stageq[WME_AC_VO], quanta); + if (sg->ff_stageq[WME_AC_VI].depth) + ieee80211_ff_age(ic, &sg->ff_stageq[WME_AC_VI], quanta); + if (sg->ff_stageq[WME_AC_BE].depth) + ieee80211_ff_age(ic, &sg->ff_stageq[WME_AC_BE], quanta); + if (sg->ff_stageq[WME_AC_BK].depth) + ieee80211_ff_age(ic, &sg->ff_stageq[WME_AC_BK], quanta); + } +} + +struct mbuf *ieee80211_ff_encap(struct ieee80211vap *, struct mbuf *, + int, struct ieee80211_key *); + +struct mbuf *ieee80211_ff_decap(struct ieee80211_node *, struct mbuf *); + +static __inline struct mbuf * +ieee80211_decap_fastframe(struct ieee80211vap *vap, struct ieee80211_node *ni, + struct mbuf *m) +{ + return IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF) ? + ieee80211_ff_decap(ni, m) : m; +} +#endif /* _KERNEL */ +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_SUPERG_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_tdma.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_tdma.h new file mode 100644 index 0000000000..35acf0349f --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_tdma.h @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting + * Copyright (c) 2007-2009 Intel 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_TDMA_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_TDMA_H_ + +/* + * TDMA-mode implementation definitions. + */ + +#define TDMA_SUBTYPE_PARAM 0x01 +#define TDMA_VERSION_V2 2 +#define TDMA_VERSION TDMA_VERSION_V2 + +/* NB: we only support 2 right now but protocol handles up to 8 */ +#define TDMA_MAXSLOTS 2 /* max slots/sta's */ + +#define TDMA_PARAM_LEN_V2 sizeof(struct ieee80211_tdma_param) + +/* + * TDMA information element. + */ +struct ieee80211_tdma_param { + u_int8_t tdma_id; /* IEEE80211_ELEMID_VENDOR */ + u_int8_t tdma_len; + u_int8_t tdma_oui[3]; /* TDMA_OUI */ + u_int8_t tdma_type; /* TDMA_OUI_TYPE */ + u_int8_t tdma_subtype; /* TDMA_SUBTYPE_PARAM */ + u_int8_t tdma_version; /* spec revision */ + u_int8_t tdma_slot; /* station slot # [0..7] */ + u_int8_t tdma_slotcnt; /* bss slot count [1..8] */ + u_int16_t tdma_slotlen; /* bss slot len (100us) */ + u_int8_t tdma_bintval; /* beacon interval (superframes) */ + u_int8_t tdma_inuse[1]; /* slot occupancy map */ + u_int8_t tdma_pad[2]; + u_int8_t tdma_tstamp[8]; /* timestamp from last beacon */ +} __packed; + +#ifdef _KERNEL +/* + * Implementation state. + */ +struct ieee80211_tdma_state { + u_int tdma_slotlen; /* bss slot length (us) */ + uint8_t tdma_version; /* protocol version to use */ + uint8_t tdma_slotcnt; /* bss slot count */ + uint8_t tdma_bintval; /* beacon interval (slots) */ + uint8_t tdma_slot; /* station slot # */ + uint8_t tdma_inuse[1]; /* mask of slots in use */ + uint8_t tdma_active[1]; /* mask of active slots */ + int tdma_count; /* active/inuse countdown */ + void *tdma_peer; /* peer station cookie */ + struct timeval tdma_lastprint; /* time of last rate-limited printf */ + int tdma_fails; /* fail count for rate-limiting */ + + /* parent method pointers */ + int (*tdma_newstate)(struct ieee80211vap *, enum ieee80211_state, + int arg); + void (*tdma_recv_mgmt)(struct ieee80211_node *, + struct mbuf *, int, int, int); + void (*tdma_opdetach)(struct ieee80211vap *); +}; + +#define TDMA_UPDATE_SLOT 0x0001 /* tdma_slot changed */ +#define TDMA_UPDATE_SLOTCNT 0x0002 /* tdma_slotcnt changed */ +#define TDMA_UPDATE_SLOTLEN 0x0004 /* tdma_slotlen changed */ +#define TDMA_UPDATE_BINTVAL 0x0008 /* tdma_bintval changed */ + +void ieee80211_tdma_vattach(struct ieee80211vap *); + +int ieee80211_tdma_getslot(struct ieee80211vap *vap); +void ieee80211_parse_tdma(struct ieee80211_node *ni, const uint8_t *ie); +uint8_t *ieee80211_add_tdma(uint8_t *frm, struct ieee80211vap *vap); +struct ieee80211_beacon_offsets; +void ieee80211_tdma_update_beacon(struct ieee80211vap *vap, + struct ieee80211_beacon_offsets *bo); +#endif /* _KERNEL */ +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_TDMA_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_var.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_var.h new file mode 100644 index 0000000000..88a630a07f --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_var.h @@ -0,0 +1,914 @@ +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting + * Copyright (c) 2009 Colin Günther, coling@gmx.de + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_VAR_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_VAR_H_ + +/* + * Definitions for IEEE 802.11 drivers. + */ +/* NB: portability glue must go first */ +#ifdef __NetBSD__ +#include +#elif __FreeBSD__ +#include +#elif __linux__ +#include +#elif __HAIKU__ +#include +#else +#error "No support for your operating system!" +#endif + +#include +#include +#include +#include +#include +#include /* for ieee80211_stats */ +#include +#include +#include +#include +#include +#include + +#define IEEE80211_TXPOWER_MAX 100 /* .5 dbM (XXX units?) */ +#define IEEE80211_TXPOWER_MIN 0 /* kill radio */ + +#define IEEE80211_DTIM_DEFAULT 1 /* default DTIM period */ +#define IEEE80211_BINTVAL_DEFAULT 100 /* default beacon interval (TU's) */ + +#define IEEE80211_BMISS_MAX 2 /* maximum consecutive bmiss allowed */ +#define IEEE80211_HWBMISS_DEFAULT 7 /* h/w bmiss threshold (beacons) */ + +#define IEEE80211_BGSCAN_INTVAL_MIN 15 /* min bg scan intvl (secs) */ +#define IEEE80211_BGSCAN_INTVAL_DEFAULT (5*60) /* default bg scan intvl */ + +#define IEEE80211_BGSCAN_IDLE_MIN 100 /* min idle time (ms) */ +#define IEEE80211_BGSCAN_IDLE_DEFAULT 250 /* default idle time (ms) */ + +#define IEEE80211_SCAN_VALID_MIN 10 /* min scan valid time (secs) */ +#define IEEE80211_SCAN_VALID_DEFAULT 60 /* default scan valid time */ + +#define IEEE80211_PS_SLEEP 0x1 /* STA is in power saving mode */ +#define IEEE80211_PS_MAX_QUEUE 50 /* maximum saved packets */ + +#define IEEE80211_FIXED_RATE_NONE 0xff +#define IEEE80211_TXMAX_DEFAULT 6 /* default ucast max retries */ + +#define IEEE80211_RTS_DEFAULT IEEE80211_RTS_MAX +#define IEEE80211_FRAG_DEFAULT IEEE80211_FRAG_MAX + +#define IEEE80211_MS_TO_TU(x) (((x) * 1000) / 1024) +#define IEEE80211_TU_TO_MS(x) (((x) * 1024) / 1000) +#define IEEE80211_TU_TO_TICKS(x)(((x) * 1024 * hz) / (1000 * 1000)) + +/* + * 802.11 control state is split into a common portion that maps + * 1-1 to a physical device and one or more "Virtual AP's" (VAP) + * that are bound to an ieee80211com instance and share a single + * underlying device. Each VAP has a corresponding OS device + * entity through which traffic flows and that applications use + * for issuing ioctls, etc. + */ + +/* + * Data common to one or more virtual AP's. State shared by + * the underlying device and the net80211 layer is exposed here; + * e.g. device-specific callbacks. + */ +struct ieee80211vap; +typedef void (*ieee80211vap_attach)(struct ieee80211vap *); + +struct ieee80211_appie { + uint16_t ie_len; /* size of ie_data */ + uint8_t ie_data[0]; /* user-specified IE's */ +}; + +struct ieee80211_tdma_param; +struct ieee80211_rate_table; +struct ieee80211_tx_ampdu; +struct ieee80211_rx_ampdu; +struct ieee80211_superg; +struct ieee80211_frame; + +struct ieee80211com { + struct ifnet *ic_ifp; /* associated device */ + ieee80211_com_lock_t ic_comlock; /* state update lock */ + TAILQ_HEAD(, ieee80211vap) ic_vaps; /* list of vap instances */ + int ic_headroom; /* driver tx headroom needs */ + enum ieee80211_phytype ic_phytype; /* XXX wrong for multi-mode */ + enum ieee80211_opmode ic_opmode; /* operation mode */ + struct ifmedia ic_media; /* interface media config */ + struct callout ic_inact; /* inactivity processing */ + struct taskqueue *ic_tq; /* deferred state thread */ + struct task ic_parent_task; /* deferred parent processing */ + struct task ic_promisc_task;/* deferred promisc update */ + struct task ic_mcast_task; /* deferred mcast update */ + struct task ic_chan_task; /* deferred channel change */ + struct task ic_bmiss_task; /* deferred beacon miss hndlr */ + + uint32_t ic_flags; /* state flags */ + uint32_t ic_flags_ext; /* extended state flags */ + uint32_t ic_flags_ht; /* HT state flags */ + uint32_t ic_flags_ven; /* vendor state flags */ + uint32_t ic_caps; /* capabilities */ + uint32_t ic_htcaps; /* HT capabilities */ + uint32_t ic_cryptocaps; /* crypto capabilities */ + uint8_t ic_modecaps[2]; /* set of mode capabilities */ + uint8_t ic_promisc; /* vap's needing promisc mode */ + uint8_t ic_allmulti; /* vap's needing all multicast*/ + uint8_t ic_nrunning; /* vap's marked running */ + uint8_t ic_curmode; /* current mode */ + uint16_t ic_bintval; /* beacon interval */ + uint16_t ic_lintval; /* listen interval */ + uint16_t ic_holdover; /* PM hold over duration */ + uint16_t ic_txpowlimit; /* global tx power limit */ + struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX]; + + /* + * Channel state: + * + * ic_channels is the set of available channels for the device; + * it is setup by the driver + * ic_nchans is the number of valid entries in ic_channels + * ic_chan_avail is a bit vector of these channels used to check + * whether a channel is available w/o searching the channel table. + * ic_chan_active is a (potentially) constrained subset of + * ic_chan_avail that reflects any mode setting or user-specified + * limit on the set of channels to use/scan + * ic_curchan is the current channel the device is set to; it may + * be different from ic_bsschan when we are off-channel scanning + * or otherwise doing background work + * ic_bsschan is the channel selected for operation; it may + * be undefined (IEEE80211_CHAN_ANYC) + * ic_prevchan is a cached ``previous channel'' used to optimize + * lookups when switching back+forth between two channels + * (e.g. for dynamic turbo) + */ + int ic_nchans; /* # entries in ic_channels */ + struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX]; + uint8_t ic_chan_avail[IEEE80211_CHAN_BYTES]; + uint8_t ic_chan_active[IEEE80211_CHAN_BYTES]; + uint8_t ic_chan_scan[IEEE80211_CHAN_BYTES]; + struct ieee80211_channel *ic_curchan; /* current channel */ + const struct ieee80211_rate_table *ic_rt; /* table for ic_curchan */ + struct ieee80211_channel *ic_bsschan; /* bss channel */ + struct ieee80211_channel *ic_prevchan; /* previous channel */ + struct ieee80211_regdomain ic_regdomain;/* regulatory data */ + struct ieee80211_appie *ic_countryie; /* calculated country ie */ + struct ieee80211_channel *ic_countryie_chan; + + /* 802.11h/DFS state */ + struct ieee80211_channel *ic_csa_newchan;/* channel for doing CSA */ + short ic_csa_mode; /* mode for doing CSA */ + short ic_csa_count; /* count for doing CSA */ + struct ieee80211_dfs_state ic_dfs; /* DFS state */ + + struct ieee80211_scan_state *ic_scan; /* scan state */ + long long ic_lastdata; /* time of last data frame */ + long long ic_lastscan; /* time last scan completed */ + + /* NB: this is the union of all vap stations/neighbors */ + int ic_max_keyix; /* max h/w key index */ + struct ieee80211_node_table ic_sta; /* stations/neighbors */ + struct ieee80211_ageq ic_stageq; /* frame staging queue */ + uint32_t ic_hash_key; /* random key for mac hash */ + + /* XXX multi-bss: split out common/vap parts */ + struct ieee80211_wme_state ic_wme; /* WME/WMM state */ + + /* XXX multi-bss: can per-vap be done/make sense? */ + enum ieee80211_protmode ic_protmode; /* 802.11g protection mode */ + uint16_t ic_nonerpsta; /* # non-ERP stations */ + uint16_t ic_longslotsta; /* # long slot time stations */ + uint16_t ic_sta_assoc; /* stations associated */ + uint16_t ic_ht_sta_assoc;/* HT stations associated */ + uint16_t ic_ht40_sta_assoc;/* HT40 stations associated */ + uint8_t ic_curhtprotmode;/* HTINFO bss state */ + enum ieee80211_protmode ic_htprotmode; /* HT protection mode */ + long long ic_lastnonerp; /* last time non-ERP sta noted*/ + long long ic_lastnonht; /* last time non-HT sta noted */ + + /* optional state for Atheros SuperG protocol extensions */ + struct ieee80211_superg *ic_superg; + + /* radiotap handling */ + struct ieee80211_radiotap_header *ic_th;/* tx radiotap headers */ + void *ic_txchan; /* channel state in ic_th */ + struct ieee80211_radiotap_header *ic_rh;/* rx radiotap headers */ + void *ic_rxchan; /* channel state in ic_rh */ + int ic_montaps; /* active monitor mode taps */ + + /* virtual ap create/delete */ + struct ieee80211vap* (*ic_vap_create)(struct ieee80211com *, + const char name[IFNAMSIZ], int unit, + int opmode, int flags, + const uint8_t bssid[IEEE80211_ADDR_LEN], + const uint8_t macaddr[IEEE80211_ADDR_LEN]); + void (*ic_vap_delete)(struct ieee80211vap *); + /* operating mode attachment */ + ieee80211vap_attach ic_vattach[IEEE80211_OPMODE_MAX]; + /* return hardware/radio capabilities */ + void (*ic_getradiocaps)(struct ieee80211com *, + int, int *, struct ieee80211_channel []); + /* check and/or prepare regdomain state change */ + int (*ic_setregdomain)(struct ieee80211com *, + struct ieee80211_regdomain *, + int, struct ieee80211_channel []); + /* send/recv 802.11 management frame */ + int (*ic_send_mgmt)(struct ieee80211_node *, + int, int); + /* send raw 802.11 frame */ + int (*ic_raw_xmit)(struct ieee80211_node *, + struct mbuf *, + const struct ieee80211_bpf_params *); + /* update device state for 802.11 slot time change */ + void (*ic_updateslot)(struct ifnet *); + /* handle multicast state changes */ + void (*ic_update_mcast)(struct ifnet *); + /* handle promiscuous mode changes */ + void (*ic_update_promisc)(struct ifnet *); + /* new station association callback/notification */ + void (*ic_newassoc)(struct ieee80211_node *, int); + /* TDMA update notification */ + void (*ic_tdma_update)(struct ieee80211_node *, + const struct ieee80211_tdma_param *, int); + /* node state management */ + struct ieee80211_node* (*ic_node_alloc)(struct ieee80211vap *, + const uint8_t [IEEE80211_ADDR_LEN]); + void (*ic_node_free)(struct ieee80211_node *); + void (*ic_node_cleanup)(struct ieee80211_node *); + void (*ic_node_age)(struct ieee80211_node *); + void (*ic_node_drain)(struct ieee80211_node *); + int8_t (*ic_node_getrssi)(const struct ieee80211_node*); + void (*ic_node_getsignal)(const struct ieee80211_node*, + int8_t *, int8_t *); + void (*ic_node_getmimoinfo)( + const struct ieee80211_node*, + struct ieee80211_mimo_info *); + /* scanning support */ + void (*ic_scan_start)(struct ieee80211com *); + void (*ic_scan_end)(struct ieee80211com *); + void (*ic_set_channel)(struct ieee80211com *); + void (*ic_scan_curchan)(struct ieee80211_scan_state *, + unsigned long); + void (*ic_scan_mindwell)(struct ieee80211_scan_state *); + + /* + * 802.11n ADDBA support. A simple/generic implementation + * of A-MPDU tx aggregation is provided; the driver may + * override these methods to provide their own support. + * A-MPDU rx re-ordering happens automatically if the + * driver passes out-of-order frames to ieee80211_input + * from an assocated HT station. + */ + int (*ic_recv_action)(struct ieee80211_node *, + const struct ieee80211_frame *, + const uint8_t *frm, const uint8_t *efrm); + int (*ic_send_action)(struct ieee80211_node *, + int category, int action, void *); + /* check if A-MPDU should be enabled this station+ac */ + int (*ic_ampdu_enable)(struct ieee80211_node *, + struct ieee80211_tx_ampdu *); + /* start/stop doing A-MPDU tx aggregation for a station */ + int (*ic_addba_request)(struct ieee80211_node *, + struct ieee80211_tx_ampdu *, + int dialogtoken, int baparamset, + int batimeout); + int (*ic_addba_response)(struct ieee80211_node *, + struct ieee80211_tx_ampdu *, + int status, int baparamset, int batimeout); + void (*ic_addba_stop)(struct ieee80211_node *, + struct ieee80211_tx_ampdu *); + /* BAR response received */ + void (*ic_bar_response)(struct ieee80211_node *, + struct ieee80211_tx_ampdu *, int status); + /* start/stop doing A-MPDU rx processing for a station */ + int (*ic_ampdu_rx_start)(struct ieee80211_node *, + struct ieee80211_rx_ampdu *, int baparamset, + int batimeout, int baseqctl); + void (*ic_ampdu_rx_stop)(struct ieee80211_node *, + struct ieee80211_rx_ampdu *); + uint64_t ic_spare[8]; +}; + +struct ieee80211_aclator; +struct ieee80211_tdma_state; +struct ieee80211_mesh_state; +struct ieee80211_hwmp_state; + +struct ieee80211vap { + struct ifmedia iv_media; /* interface media config */ + struct ifnet *iv_ifp; /* associated device */ + struct bpf_if *iv_rawbpf; /* packet filter structure */ + struct sysctl_ctx_list *iv_sysctl; /* dynamic sysctl context */ + struct sysctl_oid *iv_oid; /* net.wlan.X sysctl oid */ + + TAILQ_ENTRY(ieee80211vap) iv_next; /* list of vap instances */ + struct ieee80211com *iv_ic; /* back ptr to common state */ + uint32_t iv_debug; /* debug msg flags */ + struct ieee80211_stats iv_stats; /* statistics */ + + uint8_t iv_myaddr[IEEE80211_ADDR_LEN]; + uint32_t iv_flags; /* state flags */ + uint32_t iv_flags_ext; /* extended state flags */ + uint32_t iv_flags_ht; /* HT state flags */ + uint32_t iv_flags_ven; /* vendor state flags */ + uint32_t iv_caps; /* capabilities */ + uint32_t iv_htcaps; /* HT capabilities */ + enum ieee80211_opmode iv_opmode; /* operation mode */ + enum ieee80211_state iv_state; /* state machine state */ + enum ieee80211_state iv_nstate; /* pending state */ + int iv_nstate_arg; /* pending state arg */ + struct task iv_nstate_task; /* deferred state processing */ + struct task iv_swbmiss_task;/* deferred iv_bmiss call */ + struct callout iv_mgtsend; /* mgmt frame response timer */ + /* inactivity timer settings */ + int iv_inact_init; /* setting for new station */ + int iv_inact_auth; /* auth but not assoc setting */ + int iv_inact_run; /* authorized setting */ + int iv_inact_probe; /* inactive probe time */ + + int iv_des_nssid; /* # desired ssids */ + struct ieee80211_scan_ssid iv_des_ssid[1];/* desired ssid table */ + uint8_t iv_des_bssid[IEEE80211_ADDR_LEN]; + struct ieee80211_channel *iv_des_chan; /* desired channel */ + uint16_t iv_des_mode; /* desired mode */ + int iv_nicknamelen; /* XXX junk */ + uint8_t iv_nickname[IEEE80211_NWID_LEN]; + u_int iv_bgscanidle; /* bg scan idle threshold */ + u_int iv_bgscanintvl; /* bg scan min interval */ + u_int iv_scanvalid; /* scan cache valid threshold */ + u_int iv_scanreq_duration; + u_int iv_scanreq_mindwell; + u_int iv_scanreq_maxdwell; + uint16_t iv_scanreq_flags;/* held scan request params */ + uint8_t iv_scanreq_nssid; + struct ieee80211_scan_ssid iv_scanreq_ssid[IEEE80211_SCAN_MAX_SSID]; + /* sta-mode roaming state */ + enum ieee80211_roamingmode iv_roaming; /* roaming mode */ + struct ieee80211_roamparam iv_roamparms[IEEE80211_MODE_MAX]; + + uint8_t iv_bmissthreshold; + uint8_t iv_bmiss_count; /* current beacon miss count */ + int iv_bmiss_max; /* max bmiss before scan */ + uint16_t iv_swbmiss_count;/* beacons in last period */ + uint16_t iv_swbmiss_period;/* s/w bmiss period */ + struct callout iv_swbmiss; /* s/w beacon miss timer */ + + int iv_ampdu_rxmax; /* A-MPDU rx limit (bytes) */ + int iv_ampdu_density;/* A-MPDU density */ + int iv_ampdu_limit; /* A-MPDU tx limit (bytes) */ + int iv_amsdu_limit; /* A-MSDU tx limit (bytes) */ + u_int iv_ampdu_mintraffic[WME_NUM_AC]; + + uint32_t *iv_aid_bitmap; /* association id map */ + uint16_t iv_max_aid; + uint16_t iv_sta_assoc; /* stations associated */ + uint16_t iv_ps_sta; /* stations in power save */ + uint16_t iv_ps_pending; /* ps sta's w/ pending frames */ + uint16_t iv_txseq; /* mcast xmit seq# space */ + uint16_t iv_tim_len; /* ic_tim_bitmap size (bytes) */ + uint8_t *iv_tim_bitmap; /* power-save stations w/ data*/ + uint8_t iv_dtim_period; /* DTIM period */ + uint8_t iv_dtim_count; /* DTIM count from last bcn */ + /* set/unset aid pwrsav state */ + int iv_csa_count; /* count for doing CSA */ + + struct ieee80211_node *iv_bss; /* information for this node */ + struct ieee80211_txparam iv_txparms[IEEE80211_MODE_MAX]; + uint16_t iv_rtsthreshold; + uint16_t iv_fragthreshold; + int iv_inact_timer; /* inactivity timer wait */ + /* application-specified IE's to attach to mgt frames */ + struct ieee80211_appie *iv_appie_beacon; + struct ieee80211_appie *iv_appie_probereq; + struct ieee80211_appie *iv_appie_proberesp; + struct ieee80211_appie *iv_appie_assocreq; + struct ieee80211_appie *iv_appie_assocresp; + struct ieee80211_appie *iv_appie_wpa; + uint8_t *iv_wpa_ie; + uint8_t *iv_rsn_ie; + uint16_t iv_max_keyix; /* max h/w key index */ + ieee80211_keyix iv_def_txkey; /* default/group tx key index */ + struct ieee80211_key iv_nw_keys[IEEE80211_WEP_NKID]; + int (*iv_key_alloc)(struct ieee80211vap *, + struct ieee80211_key *, + ieee80211_keyix *, ieee80211_keyix *); + int (*iv_key_delete)(struct ieee80211vap *, + const struct ieee80211_key *); + int (*iv_key_set)(struct ieee80211vap *, + const struct ieee80211_key *, + const uint8_t mac[IEEE80211_ADDR_LEN]); + void (*iv_key_update_begin)(struct ieee80211vap *); + void (*iv_key_update_end)(struct ieee80211vap *); + + const struct ieee80211_authenticator *iv_auth; /* authenticator glue */ + void *iv_ec; /* private auth state */ + + const struct ieee80211_aclator *iv_acl; /* acl glue */ + void *iv_as; /* private aclator state */ + + struct ieee80211_tdma_state *iv_tdma; /* tdma state */ + struct ieee80211_mesh_state *iv_mesh; /* MBSS state */ + struct ieee80211_hwmp_state *iv_hwmp; /* HWMP state */ + + /* operate-mode detach hook */ + void (*iv_opdetach)(struct ieee80211vap *); + /* receive processing */ + int (*iv_input)(struct ieee80211_node *, + struct mbuf *, int, int); + void (*iv_recv_mgmt)(struct ieee80211_node *, + struct mbuf *, int, int, int); + void (*iv_recv_ctl)(struct ieee80211_node *, + struct mbuf *, int); + void (*iv_deliver_data)(struct ieee80211vap *, + struct ieee80211_node *, struct mbuf *); +#if 0 + /* send processing */ + int (*iv_send_mgmt)(struct ieee80211_node *, + int, int); +#endif + /* beacon miss processing */ + void (*iv_bmiss)(struct ieee80211vap *); + /* reset device state after 802.11 parameter/state change */ + int (*iv_reset)(struct ieee80211vap *, u_long); + /* [schedule] beacon frame update */ + void (*iv_update_beacon)(struct ieee80211vap *, int); + /* power save handling */ + void (*iv_update_ps)(struct ieee80211vap *, int); + int (*iv_set_tim)(struct ieee80211_node *, int); + /* state machine processing */ + int (*iv_newstate)(struct ieee80211vap *, + enum ieee80211_state, int); + /* 802.3 output method for raw frame xmit */ + int (*iv_output)(struct ifnet *, struct mbuf *, + struct sockaddr *, struct route *); + uint64_t iv_spare[8]; +}; + +#define IEEE80211_ADDR_EQ(a1,a2) (memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0) +#define IEEE80211_ADDR_COPY(dst,src) memcpy(dst,src,IEEE80211_ADDR_LEN) + +/* ic_flags/iv_flags */ +#define IEEE80211_F_TURBOP 0x00000001 /* CONF: ATH Turbo enabled*/ +#define IEEE80211_F_COMP 0x00000002 /* CONF: ATH comp enabled */ +#define IEEE80211_F_FF 0x00000004 /* CONF: ATH FF enabled */ +#define IEEE80211_F_BURST 0x00000008 /* CONF: bursting enabled */ +/* NB: this is intentionally setup to be IEEE80211_CAPINFO_PRIVACY */ +#define IEEE80211_F_PRIVACY 0x00000010 /* CONF: privacy enabled */ +#define IEEE80211_F_PUREG 0x00000020 /* CONF: 11g w/o 11b sta's */ +#define IEEE80211_F_SCAN 0x00000080 /* STATUS: scanning */ +#define IEEE80211_F_ASCAN 0x00000100 /* STATUS: active scan */ +#define IEEE80211_F_SIBSS 0x00000200 /* STATUS: start IBSS */ +/* NB: this is intentionally setup to be IEEE80211_CAPINFO_SHORT_SLOTTIME */ +#define IEEE80211_F_SHSLOT 0x00000400 /* STATUS: use short slot time*/ +#define IEEE80211_F_PMGTON 0x00000800 /* CONF: Power mgmt enable */ +#define IEEE80211_F_DESBSSID 0x00001000 /* CONF: des_bssid is set */ +#define IEEE80211_F_WME 0x00002000 /* CONF: enable WME use */ +#define IEEE80211_F_BGSCAN 0x00004000 /* CONF: bg scan enabled (???)*/ +#define IEEE80211_F_SWRETRY 0x00008000 /* CONF: sw tx retry enabled */ +#define IEEE80211_F_TXPOW_FIXED 0x00010000 /* TX Power: fixed rate */ +#define IEEE80211_F_IBSSON 0x00020000 /* CONF: IBSS creation enable */ +#define IEEE80211_F_SHPREAMBLE 0x00040000 /* STATUS: use short preamble */ +#define IEEE80211_F_DATAPAD 0x00080000 /* CONF: do alignment pad */ +#define IEEE80211_F_USEPROT 0x00100000 /* STATUS: protection enabled */ +#define IEEE80211_F_USEBARKER 0x00200000 /* STATUS: use barker preamble*/ +#define IEEE80211_F_CSAPENDING 0x00400000 /* STATUS: chan switch pending*/ +#define IEEE80211_F_WPA1 0x00800000 /* CONF: WPA enabled */ +#define IEEE80211_F_WPA2 0x01000000 /* CONF: WPA2 enabled */ +#define IEEE80211_F_WPA 0x01800000 /* CONF: WPA/WPA2 enabled */ +#define IEEE80211_F_DROPUNENC 0x02000000 /* CONF: drop unencrypted */ +#define IEEE80211_F_COUNTERM 0x04000000 /* CONF: TKIP countermeasures */ +#define IEEE80211_F_HIDESSID 0x08000000 /* CONF: hide SSID in beacon */ +#define IEEE80211_F_NOBRIDGE 0x10000000 /* CONF: dis. internal bridge */ +#define IEEE80211_F_PCF 0x20000000 /* CONF: PCF enabled */ +#define IEEE80211_F_DOTH 0x40000000 /* CONF: 11h enabled */ +#define IEEE80211_F_DWDS 0x80000000 /* CONF: Dynamic WDS enabled */ + +#define IEEE80211_F_BITS \ + "\20\1TURBOP\2COMP\3FF\4BURST\5PRIVACY\6PUREG\10SCAN\11ASCAN\12SIBSS" \ + "\13SHSLOT\14PMGTON\15DESBSSID\16WME\17BGSCAN\20SWRETRY\21TXPOW_FIXED" \ + "\22IBSSON\23SHPREAMBLE\24DATAPAD\25USEPROT\26USERBARKER\27CSAPENDING" \ + "\30WPA1\31WPA2\32DROPUNENC\33COUNTERM\34HIDESSID\35NOBRIDG\36PCF" \ + "\37DOTH\40DWDS" + +/* Atheros protocol-specific flags */ +#define IEEE80211_F_ATHEROS \ + (IEEE80211_F_FF | IEEE80211_F_COMP | IEEE80211_F_TURBOP) +/* Check if an Atheros capability was negotiated for use */ +#define IEEE80211_ATH_CAP(vap, ni, bit) \ + ((vap)->iv_flags & (ni)->ni_ath_flags & (bit)) + +/* ic_flags_ext/iv_flags_ext */ +#define IEEE80211_FEXT_INACT 0x00000002 /* CONF: sta inact handling */ +#define IEEE80211_FEXT_SCANWAIT 0x00000004 /* STATUS: awaiting scan */ +/* 0x00000006 reserved */ +#define IEEE80211_FEXT_BGSCAN 0x00000008 /* STATUS: complete bgscan */ +#define IEEE80211_FEXT_WPS 0x00000010 /* CONF: WPS enabled */ +#define IEEE80211_FEXT_TSN 0x00000020 /* CONF: TSN enabled */ +#define IEEE80211_FEXT_SCANREQ 0x00000040 /* STATUS: scan req params */ +#define IEEE80211_FEXT_RESUME 0x00000080 /* STATUS: start on resume */ +#define IEEE80211_FEXT_4ADDR 0x00000100 /* CONF: apply 4-addr encap */ +#define IEEE80211_FEXT_NONERP_PR 0x00000200 /* STATUS: non-ERP sta present*/ +#define IEEE80211_FEXT_SWBMISS 0x00000400 /* CONF: do bmiss in s/w */ +#define IEEE80211_FEXT_DFS 0x00000800 /* CONF: DFS enabled */ +#define IEEE80211_FEXT_DOTD 0x00001000 /* CONF: 11d enabled */ +#define IEEE80211_FEXT_STATEWAIT 0x00002000 /* STATUS: awaiting state chg */ +#define IEEE80211_FEXT_REINIT 0x00004000 /* STATUS: INIT state first */ +#define IEEE80211_FEXT_BPF 0x00008000 /* STATUS: BPF tap present */ +/* NB: immutable: should be set only when creating a vap */ +#define IEEE80211_FEXT_WDSLEGACY 0x00010000 /* CONF: legacy WDS operation */ +#define IEEE80211_FEXT_PROBECHAN 0x00020000 /* CONF: probe passive channel*/ + +#define IEEE80211_FEXT_BITS \ + "\20\2INACT\3SCANWAIT\4BGSCAN\5WPS\6TSN\7SCANREQ\10RESUME" \ + "\0114ADDR\12NONEPR_PR\13SWBMISS\14DFS\15DOTD\16STATEWAIT\17REINIT" \ + "\20BPF\21WDSLEGACY\22PROBECHAN" + +/* ic_flags_ht/iv_flags_ht */ +#define IEEE80211_FHT_NONHT_PR 0x00000001 /* STATUS: non-HT sta present */ +#define IEEE80211_FHT_GF 0x00040000 /* CONF: Greenfield enabled */ +#define IEEE80211_FHT_HT 0x00080000 /* CONF: HT supported */ +#define IEEE80211_FHT_AMPDU_TX 0x00100000 /* CONF: A-MPDU tx supported */ +#define IEEE80211_FHT_AMPDU_RX 0x00200000 /* CONF: A-MPDU rx supported */ +#define IEEE80211_FHT_AMSDU_TX 0x00400000 /* CONF: A-MSDU tx supported */ +#define IEEE80211_FHT_AMSDU_RX 0x00800000 /* CONF: A-MSDU rx supported */ +#define IEEE80211_FHT_USEHT40 0x01000000 /* CONF: 20/40 use enabled */ +#define IEEE80211_FHT_PUREN 0x02000000 /* CONF: 11n w/o legacy sta's */ +#define IEEE80211_FHT_SHORTGI20 0x04000000 /* CONF: short GI in HT20 */ +#define IEEE80211_FHT_SHORTGI40 0x08000000 /* CONF: short GI in HT40 */ +#define IEEE80211_FHT_HTCOMPAT 0x10000000 /* CONF: HT vendor OUI's */ +#define IEEE80211_FHT_RIFS 0x20000000 /* CONF: RIFS enabled */ +#define IEEE80211_FHT_STBC_TX 0x40000000 /* CONF: STBC tx enabled */ +#define IEEE80211_FHT_STBC_RX 0x80000000 /* CONF: STBC rx enabled */ + +#define IEEE80211_FHT_BITS \ + "\20\1NONHT_PR" \ + "\23GF\24HT\25AMDPU_TX\26AMPDU_TX" \ + "\27AMSDU_TX\30AMSDU_RX\31USEHT40\32PUREN\33SHORTGI20\34SHORTGI40" \ + "\35HTCOMPAT\36RIFS\37STBC_TX\40STBC_RX" + +#define IEEE80211_FVEN_BITS "\20" + +/* ic_caps/iv_caps: device driver capabilities */ +/* 0x2e available */ +#define IEEE80211_C_STA 0x00000001 /* CAPABILITY: STA available */ +#define IEEE80211_C_8023ENCAP 0x00000002 /* CAPABILITY: 802.3 encap */ +#define IEEE80211_C_FF 0x00000040 /* CAPABILITY: ATH FF avail */ +#define IEEE80211_C_TURBOP 0x00000080 /* CAPABILITY: ATH Turbo avail*/ +#define IEEE80211_C_IBSS 0x00000100 /* CAPABILITY: IBSS available */ +#define IEEE80211_C_PMGT 0x00000200 /* CAPABILITY: Power mgmt */ +#define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */ +#define IEEE80211_C_AHDEMO 0x00000800 /* CAPABILITY: Old Adhoc Demo */ +#define IEEE80211_C_SWRETRY 0x00001000 /* CAPABILITY: sw tx retry */ +#define IEEE80211_C_TXPMGT 0x00002000 /* CAPABILITY: tx power mgmt */ +#define IEEE80211_C_SHSLOT 0x00004000 /* CAPABILITY: short slottime */ +#define IEEE80211_C_SHPREAMBLE 0x00008000 /* CAPABILITY: short preamble */ +#define IEEE80211_C_MONITOR 0x00010000 /* CAPABILITY: monitor mode */ +#define IEEE80211_C_DFS 0x00020000 /* CAPABILITY: DFS/radar avail*/ +#define IEEE80211_C_MBSS 0x00040000 /* CAPABILITY: MBSS available */ +/* 0x7c0000 available */ +#define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */ +#define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */ +#define IEEE80211_C_WPA 0x01800000 /* CAPABILITY: WPA1+WPA2 avail*/ +#define IEEE80211_C_BURST 0x02000000 /* CAPABILITY: frame bursting */ +#define IEEE80211_C_WME 0x04000000 /* CAPABILITY: WME avail */ +#define IEEE80211_C_WDS 0x08000000 /* CAPABILITY: 4-addr support */ +/* 0x10000000 reserved */ +#define IEEE80211_C_BGSCAN 0x20000000 /* CAPABILITY: bg scanning */ +#define IEEE80211_C_TXFRAG 0x40000000 /* CAPABILITY: tx fragments */ +#define IEEE80211_C_TDMA 0x80000000 /* CAPABILITY: TDMA avail */ +/* XXX protection/barker? */ + +#define IEEE80211_C_OPMODE \ + (IEEE80211_C_STA | IEEE80211_C_IBSS | IEEE80211_C_HOSTAP | \ + IEEE80211_C_AHDEMO | IEEE80211_C_MONITOR | IEEE80211_C_WDS | \ + IEEE80211_C_TDMA | IEEE80211_C_MBSS) + +#define IEEE80211_C_BITS \ + "\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \ + "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \ + "\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \ + "\37TXFRAG\40TDMA" + +/* + * ic_htcaps/iv_htcaps: HT-specific device/driver capabilities + * + * NB: the low 16-bits are the 802.11 definitions, the upper + * 16-bits are used to define s/w/driver capabilities. + */ +#define IEEE80211_HTC_AMPDU 0x00010000 /* CAPABILITY: A-MPDU tx */ +#define IEEE80211_HTC_AMSDU 0x00020000 /* CAPABILITY: A-MSDU tx */ +/* NB: HT40 is implied by IEEE80211_HTCAP_CHWIDTH40 */ +#define IEEE80211_HTC_HT 0x00040000 /* CAPABILITY: HT operation */ +#define IEEE80211_HTC_SMPS 0x00080000 /* CAPABILITY: MIMO power save*/ +#define IEEE80211_HTC_RIFS 0x00100000 /* CAPABILITY: RIFS support */ + +#define IEEE80211_C_HTCAP_BITS \ + "\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \ + "\21AMPDU\22AMSDU\23HT\24SMPS\25RIFS" + +void ieee80211_ifattach(struct ieee80211com *, + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +void ieee80211_ifdetach(struct ieee80211com *); +int ieee80211_vap_setup(struct ieee80211com *, struct ieee80211vap *, + const char name[IFNAMSIZ], int unit, int opmode, int flags, + const uint8_t bssid[IEEE80211_ADDR_LEN], + const uint8_t macaddr[IEEE80211_ADDR_LEN]); +int ieee80211_vap_attach(struct ieee80211vap *, + ifm_change_cb_t, ifm_stat_cb_t); +void ieee80211_vap_detach(struct ieee80211vap *); +const struct ieee80211_rateset *ieee80211_get_suprates(struct ieee80211com *ic, + const struct ieee80211_channel *); +void ieee80211_announce(struct ieee80211com *); +void ieee80211_announce_channels(struct ieee80211com *); +void ieee80211_drain(struct ieee80211com *); +void ieee80211_media_init(struct ieee80211com *); +struct ieee80211com *ieee80211_find_vap(const uint8_t mac[IEEE80211_ADDR_LEN]); +int ieee80211_media_change(struct ifnet *); +void ieee80211_media_status(struct ifnet *, struct ifmediareq *); +int ieee80211_ioctl(struct ifnet *, u_long, caddr_t); +int ieee80211_rate2media(struct ieee80211com *, int, + enum ieee80211_phymode); +int ieee80211_media2rate(int); +int ieee80211_mhz2ieee(u_int, u_int); +int ieee80211_chan2ieee(struct ieee80211com *, + const struct ieee80211_channel *); +u_int ieee80211_ieee2mhz(u_int, u_int); +struct ieee80211_channel *ieee80211_find_channel(struct ieee80211com *, + int freq, int flags); +struct ieee80211_channel *ieee80211_find_channel_byieee(struct ieee80211com *, + int ieee, int flags); +int ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode); +enum ieee80211_phymode ieee80211_chan2mode(const struct ieee80211_channel *); +uint32_t ieee80211_mac_hash(const struct ieee80211com *, + const uint8_t addr[IEEE80211_ADDR_LEN]); + +void ieee80211_radiotap_attach(struct ieee80211com *, + struct ieee80211_radiotap_header *th, int tlen, + uint32_t tx_radiotap, + struct ieee80211_radiotap_header *rh, int rlen, + uint32_t rx_radiotap); +void ieee80211_radiotap_detach(struct ieee80211com *); +void ieee80211_radiotap_vattach(struct ieee80211vap *); +void ieee80211_radiotap_vdetach(struct ieee80211vap *); +void ieee80211_radiotap_chan_change(struct ieee80211com *); +void ieee80211_radiotap_tx(struct ieee80211vap *, struct mbuf *); +void ieee80211_radiotap_rx(struct ieee80211vap *, struct mbuf *); +void ieee80211_radiotap_rx_all(struct ieee80211com *, struct mbuf *); + +static __inline int +ieee80211_radiotap_active(const struct ieee80211com *ic) +{ + return (ic->ic_flags_ext & IEEE80211_FEXT_BPF) != 0; +} + +static __inline int +ieee80211_radiotap_active_vap(const struct ieee80211vap *vap) +{ + return (vap->iv_flags_ext & IEEE80211_FEXT_BPF) || + vap->iv_ic->ic_montaps != 0; +} + +/* + * Enqueue a task on the state thread. + */ +static __inline void +ieee80211_runtask(struct ieee80211com *ic, struct task *task) +{ + taskqueue_enqueue(ic->ic_tq, task); +} + +/* + * Wait for a queued task to complete. + */ +static __inline void +ieee80211_draintask(struct ieee80211com *ic, struct task *task) +{ + taskqueue_drain(ic->ic_tq, task); +} + +/* + * Key update synchronization methods. XXX should not be visible. + */ +static __inline void +ieee80211_key_update_begin(struct ieee80211vap *vap) +{ + vap->iv_key_update_begin(vap); +} +static __inline void +ieee80211_key_update_end(struct ieee80211vap *vap) +{ + vap->iv_key_update_end(vap); +} + +/* + * XXX these need to be here for IEEE80211_F_DATAPAD + */ + +/* + * Return the space occupied by the 802.11 header and any + * padding required by the driver. This works for a + * management or data frame. + */ +static __inline int +ieee80211_hdrspace(struct ieee80211com *ic, const void *data) +{ + int size = ieee80211_hdrsize(data); + if (ic->ic_flags & IEEE80211_F_DATAPAD) + size = roundup(size, sizeof(uint32_t)); + return size; +} + +/* + * Like ieee80211_hdrspace, but handles any type of frame. + */ +static __inline int +ieee80211_anyhdrspace(struct ieee80211com *ic, const void *data) +{ + int size = ieee80211_anyhdrsize(data); + if (ic->ic_flags & IEEE80211_F_DATAPAD) + size = roundup(size, sizeof(uint32_t)); + return size; +} + +/* + * Notify a vap that beacon state has been updated. + */ +static __inline void +ieee80211_beacon_notify(struct ieee80211vap *vap, int what) +{ + if (vap->iv_state == IEEE80211_S_RUN) + vap->iv_update_beacon(vap, what); +} + +/* + * Calculate HT channel promotion flags for a channel. + * XXX belongs in ieee80211_ht.h but needs IEEE80211_FHT_* + */ +static __inline int +ieee80211_htchanflags(const struct ieee80211_channel *c) +{ + return IEEE80211_IS_CHAN_HT40(c) ? + IEEE80211_FHT_HT | IEEE80211_FHT_USEHT40 : + IEEE80211_IS_CHAN_HT(c) ? IEEE80211_FHT_HT : 0; +} + +/* + * Debugging facilities compiled in when IEEE80211_DEBUG is defined. + * + * The intent is that any problem in the net80211 layer can be + * diagnosed by inspecting the statistics (dumped by the wlanstats + * program) and/or the msgs generated by net80211. Messages are + * broken into functional classes and can be controlled with the + * wlandebug program. Certain of these msg groups are for facilities + * that are no longer part of net80211 (e.g. IEEE80211_MSG_DOT1XSM). + */ +#define IEEE80211_MSG_11N 0x80000000 /* 11n mode debug */ +#define IEEE80211_MSG_DEBUG 0x40000000 /* IFF_DEBUG equivalent */ +#define IEEE80211_MSG_DUMPPKTS 0x20000000 /* IFF_LINK2 equivalant */ +#define IEEE80211_MSG_CRYPTO 0x10000000 /* crypto work */ +#define IEEE80211_MSG_INPUT 0x08000000 /* input handling */ +#define IEEE80211_MSG_XRATE 0x04000000 /* rate set handling */ +#define IEEE80211_MSG_ELEMID 0x02000000 /* element id parsing */ +#define IEEE80211_MSG_NODE 0x01000000 /* node handling */ +#define IEEE80211_MSG_ASSOC 0x00800000 /* association handling */ +#define IEEE80211_MSG_AUTH 0x00400000 /* authentication handling */ +#define IEEE80211_MSG_SCAN 0x00200000 /* scanning */ +#define IEEE80211_MSG_OUTPUT 0x00100000 /* output handling */ +#define IEEE80211_MSG_STATE 0x00080000 /* state machine */ +#define IEEE80211_MSG_POWER 0x00040000 /* power save handling */ +#define IEEE80211_MSG_HWMP 0x00020000 /* hybrid mesh protocol */ +#define IEEE80211_MSG_DOT1XSM 0x00010000 /* 802.1x state machine */ +#define IEEE80211_MSG_RADIUS 0x00008000 /* 802.1x radius client */ +#define IEEE80211_MSG_RADDUMP 0x00004000 /* dump 802.1x radius packets */ +#define IEEE80211_MSG_MESH 0x00002000 /* mesh networking */ +#define IEEE80211_MSG_WPA 0x00001000 /* WPA/RSN protocol */ +#define IEEE80211_MSG_ACL 0x00000800 /* ACL handling */ +#define IEEE80211_MSG_WME 0x00000400 /* WME protocol */ +#define IEEE80211_MSG_SUPERG 0x00000200 /* Atheros SuperG protocol */ +#define IEEE80211_MSG_DOTH 0x00000100 /* 802.11h support */ +#define IEEE80211_MSG_INACT 0x00000080 /* inactivity handling */ +#define IEEE80211_MSG_ROAM 0x00000040 /* sta-mode roaming */ +#define IEEE80211_MSG_RATECTL 0x00000020 /* tx rate control */ +#define IEEE80211_MSG_ACTION 0x00000010 /* action frame handling */ +#define IEEE80211_MSG_WDS 0x00000008 /* WDS handling */ +#define IEEE80211_MSG_IOCTL 0x00000004 /* ioctl handling */ +#define IEEE80211_MSG_TDMA 0x00000002 /* TDMA handling */ + +#define IEEE80211_MSG_ANY 0xffffffff /* anything */ + +#define IEEE80211_MSG_BITS \ + "\20\2TDMA\3IOCTL\4WDS\5ACTION\6RATECTL\7ROAM\10INACT\11DOTH\12SUPERG" \ + "\13WME\14ACL\15WPA\16RADKEYS\17RADDUMP\20RADIUS\21DOT1XSM\22HWMP" \ + "\23POWER\24STATE\25OUTPUT\26SCAN\27AUTH\30ASSOC\31NODE\32ELEMID" \ + "\33XRATE\34INPUT\35CRYPTO\36DUPMPKTS\37DEBUG\04011N" + +#ifdef IEEE80211_DEBUG +#define ieee80211_msg(_vap, _m) ((_vap)->iv_debug & (_m)) +#define IEEE80211_DPRINTF(_vap, _m, _fmt, ...) do { \ + if (ieee80211_msg(_vap, _m)) \ + ieee80211_note(_vap, _fmt, __VA_ARGS__); \ +} while (0) +#define IEEE80211_NOTE(_vap, _m, _ni, _fmt, ...) do { \ + if (ieee80211_msg(_vap, _m)) \ + ieee80211_note_mac(_vap, (_ni)->ni_macaddr, _fmt, __VA_ARGS__);\ +} while (0) +#define IEEE80211_NOTE_MAC(_vap, _m, _mac, _fmt, ...) do { \ + if (ieee80211_msg(_vap, _m)) \ + ieee80211_note_mac(_vap, _mac, _fmt, __VA_ARGS__); \ +} while (0) +#define IEEE80211_NOTE_FRAME(_vap, _m, _wh, _fmt, ...) do { \ + if (ieee80211_msg(_vap, _m)) \ + ieee80211_note_frame(_vap, _wh, _fmt, __VA_ARGS__); \ +} while (0) +void ieee80211_note(struct ieee80211vap *, const char *, ...); +void ieee80211_note_mac(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN], const char *, ...); +void ieee80211_note_frame(struct ieee80211vap *, + const struct ieee80211_frame *, const char *, ...); +#define ieee80211_msg_debug(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_DEBUG) +#define ieee80211_msg_dumppkts(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_DUMPPKTS) +#define ieee80211_msg_input(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_INPUT) +#define ieee80211_msg_radius(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_RADIUS) +#define ieee80211_msg_dumpradius(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_RADDUMP) +#define ieee80211_msg_dumpradkeys(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_RADKEYS) +#define ieee80211_msg_scan(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_SCAN) +#define ieee80211_msg_assoc(_vap) \ + ((_vap)->iv_debug & IEEE80211_MSG_ASSOC) + +/* + * Emit a debug message about discarding a frame or information + * element. One format is for extracting the mac address from + * the frame header; the other is for when a header is not + * available or otherwise appropriate. + */ +#define IEEE80211_DISCARD(_vap, _m, _wh, _type, _fmt, ...) do { \ + if ((_vap)->iv_debug & (_m)) \ + ieee80211_discard_frame(_vap, _wh, _type, _fmt, __VA_ARGS__);\ +} while (0) +#define IEEE80211_DISCARD_IE(_vap, _m, _wh, _type, _fmt, ...) do { \ + if ((_vap)->iv_debug & (_m)) \ + ieee80211_discard_ie(_vap, _wh, _type, _fmt, __VA_ARGS__);\ +} while (0) +#define IEEE80211_DISCARD_MAC(_vap, _m, _mac, _type, _fmt, ...) do { \ + if ((_vap)->iv_debug & (_m)) \ + ieee80211_discard_mac(_vap, _mac, _type, _fmt, __VA_ARGS__);\ +} while (0) + +void ieee80211_discard_frame(struct ieee80211vap *, + const struct ieee80211_frame *, const char *type, const char *fmt, ...); +void ieee80211_discard_ie(struct ieee80211vap *, + const struct ieee80211_frame *, const char *type, const char *fmt, ...); +void ieee80211_discard_mac(struct ieee80211vap *, + const uint8_t mac[IEEE80211_ADDR_LEN], const char *type, + const char *fmt, ...); +#else +#define IEEE80211_DPRINTF(_vap, _m, _fmt, ...) +#define IEEE80211_NOTE(_vap, _m, _ni, _fmt, ...) +#define IEEE80211_NOTE_FRAME(_vap, _m, _wh, _fmt, ...) +#define IEEE80211_NOTE_MAC(_vap, _m, _mac, _fmt, ...) +#define ieee80211_msg_dumppkts(_vap) 0 +#define ieee80211_msg(_vap, _m) 0 + +#define IEEE80211_DISCARD(_vap, _m, _wh, _type, _fmt, ...) +#define IEEE80211_DISCARD_IE(_vap, _m, _wh, _type, _fmt, ...) +#define IEEE80211_DISCARD_MAC(_vap, _m, _mac, _type, _fmt, ...) +#endif + +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_VAR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/ieee80211_wds.h b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_wds.h new file mode 100644 index 0000000000..35a7bd322f --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/ieee80211_wds.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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$ + */ +#ifndef _FBSD_COMPAT_NET80211_IEEE80211_WDS_H_ +#define _FBSD_COMPAT_NET80211_IEEE80211_WDS_H_ + +/* + * WDS implementation definitions. + */ +void ieee80211_wds_attach(struct ieee80211com *); +void ieee80211_wds_detach(struct ieee80211com *); + +void ieee80211_dwds_mcast(struct ieee80211vap *, struct mbuf *); +void ieee80211_dwds_discover(struct ieee80211_node *, struct mbuf *); +int ieee80211_node_wdsq_age(struct ieee80211_node *); +#endif /* _FBSD_COMPAT_NET80211_IEEE80211_WDS_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/opt_inet.h b/src/libs/compat/freebsd_network/compat/net80211/opt_inet.h new file mode 100644 index 0000000000..16007efdfa --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/opt_inet.h @@ -0,0 +1,6 @@ +#ifndef _FBSD_COMPAT_NET80211_OPT_INET_H_ +#define _FBSD_COMPAT_NET80211_OPT_INET_H_ + +#define INET 1 + +#endif /* _FBSD_COMPAT_NET80211_OPT_INET_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/opt_inet6.h b/src/libs/compat/freebsd_network/compat/net80211/opt_inet6.h new file mode 100644 index 0000000000..6ae7676ed4 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/opt_inet6.h @@ -0,0 +1,6 @@ +#ifndef _FBSD_COMPAT_NET80211_OPT_INET6_H_ +#define _FBSD_COMPAT_NET80211_OPT_INET6_H_ + +//#define INET6 1 + +#endif /* _FBSD_COMPAT_NET80211_OPT_INET6_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/opt_ipx.h b/src/libs/compat/freebsd_network/compat/net80211/opt_ipx.h new file mode 100644 index 0000000000..f54c7169a6 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/opt_ipx.h @@ -0,0 +1,6 @@ +#ifndef _FBSD_COMPAT_NET80211_OPT_IPX_H_ +#define _FBSD_COMPAT_NET80211_OPT_IPX_H_ + +//define IPX 1 + +#endif /* _FBSD_COMPAT_NET80211_OPT_IPX_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/net80211/opt_wlan.h b/src/libs/compat/freebsd_network/compat/net80211/opt_wlan.h new file mode 100644 index 0000000000..accc87e7b2 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/net80211/opt_wlan.h @@ -0,0 +1,8 @@ +#ifndef _FBSD_COMPAT_NET80211_OPT_WLAN_H_ +#define _FBSD_COMPAT_NET80211_OPT_WLAN_H_ + +#define IEEE80211_DEBUG 1 +//#define IEEE80211_AMDPU_AGE 1 +//#define IEEE80211_SUPPORT_MESH 1 + +#endif /* _FBSD_COMPAT_NET80211_OPT_WLAN_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/netinet/if_ether.h b/src/libs/compat/freebsd_network/compat/netinet/if_ether.h index f3affc16c0..06e32a198a 100644 --- a/src/libs/compat/freebsd_network/compat/netinet/if_ether.h +++ b/src/libs/compat/freebsd_network/compat/netinet/if_ether.h @@ -1,6 +1,11 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_NETINET_IF_ETHER_H_ #define _FBSD_COMPAT_NETINET_IF_ETHER_H_ + /* Haiku does it's own ARP management */ #define arp_ifinit(ifp, ifa) diff --git a/src/libs/compat/freebsd_network/compat/netinet/in_var.h b/src/libs/compat/freebsd_network/compat/netinet/in_var.h new file mode 100644 index 0000000000..bb732d6c5d --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/netinet/in_var.h @@ -0,0 +1,11 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_NETINET_IN_VAR_H_ +#define _FBSD_COMPAT_NETINET_IN_VAR_H_ + + +#include + +#endif /* _FBSD_COMPAT_NETINET_IN_VAR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/netinet/ip6.h b/src/libs/compat/freebsd_network/compat/netinet/ip6.h index 97946ca4c4..e646a1a212 100644 --- a/src/libs/compat/freebsd_network/compat/netinet/ip6.h +++ b/src/libs/compat/freebsd_network/compat/netinet/ip6.h @@ -60,10 +60,10 @@ * * @(#)ip.h 8.1 (Berkeley) 6/10/93 */ - #ifndef _NETINET_IP6_H_ #define _NETINET_IP6_H_ + /* * Definition for internet protocol version 6. * RFC 2460 diff --git a/src/libs/compat/freebsd_network/compat/security/mac/mac_framework.h b/src/libs/compat/freebsd_network/compat/security/mac/mac_framework.h new file mode 100644 index 0000000000..6172e82247 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/security/mac/mac_framework.h @@ -0,0 +1,9 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef FBSD_COMPAT_SECURITY_MAC_MAC_FRAMEWORK_H_ +#define FBSD_COMPAT_SECURITY_MAC_MAC_FRAMEWORK_H_ + + +#endif /* FBSD_COMPAT_SECURITY_MAC_MAC_FRAMEWORK_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/_bus_dma.h b/src/libs/compat/freebsd_network/compat/sys/_bus_dma.h index 1a272b4101..5aa4482f05 100644 --- a/src/libs/compat/freebsd_network/compat/sys/_bus_dma.h +++ b/src/libs/compat/freebsd_network/compat/sys/_bus_dma.h @@ -26,7 +26,6 @@ * $FreeBSD: src/sys/sys/_bus_dma.h,v 1.1 2006/09/03 00:26:17 jmg Exp $ * */ - #ifndef _SYS__BUS_DMA_H_ #define _SYS__BUS_DMA_H_ diff --git a/src/libs/compat/freebsd_network/compat/sys/_mutex.h b/src/libs/compat/freebsd_network/compat/sys/_mutex.h new file mode 100644 index 0000000000..8337989732 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/_mutex.h @@ -0,0 +1,20 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS__MUTEX_H_ +#define _FBSD_COMPAT_SYS__MUTEX_H_ + + +struct mtx { + int type; + union { + mutex mutex; + int32 spinlock; + recursive_lock recursive; + } u; +}; + + +#endif /* _FBSD_COMPAT_SYS__MUTEX_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/_task.h b/src/libs/compat/freebsd_network/compat/sys/_task.h index c1fab53ffb..a94e6b8ca9 100644 --- a/src/libs/compat/freebsd_network/compat/sys/_task.h +++ b/src/libs/compat/freebsd_network/compat/sys/_task.h @@ -1,9 +1,15 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS__TASK_H_ #define _FBSD_COMPAT_SYS__TASK_H_ + /* Haiku's list management */ #include + typedef void (*task_handler_t)(void *context, int pending); struct task { diff --git a/src/libs/compat/freebsd_network/compat/sys/_timeval.h b/src/libs/compat/freebsd_network/compat/sys/_timeval.h new file mode 100644 index 0000000000..6ba7a53deb --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/_timeval.h @@ -0,0 +1,11 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS__TIMEVAL_H_ +#define _FBSD_COMPAT_SYS__TIMEVAL_H_ + + +#include + +#endif /* _FBSD_COMPAT_SYS__TIMEVAL_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/_types.h b/src/libs/compat/freebsd_network/compat/sys/_types.h new file mode 100644 index 0000000000..790e013860 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/_types.h @@ -0,0 +1,20 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS__TYPES_H_ +#define _FBSD_COMPAT_SYS__TYPES_H_ + + +#ifdef __GNUCLIKE_BUILTIN_VARARGS +typedef __builtin_va_list __va_list; /* internally known to gcc */ +#else +typedef char * __va_list; +#endif /* __GNUCLIKE_BUILTIN_VARARGS */ +#if defined(__GNUC_VA_LIST_COMPATIBILITY) && !defined(__GNUC_VA_LIST) \ + && !defined(__NO_GNUC_VA_LIST) +#define __GNUC_VA_LIST +typedef __va_list __gnuc_va_list; /* compatibility w/GNU headers*/ +#endif + +#endif /* _FBSD_COMPAT_SYS__TYPES_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/bus.h b/src/libs/compat/freebsd_network/compat/sys/bus.h index 7e2b7a14a0..8afcf4c9d7 100644 --- a/src/libs/compat/freebsd_network/compat/sys/bus.h +++ b/src/libs/compat/freebsd_network/compat/sys/bus.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther. All Rights Reserved. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -6,43 +7,16 @@ #define _FBSD_COMPAT_SYS_BUS_H_ -#include -#include - #include #include +#include + // TODO per platform, these are 32-bit -typedef uint32_t bus_addr_t; -typedef uint32_t bus_size_t; - -#define BUS_SPACE_MAXADDR_32BIT 0xffffffff -#define BUS_SPACE_MAXADDR 0xffffffff - -#define BUS_SPACE_MAXSIZE_32BIT 0xffffffff -#define BUS_SPACE_MAXSIZE 0xffffffff - -typedef int bus_space_tag_t; -typedef unsigned int bus_space_handle_t; - -uint8_t bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset); -uint16_t bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset); -uint32_t bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset); -void bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, uint8_t value); -void bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, uint16_t value); -void bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, uint32_t value); // oh you glorious world of macros -#define bus_space_write_stream_4(t, h, o, v) \ - bus_space_write_4((t), (h), (o), (v)) #define bus_read_1(r, o) \ bus_space_read_1((r)->r_bustag, (r)->r_bushandle, (o)) #define bus_read_2(r, o) \ @@ -56,23 +30,21 @@ void bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, #define bus_write_4(r, o, v) \ bus_space_write_4((r)->r_bustag, (r)->r_bushandle, (o), (v)) - -#define BUS_SPACE_BARRIER_READ 1 -#define BUS_SPACE_BARRIER_WRITE 2 - -static inline void -bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, bus_size_t len, int flags) -{ - if (flags & BUS_SPACE_BARRIER_READ) - __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory"); - else - __asm__ __volatile__ ("" : : : "memory"); -} - #define bus_barrier(r, o, l, f) \ bus_space_barrier((r)->r_bustag, (r)->r_bushandle, (o), (l), (f)) +#define FILTER_STRAY B_UNHANDLED_INTERRUPT +#define FILTER_HANDLED B_HANDLED_INTERRUPT +#define FILTER_SCHEDULE_THREAD B_INVOKE_SCHEDULER + +/* Note that we reversed the original order, so whenever actual (negative) + numbers are used in a driver, we have to change it. */ +#define BUS_PROBE_SPECIFIC 0 +#define BUS_PROBE_LOW_PRIORITY 10 +#define BUS_PROBE_DEFAULT 20 +#define BUS_PROBE_GENERIC 100 + + struct resource; struct resource_spec { @@ -87,16 +59,6 @@ enum intr_type { INTR_MPSAFE = 512, }; -#define FILTER_STRAY B_UNHANDLED_INTERRUPT -#define FILTER_HANDLED B_HANDLED_INTERRUPT -#define FILTER_SCHEDULE_THREAD B_INVOKE_SCHEDULER - -/* Note that we reversed the original order, so whenever actual (negative) - numbers are used in a driver, we have to change it. */ -#define BUS_PROBE_SPECIFIC 0 -#define BUS_PROBE_LOW_PRIORITY 10 -#define BUS_PROBE_DEFAULT 20 -#define BUS_PROBE_GENERIC 100 int bus_generic_detach(device_t dev); int bus_generic_suspend(device_t dev); @@ -118,6 +80,8 @@ int bus_alloc_resources(device_t dev, struct resource_spec *resourceSpec, void bus_release_resources(device_t dev, const struct resource_spec *resourceSpec, struct resource **resources); +int bus_child_present(device_t child); + static inline struct resource * bus_alloc_resource_any(device_t dev, int type, int *rid, uint32 flags) { @@ -154,18 +118,18 @@ int bus_generic_attach(device_t dev); int device_set_driver(device_t dev, driver_t *driver); int device_is_alive(device_t dev); + static inline struct sysctl_ctx_list * device_get_sysctl_ctx(device_t dev) { return NULL; } + static inline void * device_get_sysctl_tree(device_t dev) { return NULL; } -#include - #endif /* _FBSD_COMPAT_SYS_BUS_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/bus_dma.h b/src/libs/compat/freebsd_network/compat/sys/bus_dma.h index 24a46d0565..362019f783 100644 --- a/src/libs/compat/freebsd_network/compat/sys/bus_dma.h +++ b/src/libs/compat/freebsd_network/compat/sys/bus_dma.h @@ -68,12 +68,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $FreeBSD: src/sys/sys/bus_dma.h,v 1.30 2006/09/03 00:26:17 jmg Exp $ */ - #ifndef _BUS_DMA_H_ #define _BUS_DMA_H_ #include + /* * Machine independent interface for mapping physical addresses to peripheral * bus 'physical' addresses, and assisting with DMA operations. diff --git a/src/libs/compat/freebsd_network/compat/sys/callout.h b/src/libs/compat/freebsd_network/compat/sys/callout.h index cf8b0ccfd2..c625569890 100644 --- a/src/libs/compat/freebsd_network/compat/sys/callout.h +++ b/src/libs/compat/freebsd_network/compat/sys/callout.h @@ -1,13 +1,14 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FBSD_COMPAT_SYS_CALLOUT_H_ #define _FBSD_COMPAT_SYS_CALLOUT_H_ + #include -#include #include @@ -19,8 +20,10 @@ struct callout { int c_flags; }; + #define CALLOUT_MPSAFE 0x0001 + void callout_init_mtx(struct callout *c, struct mtx *mutex, int flags); int callout_reset(struct callout *c, int, void (*func)(void *), void *arg); int callout_pending(struct callout *c); @@ -30,14 +33,9 @@ int callout_active(struct callout *c); #define callout_stop(c) _callout_stop_safe(c, 0) int _callout_stop_safe(struct callout *, int); +inline void +callout_init(struct callout *c, int mpsafe); -static inline void -callout_init(struct callout *c, int mpsafe) -{ - if (mpsafe) - callout_init_mtx(c, NULL, 0); - else - callout_init_mtx(c, &Giant, 0); -} +int callout_schedule(struct callout *, int); #endif /* _FBSD_COMPAT_SYS_CALLOUT_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/cdefs.h b/src/libs/compat/freebsd_network/compat/sys/cdefs.h index 33b847bebd..1e24e18225 100644 --- a/src/libs/compat/freebsd_network/compat/sys/cdefs.h +++ b/src/libs/compat/freebsd_network/compat/sys/cdefs.h @@ -1,6 +1,314 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * 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. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 + * $FreeBSD$ + */ #ifndef _FBSD_COMPAT_SYS_CDEFS_H_ #define _FBSD_COMPAT_SYS_CDEFS_H_ #define __FBSDID(str) static const char __fbsdid[] = str +/* + * This code has been put in place to help reduce the addition of + * compiler specific defines in FreeBSD code. It helps to aid in + * having a compiler-agnostic source tree. + */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) +#define __GNUCLIKE_ASM 3 +#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS +#else +#define __GNUCLIKE_ASM 2 +#endif +#define __GNUCLIKE___TYPEOF 1 +#define __GNUCLIKE___OFFSETOF 1 +#define __GNUCLIKE___SECTION 1 + +#define __GNUCLIKE_ATTRIBUTE_MODE_DI 1 + +#ifndef __INTEL_COMPILER +# define __GNUCLIKE_CTOR_SECTION_HANDLING 1 +#endif + +#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 +# if defined(__INTEL_COMPILER) && defined(__cplusplus) \ + && __INTEL_COMPILER < 800 +# undef __GNUCLIKE_BUILTIN_CONSTANT_P +# endif + +#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER) +# define __GNUCLIKE_BUILTIN_VARARGS 1 +# define __GNUCLIKE_BUILTIN_STDARG 1 +# define __GNUCLIKE_BUILTIN_VAALIST 1 +#endif + +#if defined(__GNUC__) +# define __GNUC_VA_LIST_COMPATIBILITY 1 +#endif + +#ifndef __INTEL_COMPILER +# define __GNUCLIKE_BUILTIN_NEXT_ARG 1 +# define __GNUCLIKE_MATH_BUILTIN_RELOPS +#endif + +#define __GNUCLIKE_BUILTIN_MEMCPY 1 + +/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ +#define __CC_SUPPORTS_INLINE 1 +#define __CC_SUPPORTS___INLINE 1 +#define __CC_SUPPORTS___INLINE__ 1 + +#define __CC_SUPPORTS___FUNC__ 1 +#define __CC_SUPPORTS_WARNING 1 + +#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ + +#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 + +#endif /* __GNUC__ || __INTEL_COMPILER */ + + +/* + * Macro to test if we're using a specific version of gcc or later. + */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __GNUC_PREREQ__(ma, mi) \ + (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect((exp), 1) +#define __predict_false(exp) __builtin_expect((exp), 0) +#else +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) +#endif + +/* + * We define this here since , , and + * require it. + */ +#if __GNUC_PREREQ__(4, 1) +#define __offsetof(type, field) __builtin_offsetof(type, field) +#else +#ifndef __cplusplus +#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) +#else +#define __offsetof(type, field) \ + (__offsetof__ (reinterpret_cast \ + (&reinterpret_cast \ + (static_cast (0)->field)))) +#endif +#endif +#define __rangeof(type, start, end) \ + (__offsetof(type, end) - __offsetof(type, start)) + +/* + * Compiler-dependent macros to help declare dead (non-returning) and + * pure (no side effects) functions, and unused variables. They are + * null except for versions of gcc that are known to support the features + * properly (old versions of gcc-2 supported the dead and pure features + * in a different (wrong) way). If we do not provide an implementation + * for a given compiler, let the compile fail if it is told to use + * a feature that we cannot live without. + */ +#ifdef lint +#define __dead2 +#define __pure2 +#define __unused +#define __packed +#define __aligned(x) +#define __section(x) +#else +#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) +#define __dead2 +#define __pure2 +#define __unused +#endif +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused +/* XXX Find out what to do for __packed, __aligned and __section */ +#endif +#if __GNUC_PREREQ__(2, 7) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused __attribute__((__unused__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __used __attribute__((__used__)) +#else +#if __GNUC_PREREQ__(2, 7) +#define __used +#endif +#endif + +#if defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused __attribute__((__unused__)) +#define __used __attribute__((__used__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#endif +#endif + +/* + * Compiler-dependent macros to declare that functions take printf-like + * or scanf-like arguments. They are null except for versions of gcc + * that are known to support the features properly (old versions of gcc-2 + * didn't permit keeping the keywords out of the application namespace). + */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __printflike(fmtarg, firstvararg) +#define __scanflike(fmtarg, firstvararg) +#define __format_arg(fmtarg) +#else +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#define __scanflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) +#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __noinline __attribute__ ((__noinline__)) +#else +#define __noinline +#endif + +#if __GNUC_PREREQ__(3, 3) +#define __nonnull(x) __attribute__((__nonnull__(x))) +#else +#define __nonnull(x) +#endif + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI + * mode -- there must be no spaces between its arguments, and for nested + * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also + * concatenate double-quoted strings produced by the __STRING macro, but + * this only works with ANSI C. + * + * __XSTRING is like __STRING, but it expands any macros in its argument + * first. It is only available with ANSI C. + */ +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#define __CONCAT1(x,y) x ## y +#define __CONCAT(x,y) __CONCAT1(x,y) +#define __STRING(x) #x /* stringify without expanding x */ +#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ + +#define __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) +#define __inline inline /* convert to C++ keyword */ +#else +#if !(defined(__CC_SUPPORTS___INLINE)) +#define __inline /* delete GCC keyword */ +#endif /* ! __CC_SUPPORTS___INLINE */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#if !defined(__CC_SUPPORTS___INLINE) +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +/* + * In non-ANSI C environments, new programs will want ANSI-only C keywords + * deleted from the program and old programs will want them left alone. + * When using a compiler other than gcc, programs using the ANSI C keywords + * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. + * When using "gcc -traditional", we assume that this is the intent; if + * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. + */ +#ifndef NO_ANSI_KEYWORDS +#define const /* delete ANSI C keywords */ +#define inline +#define signed +#define volatile +#endif /* !NO_ANSI_KEYWORDS */ +#endif /* !__CC_SUPPORTS___INLINE */ +#endif /* !(__STDC__ || __cplusplus) */ + +#ifndef __DECONST +#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) +#endif + #endif diff --git a/src/libs/compat/freebsd_network/compat/sys/condvar.h b/src/libs/compat/freebsd_network/compat/sys/condvar.h new file mode 100644 index 0000000000..d407acbc60 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/condvar.h @@ -0,0 +1,20 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_CONDVAR_H_ +#define _FBSD_COMPAT_SYS_CONDVAR_H_ + + +#include + +struct cv { + struct ConditionVariable* condVar; +}; + +void cv_init(struct cv*, const char*); +void cv_wait(struct cv*, struct mtx*); +int cv_timedwait(struct cv*, struct mtx*, int); +void cv_signal(struct cv*); + +#endif /* _FBSD_COMPAT_SYS_CONDVAR_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/endian.h b/src/libs/compat/freebsd_network/compat/sys/endian.h index 82aee8f1b8..6261634319 100644 --- a/src/libs/compat/freebsd_network/compat/sys/endian.h +++ b/src/libs/compat/freebsd_network/compat/sys/endian.h @@ -25,7 +25,6 @@ * * $FreeBSD: src/sys/sys/endian.h,v 1.6 2003/10/15 20:05:57 obrien Exp $ */ - #ifndef _FBSD_COMPAT_SYS_ENDIAN_H_ #define _FBSD_COMPAT_SYS_ENDIAN_H_ @@ -34,19 +33,18 @@ #include +#include +#include #include - #define _BYTE_ORDER BYTE_ORDER #define _LITTLE_ENDIAN LITTLE_ENDIAN #define _BIG_ENDIAN BIG_ENDIAN - #define __bswap16(x) __swap_int16(x) #define __bswap32(x) __swap_int32(x) #define __bswap64(x) __swap_int64(x) - /* * General byte order swapping functions. */ diff --git a/src/libs/compat/freebsd_network/compat/sys/errno.h b/src/libs/compat/freebsd_network/compat/sys/errno.h index 0076e9302f..fd307ce311 100644 --- a/src/libs/compat/freebsd_network/compat/sys/errno.h +++ b/src/libs/compat/freebsd_network/compat/sys/errno.h @@ -1,6 +1,16 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_ERRNO_H_ #define _FBSD_COMPAT_SYS_ERRNO_H_ -#define EJUSTRETURN (B_ERRORS_END + 1) + +#include + + +/* pseudo-errors returned inside freebsd compat layer to modify return to process */ +#define ERESTART (B_ERRORS_END + 1) /* restart syscall */ +#define EJUSTRETURN (B_ERRORS_END + 2) /* don't modify regs, just return */ #endif diff --git a/src/libs/compat/freebsd_network/compat/sys/event.h b/src/libs/compat/freebsd_network/compat/sys/event.h index ad918c2ecf..b9719f01b9 100644 --- a/src/libs/compat/freebsd_network/compat/sys/event.h +++ b/src/libs/compat/freebsd_network/compat/sys/event.h @@ -1,6 +1,11 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_EVENT_H_ #define _FBSD_COMPAT_SYS_EVENT_H_ + struct knlist { }; diff --git a/src/libs/compat/freebsd_network/compat/sys/eventhandler.h b/src/libs/compat/freebsd_network/compat/sys/eventhandler.h index 9bd8e25787..9a53c98760 100644 --- a/src/libs/compat/freebsd_network/compat/sys/eventhandler.h +++ b/src/libs/compat/freebsd_network/compat/sys/eventhandler.h @@ -25,7 +25,6 @@ * * $FreeBSD: src/sys/sys/eventhandler.h,v 1.33.2.1 2006/05/16 07:27:49 ps Exp $ */ - #ifndef SYS_EVENTHANDLER_H #define SYS_EVENTHANDLER_H diff --git a/src/libs/compat/freebsd_network/compat/sys/firmware.h b/src/libs/compat/freebsd_network/compat/sys/firmware.h new file mode 100644 index 0000000000..a1a8a78f6a --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/firmware.h @@ -0,0 +1,21 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_FIRMWARE_H_ +#define _FBSD_COMPAT_SYS_FIRMWARE_H_ + + +struct firmware { + const char* name; /* system-wide name */ + const void* data; /* location of image */ + size_t datasize; /* size of image in bytes */ + unsigned int version; /* version of the image */ +}; + +const struct firmware* firmware_get(const char*); + +#define FIRMWARE_UNLOAD 0x0001 /* unload if unreferenced */ +void firmware_put(const struct firmware*, int); + +#endif /* _FBSD_COMPAT_SYS_FIRMWARE_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h index aa6df2e160..df0eec48a1 100644 --- a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h +++ b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther. All Rights Reserved. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -12,6 +13,7 @@ #include #include + #undef ASSERT /* private/kernel/debug.h sets it */ @@ -52,12 +54,52 @@ extern const char *gDriverName; driver_t *__haiku_select_miibus_driver(device_t dev); driver_t *__haiku_probe_miibus(device_t dev, driver_t *drivers[]); +status_t init_wlan_stack(void); +void uninit_wlan_stack(void); +status_t start_wlan(device_t); +status_t stop_wlan(device_t); +status_t wlan_control(void*, uint32, void*, size_t); +status_t wlan_close(void*); + /* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to * force the rest of the stuff to be linked back with the driver. * While gcc 2.95 packs everything from the static library onto * the final binary, gcc 4.x rightfuly doesn't. */ #define HAIKU_FBSD_DRIVER_GLUE(publicname, name, busname) \ + extern const char *gDeviceNameList[]; \ + extern device_hooks gDeviceHooks; \ + extern driver_t *DRIVER_MODULE_NAME(name, busname); \ + const char *gDriverName = #publicname; \ + int32 api_version = B_CUR_DRIVER_API_VERSION; \ + status_t init_hardware() \ + { \ + return _fbsd_init_hardware(DRIVER_MODULE_NAME(name, busname)); \ + } \ + status_t init_driver() \ + { \ + return _fbsd_init_driver(DRIVER_MODULE_NAME(name, busname)); \ + } \ + void uninit_driver() \ + { _fbsd_uninit_driver(DRIVER_MODULE_NAME(name, busname)); } \ + const char **publish_devices() \ + { return gDeviceNameList; } \ + device_hooks *find_device(const char *name) \ + { return &gDeviceHooks; } \ + status_t init_wlan_stack(void) \ + { return B_OK; } \ + void uninit_wlan_stack(void) {} \ + status_t start_wlan(device_t dev) \ + { return B_OK; } \ + status_t stop_wlan(device_t dev) \ + { return B_OK; } \ + status_t wlan_control(void *cookie, uint32 op, void *arg, \ + size_t length) \ + { return B_BAD_VALUE; } \ + status_t wlan_close(void* cookie) \ + { return B_OK; } + +#define HAIKU_FBSD_WLAN_DRIVER_GLUE(publicname, name, busname) \ extern const char *gDeviceNameList[]; \ extern device_hooks gDeviceHooks; \ extern driver_t *DRIVER_MODULE_NAME(name, busname); \ @@ -120,6 +162,7 @@ enum { FBSD_TASKQUEUES = 1 << 0, FBSD_FAST_TASKQUEUE = 1 << 1, FBSD_SWI_TASKQUEUE = 1 << 2, + FBSD_WLAN = 1 << 3, }; #define HAIKU_DRIVER_REQUIREMENTS(flags) \ @@ -127,6 +170,11 @@ enum { #define HAIKU_DRIVER_REQUIRES(flag) (__haiku_driver_requirements & (flag)) +extern const uint __haiku_firmware_version; + +#define HAIKU_FIRMWARE_VERSION(version) \ + const uint __haiku_firmware_version = (version) + #define HAIKU_INTR_REGISTER_STATE \ cpu_status __haiku_cpu_state = 0 diff --git a/src/libs/compat/freebsd_network/compat/sys/ioccom.h b/src/libs/compat/freebsd_network/compat/sys/ioccom.h new file mode 100644 index 0000000000..158c95f18e --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/ioccom.h @@ -0,0 +1,28 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_IOCCOM_H_ +#define _FBSD_COMPAT_SYS_IOCCOM_H_ + + +/* + * Ioctl's have the command encoded in the lower word, and the size of + * any in or out parameters in the upper word. The high 3 bits of the + * upper word are used to encode the in/out status of the parameter. + */ +#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ + +#define IOC_OUT 0x40000000 /* copy out parameters */ +#define IOC_IN 0x80000000 /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) + + +#define _IOC(inout,group,num,len) ((unsigned long) \ + ((inout) | (((len) & IOCPARM_MASK) << 16) | ((group) << 8) | (num))) + +#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) +/* this should be _IORW, but stdio got there first */ +#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) + +#endif /* _FBSD_COMPAT_SYS_IOCCOM_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/kernel.h b/src/libs/compat/freebsd_network/compat/sys/kernel.h index 6731994198..6502c2b532 100644 --- a/src/libs/compat/freebsd_network/compat/sys/kernel.h +++ b/src/libs/compat/freebsd_network/compat/sys/kernel.h @@ -1,38 +1,51 @@ +/* + * Copyright 2007-2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_KERNEL_H_ #define _FBSD_COMPAT_SYS_KERNEL_H_ + #include -#include #include #include -#include -#include +#include +#include + + +/* + * + * In FreeBSD hz holds the count of how often the thread scheduler is invoked + * per second. Moreover this is the rate at which FreeBSD can generate callouts + * (kind of timeout mechanism). + * For FreeBSD 8 this is typically 1000 times per second. This value is defined + * in a file called subr_param.c + * + * For Haiku this value is much higher, due to using another timeout scheduling + * mechanism, which has a resolution of 1 MHz. So hz for Haiku is set to + * 1000000. Suffixing LL prevents integer overflows during calculations. + * as it defines a long long constant.*/ #define hz 1000000LL -#define bootverbose 1 - -#define KASSERT(cond,msg) do { \ - if (!(cond)) \ - panic msg; \ -} while (0) typedef void (*system_init_func_t)(void *); + struct __system_init { system_init_func_t func; }; -/* TODO */ +/* TODO implement SYSINIT/SYSUNINIT subsystem */ #define SYSINIT(uniquifier, subsystem, order, func, ident) \ - struct __system_init __init_##uniquifier = { func } + struct __system_init __init_##uniquifier = { (system_init_func_t) func } + +#define SYSUNINIT(uniquifier, subsystem, order, func, ident) \ + struct __system_init __uninit_##uniquifier = { (system_init_func_t) func } #define TUNABLE_INT(path, var) -#define __packed __attribute__ ((packed)) -#define __printflike(a, b) __attribute__ ((format (__printf__, a, b))) - -int printf(const char *format, ...) __printflike(1, 2); +extern int ticks; #endif diff --git a/src/libs/compat/freebsd_network/compat/sys/ktr.h b/src/libs/compat/freebsd_network/compat/sys/ktr.h index 7270ccdd39..2e817a74c8 100644 --- a/src/libs/compat/freebsd_network/compat/sys/ktr.h +++ b/src/libs/compat/freebsd_network/compat/sys/ktr.h @@ -32,7 +32,6 @@ /* * Wraparound kernel trace buffer support. */ - #ifndef _SYS_KTR_H_ #define _SYS_KTR_H_ diff --git a/src/libs/compat/freebsd_network/compat/sys/libkern.h b/src/libs/compat/freebsd_network/compat/sys/libkern.h new file mode 100644 index 0000000000..49523b5a73 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/libkern.h @@ -0,0 +1,21 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_LIBKERN_H_ +#define _FBSD_COMPAT_SYS_LIBKERN_H_ + + +#include +#include +#include + + +extern int random(void); +uint32_t arc4random(void); + +static __inline int imax(int a, int b) { return (a > b ? a : b); } + +static __inline int abs(int a) { return (a < 0 ? -a : a); } + +#endif /* _FBSD_COMPAT_SYS_LIBKERN_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/limits.h b/src/libs/compat/freebsd_network/compat/sys/limits.h new file mode 100644 index 0000000000..492074debb --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/limits.h @@ -0,0 +1,9 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_LIMITS_H_ +#define _FBSD_COMPAT_SYS_LIMITS_H_ + + +#endif /* _FBSD_COMPAT_SYS_LIMITS_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/linker.h b/src/libs/compat/freebsd_network/compat/sys/linker.h new file mode 100644 index 0000000000..52cd150ece --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/linker.h @@ -0,0 +1,9 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_LINKER_H_ +#define _FBSD_COMPAT_SYS_LINKER_H_ + + +#endif /* _FBSD_COMPAT_SYS_LINKER_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/linker_set.h b/src/libs/compat/freebsd_network/compat/sys/linker_set.h new file mode 100644 index 0000000000..41c964df38 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/linker_set.h @@ -0,0 +1,64 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_LINKER_SET_H_ +#define _FBSD_COMPAT_SYS_LINKER_SET_H_ + + +#ifndef _FBSD_COMPAT_SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +/* + * The following macros are used to declare global sets of objects, which + * are collected by the linker into a `linker_set' as defined below. + * For ELF, this is done by constructing a separate segment for each set. + */ + +/* + * Private macros, not to be used outside this header file. + */ +#ifdef __GNUCLIKE___SECTION +#define __MAKE_SET(set, sym) \ + static void const * const __set_##set##_sym_##sym \ + __section("set_" #set) __used = &sym +#else /* !__GNUCLIKE___SECTION */ +#ifndef lint +#error this file needs to be ported to your compiler +#endif /* lint */ +#define __MAKE_SET(set, sym) extern void const * const (__set_##set##_sym_##sym) +#endif /* __GNUCLIKE___SECTION */ + +/* + * Public macros. + */ +#define TEXT_SET(set, sym) __MAKE_SET(set, sym) +#define DATA_SET(set, sym) __MAKE_SET(set, sym) +#define BSS_SET(set, sym) __MAKE_SET(set, sym) +#define ABS_SET(set, sym) __MAKE_SET(set, sym) +#define SET_ENTRY(set, sym) __MAKE_SET(set, sym) + +/* + * Initialize before referring to a given linker set. + */ +#define SET_DECLARE(set, ptype) \ + extern ptype *__CONCAT(__start_set_,set); \ + extern ptype *__CONCAT(__stop_set_,set) + +#define SET_BEGIN(set) \ + (&__CONCAT(__start_set_,set)) +#define SET_LIMIT(set) \ + (&__CONCAT(__stop_set_,set)) + +/* + * Iterate over all the elements of a set. + * + * Sets always contain addresses of things, and "pvar" points to words + * containing those addresses. Thus is must be declared as "type **pvar", + * and the address of each set item is obtained inside the loop by "*pvar". + */ +#define SET_FOREACH(pvar, set) \ + for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) + +#endif /* _FBSD_COMPAT_SYS_LINKER_SET_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/malloc.h b/src/libs/compat/freebsd_network/compat/sys/malloc.h index 2a1affc871..7dc4018101 100644 --- a/src/libs/compat/freebsd_network/compat/sys/malloc.h +++ b/src/libs/compat/freebsd_network/compat/sys/malloc.h @@ -1,20 +1,33 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FBSD_COMPAT_SYS_MALLOC_H_ #define _FBSD_COMPAT_SYS_MALLOC_H_ + #include #include +#include +#include +#include + + +/* + * flags to malloc. + */ #define M_NOWAIT 0x0001 #define M_WAITOK 0x0002 #define M_ZERO 0x0100 +#define M_MAGIC 877983977 /* time when first defined :-) */ + #define M_DEVBUF + void *_kernel_malloc(size_t size, int flags); void _kernel_free(void *ptr); @@ -46,4 +59,9 @@ void _kernel_contigfree(void *addr, unsigned long size); _kernel_contigfree(addr, size) #endif +#define MALLOC_DEFINE(type, shortdesc, longdesc) int type[1] + +#define MALLOC_DECLARE(type) \ + extern int type[1] + #endif /* _FBSD_COMPAT_SYS_MALLOC_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h b/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h index 4cde15ad21..2983efd461 100644 --- a/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h +++ b/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h @@ -48,7 +48,6 @@ (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ } while (0) - /* #define MEXT_IS_REF(m) (((m)->m_ext.ref_cnt != NULL) \ && (*((m)->m_ext.ref_cnt) > 1)) diff --git a/src/libs/compat/freebsd_network/compat/sys/mbuf.h b/src/libs/compat/freebsd_network/compat/sys/mbuf.h index 37c5a4caff..7237315dfb 100644 --- a/src/libs/compat/freebsd_network/compat/sys/mbuf.h +++ b/src/libs/compat/freebsd_network/compat/sys/mbuf.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -6,8 +7,9 @@ #define _FBSD_COMPAT_SYS_MBUF_H_ -#include -#include +#include +#include +#include #define MLEN ((int)(MSIZE - sizeof(struct m_hdr))) @@ -15,9 +17,16 @@ #define MINCLSIZE (MHLEN + 1) + +extern int max_linkhdr; +extern int max_protohdr; +extern int max_hdr; +extern int max_datalen; /* MHLEN - max_hdr */ + + struct m_hdr { - struct mbuf * mh_next; - struct mbuf * mh_nextpkt; + struct mbuf* mh_next; + struct mbuf* mh_nextpkt; caddr_t mh_data; int mh_len; int mh_flags; @@ -25,12 +34,21 @@ struct m_hdr { }; struct pkthdr { - struct ifnet * rcvif; - int len; - int csum_flags; - int csum_data; - uint16_t tso_segsz; - uint16_t ether_vtag; + struct ifnet* rcvif; + int len; + int csum_flags; + int csum_data; + uint16_t tso_segsz; + uint16_t ether_vtag; + SLIST_HEAD(packet_tags, m_tag) tags; +}; + +struct m_tag { + SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ + u_int16_t m_tag_id; /* Tag ID */ + u_int16_t m_tag_len; /* Length of data */ + u_int32_t m_tag_cookie; /* ABI/Module ID */ + void (*m_tag_free)(struct m_tag *); }; struct m_ext { @@ -65,28 +83,41 @@ struct mbuf { #define m_pktdat M_dat.MH.MH_dat.MH_databuf #define m_dat M_dat.M_databuf - #define M_DONTWAIT M_NOWAIT #define M_TRYWAIT M_WAITOK #define M_WAIT M_WAITOK #define MT_DATA 1 -#define M_EXT 0x0001 -#define M_PKTHDR 0x0002 -#define M_RDONLY 0x0008 - -#define EXT_CLUSTER 1 -#define EXT_PACKET 3 -#define EXT_JUMBO9 4 -#define EXT_NET_DRV 100 - +#define M_EXT 0x00000001 +#define M_PKTHDR 0x00000002 +#define M_RDONLY 0x00000008 +#define M_PROTO1 0x00000010 /* protocol-specific */ +#define M_PROTO2 0x00000020 /* protocol-specific */ +#define M_PROTO3 0x00000040 /* protocol-specific */ +#define M_PROTO4 0x00000080 /* protocol-specific */ +#define M_PROTO5 0x00000100 /* protocol-specific */ #define M_BCAST 0x00000200 #define M_MCAST 0x00000400 #define M_FRAG 0x00000800 #define M_FIRSTFRAG 0x00001000 #define M_LASTFRAG 0x00002000 #define M_VLANTAG 0x00010000 +#define M_PROTO6 0x00080000 /* protocol-specific */ +#define M_PROTO7 0x00100000 /* protocol-specific */ +#define M_PROTO8 0x00200000 /* protocol-specific */ + +/* + * Flags preserved when copying m_pkthdr. + */ +#define M_COPYFLAGS \ + (M_PKTHDR|M_RDONLY|M_BCAST|M_MCAST|\ + M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_VLANTAG) + +#define EXT_CLUSTER 1 +#define EXT_PACKET 3 +#define EXT_JUMBO9 4 +#define EXT_NET_DRV 100 #define CSUM_IP 0x0001 #define CSUM_TCP 0x0002 @@ -102,45 +133,9 @@ struct mbuf { #define MGET(m, how, type) ((m) = m_get((how), (type))) #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) #define MCLGET(m, how) m_clget((m), (how)) -#define MEXTADD(m, buf, size, free, args, flags, type) \ - m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type)) - - -struct mbuf *m_getcl(int how, short type, int flags); -void m_freem(struct mbuf *mbuf); -struct mbuf *m_free(struct mbuf *m); -struct mbuf *m_defrag(struct mbuf *m, int); -void m_adj(struct mbuf *m, int); -struct mbuf *m_pullup(struct mbuf *m, int len); -struct mbuf *m_prepend(struct mbuf *m, int, int); -void m_move_pkthdr(struct mbuf *, struct mbuf *); - -u_int m_length(struct mbuf *m, struct mbuf **last); -u_int m_fixhdr(struct mbuf *m); -void m_cat(struct mbuf *m, struct mbuf *n); -struct mbuf *m_collapse(struct mbuf *m, int how, int maxfrags); -void m_copydata(const struct mbuf *m, int off, int len, caddr_t cp); - -struct ifnet; -struct mbuf *m_devget(char *, int, int, struct ifnet *, - void (*)(char *, caddr_t, u_int)); -void m_copyback(struct mbuf *, int, int, caddr_t); - -struct mbuf *m_get(int how, short type); -struct mbuf *m_gethdr(int how, short type); -struct mbuf *m_getjcl(int how, short type, int flags, int size); -void m_clget(struct mbuf *m, int how); -void *m_cljget(struct mbuf *m, int how, int size); - -void m_extadd(struct mbuf *m, caddr_t buffer, u_int size, - void (*freeHook)(void *, void *), void *args, int flags, int type); - #define mtod(m, type) ((type)((m)->m_data)) -#define m_tag_delete(mb, tag) \ - panic("m_tag_delete unsupported."); - /* Check if the supplied mbuf has a packet header, or else panic. */ #define M_ASSERTPKTHDR(m) \ KASSERT(m != NULL && m->m_flags & M_PKTHDR, \ @@ -149,9 +144,102 @@ void m_extadd(struct mbuf *m, caddr_t buffer, u_int size, #define MBUF_CHECKSLEEP(how) do { } while (0) #define MBTOM(how) (how) -extern int max_linkhdr; -extern int max_protohdr; -extern int max_hdr; +#define MTAG_PERSISTENT 0x800 + +// TODO After all network driver are updated to the FreeBSD 8 version this can +// changed +#if __FreeBSD_version__ >= 8 +#define MEXTADD(m, buf, size, free, arg1, arg2, flags, type) \ + m_extadd((m), (caddr_t)(buf), (size), (free),(arg1),(arg2),(flags), (type)) +#else +#define MEXTADD(m, buf, size, free, args, flags, type) \ + m_extadd((m), (caddr_t)(buf), (size), (free),(args),(flags), (type)) +#endif + +void m_adj(struct mbuf*, int); +void m_align(struct mbuf*, int); +void m_cat(struct mbuf*, struct mbuf*); +void m_clget(struct mbuf*, int); +void* m_cljget(struct mbuf*, int, int); +struct mbuf* m_collapse(struct mbuf*, int, int); +void m_copyback(struct mbuf*, int, int, caddr_t); +void m_copydata(const struct mbuf*, int, int, caddr_t); +struct mbuf* m_copypacket(struct mbuf*, int); +struct mbuf* m_defrag(struct mbuf*, int); +struct mbuf* m_devget(char*, int, int, struct ifnet*, + void(*) (char*, caddr_t, u_int)); +struct mbuf* m_dup(struct mbuf*, int); +int m_dup_pkthdr(struct mbuf*, struct mbuf*, int); + +// TODO After all network driver are updated to the FreeBSD 8 version this can +// changed +#if __FreeBSD_version__ >= 8 +void m_extadd(struct mbuf*, caddr_t, u_int, + void(*) (void*, void*), void*, void*, int, int); +#else +void m_extadd(struct mbuf*, caddr_t, u_int, + void(*) (void*, void*), void*, int, int); +#endif + +u_int m_fixhdr(struct mbuf*); +struct mbuf* m_free(struct mbuf*); +void m_freem(struct mbuf*); +struct mbuf* m_get(int, short); +struct mbuf* m_gethdr(int, short); +struct mbuf* m_getjcl(int, short, int, int); +u_int m_length(struct mbuf*, struct mbuf**); +struct mbuf* m_getcl(int, short, int); +void m_move_pkthdr(struct mbuf*, struct mbuf*); +struct mbuf* m_prepend(struct mbuf *, int, int); +struct mbuf* m_pulldown(struct mbuf*, int, int, int*); +struct mbuf* m_pullup(struct mbuf*, int); +struct mbuf* m_split(struct mbuf*, int, int); +struct mbuf* m_unshare(struct mbuf*, int); + +/* Packet tag routines. */ +struct m_tag* m_tag_alloc(u_int32_t, int, int, int); +void m_tag_delete(struct mbuf*, struct m_tag*); +void m_tag_delete_chain(struct mbuf*, struct m_tag*); +void m_tag_free_default(struct m_tag*); +struct m_tag* m_tag_locate(struct mbuf*, u_int32_t, int, struct m_tag*); +struct m_tag* m_tag_copy(struct m_tag*, int); +int m_tag_copy_chain(struct mbuf*, struct mbuf*, int); +void m_tag_delete_nonpersistent(struct mbuf*); + + +static __inline void +m_tag_setup(struct m_tag* tagPointer, u_int32_t cookie, int type, int length) +{ + + tagPointer->m_tag_id = type; + tagPointer->m_tag_len = length; + tagPointer->m_tag_cookie = cookie; +} + + +static __inline void +m_tag_free(struct m_tag* tag) +{ + + (*tag->m_tag_free)(tag); +} + + +static __inline void +m_tag_prepend(struct mbuf* memoryBuffer, struct m_tag* tag) +{ + + SLIST_INSERT_HEAD(&memoryBuffer->m_pkthdr.tags, tag, m_tag_link); +} + + +static __inline void +m_tag_unlink(struct mbuf* memoryBuffer, struct m_tag* tag) +{ + + SLIST_REMOVE(&memoryBuffer->m_pkthdr.tags, tag, m_tag, m_tag_link); +} + #include diff --git a/src/libs/compat/freebsd_network/compat/sys/module.h b/src/libs/compat/freebsd_network/compat/sys/module.h index 7e38091c35..4315069b72 100644 --- a/src/libs/compat/freebsd_network/compat/sys/module.h +++ b/src/libs/compat/freebsd_network/compat/sys/module.h @@ -1,6 +1,20 @@ #ifndef _FBSD_COMPAT_SYS_MODULE_H_ #define _FBSD_COMPAT_SYS_MODULE_H_ + +#include + + +typedef struct module* module_t; + +typedef enum modeventtype { + MOD_LOAD, + MOD_UNLOAD, + MOD_SHUTDOWN, + MOD_QUIESCE +} modeventtype_t; + + #define DECLARE_MODULE(name, data, sub, order) #define MODULE_VERSION(name, version) diff --git a/src/libs/compat/freebsd_network/compat/sys/mount.h b/src/libs/compat/freebsd_network/compat/sys/mount.h new file mode 100644 index 0000000000..4d447271f5 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/mount.h @@ -0,0 +1,9 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_MOUNT_H_ +#define _FBSD_COMPAT_SYS_MOUNT_H_ + + +#endif /* _FBSD_COMPAT_SYS_MOUNT_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/mutex.h b/src/libs/compat/freebsd_network/compat/sys/mutex.h index c4ee8c84a6..fb8be0e980 100644 --- a/src/libs/compat/freebsd_network/compat/sys/mutex.h +++ b/src/libs/compat/freebsd_network/compat/sys/mutex.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -8,15 +9,11 @@ #include +#include +#include +#include +#include -struct mtx { - int type; - union { - mutex mutex; - int32 spinlock; - recursive_lock recursive; - } u; -}; #define MA_OWNED 0x1 #define MA_NOTOWNED 0x2 @@ -30,38 +27,65 @@ struct mtx { #define MTX_NETWORK_LOCK "network driver" +#define NET_LOCK_GIANT() +#define NET_UNLOCK_GIANT() -static inline void mtx_lock(struct mtx *mtx) + +extern struct mtx Giant; + + +void mtx_init(struct mtx*, const char*, const char*, int); +void mtx_destroy(struct mtx*); + + +static inline void +mtx_lock(struct mtx* mutex) { - if (mtx->type == MTX_DEF) - mutex_lock(&mtx->u.mutex); - else if (mtx->type == MTX_RECURSE) - recursive_lock_lock(&mtx->u.recursive); + if (mutex->type == MTX_DEF) + mutex_lock(&mutex->u.mutex); + else if (mutex->type == MTX_RECURSE) + recursive_lock_lock(&mutex->u.recursive); } -static inline void mtx_unlock(struct mtx *mtx) +static inline void +mtx_unlock(struct mtx* mutex) { - if (mtx->type == MTX_DEF) - mutex_unlock(&mtx->u.mutex); - else if (mtx->type == MTX_RECURSE) - recursive_lock_unlock(&mtx->u.recursive); + if (mutex->type == MTX_DEF) + mutex_unlock(&mutex->u.mutex); + else if (mutex->type == MTX_RECURSE) + recursive_lock_unlock(&mutex->u.recursive); } -static inline int mtx_initialized(struct mtx *mtx) +static inline int +mtx_initialized(struct mtx* mutex) { /* XXX */ return 1; } -void mtx_init(struct mtx *m, const char *name, const char *type, int opts); -void mtx_destroy(struct mtx *m); - -#define NET_LOCK_GIANT() -#define NET_UNLOCK_GIANT() - -extern struct mtx Giant; +static inline int +mtx_owned(struct mtx* mutex) +{ + if (mutex->type == MTX_DEF) +#if KDEBUG + return mutex->u.mutex.holder == thread_get_current_thread_id(); +#else + return 0; + // found no way how to determine the holder of the mutex + // so we setting it to 0 because a starving thread is easier + // to detect than a race condition; Colin Günther +#endif + else if (mutex->type == MTX_RECURSE) +#if KDEBUG + return mutex->u.recursive.lock.holder == thread_get_current_thread_id(); +#else + return mutex->u.recursive.holder == thread_get_current_thread_id(); +#endif + else + return 0; +} #endif /* _FBSD_COMPAT_SYS_MUTEX_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/namei.h b/src/libs/compat/freebsd_network/compat/sys/namei.h new file mode 100644 index 0000000000..3da8a0a778 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/namei.h @@ -0,0 +1,9 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_NAMEI_H_ +#define _FBSD_COMPAT_SYS_NAMEI_H_ + + +#endif /* _FBSD_COMPAT_SYS_NAMEI_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/param.h b/src/libs/compat/freebsd_network/compat/sys/param.h index 3d685a610b..01c9978680 100644 --- a/src/libs/compat/freebsd_network/compat/sys/param.h +++ b/src/libs/compat/freebsd_network/compat/sys/param.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -8,27 +9,28 @@ #include +#include +#include +#include +#include + /* The version this compatibility layer is based on */ -#define __FreeBSD_version 700053 - +#define __FreeBSD_version 800107 #define MAXBSIZE 0x10000 #define PAGE_SHIFT 12 #define PAGE_MASK (PAGE_SIZE - 1) - #define trunc_page(x) ((x) & ~PAGE_MASK) - #define ptoa(x) ((unsigned long)((x) << PAGE_SHIFT)) #define atop(x) ((unsigned long)((x) >> PAGE_SHIFT)) /* MAJOR FIXME */ #define Maxmem (32768) - #ifndef MSIZE #define MSIZE 256 #endif @@ -46,8 +48,27 @@ #define ALIGN_BYTES (sizeof(int) - 1) #define ALIGN(x) ((((unsigned)x) + ALIGN_BYTES) & ~ALIGN_BYTES) +/* Macros for counting and rounding. */ +#ifndef howmany +#define howmany(x, y) (((x)+((y)-1))/(y)) +#endif #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ #define roundup2(x, y) (((x) + ((y) - 1)) & (~((y) - 1))) #define rounddown(x, y) (((x) / (y)) * (y)) +#define PRIMASK 0x0ff +#define PCATCH 0x100 +#define PDROP 0x200 +#define PBDRY 0x400 + +#define NBBY 8 /* number of bits in a byte */ + +/* Bit map related macros. */ +#define setbit(a,i) (((unsigned char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY)) +#define clrbit(a,i) (((unsigned char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY))) +#define isset(a,i) \ + (((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) +#define isclr(a,i) \ + ((((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0) + #endif /* _FBSD_COMPAT_SYS_PARAM_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/pcpu.h b/src/libs/compat/freebsd_network/compat/sys/pcpu.h new file mode 100644 index 0000000000..aacd760aba --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/pcpu.h @@ -0,0 +1,14 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_PCPU_H_ +#define _FBSD_COMPAT_SYS_PCPU_H_ + + +#include + + +#define curthread (thread_get_current_thread()) + +#endif /* _FBSD_COMPAT_SYS_PCPU_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/priv.h b/src/libs/compat/freebsd_network/compat/sys/priv.h new file mode 100644 index 0000000000..8b78ce4460 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/priv.h @@ -0,0 +1,30 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_PRIV_H_ +#define _FBSD_COMPAT_SYS_PRIV_H_ + + +/* + * 802.11-related privileges. + */ +#define PRIV_NET80211_GETKEY 440 /* Query 802.11 keys. */ +#define PRIV_NET80211_MANAGE 441 /* Administer 802.11. */ + +#define PRIV_DRIVER 14 /* Low-level driver privilege. */ + + +/* + * Privilege check interfaces, modeled after historic suser() interfacs, but + * with the addition of a specific privilege name. No flags are currently + * defined for the API. Historically, flags specified using the real uid + * instead of the effective uid, and whether or not the check should be + * allowed in jail. + */ +struct thread; + + +int priv_check(struct thread*, int); + +#endif /* _FBSD_COMPAT_SYS_PRIV_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/proc.h b/src/libs/compat/freebsd_network/compat/sys/proc.h new file mode 100644 index 0000000000..4521eecba8 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/proc.h @@ -0,0 +1,16 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_PROC_H_ +#define _FBSD_COMPAT_SYS_PROC_H_ + + +#include +#include +#include +#include +#include +#include + +#endif /* _FBSD_COMPAT_SYS_PROC_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/queue.h b/src/libs/compat/freebsd_network/compat/sys/queue.h index 2112256024..7f2428779c 100644 --- a/src/libs/compat/freebsd_network/compat/sys/queue.h +++ b/src/libs/compat/freebsd_network/compat/sys/queue.h @@ -29,7 +29,6 @@ * @(#)queue.h 8.5 (Berkeley) 8/20/94 * $FreeBSD: src/sys/sys/queue.h,v 1.60.2.1 2005/08/16 22:41:39 phk Exp $ */ - #ifndef _SYS_QUEUE_H_ #define _SYS_QUEUE_H_ diff --git a/src/libs/compat/freebsd_network/compat/sys/rman.h b/src/libs/compat/freebsd_network/compat/sys/rman.h index c3fbc556f9..9ec6c00978 100644 --- a/src/libs/compat/freebsd_network/compat/sys/rman.h +++ b/src/libs/compat/freebsd_network/compat/sys/rman.h @@ -6,7 +6,7 @@ #define _FBSD_COMPAT_SYS_RMAN_H_ -#include +#include #include @@ -14,6 +14,7 @@ #define RF_SHAREABLE 0x0004 #define RF_OPTIONAL 0x0080 + struct resource { int r_type; bus_space_tag_t r_bustag; /* bus_space tag */ @@ -21,6 +22,7 @@ struct resource { area_id r_mapped_area; }; + bus_space_handle_t rman_get_bushandle(struct resource *); bus_space_tag_t rman_get_bustag(struct resource *); diff --git a/src/libs/compat/freebsd_network/compat/sys/sleepqueue.h b/src/libs/compat/freebsd_network/compat/sys/sleepqueue.h new file mode 100644 index 0000000000..58a10e2e73 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/sleepqueue.h @@ -0,0 +1,16 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All Rights Reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_SLEEPQUEUE_H_ +#define _FBSD_COMPAT_SYS_SLEEPQUEUE_H_ + + +void sleepq_add(void*, struct mtx*, const char*, int, int); +int sleepq_broadcast(void*, int, int, int); +void sleepq_lock(void*); +void sleepq_release(void*); +void sleepq_remove(struct thread*, void*); +int sleepq_timedwait(void*, int); + +#endif /* _FBSD_COMPAT_SYS_SLEEPQUEUE_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/socket.h b/src/libs/compat/freebsd_network/compat/sys/socket.h new file mode 100644 index 0000000000..dc83ed2edd --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/socket.h @@ -0,0 +1,18 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_SOCKET_H_ +#define _FBSD_COMPAT_SYS_SOCKET_H_ + + +#include + +#include +#include + + +// TODO Should be incorporated into Haikus socket.h with a number below AF_MAX +#define AF_IEEE80211 AF_MAX + 1 /* IEEE 802.11 protocol */ + +#endif /* _FBSD_COMPAT_SYS_SOCKET_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/sockio.h b/src/libs/compat/freebsd_network/compat/sys/sockio.h index dd28e36d13..909b207a96 100644 --- a/src/libs/compat/freebsd_network/compat/sys/sockio.h +++ b/src/libs/compat/freebsd_network/compat/sys/sockio.h @@ -1,8 +1,26 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_SOCKIO_H_ #define _FBSD_COMPAT_SYS_SOCKIO_H_ + #include +#include + + #define SIOCSIFCAP SIOCSPACKETCAP +// TODO look whether those ioctls are already used by Haiku +// and add them to Haiku's sockio.h eventually +#define SIOCGPRIVATE_0 _IOWR('i', 80, struct ifreq) /* device private 0 */ +#define SIOCGPRIVATE_1 _IOWR('i', 81, struct ifreq) /* device private 1 */ + +#define SIOCSDRVSPEC _IOW('i', 123, struct ifdrv) /* set driver-specific + parameters */ +#define SIOCGDRVSPEC _IOWR('i', 123, struct ifdrv) /* get driver-specific + parameters */ + #endif diff --git a/src/libs/compat/freebsd_network/compat/sys/sysctl.h b/src/libs/compat/freebsd_network/compat/sys/sysctl.h index 5f62b85b5b..642bf299e8 100644 --- a/src/libs/compat/freebsd_network/compat/sys/sysctl.h +++ b/src/libs/compat/freebsd_network/compat/sys/sysctl.h @@ -1,6 +1,14 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_SYSCTL_H_ #define _FBSD_COMPAT_SYS_SYSCTL_H_ + +#include + + #ifdef _KERNEL struct sysctl_req { @@ -70,6 +78,8 @@ static inline int sysctl_handle_int(SYSCTL_HANDLER_ARGS) { return -1; } static inline int sysctl_handle_string(SYSCTL_HANDLER_ARGS) { return -1; } +#define SYSCTL_OUT(r, p, l) -1 + #define __DESCR(x) "" #define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ @@ -115,16 +125,22 @@ static inline int sysctl_handle_string(SYSCTL_HANDLER_ARGS) { return -1; } sysctl_add_oid(ctx, parent, nbr, name, (access), \ ptr, arg, handler, fmt, __DESCR(descr)) + static inline void * SYSCTL_CHILDREN(void *ptr) { return NULL; } + #define SYSCTL_STATIC_CHILDREN(...) NULL +#define SYSCTL_DECL(name) \ + extern struct sysctl_oid_list sysctl_##name##_children + #define SYSCTL_NODE(...) #define SYSCTL_INT(...) +#define SYSCTL_PROC(...) #endif diff --git a/src/libs/compat/freebsd_network/compat/sys/systm.h b/src/libs/compat/freebsd_network/compat/sys/systm.h index fc3628a6d8..6ffe83a36e 100644 --- a/src/libs/compat/freebsd_network/compat/sys/systm.h +++ b/src/libs/compat/freebsd_network/compat/sys/systm.h @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -7,16 +8,33 @@ #include - -#include -#include - -#include -#include -#include +#include #include +#include +#include +#include + +#include + + +int printf(const char *format, ...) __printflike(1, 2); + + +#define ovbcopy(f, t, l) bcopy((f), (t), (l)) + +#define bootverbose 1 + +#ifdef INVARIANTS +#define KASSERT(cond,msg) do { \ + if (!(cond)) \ + panic msg; \ +} while (0) +#else +#define KASSERT(exp,msg) do { \ +} while (0) +#endif #define DELAY(n) \ do { \ @@ -26,10 +44,50 @@ snooze(n); \ } while (0) -static inline void -wakeup(void *identifier) -{ - panic("wakeup() called."); +void wakeup(void *); + +#ifndef CTASSERT /* Allow lint to override */ +#define CTASSERT(x) _CTASSERT(x, __LINE__) +#define _CTASSERT(x, y) __CTASSERT(x, y) +#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] +#endif + + +static inline int +copyin(const void * __restrict udaddr, void * __restrict kaddr, + size_t len) __nonnull(1) __nonnull(2) { + return user_memcpy(kaddr, udaddr, len); } + +static inline int +copyout(const void * __restrict kaddr, void * __restrict udaddr, + size_t len) __nonnull(1) __nonnull(2) { + return user_memcpy(udaddr, kaddr, len); +} + + +int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); +extern int sprintf(char *buf, const char *, ...); + +extern void driver_vprintf(const char *format, va_list vl); +#define vprintf(fmt, vl) driver_vprintf(fmt, vl) + +extern int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); + +int msleep(void* chan, struct mtx* mutex, int pri, const char* wmesg, int timo); + +#define tsleep(chan, pri, wmesg, timo) \ + msleep((chan), NULL, (pri), (wmesg), (timo)) + +// TODO call tsleep with an identifier != NULL +#define pause(wmesg, timo) tsleep(NULL, 0, wmesg, timo) + + +struct unrhdr; +struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex); +void delete_unrhdr(struct unrhdr *uh); +int alloc_unr(struct unrhdr *uh); +void free_unr(struct unrhdr *uh, u_int item); + #endif /* _FBSD_COMPAT_SYS_SYSTM_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/taskqueue.h b/src/libs/compat/freebsd_network/compat/sys/taskqueue.h index 9143d2b9f6..77fa6a0604 100644 --- a/src/libs/compat/freebsd_network/compat/sys/taskqueue.h +++ b/src/libs/compat/freebsd_network/compat/sys/taskqueue.h @@ -1,24 +1,32 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_TASKQUEUE_H_ #define _FBSD_COMPAT_SYS_TASKQUEUE_H_ -#include + +#include #include + #define PI_NET (B_REAL_TIME_DISPLAY_PRIORITY - 1) -struct taskqueue; - #define TASK_INIT(taskp, prio, hand, arg) task_init(taskp, prio, hand, arg) + typedef void (*taskqueue_enqueue_fn)(void *context); + +struct taskqueue; struct taskqueue *taskqueue_create(const char *name, int mflags, - taskqueue_enqueue_fn enqueue, void *context, void **); + taskqueue_enqueue_fn enqueue, void *context); int taskqueue_start_threads(struct taskqueue **tq, int count, int pri, const char *name, ...) __printflike(4, 5); void taskqueue_free(struct taskqueue *tq); void taskqueue_drain(struct taskqueue *tq, struct task *task); - +void taskqueue_block(struct taskqueue *queue); +void taskqueue_unblock(struct taskqueue *queue); int taskqueue_enqueue(struct taskqueue *tq, struct task *task); void taskqueue_thread_enqueue(void *context); diff --git a/src/libs/compat/freebsd_network/compat/sys/time.h b/src/libs/compat/freebsd_network/compat/sys/time.h new file mode 100644 index 0000000000..1bbabb743a --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/time.h @@ -0,0 +1,20 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_TIME_H_ +#define _FBSD_COMPAT_SYS_TIME_H_ + + +#include + +#include +#include + + +#define time_uptime system_time() / 1000000 + + +int ppsratecheck(struct timeval*, int*, int); + +#endif /* _FBSD_COMPAT_SYS_TIME_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/types.h b/src/libs/compat/freebsd_network/compat/sys/types.h index 878876a913..6ddc0ff23b 100644 --- a/src/libs/compat/freebsd_network/compat/sys/types.h +++ b/src/libs/compat/freebsd_network/compat/sys/types.h @@ -1,9 +1,20 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _FBSD_COMPAT_SYS_TYPES_H_ #define _FBSD_COMPAT_SYS_TYPES_H_ + #include #include +#include + +#include +#include + + typedef int boolean_t; #endif diff --git a/src/libs/compat/freebsd_network/compat/vm/uma.h b/src/libs/compat/freebsd_network/compat/vm/uma.h new file mode 100644 index 0000000000..5f6b8e9915 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/vm/uma.h @@ -0,0 +1,12 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_VM_UMA_H_ +#define _FBSD_COMPAT_VM_UMA_H_ + + +#include +#include + +#endif /* _FBSD_COMPAT_VM_UMA_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/vm/vm.h b/src/libs/compat/freebsd_network/compat/vm/vm.h index f9438de361..982426560c 100644 --- a/src/libs/compat/freebsd_network/compat/vm/vm.h +++ b/src/libs/compat/freebsd_network/compat/vm/vm.h @@ -9,13 +9,15 @@ #include #include -// for 32 bit machines + +// TODO at the moment for 32 bit machines only typedef uint32_t vm_offset_t; typedef uint32_t vm_paddr_t; typedef void *pmap_t; + #define vmspace_pmap(...) NULL #define pmap_extract(...) NULL diff --git a/src/libs/compat/freebsd_network/condvar.c b/src/libs/compat/freebsd_network/condvar.c new file mode 100644 index 0000000000..0c78a2be78 --- /dev/null +++ b/src/libs/compat/freebsd_network/condvar.c @@ -0,0 +1,42 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include +#include + +#include "condvar.h" + + +void cv_init(struct cv* conditionVariable, const char* description) +{ + _cv_init(conditionVariable, description); +} + + +void cv_signal(struct cv* conditionVariable) +{ + _cv_signal(conditionVariable); +} + + +int cv_timedwait(struct cv* conditionVariable, struct mtx* mutex, int timeout) +{ + int status; + + mtx_unlock(mutex); + status = _cv_timedwait_unlocked(conditionVariable, timeout); + mtx_lock(mutex); + + return status; +} + + +void cv_wait(struct cv* conditionVariable, struct mtx* mutex) +{ + mtx_unlock(mutex); + _cv_wait_unlocked(conditionVariable); + mtx_lock(mutex); +} diff --git a/src/libs/compat/freebsd_network/condvar.h b/src/libs/compat/freebsd_network/condvar.h new file mode 100644 index 0000000000..8ed4ce6619 --- /dev/null +++ b/src/libs/compat/freebsd_network/condvar.h @@ -0,0 +1,22 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All Rights Reserved. Distributed under the terms of the MIT License. + */ +#ifndef CONDVAR_H_ +#define CONDVAR_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +void _cv_init(struct cv*, const char*); +void _cv_wait_unlocked(struct cv *); +int _cv_timedwait_unlocked(struct cv*, int); +void _cv_signal(struct cv*); + +#ifdef __cplusplus +} +#endif + +#endif /* CONDVAR_H_ */ diff --git a/src/libs/compat/freebsd_network/device.c b/src/libs/compat/freebsd_network/device.c index b01aa591bb..14bd1664a2 100644 --- a/src/libs/compat/freebsd_network/device.c +++ b/src/libs/compat/freebsd_network/device.c @@ -2,10 +2,10 @@ * Copyright 2007-2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2004, Marcus Overhagen. All Rights Reserved. - * * Distributed under the terms of the MIT License. */ + #include "device.h" #include @@ -19,6 +19,7 @@ #include #include #include +#include static status_t @@ -36,9 +37,6 @@ compat_open(const char *name, uint32 flags, void **cookie) if (i == MAX_DEVICES) return B_ERROR; - if (get_module(NET_STACK_MODULE_NAME, (module_info **)&gStack) != B_OK) - return B_ERROR; - ifp = gDevices[i]; if_printf(ifp, "compat_open(0x%lx)\n", flags); @@ -49,8 +47,10 @@ compat_open(const char *name, uint32 flags, void **cookie) ifp->if_init(ifp->if_softc); - ifp->if_flags &= ~IFF_UP; - ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); + if (!HAIKU_DRIVER_REQUIRES(FBSD_WLAN)) { + ifp->if_flags &= ~IFF_UP; + ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); + } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_media = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0); @@ -71,9 +71,12 @@ compat_close(void *cookie) if_printf(ifp, "compat_close()\n"); - atomic_or(&ifp->flags, DEVICE_CLOSED); + atomic_or(&ifp->flags, DEVICE_CLOSED); + + wlan_close(cookie); release_sem_etc(ifp->receive_sem, 1, B_RELEASE_ALL); + return B_OK; } @@ -277,7 +280,7 @@ compat_control(void *cookie, uint32 op, void *arg, size_t length) return B_OK; } - return B_BAD_VALUE; + return wlan_control(cookie, op, arg, length); } @@ -289,4 +292,3 @@ device_hooks gDeviceHooks = { compat_read, compat_write, }; - diff --git a/src/libs/compat/freebsd_network/device.h b/src/libs/compat/freebsd_network/device.h index fe1d6ab379..00544d9909 100644 --- a/src/libs/compat/freebsd_network/device.h +++ b/src/libs/compat/freebsd_network/device.h @@ -1,8 +1,8 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. All Rights Reserved. * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved. * Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2004, Marcus Overhagen. All Rights Reserved. - * * Distributed under the terms of the MIT License. */ #ifndef DEVICE_H @@ -21,46 +21,9 @@ #include #include -#include +#include "shared.h" -#define MAX_DEVICES 8 - -struct ifnet; - -struct device { - struct device *parent; - struct device *root; - - driver_t *driver; - struct list children; - - int32 flags; - - char device_name[128]; - int unit; - char nameunit[64]; - const char *description; - void *softc; - void *ivars; - - struct { - int (*probe)(device_t dev); - int (*attach)(device_t dev); - int (*detach)(device_t dev); - int (*suspend)(device_t dev); - int (*resume)(device_t dev); - void (*shutdown)(device_t dev); - - int (*miibus_readreg)(device_t, int, int); - int (*miibus_writereg)(device_t, int, int, int); - void (*miibus_statchg)(device_t); - void (*miibus_linkchg)(device_t); - void (*miibus_mediainit)(device_t); - } methods; - - struct list_link link; -}; struct root_device_softc { struct pci_info pci_info; @@ -78,10 +41,6 @@ enum { extern struct net_stack_module_info *gStack; extern pci_module_info *gPci; -extern const char *gDeviceNameList[]; -extern struct ifnet *gDevices[]; -extern int32 gDeviceCount; - static inline void __unimplemented(const char *method) @@ -91,7 +50,6 @@ __unimplemented(const char *method) panic(msg); } - #define UNIMPLEMENTED() __unimplemented(__FUNCTION__) status_t init_mbufs(void); @@ -103,7 +61,13 @@ void uninit_mutexes(void); status_t init_taskqueues(void); void uninit_taskqueues(void); -device_t find_root_device(int unit); +status_t init_condition_variables(void); +void uninit_condition_variables(void); + +status_t init_clock(void); +void uninit_clock(void); + +device_t find_root_device(int); /* busdma_machdep.c */ void init_bounce_pages(void); @@ -116,7 +80,7 @@ void driver_vprintf(const char *format, va_list vl); void device_sprintf_name(device_t dev, const char *format, ...) __attribute__ ((format (__printf__, 2, 3))); -void ifq_init(struct ifqueue *ifq, const char *name); -void ifq_uninit(struct ifqueue *ifq); +void ifq_init(struct ifqueue *, const char *); +void ifq_uninit(struct ifqueue *); #endif /* DEVICE_H */ diff --git a/src/libs/compat/freebsd_network/driver.c b/src/libs/compat/freebsd_network/driver.c index 2a9f7b5dc4..515dc4d37e 100644 --- a/src/libs/compat/freebsd_network/driver.c +++ b/src/libs/compat/freebsd_network/driver.c @@ -2,10 +2,10 @@ * Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved. * Copyright 2004, Marcus Overhagen. All Rights Reserved. - * * Distributed under the terms of the MIT License. */ + /*! Driver functions that adapt the FreeBSD driver to Haiku's driver API. The actual driver functions are exported by the HAIKU_FBSD_DRIVER_GLUE macro, and just call the functions here. @@ -26,7 +26,8 @@ #include #include -#define TRACE_DRIVER + +//#define TRACE_DRIVER #ifdef TRACE_DRIVER # define TRACE(x) dprintf x #else @@ -158,12 +159,20 @@ _fbsd_init_driver(driver_t *driver) init_bounce_pages(); + status = init_condition_variables(); + if (status < B_OK) + goto err3; + if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) { status = init_taskqueues(); if (status < B_OK) - goto err3; + goto err4; } + status = init_wlan_stack(); + if (status < B_OK) + goto err5; + while (gDeviceCount < MAX_DEVICES) { device_t root, device; bool found = false; @@ -198,8 +207,13 @@ _fbsd_init_driver(driver_t *driver) if (status == B_OK) status = B_ERROR; + uninit_wlan_stack(); + +err5: if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) uninit_taskqueues(); +err4: + uninit_condition_variables(); err3: uninit_mbufs(); err2: @@ -221,6 +235,8 @@ _fbsd_uninit_driver(driver_t *driver) device_delete_child(NULL, gDevices[i]->root_device); } + uninit_wlan_stack(); + uninit_condition_variables(); uninit_bounce_pages(); uninit_mbufs(); if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) diff --git a/src/libs/compat/freebsd_network/eventhandler.c b/src/libs/compat/freebsd_network/eventhandler.c index 5714b1e366..1d4ac8255c 100644 --- a/src/libs/compat/freebsd_network/eventhandler.c +++ b/src/libs/compat/freebsd_network/eventhandler.c @@ -6,10 +6,12 @@ * Michael Weirauch, dev@m-phasis.de */ + #include #include + eventhandler_tag eventhandler_register(struct eventhandler_list *list, const char *name, void *func, void *arg, int priority) diff --git a/src/libs/compat/freebsd_network/fbsd_busdma_x86.c b/src/libs/compat/freebsd_network/fbsd_busdma_x86.c index 90a6d09e2c..7c26791d77 100644 --- a/src/libs/compat/freebsd_network/fbsd_busdma_x86.c +++ b/src/libs/compat/freebsd_network/fbsd_busdma_x86.c @@ -23,7 +23,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include __FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.74.2.4 2006/10/21 16:26:53 hrs Exp $"); @@ -51,7 +50,6 @@ __FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.74.2.4 2006/10/21 16: #define free(a, b) kernel_free(a, b) #define contigmalloc(a, b, c, d, e, f, g) kernel_contigmalloc(a, b, c, d, e, f, g) #define contigfree(a, b, c) kernel_contigfree(a, b, c) -#define __unused void busdma_swi(void); void init_bounce_pages(void); void uninit_bounce_pages(void); @@ -149,7 +147,8 @@ static __inline int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); * If paddr is within the bounds of the dma tag then call the filter callback * to check for a match, if there is no filter callback then assume a match. */ -static __inline int +static __inline +int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr) { int retval; @@ -198,7 +197,8 @@ busdma_lock_mutex(void *arg, bus_dma_lock_op_t op) * with the tag are meant to never be defered. * XXX Should have a way to identify which driver is responsible here. */ -static void +static +void dflt_lock(void *arg, bus_dma_lock_op_t op) { panic("driver error: busdma dflt_lock called"); @@ -206,6 +206,7 @@ dflt_lock(void *arg, bus_dma_lock_op_t op) #define BUS_DMA_COULD_BOUNCE BUS_DMA_BUS3 #define BUS_DMA_MIN_ALLOC_COMP BUS_DMA_BUS4 + /* * Allocate a device specific dma_tag. */ @@ -464,7 +465,6 @@ bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) return (0); } - /* * Allocate a piece of memory that can be efficiently mapped into * bus device space based on the constraints lited in the dma tag. @@ -742,7 +742,6 @@ bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, return (0); } - /* * Like _bus_dmamap_load(), but for mbufs. */ @@ -937,7 +936,6 @@ _bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op) } } - void init_bounce_pages() { @@ -949,7 +947,6 @@ init_bounce_pages() mtx_init(&bounce_lock, "bounce pages lock", NULL, MTX_DEF); } - /* Haiku extension */ void uninit_bounce_pages() @@ -959,7 +956,6 @@ uninit_bounce_pages() mtx_destroy(&bounce_lock); } - static struct sysctl_ctx_list * busdma_sysctl_tree(struct bounce_zone *bz) { diff --git a/src/libs/compat/freebsd_network/fbsd_ether.c b/src/libs/compat/freebsd_network/fbsd_ether.c index 6e661909d2..e219cc6743 100644 --- a/src/libs/compat/freebsd_network/fbsd_ether.c +++ b/src/libs/compat/freebsd_network/fbsd_ether.c @@ -29,7 +29,6 @@ * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.193.2.12 2006/08/28 02:54:14 thompsa Exp $ */ - #include #include #include @@ -107,7 +106,6 @@ ether_crc32_be(const uint8_t *buf, size_t len) return (crc); } - char * ether_sprintf(const u_char *ap) { diff --git a/src/libs/compat/freebsd_network/fbsd_if_media.c b/src/libs/compat/freebsd_network/fbsd_if_media.c index 07b6fe276f..31ec12ddb9 100644 --- a/src/libs/compat/freebsd_network/fbsd_if_media.c +++ b/src/libs/compat/freebsd_network/fbsd_if_media.c @@ -45,12 +45,14 @@ * Many thanks to Matt Thomas for providing the information necessary * to implement this interface. */ +#include #include #include #include #include #include +#include #include #include diff --git a/src/libs/compat/freebsd_network/fbsd_mbuf.c b/src/libs/compat/freebsd_network/fbsd_mbuf.c index 4486d1fe8e..58adc17d38 100644 --- a/src/libs/compat/freebsd_network/fbsd_mbuf.c +++ b/src/libs/compat/freebsd_network/fbsd_mbuf.c @@ -28,8 +28,8 @@ * * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94 */ - #include +#include #include /* @@ -61,7 +61,6 @@ m_copydata(const struct mbuf *m, int off, int len, caddr_t cp) } } - /* * Concatenate mbuf chain n to m. * Both chains must be of the same type (e.g. MT_DATA). @@ -87,7 +86,6 @@ m_cat(struct mbuf *m, struct mbuf *n) } } - u_int m_length(struct mbuf *m0, struct mbuf **last) { @@ -105,7 +103,6 @@ m_length(struct mbuf *m0, struct mbuf **last) return (len); } - u_int m_fixhdr(struct mbuf *m0) { @@ -116,33 +113,23 @@ m_fixhdr(struct mbuf *m0) return (len); } - -static int -m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int how) -{ - return 1; -} - - /* * Duplicate "from"'s mbuf pkthdr in "to". * "from" must have M_PKTHDR set, and "to" must be empty. * In particular, this does a deep copy of the packet tags. */ -static int +int m_dup_pkthdr(struct mbuf *to, struct mbuf *from, int how) { MBUF_CHECKSLEEP(how); - /* to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); */ - to->m_flags = (to->m_flags & M_EXT); + to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); if ((to->m_flags & M_EXT) == 0) to->m_data = to->m_pktdat; to->m_pkthdr = from->m_pkthdr; - /* SLIST_INIT(&to->m_pkthdr.tags); */ + SLIST_INIT(&to->m_pkthdr.tags); return (m_tag_copy_chain(to, from, MBTOM(how))); } - /* * Defragment a mbuf chain, returning the shortest possible * chain of mbufs and clusters. If allocation fails and @@ -210,7 +197,6 @@ nospace: return (NULL); } - void m_adj(struct mbuf *mp, int req_len) { @@ -285,7 +271,6 @@ m_adj(struct mbuf *mp, int req_len) } } - /* * Rearange an mbuf chain so that len bytes are contiguous * and in the data area of an mbuf (so that mtod and dtom @@ -348,7 +333,6 @@ bad: return (NULL); } - /* * Lesser-used path for M_PREPEND: * allocate new mbuf to prepend to chain, @@ -377,7 +361,6 @@ m_prepend(struct mbuf *m, int len, int how) return (m); } - /* * "Move" mbuf pkthdr from "from" to "to". * "from" must have M_PKTHDR set, and "to" must be empty. @@ -392,16 +375,11 @@ m_move_pkthdr(struct mbuf *to, struct mbuf *from) if (to->m_flags & M_PKTHDR) m_tag_delete_chain(to, NULL); #endif - /* to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); */ - /* we don't have M_COPYFLAGS -hugo */ - to->m_flags = to->m_flags & M_EXT; + to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); if ((to->m_flags & M_EXT) == 0) to->m_data = to->m_pktdat; to->m_pkthdr = from->m_pkthdr; /* especially tags */ - /* we don't have tags -hugo */ -#if 0 SLIST_INIT(&from->m_pkthdr.tags); /* purge tags from src */ -#endif from->m_flags &= ~M_PKTHDR; } @@ -606,3 +584,389 @@ again: bad: return NULL; } + +/* + * Attach the the cluster from *m to *n, set up m_ext in *n + * and bump the refcount of the cluster. + */ +static void +mb_dupcl(struct mbuf *n, struct mbuf *m) +{ + KASSERT((m->m_flags & M_EXT) == M_EXT, ("%s: M_EXT not set", __func__)); + KASSERT((n->m_flags & M_EXT) == 0, ("%s: M_EXT set", __func__)); + + n->m_ext.ext_buf = m->m_ext.ext_buf; + n->m_ext.ext_size = m->m_ext.ext_size; + n->m_ext.ext_type = m->m_ext.ext_type; + n->m_flags |= M_EXT; +} + +/* + * Partition an mbuf chain in two pieces, returning the tail -- + * all but the first len0 bytes. In case of failure, it returns NULL and + * attempts to restore the chain to its original state. + * + * Note that the resulting mbufs might be read-only, because the new + * mbuf can end up sharing an mbuf cluster with the original mbuf if + * the "breaking point" happens to lie within a cluster mbuf. Use the + * M_WRITABLE() macro to check for this case. + */ +struct mbuf * +m_split(struct mbuf *m0, int len0, int wait) +{ + struct mbuf *m, *n; + u_int len = len0, remain; + + MBUF_CHECKSLEEP(wait); + for (m = m0; m && len > m->m_len; m = m->m_next) + len -= m->m_len; + if (m == NULL) + return (NULL); + remain = m->m_len - len; + if (m0->m_flags & M_PKTHDR) { + MGETHDR(n, wait, m0->m_type); + if (n == NULL) + return (NULL); + n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif; + n->m_pkthdr.len = m0->m_pkthdr.len - len0; + m0->m_pkthdr.len = len0; + if (m->m_flags & M_EXT) + goto extpacket; + if (remain > MHLEN) { + /* m can't be the lead packet */ + MH_ALIGN(n, 0); + n->m_next = m_split(m, len, wait); + if (n->m_next == NULL) { + (void) m_free(n); + return (NULL); + } else { + n->m_len = 0; + return (n); + } + } else + MH_ALIGN(n, remain); + } else if (remain == 0) { + n = m->m_next; + m->m_next = NULL; + return (n); + } else { + MGET(n, wait, m->m_type); + if (n == NULL) + return (NULL); + M_ALIGN(n, remain); + } +extpacket: + if (m->m_flags & M_EXT) { + n->m_data = m->m_data + len; + mb_dupcl(n, m); + } else { + bcopy(mtod(m, caddr_t) + len, mtod(n, caddr_t), remain); + } + n->m_len = remain; + m->m_len = len; + n->m_next = m->m_next; + m->m_next = NULL; + return (n); +} + +/* + * Copy a packet header mbuf chain into a completely new chain, including + * copying any mbuf clusters. Use this instead of m_copypacket() when + * you need a writable copy of an mbuf chain. + */ +struct mbuf * +m_dup(struct mbuf *m, int how) +{ + struct mbuf **p, *top = NULL; + int remain, moff, nsize; + + MBUF_CHECKSLEEP(how); + /* Sanity check */ + if (m == NULL) + return (NULL); + M_ASSERTPKTHDR(m); + + /* While there's more data, get a new mbuf, tack it on, and fill it */ + remain = m->m_pkthdr.len; + moff = 0; + p = ⊤ + while (remain > 0 || top == NULL) { /* allow m->m_pkthdr.len == 0 */ + struct mbuf *n; + + /* Get the next new mbuf */ + if (remain >= MINCLSIZE) { + n = m_getcl(how, m->m_type, 0); + nsize = MCLBYTES; + } else { + n = m_get(how, m->m_type); + nsize = MLEN; + } + if (n == NULL) + goto nospace; + + if (top == NULL) { /* First one, must be PKTHDR */ + if (!m_dup_pkthdr(n, m, how)) { + m_free(n); + goto nospace; + } + if ((n->m_flags & M_EXT) == 0) + nsize = MHLEN; + } + n->m_len = 0; + + /* Link it into the new chain */ + *p = n; + p = &n->m_next; + + /* Copy data from original mbuf(s) into new mbuf */ + while (n->m_len < nsize && m != NULL) { + int chunk = min(nsize - n->m_len, m->m_len - moff); + + bcopy(m->m_data + moff, n->m_data + n->m_len, chunk); + moff += chunk; + n->m_len += chunk; + remain -= chunk; + if (moff == m->m_len) { + m = m->m_next; + moff = 0; + } + } + + /* Check correct total mbuf length */ + KASSERT((remain > 0 && m != NULL) || (remain == 0 && m == NULL), + ("%s: bogus m_pkthdr.len", __func__)); + } + return (top); + +nospace: + m_freem(top); + return (NULL); +} + +/* + * Create a writable copy of the mbuf chain. While doing this + * we compact the chain with a goal of producing a chain with + * at most two mbufs. The second mbuf in this chain is likely + * to be a cluster. The primary purpose of this work is to create + * a writable packet for encryption, compression, etc. The + * secondary goal is to linearize the data so the data can be + * passed to crypto hardware in the most efficient manner possible. + */ +struct mbuf * +m_unshare(struct mbuf *m0, int how) +{ + struct mbuf *m, *mprev; + struct mbuf *n, *mfirst, *mlast; + int len, off; + + mprev = NULL; + for (m = m0; m != NULL; m = mprev->m_next) { + /* + * Regular mbufs are ignored unless there's a cluster + * in front of it that we can use to coalesce. We do + * the latter mainly so later clusters can be coalesced + * also w/o having to handle them specially (i.e. convert + * mbuf+cluster -> cluster). This optimization is heavily + * influenced by the assumption that we're running over + * Ethernet where MCLBYTES is large enough that the max + * packet size will permit lots of coalescing into a + * single cluster. This in turn permits efficient + * crypto operations, especially when using hardware. + */ + if ((m->m_flags & M_EXT) == 0) { + if (mprev && (mprev->m_flags & M_EXT) && + m->m_len <= M_TRAILINGSPACE(mprev)) { + /* XXX: this ignores mbuf types */ + memcpy(mtod(mprev, caddr_t) + mprev->m_len, + mtod(m, caddr_t), m->m_len); + mprev->m_len += m->m_len; + mprev->m_next = m->m_next; /* unlink from chain */ + m_free(m); /* reclaim mbuf */ +#if 0 + newipsecstat.ips_mbcoalesced++; +#endif + } else { + mprev = m; + } + continue; + } + /* + * Writable mbufs are left alone (for now). + */ + if (M_WRITABLE(m)) { + mprev = m; + continue; + } + + /* + * Not writable, replace with a copy or coalesce with + * the previous mbuf if possible (since we have to copy + * it anyway, we try to reduce the number of mbufs and + * clusters so that future work is easier). + */ + KASSERT(m->m_flags & M_EXT, ("m_flags 0x%x", m->m_flags)); + /* NB: we only coalesce into a cluster or larger */ + if (mprev != NULL && (mprev->m_flags & M_EXT) && + m->m_len <= M_TRAILINGSPACE(mprev)) { + /* XXX: this ignores mbuf types */ + memcpy(mtod(mprev, caddr_t) + mprev->m_len, + mtod(m, caddr_t), m->m_len); + mprev->m_len += m->m_len; + mprev->m_next = m->m_next; /* unlink from chain */ + m_free(m); /* reclaim mbuf */ +#if 0 + newipsecstat.ips_clcoalesced++; +#endif + continue; + } + + /* + * Allocate new space to hold the copy... + */ + /* XXX why can M_PKTHDR be set past the first mbuf? */ + if (mprev == NULL && (m->m_flags & M_PKTHDR)) { + /* + * NB: if a packet header is present we must + * allocate the mbuf separately from any cluster + * because M_MOVE_PKTHDR will smash the data + * pointer and drop the M_EXT marker. + */ + MGETHDR(n, how, m->m_type); + if (n == NULL) { + m_freem(m0); + return (NULL); + } + M_MOVE_PKTHDR(n, m); + MCLGET(n, how); + if ((n->m_flags & M_EXT) == 0) { + m_free(n); + m_freem(m0); + return (NULL); + } + } else { + n = m_getcl(how, m->m_type, m->m_flags); + if (n == NULL) { + m_freem(m0); + return (NULL); + } + } + /* + * ... and copy the data. We deal with jumbo mbufs + * (i.e. m_len > MCLBYTES) by splitting them into + * clusters. We could just malloc a buffer and make + * it external but too many device drivers don't know + * how to break up the non-contiguous memory when + * doing DMA. + */ + len = m->m_len; + off = 0; + mfirst = n; + mlast = NULL; + for (;;) { + int cc = min(len, MCLBYTES); + memcpy(mtod(n, caddr_t), mtod(m, caddr_t) + off, cc); + n->m_len = cc; + if (mlast != NULL) + mlast->m_next = n; + mlast = n; +#if 0 + newipsecstat.ips_clcopied++; +#endif + + len -= cc; + if (len <= 0) + break; + off += cc; + + n = m_getcl(how, m->m_type, m->m_flags); + if (n == NULL) { + m_freem(mfirst); + m_freem(m0); + return (NULL); + } + } + n->m_next = m->m_next; + if (mprev == NULL) + m0 = mfirst; /* new head of chain */ + else + mprev->m_next = mfirst; /* replace old mbuf */ + m_free(m); /* release old mbuf */ + mprev = mfirst; + } + return (m0); +} + +/* + * Set the m_data pointer of a newly-allocated mbuf + * to place an object of the specified size at the + * end of the mbuf, longword aligned. + */ +void +m_align(struct mbuf *m, int len) +{ + int adjust; + + if (m->m_flags & M_EXT) + adjust = m->m_ext.ext_size - len; + else if (m->m_flags & M_PKTHDR) + adjust = MHLEN - len; + else + adjust = MLEN - len; + m->m_data += adjust &~ (sizeof(long)-1); +} + +/* + * Copy an entire packet, including header (which must be present). + * An optimization of the common case `m_copym(m, 0, M_COPYALL, how)'. + * Note that the copy is read-only, because clusters are not copied, + * only their reference counts are incremented. + * Preserve alignment of the first mbuf so if the creator has left + * some room at the beginning (e.g. for inserting protocol headers) + * the copies still have the room available. + */ +struct mbuf * +m_copypacket(struct mbuf *m, int how) +{ + struct mbuf *top, *n, *o; + + MBUF_CHECKSLEEP(how); + MGET(n, how, m->m_type); + top = n; + if (n == NULL) + goto nospace; + + if (!m_dup_pkthdr(n, m, how)) + goto nospace; + n->m_len = m->m_len; + if (m->m_flags & M_EXT) { + n->m_data = m->m_data; + mb_dupcl(n, m); + } else { + n->m_data = n->m_pktdat + (m->m_data - m->m_pktdat ); + bcopy(mtod(m, char *), mtod(n, char *), n->m_len); + } + + m = m->m_next; + while (m) { + MGET(o, how, m->m_type); + if (o == NULL) + goto nospace; + + n->m_next = o; + n = n->m_next; + + n->m_len = m->m_len; + if (m->m_flags & M_EXT) { + n->m_data = m->m_data; + mb_dupcl(n, m); + } else { + bcopy(mtod(m, char *), mtod(n, char *), n->m_len); + } + + m = m->m_next; + } + return top; +nospace: + m_freem(top); + return (NULL); +} diff --git a/src/libs/compat/freebsd_network/fbsd_mbuf2.c b/src/libs/compat/freebsd_network/fbsd_mbuf2.c new file mode 100644 index 0000000000..3f7661c26c --- /dev/null +++ b/src/libs/compat/freebsd_network/fbsd_mbuf2.c @@ -0,0 +1,452 @@ +/* $KAME: uipc_mbuf2.c,v 1.31 2001/11/28 11:08:53 itojun Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */ + +/*- + * Copyright (C) 1999 WIDE Project. + * 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. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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. + */ +/*- + * Copyright (c) 1982, 1986, 1988, 1991, 1993 + * The Regents of the University of California. 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. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * @(#)uipc_mbuf.c 8.4 (Berkeley) 2/14/95 + */ +#include +__FBSDID("$FreeBSD$"); + +/*#define PULLDOWN_DEBUG*/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define malloc(size, tag, flags) kernel_malloc(size, tag, flags) +#define free(pointer, tag) kernel_free(pointer, tag) + +/* can't call it m_dup(), as freebsd[34] uses m_dup() with different arg */ +static struct mbuf *m_dup1(struct mbuf *, int, int, int); + +/* + * ensure that [off, off + len) is contiguous on the mbuf chain "m". + * packet chain before "off" is kept untouched. + * if offp == NULL, the target will start at on resulting chain. + * if offp != NULL, the target will start at on resulting chain. + * + * on error return (NULL return value), original "m" will be freed. + * + * XXX: M_TRAILINGSPACE/M_LEADINGSPACE only permitted on writable ext_buf. + */ +struct mbuf * +m_pulldown(struct mbuf *m, int off, int len, int *offp) +{ + struct mbuf *n, *o; + int hlen, tlen, olen; + int writable; + + /* check invalid arguments. */ + if (m == NULL) + panic("m == NULL in m_pulldown()"); + if (len > MCLBYTES) { + m_freem(m); + return NULL; /* impossible */ + } + +#ifdef PULLDOWN_DEBUG + { + struct mbuf *t; + printf("before:"); + for (t = m; t; t = t->m_next) + printf(" %d", t->m_len); + printf("\n"); + } +#endif + n = m; + while (n != NULL && off > 0) { + if (n->m_len > off) + break; + off -= n->m_len; + n = n->m_next; + } + /* be sure to point non-empty mbuf */ + while (n != NULL && n->m_len == 0) + n = n->m_next; + if (!n) { + m_freem(m); + return NULL; /* mbuf chain too short */ + } + + /* + * XXX: This code is flawed because it considers a "writable" mbuf + * data region to require all of the following: + * (i) mbuf _has_ to have M_EXT set; if it is just a regular + * mbuf, it is still not considered "writable." + * (ii) since mbuf has M_EXT, the ext_type _has_ to be + * EXT_CLUSTER. Anything else makes it non-writable. + * (iii) M_WRITABLE() must evaluate true. + * Ideally, the requirement should only be (iii). + * + * If we're writable, we're sure we're writable, because the ref. count + * cannot increase from 1, as that would require posession of mbuf + * n by someone else (which is impossible). However, if we're _not_ + * writable, we may eventually become writable )if the ref. count drops + * to 1), but we'll fail to notice it unless we re-evaluate + * M_WRITABLE(). For now, we only evaluate once at the beginning and + * live with this. + */ + /* + * XXX: This is dumb. If we're just a regular mbuf with no M_EXT, + * then we're not "writable," according to this code. + */ + writable = 0; + if ((n->m_flags & M_EXT) == 0 || + (n->m_ext.ext_type == EXT_CLUSTER && M_WRITABLE(n))) + writable = 1; + + /* + * the target data is on . + * if we got enough data on the mbuf "n", we're done. + */ + if ((off == 0 || offp) && len <= n->m_len - off && writable) + goto ok; + + /* + * when len <= n->m_len - off and off != 0, it is a special case. + * len bytes from sits in single mbuf, but the caller does + * not like the starting position (off). + * chop the current mbuf into two pieces, set off to 0. + */ + if (len <= n->m_len - off) { + o = m_dup1(n, off, n->m_len - off, M_DONTWAIT); + if (o == NULL) { + m_freem(m); + return NULL; /* ENOBUFS */ + } + n->m_len = off; + o->m_next = n->m_next; + n->m_next = o; + n = n->m_next; + off = 0; + goto ok; + } + + /* + * we need to take hlen from and tlen from m_next, 0>, + * and construct contiguous mbuf with m_len == len. + * note that hlen + tlen == len, and tlen > 0. + */ + hlen = n->m_len - off; + tlen = len - hlen; + + /* + * ensure that we have enough trailing data on mbuf chain. + * if not, we can do nothing about the chain. + */ + olen = 0; + for (o = n->m_next; o != NULL; o = o->m_next) + olen += o->m_len; + if (hlen + olen < len) { + m_freem(m); + return NULL; /* mbuf chain too short */ + } + + /* + * easy cases first. + * we need to use m_copydata() to get data from m_next, 0>. + */ + if ((off == 0 || offp) && M_TRAILINGSPACE(n) >= tlen + && writable) { + m_copydata(n->m_next, 0, tlen, mtod(n, caddr_t) + n->m_len); + n->m_len += tlen; + m_adj(n->m_next, tlen); + goto ok; + } + if ((off == 0 || offp) && M_LEADINGSPACE(n->m_next) >= hlen + && writable) { + n->m_next->m_data -= hlen; + n->m_next->m_len += hlen; + bcopy(mtod(n, caddr_t) + off, mtod(n->m_next, caddr_t), hlen); + n->m_len -= hlen; + n = n->m_next; + off = 0; + goto ok; + } + + /* + * now, we need to do the hard way. don't m_copy as there's no room + * on both end. + */ + if (len > MLEN) + o = m_getcl(M_DONTWAIT, m->m_type, 0); + else + o = m_get(M_DONTWAIT, m->m_type); + if (!o) { + m_freem(m); + return NULL; /* ENOBUFS */ + } + /* get hlen from into */ + o->m_len = hlen; + bcopy(mtod(n, caddr_t) + off, mtod(o, caddr_t), hlen); + n->m_len -= hlen; + /* get tlen from m_next, 0> into */ + m_copydata(n->m_next, 0, tlen, mtod(o, caddr_t) + o->m_len); + o->m_len += tlen; + m_adj(n->m_next, tlen); + o->m_next = n->m_next; + n->m_next = o; + n = o; + off = 0; + +ok: +#ifdef PULLDOWN_DEBUG + { + struct mbuf *t; + printf("after:"); + for (t = m; t; t = t->m_next) + printf("%c%d", t == n ? '*' : ' ', t->m_len); + printf(" (off=%d)\n", off); + } +#endif + if (offp) + *offp = off; + return n; +} + +static struct mbuf * +m_dup1(struct mbuf *m, int off, int len, int wait) +{ + struct mbuf *n; + int copyhdr; + + if (len > MCLBYTES) + return NULL; + if (off == 0 && (m->m_flags & M_PKTHDR) != 0) + copyhdr = 1; + else + copyhdr = 0; + if (len >= MINCLSIZE) { + if (copyhdr == 1) + n = m_getcl(wait, m->m_type, M_PKTHDR); + else + n = m_getcl(wait, m->m_type, 0); + } else { + if (copyhdr == 1) + n = m_gethdr(wait, m->m_type); + else + n = m_get(wait, m->m_type); + } + if (!n) + return NULL; /* ENOBUFS */ + + if (copyhdr && !m_dup_pkthdr(n, m, wait)) { + m_free(n); + return NULL; + } + m_copydata(m, off, len, mtod(n, caddr_t)); + n->m_len = len; + return n; +} + +/* Free a packet tag. */ +void +m_tag_free_default(struct m_tag *t) +{ +#ifdef MAC + if (t->m_tag_id == PACKET_TAG_MACLABEL) + mac_mbuf_tag_destroy(t); +#endif + free(t, M_PACKET_TAGS); +} + +/* Get a packet tag structure along with specified data following. */ +struct m_tag * +m_tag_alloc(u_int32_t cookie, int type, int len, int wait) +{ + struct m_tag *t; + + MBUF_CHECKSLEEP(wait); + if (len < 0) + return NULL; + t = malloc(len + sizeof(struct m_tag), M_PACKET_TAGS, wait); + if (t == NULL) + return NULL; + m_tag_setup(t, cookie, type, len); + t->m_tag_free = m_tag_free_default; + return t; +} + +/* Unlink and free a packet tag. */ +void +m_tag_delete(struct mbuf *m, struct m_tag *t) +{ + + KASSERT(m && t, ("m_tag_delete: null argument, m %p t %p", m, t)); + m_tag_unlink(m, t); + m_tag_free(t); +} + +/* Unlink and free a packet tag chain, starting from given tag. */ +void +m_tag_delete_chain(struct mbuf *m, struct m_tag *t) +{ + struct m_tag *p, *q; + + KASSERT(m, ("m_tag_delete_chain: null mbuf")); + if (t != NULL) + p = t; + else + p = SLIST_FIRST(&m->m_pkthdr.tags); + if (p == NULL) + return; + while ((q = SLIST_NEXT(p, m_tag_link)) != NULL) + m_tag_delete(m, q); + m_tag_delete(m, p); +} + +/* + * Strip off all tags that would normally vanish when + * passing through a network interface. Only persistent + * tags will exist after this; these are expected to remain + * so long as the mbuf chain exists, regardless of the + * path the mbufs take. + */ +void +m_tag_delete_nonpersistent(struct mbuf *m) +{ + struct m_tag *p, *q; + + SLIST_FOREACH_SAFE(p, &m->m_pkthdr.tags, m_tag_link, q) + if ((p->m_tag_id & MTAG_PERSISTENT) == 0) + m_tag_delete(m, p); +} + +/* Find a tag, starting from a given position. */ +struct m_tag * +m_tag_locate(struct mbuf *m, u_int32_t cookie, int type, struct m_tag *t) +{ + struct m_tag *p; + + KASSERT(m, ("m_tag_locate: null mbuf")); + if (t == NULL) + p = SLIST_FIRST(&m->m_pkthdr.tags); + else + p = SLIST_NEXT(t, m_tag_link); + while (p != NULL) { + if (p->m_tag_cookie == cookie && p->m_tag_id == type) + return p; + p = SLIST_NEXT(p, m_tag_link); + } + return NULL; +} + +/* Copy a single tag. */ +struct m_tag * +m_tag_copy(struct m_tag *t, int how) +{ + struct m_tag *p; + + MBUF_CHECKSLEEP(how); + KASSERT(t, ("m_tag_copy: null tag")); + p = m_tag_alloc(t->m_tag_cookie, t->m_tag_id, t->m_tag_len, how); + if (p == NULL) + return (NULL); +#ifdef MAC + /* + * XXXMAC: we should probably pass off the initialization, and + * copying here? can we hide that PACKET_TAG_MACLABEL is + * special from the mbuf code? + */ + if (t->m_tag_id == PACKET_TAG_MACLABEL) { + if (mac_mbuf_tag_init(p, how) != 0) { + m_tag_free(p); + return (NULL); + } + mac_mbuf_tag_copy(t, p); + } else +#endif + bcopy(t + 1, p + 1, t->m_tag_len); /* Copy the data */ + return p; +} + +/* + * Copy two tag chains. The destination mbuf (to) loses any attached + * tags even if the operation fails. This should not be a problem, as + * m_tag_copy_chain() is typically called with a newly-allocated + * destination mbuf. + */ +int +m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int how) +{ + struct m_tag *p, *t, *tprev = NULL; + + MBUF_CHECKSLEEP(how); + KASSERT(to && from, + ("m_tag_copy_chain: null argument, to %p from %p", to, from)); + m_tag_delete_chain(to, NULL); + SLIST_FOREACH(p, &from->m_pkthdr.tags, m_tag_link) { + t = m_tag_copy(p, how); + if (t == NULL) { + m_tag_delete_chain(to, NULL); + return 0; + } + if (tprev == NULL) + SLIST_INSERT_HEAD(&to->m_pkthdr.tags, t, m_tag_link); + else + SLIST_INSERT_AFTER(tprev, t, m_tag_link); + tprev = t; + } + return 1; +} diff --git a/src/libs/compat/freebsd_network/fbsd_mii.c b/src/libs/compat/freebsd_network/fbsd_mii.c index 75cbc77615..cca08c0fa0 100644 --- a/src/libs/compat/freebsd_network/fbsd_mii.c +++ b/src/libs/compat/freebsd_network/fbsd_mii.c @@ -36,7 +36,6 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - #include "device.h" #include diff --git a/src/libs/compat/freebsd_network/fbsd_mii_physubr.c b/src/libs/compat/freebsd_network/fbsd_mii_physubr.c index cfd7f27bda..1fa0b65869 100644 --- a/src/libs/compat/freebsd_network/fbsd_mii_physubr.c +++ b/src/libs/compat/freebsd_network/fbsd_mii_physubr.c @@ -36,7 +36,6 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - #include __FBSDID("$FreeBSD: src/sys/dev/mii/mii_physubr.c,v 1.22.2.2 2006/07/29 08:30:12 oleg Exp $"); @@ -52,7 +51,6 @@ __FBSDID("$FreeBSD: src/sys/dev/mii/mii_physubr.c,v 1.22.2.2 2006/07/29 08:30:12 #include #include - #include #include @@ -394,9 +392,6 @@ mii_add_media(struct mii_softc *sc) BMCR_AUTOEN); PRINT("auto"); } - - - #undef ADD #undef PRINT } @@ -531,6 +526,7 @@ mii_phy_detach(device_t dev) return(0); } + const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd) { diff --git a/src/libs/compat/freebsd_network/fbsd_time.c b/src/libs/compat/freebsd_network/fbsd_time.c new file mode 100644 index 0000000000..7ab8fcae72 --- /dev/null +++ b/src/libs/compat/freebsd_network/fbsd_time.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. 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. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * @(#)kern_time.c 8.1 (Berkeley) 6/10/93 + */ +#include +#include + +int +ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps) +{ + int now; + + /* + * Reset the last time and counter if this is the first call + * or more than a second has passed since the last update of + * lasttime. + */ + now = ticks; + if (lasttime->tv_sec == 0 || (u_int)(now - lasttime->tv_sec) >= hz) { + lasttime->tv_sec = now; + *curpps = 1; + return (maxpps != 0); + } else { + (*curpps)++; /* NB: ignore potential overflow */ + return (maxpps < 0 || *curpps < maxpps); + } +} diff --git a/src/libs/compat/freebsd_network/firmware.c b/src/libs/compat/freebsd_network/firmware.c new file mode 100644 index 0000000000..67f2745577 --- /dev/null +++ b/src/libs/compat/freebsd_network/firmware.c @@ -0,0 +1,93 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All Rights Reserved. Distributed under the terms of the MIT License. + * + */ + + +#include +#include +#include + +#include +#include + +#include +#include +#include + + +const struct firmware* +firmware_get(const char* imageName) +{ + int fileDescriptor; + struct firmware* firmware = NULL; + int32 firmwareFileSize; + char* firmwareName; + char* firmwarePath; + ssize_t readCount; + + firmwarePath = (char*)malloc(B_PATH_NAME_LENGTH); + if (firmwarePath == NULL) + goto cleanup0; + + if (find_directory(B_SYSTEM_DATA_DIRECTORY, -1, false, + firmwarePath, B_PATH_NAME_LENGTH) != B_OK) + goto cleanup1; + + strlcat(firmwarePath, "/firmware/", B_PATH_NAME_LENGTH); + strlcat(firmwarePath, gDriverName, B_PATH_NAME_LENGTH); + strlcat(firmwarePath, "/", B_PATH_NAME_LENGTH); + strlcat(firmwarePath, imageName, B_PATH_NAME_LENGTH); + + fileDescriptor = open(firmwarePath, B_READ_ONLY); + if (fileDescriptor == -1) + goto cleanup1; + + firmwareFileSize = lseek(fileDescriptor, 0, SEEK_END); + lseek(fileDescriptor, 0, SEEK_SET); + + firmwareName = (char*)malloc(strlen(imageName) + 1); + if (firmwareName == NULL) + goto cleanup2; + + strncpy(firmwareName, imageName, strlen(imageName) + 1); + + firmware = (struct firmware*)malloc(sizeof(struct firmware)); + if (firmware == NULL) + goto cleanup3; + + firmware->data = malloc(firmwareFileSize); + if (firmware->data == NULL) + goto cleanup4; + + readCount = read(fileDescriptor, (void*)firmware->data, firmwareFileSize); + if (readCount == -1) + goto cleanup5; + + firmware->datasize = firmwareFileSize; + firmware->name = firmwareName; + firmware->version = __haiku_firmware_version; + goto cleanup2; + +cleanup5: + free(&firmware->data); +cleanup4: + free(firmware); + firmware = NULL; +cleanup3: + free(firmwareName); +cleanup2: + close(fileDescriptor); +cleanup1: + free(firmwarePath); +cleanup0: + return firmware; +} + + +void +firmware_put(const struct firmware* pointer, int flags) +{ + +} diff --git a/src/libs/compat/freebsd_network/if.c b/src/libs/compat/freebsd_network/if.c index f8204024ce..b087fd1ab7 100644 --- a/src/libs/compat/freebsd_network/if.c +++ b/src/libs/compat/freebsd_network/if.c @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007-2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2004, Marcus Overhagen. All Rights Reserved. @@ -18,14 +19,24 @@ #include #include +#include #include #include #include +#include + + +/* + * The allocation of network interfaces is a rather non-atomic affair; we + * need to select an index before we are ready to expose the interface for + * use, so will use this pointer value to indicate reservation. + */ +#define IFNET_HOLD (void *)(uintptr_t)(-1) static void -insert_into_device_name_list(struct ifnet* ifp) +insert_into_device_name_list(struct ifnet * ifp) { int i; for (i = 0; i < MAX_DEVICES; i++) { @@ -40,7 +51,7 @@ insert_into_device_name_list(struct ifnet* ifp) static void -remove_from_device_name_list(struct ifnet* ifp) +remove_from_device_name_list(struct ifnet * ifp) { int i; for (i = 0; i < MAX_DEVICES; i++) { @@ -65,11 +76,84 @@ remove_from_device_name_list(struct ifnet* ifp) } +struct ifnet * +ifnet_byindex(u_short idx) +{ + struct ifnet *ifp; + + IFNET_RLOCK_NOSLEEP(); + ifp = ifnet_byindex_locked(idx); + IFNET_RUNLOCK_NOSLEEP(); + + return (ifp); +} + + +struct ifnet * +ifnet_byindex_locked(u_short idx) +{ + struct ifnet *ifp; + + ifp = gDevices[idx]; + + return (ifp); +} + + +static void +ifnet_setbyindex_locked(u_short idx, struct ifnet *ifp) +{ + gDevices[idx] = ifp; +} + + +static void +ifnet_setbyindex(u_short idx, struct ifnet *ifp) +{ + IFNET_WLOCK(); + ifnet_setbyindex_locked(idx, ifp); + IFNET_WUNLOCK(); +} + + +/* + * Allocate an ifindex array entry; return 0 on success or an error on + * failure. + */ +static int +ifindex_alloc_locked(u_short *idxp) +{ + u_short index; + + for (index = 0; index < MAX_DEVICES; index++) { + if (gDevices[index] == NULL) { + break; + } + } + + if (index == MAX_DEVICES) + return ENOSPC; + + gDeviceCount++; + *idxp = index; + + return ENOERR; +} + + +static void +ifindex_free_locked(u_short idx) +{ + gDevices[idx] = NULL; + gDeviceCount--; +} + + struct ifnet * if_alloc(u_char type) { char semName[64]; - int i; + u_short index; struct ifnet *ifp = _kernel_malloc(sizeof(struct ifnet), M_ZERO); if (ifp == NULL) @@ -81,12 +165,22 @@ if_alloc(u_char type) if (ifp->receive_sem < B_OK) goto err1; - if (type == IFT_ETHER) { - ifp->if_l2com = _kernel_malloc(sizeof(struct arpcom), M_ZERO); - if (ifp->if_l2com == NULL) - goto err2; + switch (type) { + case IFT_ETHER: + { + ifp->if_l2com = _kernel_malloc(sizeof(struct arpcom), M_ZERO); + IFP2AC(ifp)->ac_ifp = ifp; + break; + } + case IFT_IEEE80211: + { + ifp->if_l2com = _kernel_malloc(sizeof(struct ieee80211com), M_ZERO); + ((struct ieee80211com *)(ifp->if_l2com))->ic_ifp = ifp; + if (ifp->if_l2com == NULL) + goto err2; - IFP2AC(ifp)->ac_ifp = ifp; + break; + } } ifp->link_state_sem = -1; @@ -95,26 +189,36 @@ if_alloc(u_char type) ifp->if_type = type; ifq_init(&ifp->receive_queue, semName); - // Search for the first free device slot, and use that one - for (i = 0; i < MAX_DEVICES; i++) { - if (gDevices[i] == NULL) { - ifp->if_index = i; - gDevices[i] = ifp; - gDeviceCount++; - break; - } - } + /* WLAN specific, doesn't hurt when initilized for other devices */ + ifp->scan_done_sem = -1; - if (i == MAX_DEVICES) { + // Search for the first free device slot, and use that one + IFNET_WLOCK(); + if (ifindex_alloc_locked(&index) != ENOERR) { + IFNET_WUNLOCK(); panic("too many devices"); - return NULL; + goto err3; } + ifnet_setbyindex_locked(index, IFNET_HOLD); + IFNET_WUNLOCK(); + + ifp->if_index = index; + ifnet_setbyindex(ifp->if_index, ifp); IF_ADDR_LOCK_INIT(ifp); return ifp; +err3: + switch (type) { + case IFT_ETHER: + case IFT_IEEE80211: + _kernel_free(ifp->if_l2com); + break; + } + err2: delete_sem(ifp->receive_sem); + err1: _kernel_free(ifp); return NULL; @@ -124,14 +228,22 @@ err1: void if_free(struct ifnet *ifp) { - remove_from_device_name_list(ifp); + // IFT_IEEE80211 devices won't be in this list, + // so don't try to remove them. + if (ifp->if_type == IFT_ETHER) + remove_from_device_name_list(ifp); - gDevices[ifp->if_index] = NULL; - gDeviceCount--; + IFNET_WLOCK(); + ifindex_free_locked(ifp->if_index); + IFNET_WUNLOCK(); IF_ADDR_LOCK_DESTROY(ifp); - if (ifp->if_type == IFT_ETHER) - _kernel_free(ifp->if_l2com); + switch (ifp->if_type) { + case IFT_ETHER: + case IFT_IEEE80211: + _kernel_free(ifp->if_l2com); + break; + } delete_sem(ifp->receive_sem); ifq_uninit(&ifp->receive_queue); @@ -158,7 +270,17 @@ if_initname(struct ifnet *ifp, const char *name, int unit) driver_printf("%s: /dev/%s\n", gDriverName, ifp->device_name); - insert_into_device_name_list(ifp); + /* + * For wlan devices we only want to see the cloned wlan device + * in the list. + * Remember: For each wlan device, there is a base device of type + * IFT_IEEE80211. On top of that a clone device is created of + * typpe IFT_ETHER. + * Haiku shall only see the cloned device as it is the one + * FreeBSD 8 uses for wireless i/o, too. + */ + if (ifp->if_type == IFT_ETHER) + insert_into_device_name_list(ifp); ifp->root_device = find_root_device(unit); } @@ -184,6 +306,16 @@ ifq_uninit(struct ifqueue *ifq) } +static int +if_transmit(struct ifnet *ifp, struct mbuf *m) +{ + int error; + + IFQ_HANDOFF(ifp, m, error); + return (error); +} + + void if_attach(struct ifnet *ifp) { @@ -193,15 +325,24 @@ if_attach(struct ifnet *ifp) IF_ADDR_LOCK_INIT(ifp); - ifq_init((struct ifqueue *)&ifp->if_snd, ifp->if_xname); + ifp->if_lladdr.sdl_family = AF_LINK; + + ifq_init((struct ifqueue *) &ifp->if_snd, ifp->if_xname); + + if (ifp->if_transmit == NULL) { + ifp->if_transmit = if_transmit; + } } void if_detach(struct ifnet *ifp) { + if (HAIKU_DRIVER_REQUIRES(FBSD_SWI_TASKQUEUE)) + taskqueue_drain(taskqueue_swi, &ifp->if_linktask); + IF_ADDR_LOCK_DESTROY(ifp); - ifq_uninit((struct ifqueue *)&ifp->if_snd); + ifq_uninit((struct ifqueue *) &ifp->if_snd); } @@ -210,7 +351,7 @@ if_start(struct ifnet *ifp) { #ifdef IFF_NEEDSGIANT if (ifp->if_flags & IFF_NEEDSGIANT) - panic("freebsd compat.: unsupported giant requirement"); + panic("freebsd compat.: unsupported giant requirement"); #endif ifp->if_start(ifp); } @@ -244,13 +385,12 @@ if_link_state_change(struct ifnet *ifp, int linkState) static struct ifmultiaddr * if_findmulti(struct ifnet *ifp, struct sockaddr *_address) { - struct sockaddr_dl *address = (struct sockaddr_dl *)_address; + struct sockaddr_dl *address = (struct sockaddr_dl *) _address; struct ifmultiaddr *ifma; TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link) { if (memcmp(LLADDR(address), - LLADDR((struct sockaddr_dl *)ifma->ifma_addr), - ETHER_ADDR_LEN) == 0) + LLADDR((struct sockaddr_dl *)ifma->ifma_addr), ETHER_ADDR_LEN) == 0) return ifma; } @@ -268,7 +408,7 @@ _if_addmulti(struct ifnet *ifp, struct sockaddr *address) return addr; } - addr = (struct ifmultiaddr *)malloc(sizeof(struct ifmultiaddr)); + addr = (struct ifmultiaddr *) malloc(sizeof(struct ifmultiaddr)); if (addr == NULL) return NULL; @@ -277,7 +417,7 @@ _if_addmulti(struct ifnet *ifp, struct sockaddr *address) addr->ifma_protospec = NULL; memcpy(&addr->ifma_addr_storage, address, sizeof(struct sockaddr_dl)); - addr->ifma_addr = (struct sockaddr *)&addr->ifma_addr_storage; + addr->ifma_addr = (struct sockaddr *) &addr->ifma_addr_storage; addr->ifma_refcount = 1; @@ -289,7 +429,7 @@ _if_addmulti(struct ifnet *ifp, struct sockaddr *address) int if_addmulti(struct ifnet *ifp, struct sockaddr *address, - struct ifmultiaddr **out) + struct ifmultiaddr **out) { struct ifmultiaddr *result; int refcount = 0; @@ -345,9 +485,130 @@ if_delmulti(struct ifnet *ifp, struct sockaddr *address) } +/* + * if_freemulti: free ifmultiaddr structure and possibly attached related + * addresses. The caller is responsible for implementing reference + * counting, notifying the driver, handling routing messages, and releasing + * any dependent link layer state. + */ +static void +if_freemulti(struct ifmultiaddr *ifma) +{ + + KASSERT(ifma->ifma_refcount == 0, ("if_freemulti: refcount %d", + ifma->ifma_refcount)); + KASSERT(ifma->ifma_protospec == NULL, + ("if_freemulti: protospec not NULL")); + + if (ifma->ifma_lladdr != NULL) + free(ifma->ifma_lladdr); + free(ifma->ifma_addr); + free(ifma); +} + + +/* + * Perform deletion of network-layer and/or link-layer multicast address. + * + * Return 0 if the reference count was decremented. + * Return 1 if the final reference was released, indicating that the + * hardware hash filter should be reprogrammed. + */ +static int +if_delmulti_locked(struct ifnet *ifp, struct ifmultiaddr *ifma, + int detaching) +{ + if (ifp != NULL && ifma->ifma_ifp != NULL) { + KASSERT(ifma->ifma_ifp == ifp, + ("%s: inconsistent ifp %p", __func__, ifp)); + IF_ADDR_LOCK_ASSERT(ifp); + } + + ifp = ifma->ifma_ifp; + + /* + * If the ifnet is detaching, null out references to ifnet, + * so that upper protocol layers will notice, and not attempt + * to obtain locks for an ifnet which no longer exists. The + * routing socket announcement must happen before the ifnet + * instance is detached from the system. + */ + if (detaching) { +#ifdef DIAGNOSTIC + printf("%s: detaching ifnet instance %p\n", __func__, ifp); +#endif + /* + * ifp may already be nulled out if we are being reentered + * to delete the ll_ifma. + */ + if (ifp != NULL) { + ifma->ifma_ifp = NULL; + } + } + + if (--ifma->ifma_refcount > 0) + return 0; + + if (ifp != NULL) + TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link); + + if_freemulti(ifma); + + /* + * The last reference to this instance of struct ifmultiaddr + * was released; the hardware should be notified of this change. + */ + return 1; +} + + +/* + * Remove any multicast network addresses from an interface. + */ +void +if_purgemaddrs(struct ifnet *ifp) +{ + struct ifmultiaddr *ifma; + struct ifmultiaddr *next; + + IF_ADDR_LOCK(ifp); + TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, next) + if_delmulti_locked(ifp, ifma, 1); + IF_ADDR_UNLOCK(ifp); +} + + +void +if_addr_rlock(struct ifnet *ifp) +{ + IF_ADDR_LOCK(ifp); +} + + +void +if_addr_runlock(struct ifnet *ifp) +{ + IF_ADDR_UNLOCK(ifp); +} + + +void +if_maddr_rlock(struct ifnet *ifp) +{ + IF_ADDR_LOCK(ifp); +} + + +void +if_maddr_runlock(struct ifnet *ifp) +{ + IF_ADDR_UNLOCK(ifp); +} + + int ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, - struct rtentry *rt0) + struct route *ro) { int error = 0; IFQ_HANDOFF(ifp, m, error); @@ -355,8 +616,7 @@ ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } -static void -ether_input(struct ifnet *ifp, struct mbuf *m) +static void ether_input(struct ifnet *ifp, struct mbuf *m) { IF_ENQUEUE(&ifp->receive_queue, m); release_sem_etc(ifp->receive_sem, 1, B_DO_NOT_RESCHEDULE); @@ -373,8 +633,8 @@ ether_ifattach(struct ifnet *ifp, const uint8_t *macAddress) ifp->if_output = ether_output; ifp->if_input = ether_input; ifp->if_resolvemulti = NULL; /* done in the stack */ + ifp->if_broadcastaddr = etherbroadcastaddr; - ifp->if_lladdr.sdl_family = AF_LINK; memcpy(IF_LLADDR(ifp), macAddress, ETHER_ADDR_LEN); // TODO: according to FreeBSD's if_ethersubr.c, this should be removed @@ -394,7 +654,7 @@ ether_ifdetach(struct ifnet *ifp) int ether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) { - struct ifreq *ifr = (struct ifreq *)data; + struct ifreq *ifr = (struct ifreq *) data; switch (command) { case SIOCSIFMTU: @@ -402,8 +662,8 @@ ether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) return EINVAL; else ; - /* need to fix our ifreq to work with C... */ - /* ifp->ifr_mtu = ifr->ifr_mtu; */ + /* need to fix our ifreq to work with C... */ + /* ifp->ifr_mtu = ifr->ifr_mtu; */ break; default: @@ -412,37 +672,3 @@ ether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) return 0; } - -/* - * Wrapper functions for struct ifnet address list locking macros. These are - * used by kernel modules to avoid encoding programming interface or binary - * interface assumptions that may be violated when kernel-internal locking - * approaches change. - */ -void -if_addr_rlock(struct ifnet *ifp) -{ - - IF_ADDR_LOCK(ifp); -} - -void -if_addr_runlock(struct ifnet *ifp) -{ - - IF_ADDR_UNLOCK(ifp); -} - -void -if_maddr_rlock(struct ifnet *ifp) -{ - - IF_ADDR_LOCK(ifp); -} - -void -if_maddr_runlock(struct ifnet *ifp) -{ - - IF_ADDR_UNLOCK(ifp); -} diff --git a/src/libs/compat/freebsd_network/libkern.c b/src/libs/compat/freebsd_network/libkern.c new file mode 100644 index 0000000000..4d18cb3ac7 --- /dev/null +++ b/src/libs/compat/freebsd_network/libkern.c @@ -0,0 +1,14 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include + + +uint32_t +arc4random(void) +{ + return random(); +} diff --git a/src/libs/compat/freebsd_network/mbuf.c b/src/libs/compat/freebsd_network/mbuf.c index a2e6ec47a6..69f944a5fb 100644 --- a/src/libs/compat/freebsd_network/mbuf.c +++ b/src/libs/compat/freebsd_network/mbuf.c @@ -1,16 +1,17 @@ /* * Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2004, Marcus Overhagen. All Rights Reserved. - * * Distributed under the terms of the MIT License. */ + #include "device.h" #include #include #include +#include #include #include @@ -26,6 +27,9 @@ int max_protohdr = 40 + 20; /* ip6 + tcp */ /* max_linkhdr + max_protohdr, but that's not allowed by gcc. */ int max_hdr = 16 + 40 + 20; +/* MHLEN - max_hdr */ +int max_datalen = MHLEN - (16 + 40 + 20); + static int m_to_oc_flags(int how) @@ -38,20 +42,20 @@ m_to_oc_flags(int how) static int -construct_mbuf(struct mbuf *mb, short type, int flags) +construct_mbuf(struct mbuf *memoryBuffer, short type, int flags) { - mb->m_next = NULL; - mb->m_nextpkt = NULL; - mb->m_len = 0; - mb->m_flags = flags; - mb->m_type = type; + memoryBuffer->m_next = NULL; + memoryBuffer->m_nextpkt = NULL; + memoryBuffer->m_len = 0; + memoryBuffer->m_flags = flags; + memoryBuffer->m_type = type; if (flags & M_PKTHDR) { - mb->m_data = mb->m_pktdat; - memset(&mb->m_pkthdr, 0, sizeof(mb->m_pkthdr)); - /* SLIST_INIT(&m->m_pkthdr.tags); */ + memoryBuffer->m_data = memoryBuffer->m_pktdat; + memset(&memoryBuffer->m_pkthdr, 0, sizeof(memoryBuffer->m_pkthdr)); + SLIST_INIT(&memoryBuffer->m_pkthdr.tags); } else { - mb->m_data = mb->m_dat; + memoryBuffer->m_data = memoryBuffer->m_dat; } return 0; @@ -59,7 +63,7 @@ construct_mbuf(struct mbuf *mb, short type, int flags) static int -construct_ext_sized_mbuf(struct mbuf *mb, int how, int size) +construct_ext_sized_mbuf(struct mbuf *memoryBuffer, int how, int size) { object_cache *cache; int extType; @@ -73,16 +77,16 @@ construct_ext_sized_mbuf(struct mbuf *mb, int how, int size) cache = sJumbo9ChunkCache; extType = EXT_JUMBO9; } - mb->m_ext.ext_buf = object_cache_alloc(cache, m_to_oc_flags(how)); - if (mb->m_ext.ext_buf == NULL) + memoryBuffer->m_ext.ext_buf = object_cache_alloc(cache, m_to_oc_flags(how)); + if (memoryBuffer->m_ext.ext_buf == NULL) return B_NO_MEMORY; - mb->m_data = mb->m_ext.ext_buf; - mb->m_flags |= M_EXT; + memoryBuffer->m_data = memoryBuffer->m_ext.ext_buf; + memoryBuffer->m_flags |= M_EXT; /* mb->m_ext.ext_free = NULL; */ /* mb->m_ext.ext_args = NULL; */ - mb->m_ext.ext_size = size; - mb->m_ext.ext_type = extType; + memoryBuffer->m_ext.ext_size = size; + memoryBuffer->m_ext.ext_type = extType; /* mb->m_ext.ref_cnt = NULL; */ return 0; @@ -90,38 +94,38 @@ construct_ext_sized_mbuf(struct mbuf *mb, int how, int size) static inline int -construct_ext_mbuf(struct mbuf *mb, int how) +construct_ext_mbuf(struct mbuf *memoryBuffer, int how) { - return construct_ext_sized_mbuf(mb, how, MCLBYTES); + return construct_ext_sized_mbuf(memoryBuffer, how, MCLBYTES); } static int -construct_pkt_mbuf(int how, struct mbuf *mb, short type, int flags) +construct_pkt_mbuf(int how, struct mbuf *memoryBuffer, short type, int flags) { - construct_mbuf(mb, type, flags); - if (construct_ext_mbuf(mb, how) < 0) + construct_mbuf(memoryBuffer, type, flags); + if (construct_ext_mbuf(memoryBuffer, how) < 0) return -1; - mb->m_ext.ext_type |= EXT_PACKET; + memoryBuffer->m_ext.ext_type |= EXT_PACKET; return 0; } static void -destruct_pkt_mbuf(struct mbuf *mb) +destruct_pkt_mbuf(struct mbuf *memoryBuffer) { object_cache *cache; - if ((mb->m_ext.ext_type & EXT_CLUSTER) != 0) + if ((memoryBuffer->m_ext.ext_type & EXT_CLUSTER) != 0) cache = sChunkCache; - else if ((mb->m_ext.ext_type & EXT_JUMBO9) != 0) + else if ((memoryBuffer->m_ext.ext_type & EXT_JUMBO9) != 0) cache = sJumbo9ChunkCache; else { panic("unknown cache"); return; } - object_cache_free(cache, mb->m_ext.ext_buf); - mb->m_ext.ext_buf = NULL; + object_cache_free(cache, memoryBuffer->m_ext.ext_buf); + memoryBuffer->m_ext.ext_buf = NULL; } @@ -187,82 +191,92 @@ m_getjcl(int how, short type, int flags, int size) void -m_clget(struct mbuf *m, int how) +m_clget(struct mbuf *memoryBuffer, int how) { - m->m_ext.ext_buf = NULL; + memoryBuffer->m_ext.ext_buf = NULL; /* called checks for errors by looking for M_EXT */ - construct_ext_mbuf(m, how); + construct_ext_mbuf(memoryBuffer, how); } void * -m_cljget(struct mbuf *m, int how, int size) +m_cljget(struct mbuf *memoryBuffer, int how, int size) { - if (m == NULL) + if (memoryBuffer == NULL) panic("m_cljget doesn't support allocate mbuf"); - m->m_ext.ext_buf = NULL; - construct_ext_sized_mbuf(m, how, size); + memoryBuffer->m_ext.ext_buf = NULL; + construct_ext_sized_mbuf(memoryBuffer, how, size); /* shouldn't be used */ return NULL; } void -m_freem(struct mbuf *mb) +m_freem(struct mbuf *memoryBuffer) { - while (mb) - mb = m_free(mb); + while (memoryBuffer) + memoryBuffer = m_free(memoryBuffer); } static void -mb_free_ext(struct mbuf *m) +mb_free_ext(struct mbuf *memoryBuffer) { /* if (m->m_ext.ref_count != NULL) panic("unsupported"); */ - if (m->m_ext.ext_type == EXT_PACKET) - destruct_pkt_mbuf(m); - else if (m->m_ext.ext_type == EXT_CLUSTER) { - object_cache_free(sChunkCache, m->m_ext.ext_buf); - m->m_ext.ext_buf = NULL; - } else if (m->m_ext.ext_type == EXT_JUMBO9) { - object_cache_free(sJumbo9ChunkCache, m->m_ext.ext_buf); - m->m_ext.ext_buf = NULL; + if (memoryBuffer->m_ext.ext_type == EXT_PACKET) + destruct_pkt_mbuf(memoryBuffer); + else if (memoryBuffer->m_ext.ext_type == EXT_CLUSTER) { + object_cache_free(sChunkCache, memoryBuffer->m_ext.ext_buf); + memoryBuffer->m_ext.ext_buf = NULL; + } else if (memoryBuffer->m_ext.ext_type == EXT_JUMBO9) { + object_cache_free(sJumbo9ChunkCache, memoryBuffer->m_ext.ext_buf); + memoryBuffer->m_ext.ext_buf = NULL; } else panic("unknown type"); - object_cache_free(sMBufCache, m); + object_cache_free(sMBufCache, memoryBuffer); } struct mbuf * -m_free(struct mbuf *m) +m_free(struct mbuf *memoryBuffer) { - struct mbuf *next = m->m_next; + struct mbuf *next = memoryBuffer->m_next; - if (m->m_flags & M_EXT) - mb_free_ext(m); + if (memoryBuffer->m_flags & M_EXT) + mb_free_ext(memoryBuffer); else - object_cache_free(sMBufCache, m); + object_cache_free(sMBufCache, memoryBuffer); return next; } +// TODO once all driver are updated to FreeBSD 8 this can be changed +#if __FreeBSD_version__ >= 8 +m_extadd(struct mbuf *memoryBuffer, caddr_t buffer, u_int size, + void (*freeHook)(void *, void *), void *arg1, void *arg2, int flags, int type) +{ + // TODO: implement? + panic("m_extadd() called."); +} +#else void -m_extadd(struct mbuf *m, caddr_t buffer, u_int size, +m_extadd(struct mbuf *memoryBuffer, caddr_t buffer, u_int size, void (*freeHook)(void *, void *), void *args, int flags, int type) { // TODO: implement? panic("m_extadd() called."); } +#endif status_t -init_mbufs(void) +init_mbufs() { sMBufCache = create_object_cache("mbufs", MSIZE, 8, NULL, NULL, NULL); if (sMBufCache == NULL) @@ -287,10 +301,9 @@ clean: void -uninit_mbufs(void) +uninit_mbufs() { delete_object_cache(sMBufCache); delete_object_cache(sChunkCache); delete_object_cache(sJumbo9ChunkCache); } - diff --git a/src/libs/compat/freebsd_network/mii.c b/src/libs/compat/freebsd_network/mii.c index 3233511f22..4721938e24 100644 --- a/src/libs/compat/freebsd_network/mii.c +++ b/src/libs/compat/freebsd_network/mii.c @@ -6,6 +6,7 @@ * Hugo Santos, hugosantos@gmail.com */ + #include "device.h" #include @@ -15,44 +16,44 @@ int -__haiku_miibus_readreg(device_t dev, int phy, int reg) +__haiku_miibus_readreg(device_t device, int phy, int reg) { - if (dev->methods.miibus_readreg == NULL) + if (device->methods.miibus_readreg == NULL) panic("miibus_readreg, no support"); - return dev->methods.miibus_readreg(dev, phy, reg); + return device->methods.miibus_readreg(device, phy, reg); } int -__haiku_miibus_writereg(device_t dev, int phy, int reg, int data) +__haiku_miibus_writereg(device_t device, int phy, int reg, int data) { - if (dev->methods.miibus_writereg == NULL) + if (device->methods.miibus_writereg == NULL) panic("miibus_writereg, no support"); - return dev->methods.miibus_writereg(dev, phy, reg, data); + return device->methods.miibus_writereg(device, phy, reg, data); } void -__haiku_miibus_statchg(device_t dev) +__haiku_miibus_statchg(device_t device) { - if (dev->methods.miibus_statchg) - dev->methods.miibus_statchg(dev); + if (device->methods.miibus_statchg) + device->methods.miibus_statchg(device); } void -__haiku_miibus_linkchg(device_t dev) +__haiku_miibus_linkchg(device_t device) { - if (dev->methods.miibus_linkchg) - dev->methods.miibus_linkchg(dev); + if (device->methods.miibus_linkchg) + device->methods.miibus_linkchg(device); } void -__haiku_miibus_mediainit(device_t dev) +__haiku_miibus_mediainit(device_t device) { - if (dev->methods.miibus_mediainit) - dev->methods.miibus_mediainit(dev); + if (device->methods.miibus_mediainit) + device->methods.miibus_mediainit(device); } diff --git a/src/libs/compat/freebsd_network/mutex.c b/src/libs/compat/freebsd_network/mutex.c index ae2da1af7b..7c7ecbef0e 100644 --- a/src/libs/compat/freebsd_network/mutex.c +++ b/src/libs/compat/freebsd_network/mutex.c @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. * @@ -6,6 +7,7 @@ * Hugo Santos, hugosantos@gmail.com */ + #include "device.h" #include @@ -14,29 +16,33 @@ // these methods are bit unfriendly, a bit too much panic() around struct mtx Giant; +struct mtx ifnet_lock; +struct mtx gIdStoreLock; void -mtx_init(struct mtx *m, const char *name, const char *type, int opts) +mtx_init(struct mtx *mutex, const char *name, const char *type, + int options) { - if (opts == MTX_DEF) { - mutex_init_etc(&m->u.mutex, name, MUTEX_FLAG_CLONE_NAME); - } else if (opts == MTX_RECURSE) { - recursive_lock_init_etc(&m->u.recursive, name, MUTEX_FLAG_CLONE_NAME); + if (options == MTX_DEF) { + mutex_init_etc(&mutex->u.mutex, name, MUTEX_FLAG_CLONE_NAME); + } else if (options == MTX_RECURSE) { + recursive_lock_init_etc(&mutex->u.recursive, name, + MUTEX_FLAG_CLONE_NAME); } else panic("Uh-oh, someone is pressing the wrong buttons"); - m->type = opts; + mutex->type = options; } void -mtx_destroy(struct mtx *m) +mtx_destroy(struct mtx *mutex) { - if (m->type == MTX_DEF) { - mutex_destroy(&m->u.mutex); - } else if (m->type == MTX_RECURSE) { - recursive_lock_destroy(&m->u.recursive); + if (mutex->type == MTX_DEF) { + mutex_destroy(&mutex->u.mutex); + } else if (mutex->type == MTX_RECURSE) { + recursive_lock_destroy(&mutex->u.recursive); } else panic("Uh-oh, someone is pressing the wrong buttons"); } @@ -46,6 +52,8 @@ status_t init_mutexes() { mtx_init(&Giant, "Banana Giant", NULL, MTX_DEF); + mtx_init(&ifnet_lock, "gDevices", NULL, MTX_DEF); + mtx_init(&gIdStoreLock, "Identity Store", NULL, MTX_DEF); return B_OK; } @@ -55,5 +63,6 @@ void uninit_mutexes() { mtx_destroy(&Giant); + mtx_destroy(&ifnet_lock); + mtx_destroy(&gIdStoreLock); } - diff --git a/src/libs/compat/freebsd_network/priv.c b/src/libs/compat/freebsd_network/priv.c new file mode 100644 index 0000000000..6a1351e09c --- /dev/null +++ b/src/libs/compat/freebsd_network/priv.c @@ -0,0 +1,23 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include + + +/* + * FreeBSD has a more sophisticated privilege checking system. + * We only check for superuser rights. + */ +int priv_check(struct thread *thread, int privilegeLevel) +{ + if (thread_get_current_thread()->team->effective_uid == 0) + return ENOERR; + + return EPERM; +} diff --git a/src/libs/compat/freebsd_network/shared.h b/src/libs/compat/freebsd_network/shared.h new file mode 100644 index 0000000000..a1ffb40a96 --- /dev/null +++ b/src/libs/compat/freebsd_network/shared.h @@ -0,0 +1,56 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. All Rights Reserved. + * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved. + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Copyright 2004, Marcus Overhagen. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef SHARED_H_ +#define SHARED_H_ + + +#define MAX_DEVICES 8 + + +struct ifnet; + +struct device { + struct device *parent; + struct device *root; + + driver_t *driver; + struct list children; + + int32 flags; + + char device_name[128]; + int unit; + char nameunit[64]; + const char *description; + void *softc; + void *ivars; + + struct { + int (*probe)(device_t dev); + int (*attach)(device_t dev); + int (*detach)(device_t dev); + int (*suspend)(device_t dev); + int (*resume)(device_t dev); + void (*shutdown)(device_t dev); + + int (*miibus_readreg)(device_t, int, int); + int (*miibus_writereg)(device_t, int, int, int); + void (*miibus_statchg)(device_t); + void (*miibus_linkchg)(device_t); + void (*miibus_mediainit)(device_t); + } methods; + + struct list_link link; +}; + + +extern const char *gDeviceNameList[]; +extern struct ifnet *gDevices[]; +extern int32 gDeviceCount; + +#endif /* SHARED_H_ */ diff --git a/src/libs/compat/freebsd_network/sleepqueue.c b/src/libs/compat/freebsd_network/sleepqueue.c new file mode 100644 index 0000000000..1e9eae8044 --- /dev/null +++ b/src/libs/compat/freebsd_network/sleepqueue.c @@ -0,0 +1,51 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include +#include + + +void +sleepq_add(void* identifier, struct mtx* mutex, const char* description, + int flags, int queue) +{ + +} + + +int +sleepq_broadcast(void* identifier, int flags, int priority, int queue) +{ + return 0; +} + + +void +sleepq_lock(void* identifier) +{ + +} + + +void +sleepq_release(void* identifier) +{ + +} + + +void +sleepq_remove(struct thread* thread, void* identifier) +{ + +} + + +int +sleepq_timedwait(void* identifier, int priority) +{ + return 0; +} diff --git a/src/libs/compat/freebsd_network/synch.c b/src/libs/compat/freebsd_network/synch.c new file mode 100644 index 0000000000..9fb89d8bbf --- /dev/null +++ b/src/libs/compat/freebsd_network/synch.c @@ -0,0 +1,44 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +#define ticks_to_msecs(t) (1000 * (t) / hz) + + +int +msleep(void* identifier, struct mtx* mutex, int priority, + const char* description, int timeout) +{ + int status; + + // TODO can be removed once the sleepq functions are implemented. + status = snooze(ticks_to_msecs(timeout)); + + sleepq_lock(identifier); + sleepq_add(identifier, mutex, description, 0, 0); + sleepq_release(identifier); + + status = sleepq_timedwait(identifier, timeout); + + sleepq_lock(identifier); + sleepq_remove(NULL, identifier); + sleepq_release(identifier); + + return status; +} + + +void +wakeup(void* identifier) +{ + sleepq_lock(identifier); + sleepq_broadcast(identifier, 0, 0, 0); + sleepq_release(identifier); +} diff --git a/src/libs/compat/freebsd_network/taskqueue.c b/src/libs/compat/freebsd_network/taskqueue.c index d998b98f98..7f2f5e82ca 100644 --- a/src/libs/compat/freebsd_network/taskqueue.c +++ b/src/libs/compat/freebsd_network/taskqueue.c @@ -1,4 +1,5 @@ /* + * Copyright 2009, Colin Günther, coling@gmx.de. * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. * @@ -6,6 +7,7 @@ * Hugo Santos, hugosantos@gmail.com */ + #include "device.h" #include @@ -13,6 +15,12 @@ #include #include + +#define TQ_FLAGS_ACTIVE (1 << 0) +#define TQ_FLAGS_BLOCKED (1 << 1) +#define TQ_FLAGS_PENDING (1 << 2) + + struct taskqueue { char tq_name[64]; mutex tq_mutex; @@ -25,16 +33,16 @@ struct taskqueue { thread_id *tq_threads; thread_id tq_thread_storage; int tq_threadcount; + int tq_flags; }; - struct taskqueue *taskqueue_fast = NULL; struct taskqueue *taskqueue_swi = NULL; static struct taskqueue * _taskqueue_create(const char *name, int mflags, int fast, - taskqueue_enqueue_fn enqueue, void *context) + taskqueue_enqueue_fn enqueueFunction, void *context) { struct taskqueue *tq = malloc(sizeof(struct taskqueue)); if (tq == NULL) @@ -50,46 +58,47 @@ _taskqueue_create(const char *name, int mflags, int fast, strlcpy(tq->tq_name, name, sizeof(tq->tq_name)); list_init_etc(&tq->tq_list, offsetof(struct task, ta_link)); - tq->tq_enqueue = enqueue; + tq->tq_enqueue = enqueueFunction; tq->tq_arg = context; tq->tq_sem = -1; tq->tq_threads = NULL; tq->tq_threadcount = 0; + tq->tq_flags = TQ_FLAGS_ACTIVE; return tq; } static void -tq_lock(struct taskqueue *tq, cpu_status *status) +tq_lock(struct taskqueue *taskQueue, cpu_status *status) { - if (tq->tq_fast) { + if (taskQueue->tq_fast) { *status = disable_interrupts(); - acquire_spinlock(&tq->tq_spinlock); + acquire_spinlock(&taskQueue->tq_spinlock); } else { - mutex_lock(&tq->tq_mutex); + mutex_lock(&taskQueue->tq_mutex); } } static void -tq_unlock(struct taskqueue *tq, cpu_status status) +tq_unlock(struct taskqueue *taskQueue, cpu_status status) { - if (tq->tq_fast) { - release_spinlock(&tq->tq_spinlock); + if (taskQueue->tq_fast) { + release_spinlock(&taskQueue->tq_spinlock); restore_interrupts(status); } else { - mutex_unlock(&tq->tq_mutex); + mutex_unlock(&taskQueue->tq_mutex); } } struct taskqueue * -taskqueue_create(const char *name, int mflags, taskqueue_enqueue_fn enqueue, - void *context, void **unused) +taskqueue_create(const char *name, int mflags, + taskqueue_enqueue_fn enqueueFunction, void *context) { - return _taskqueue_create(name, mflags, 0, enqueue, context); + return _taskqueue_create(name, mflags, 0, enqueueFunction, context); } @@ -126,10 +135,10 @@ tq_handle_thread(void *data) static int -_taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, +_taskqueue_start_threads(struct taskqueue **taskQueue, int count, int priority, const char *name) { - struct taskqueue *tq = (*tqp); + struct taskqueue *tq = (*taskQueue); int i, j; if (count == 0) @@ -156,7 +165,7 @@ _taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, for (i = 0; i < count; i++) { tq->tq_threads[i] = spawn_kernel_thread(tq_handle_thread, tq->tq_name, - prio, tq); + priority, tq); if (tq->tq_threads[i] < B_OK) { status_t status = tq->tq_threads[i]; for (j = 0; j < i; j++) @@ -179,7 +188,7 @@ _taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, int -taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, +taskqueue_start_threads(struct taskqueue **taskQueue, int count, int priority, const char *format, ...) { /* we assume that start_threads is called in a sane place, and thus @@ -197,7 +206,7 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, va_end(vl); /*tq_lock(*tqp, &state);*/ - result = _taskqueue_start_threads(tqp, count, prio, name); + result = _taskqueue_start_threads(taskQueue, count, priority, name); /*tq_unlock(*tqp, state);*/ return result; @@ -205,55 +214,62 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, void -taskqueue_free(struct taskqueue *tq) +taskqueue_free(struct taskqueue *taskQueue) { /* lock and drain list? */ - if (!tq->tq_fast) - mutex_destroy(&tq->tq_mutex); - if (tq->tq_sem != -1) { + taskQueue->tq_flags &= ~TQ_FLAGS_ACTIVE; + if (!taskQueue->tq_fast) + mutex_destroy(&taskQueue->tq_mutex); + if (taskQueue->tq_sem != -1) { int i; - delete_sem(tq->tq_sem); + delete_sem(taskQueue->tq_sem); - for (i = 0; i < tq->tq_threadcount; i++) { + for (i = 0; i < taskQueue->tq_threadcount; i++) { status_t status; - wait_for_thread(tq->tq_threads[i], &status); + wait_for_thread(taskQueue->tq_threads[i], &status); } - if (tq->tq_threadcount > 1) - free(tq->tq_threads); + if (taskQueue->tq_threadcount > 1) + free(taskQueue->tq_threads); } - free(tq); + free(taskQueue); } void -taskqueue_drain(struct taskqueue *tq, struct task *task) +taskqueue_drain(struct taskqueue *taskQueue, struct task *task) { cpu_status status; - tq_lock(tq, &status); - if (task->ta_pending != 0) - UNIMPLEMENTED(); - tq_unlock(tq, status); + tq_lock(taskQueue, &status); + while (task->ta_pending != 0) { + tq_unlock(taskQueue, status); + snooze(0); + tq_lock(taskQueue, &status); + } + tq_unlock(taskQueue, status); } int -taskqueue_enqueue(struct taskqueue *tq, struct task *task) +taskqueue_enqueue(struct taskqueue *taskQueue, struct task *task) { cpu_status status; - tq_lock(tq, &status); + tq_lock(taskQueue, &status); /* we don't really support priorities */ if (task->ta_pending) { task->ta_pending++; } else { - list_add_item(&tq->tq_list, task); + list_add_item(&taskQueue->tq_list, task); task->ta_pending = 1; - tq->tq_enqueue(tq->tq_arg); + if ((taskQueue->tq_flags & TQ_FLAGS_BLOCKED) == 0) + taskQueue->tq_enqueue(taskQueue->tq_arg); + else + taskQueue->tq_flags |= TQ_FLAGS_PENDING; } - tq_unlock(tq, status); + tq_unlock(taskQueue, status); return 0; } @@ -267,27 +283,27 @@ taskqueue_thread_enqueue(void *context) int -taskqueue_enqueue_fast(struct taskqueue *tq, struct task *task) +taskqueue_enqueue_fast(struct taskqueue *taskQueue, struct task *task) { - return taskqueue_enqueue(tq, task); + return taskqueue_enqueue(taskQueue, task); } struct taskqueue * taskqueue_create_fast(const char *name, int mflags, - taskqueue_enqueue_fn enqueue, void *context) + taskqueue_enqueue_fn enqueueFunction, void *context) { - return _taskqueue_create(name, mflags, 1, enqueue, context); + return _taskqueue_create(name, mflags, 1, enqueueFunction, context); } void -task_init(struct task *t, int prio, task_handler_t handler, void *context) +task_init(struct task *task, int prio, task_handler_t handler, void *context) { - t->ta_priority = prio; - t->ta_handler = handler; - t->ta_argument = context; - t->ta_pending = 0; + task->ta_priority = prio; + task->ta_handler = handler; + task->ta_argument = context; + task->ta_pending = 0; } @@ -345,3 +361,29 @@ uninit_taskqueues() if (HAIKU_DRIVER_REQUIRES(FBSD_FAST_TASKQUEUE)) taskqueue_free(taskqueue_fast); } + + +void +taskqueue_block(struct taskqueue *taskQueue) +{ + cpu_status status; + + tq_lock(taskQueue, &status); + taskQueue->tq_flags |= TQ_FLAGS_BLOCKED; + tq_unlock(taskQueue, status); +} + + +void +taskqueue_unblock(struct taskqueue *taskQueue) +{ + cpu_status status; + + tq_lock(taskQueue, &status); + taskQueue->tq_flags &= ~TQ_FLAGS_BLOCKED; + if (taskQueue->tq_flags & TQ_FLAGS_PENDING) { + taskQueue->tq_flags &= ~TQ_FLAGS_PENDING; + taskQueue->tq_enqueue(taskQueue->tq_arg); + } + tq_unlock(taskQueue, status); +} diff --git a/src/libs/compat/freebsd_network/timeout.c b/src/libs/compat/freebsd_network/timeout.c new file mode 100644 index 0000000000..08ec4532cd --- /dev/null +++ b/src/libs/compat/freebsd_network/timeout.c @@ -0,0 +1,26 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include + + +inline void +callout_init(struct callout *callout, int mpsafe) +{ + if (mpsafe) + callout_init_mtx(callout, NULL, 0); + else + callout_init_mtx(callout, &Giant, 0); +} + + +int +callout_schedule(struct callout *callout, int to_ticks) +{ + return callout_reset(callout, to_ticks, callout->c_func, callout->c_arg); +} diff --git a/src/libs/compat/freebsd_network/unit.c b/src/libs/compat/freebsd_network/unit.c new file mode 100644 index 0000000000..f7c4c3bd67 --- /dev/null +++ b/src/libs/compat/freebsd_network/unit.c @@ -0,0 +1,96 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. + * All Rights Reserved. Distributed under the terms of the MIT License. + * + */ + + +/*! Implementation of a number allocator.*/ + + +#include "unit.h" + +#include + +#include + + +extern struct mtx gIdStoreLock; + + +struct unrhdr* +new_unrhdr(int low, int high, struct mtx* mutex) { + struct unrhdr* idStore; + uint32 maxIdCount = high - low + 1; + + KASSERT(low <= high, + ("ID-Store: use error: %s(%u, %u)", __func__, low, high)); + + idStore = malloc(sizeof *idStore); + if (idStore == NULL) + return NULL; + + if (_new_unrhdr_buffer(idStore, maxIdCount) != B_OK) { + free(idStore); + return NULL; + } + + if (mutex) + idStore->storeMutex = mutex; + else + idStore->storeMutex = &gIdStoreLock; + + idStore->idBias = low; + + return idStore; +} + + +void +delete_unrhdr(struct unrhdr* idStore) { + KASSERT(uh != NULL, + ("ID-Store: %s: NULL pointer as argument.", __func__)); + + mtx_lock(idStore->storeMutex); + + KASSERT(uh->idBuffer->root_size == 0, + ("ID-Store: %s: some ids are still in use..", __func__)); + + _delete_unrhdr_buffer_locked(idStore); + mtx_unlock(idStore->storeMutex); + + free(idStore); + idStore = NULL; +} + + +int +alloc_unr(struct unrhdr* idStore) { + int id; + + KASSERT(uh != NULL, + ("ID-Store: %s: NULL pointer as argument.", __func__)); + + mtx_lock(idStore->storeMutex); + id = _alloc_unr_locked(idStore); + mtx_unlock(idStore->storeMutex); + + return id; +} + + +void +free_unr(struct unrhdr* idStore, u_int identity) { + + KASSERT(uh != NULL, + ("ID-Store: %s: NULL pointer as argument.", __func__)); + + mtx_lock(idStore->storeMutex); + + KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second " + + "parameter is not in interval.", __func__, uh, item)); + + _free_unr_locked(idStore, identity); + + mtx_unlock(idStore->storeMutex); +} diff --git a/src/libs/compat/freebsd_network/unit.h b/src/libs/compat/freebsd_network/unit.h new file mode 100644 index 0000000000..5ef7d97d1d --- /dev/null +++ b/src/libs/compat/freebsd_network/unit.h @@ -0,0 +1,35 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de + * All Rights Reserved. Distributed under the terms of the MIT License. + */ +#ifndef UNIT_H_ +#define UNIT_H_ + + +#include + + +struct radix_bitmap; +struct unrhdr { + struct radix_bitmap* idBuffer; + struct mtx* storeMutex; + int32 idBias; +}; + + +#ifdef __cplusplus +extern "C" { +#endif + + +status_t _new_unrhdr_buffer(struct unrhdr*, uint32); +void _delete_unrhdr_buffer_locked(struct unrhdr*); +int _alloc_unr_locked(struct unrhdr*); +void _free_unr_locked(struct unrhdr*, u_int); + + +#ifdef __cplusplus +} +#endif + +#endif /* UNIT_H_ */