Path: blob/main/sys/netgraph/bluetooth/include/ng_bluetooth.h
34814 views
/*1* bluetooth.h2*/34/*-5* SPDX-License-Identifier: BSD-2-Clause6*7* Copyright (c) 2001-2002 Maksim Yevmenkin <[email protected]>8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*31* $Id: ng_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $32*/3334#ifndef _NETGRAPH_BLUETOOTH_H_35#define _NETGRAPH_BLUETOOTH_H_3637#include <sys/queue.h>3839/*40* Version of the stack41*/4243#define NG_BLUETOOTH_VERSION 14445/*46* Declare the base of the Bluetooth sysctl hierarchy,47* but only if this file cares about sysctl's48*/4950#ifdef SYSCTL_DECL51SYSCTL_DECL(_net_bluetooth);52SYSCTL_DECL(_net_bluetooth_hci);53SYSCTL_DECL(_net_bluetooth_l2cap);54SYSCTL_DECL(_net_bluetooth_rfcomm);55SYSCTL_DECL(_net_bluetooth_sco);56#endif /* SYSCTL_DECL */5758/*59* Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we60* do not need mutex and other locking stuff61*/6263struct mbuf;6465struct ng_bt_mbufq {66struct mbuf *head; /* first item in the queue */67struct mbuf *tail; /* last item in the queue */68u_int32_t len; /* number of items in the queue */69u_int32_t maxlen; /* maximal number of items in the queue */70u_int32_t drops; /* number if dropped items */71};72typedef struct ng_bt_mbufq ng_bt_mbufq_t;73typedef struct ng_bt_mbufq * ng_bt_mbufq_p;7475#define NG_BT_MBUFQ_INIT(q, _maxlen) \76do { \77(q)->head = NULL; \78(q)->tail = NULL; \79(q)->len = 0; \80(q)->maxlen = (_maxlen); \81(q)->drops = 0; \82} while (0)8384#define NG_BT_MBUFQ_DESTROY(q) \85do { \86NG_BT_MBUFQ_DRAIN((q)); \87} while (0)8889#define NG_BT_MBUFQ_FIRST(q) (q)->head9091#define NG_BT_MBUFQ_LEN(q) (q)->len9293#define NG_BT_MBUFQ_FULL(q) ((q)->len >= (q)->maxlen)9495#define NG_BT_MBUFQ_DROP(q) (q)->drops ++9697#define NG_BT_MBUFQ_ENQUEUE(q, i) \98do { \99(i)->m_nextpkt = NULL; \100\101if ((q)->tail == NULL) \102(q)->head = (i); \103else \104(q)->tail->m_nextpkt = (i); \105\106(q)->tail = (i); \107(q)->len ++; \108} while (0)109110#define NG_BT_MBUFQ_DEQUEUE(q, i) \111do { \112(i) = (q)->head; \113if ((i) != NULL) { \114(q)->head = (q)->head->m_nextpkt; \115if ((q)->head == NULL) \116(q)->tail = NULL; \117\118(q)->len --; \119(i)->m_nextpkt = NULL; \120} \121} while (0)122123#define NG_BT_MBUFQ_PREPEND(q, i) \124do { \125(i)->m_nextpkt = (q)->head; \126if ((q)->tail == NULL) \127(q)->tail = (i); \128\129(q)->head = (i); \130(q)->len ++; \131} while (0)132133#define NG_BT_MBUFQ_DRAIN(q) \134do { \135struct mbuf *m = NULL; \136\137for (;;) { \138NG_BT_MBUFQ_DEQUEUE((q), m); \139if (m == NULL) \140break; \141\142NG_FREE_M(m); \143} \144} while (0)145146/*147* Netgraph item queue and useful itemq macros148*/149150struct ng_item;151152struct ng_bt_itemq {153STAILQ_HEAD(, ng_item) queue; /* actually items queue */154u_int32_t len; /* number of items in the queue */155u_int32_t maxlen; /* maximal number of items in the queue */156u_int32_t drops; /* number if dropped items */157};158typedef struct ng_bt_itemq ng_bt_itemq_t;159typedef struct ng_bt_itemq * ng_bt_itemq_p;160161#define NG_BT_ITEMQ_INIT(q, _maxlen) \162do { \163STAILQ_INIT(&(q)->queue); \164(q)->len = 0; \165(q)->maxlen = (_maxlen); \166(q)->drops = 0; \167} while (0)168169#define NG_BT_ITEMQ_DESTROY(q) \170do { \171NG_BT_ITEMQ_DRAIN((q)); \172} while (0)173174#define NG_BT_ITEMQ_FIRST(q) STAILQ_FIRST(&(q)->queue)175176#define NG_BT_ITEMQ_LEN(q) NG_BT_MBUFQ_LEN((q))177178#define NG_BT_ITEMQ_FULL(q) NG_BT_MBUFQ_FULL((q))179180#define NG_BT_ITEMQ_DROP(q) NG_BT_MBUFQ_DROP((q))181182#define NG_BT_ITEMQ_ENQUEUE(q, i) \183do { \184STAILQ_INSERT_TAIL(&(q)->queue, (i), el_next); \185(q)->len ++; \186} while (0)187188#define NG_BT_ITEMQ_DEQUEUE(q, i) \189do { \190(i) = STAILQ_FIRST(&(q)->queue); \191if ((i) != NULL) { \192STAILQ_REMOVE_HEAD(&(q)->queue, el_next); \193(q)->len --; \194} \195} while (0)196197#define NG_BT_ITEMQ_PREPEND(q, i) \198do { \199STAILQ_INSERT_HEAD(&(q)->queue, (i), el_next); \200(q)->len ++; \201} while (0)202203#define NG_BT_ITEMQ_DRAIN(q) \204do { \205struct ng_item *i = NULL; \206\207for (;;) { \208NG_BT_ITEMQ_DEQUEUE((q), i); \209if (i == NULL) \210break; \211\212NG_FREE_ITEM(i); \213} \214} while (0)215216/*217* Get Bluetooth stack sysctl globals218*/219220u_int32_t bluetooth_hci_command_timeout (void);221u_int32_t bluetooth_hci_connect_timeout (void);222u_int32_t bluetooth_hci_max_neighbor_age (void);223u_int32_t bluetooth_l2cap_rtx_timeout (void);224u_int32_t bluetooth_l2cap_ertx_timeout (void);225u_int32_t bluetooth_sco_rtx_timeout (void);226227#define BDADDR_BREDR 0228#define BDADDR_LE_PUBLIC 1229#define BDADDR_LE_RANDOM 2230231#endif /* _NETGRAPH_BLUETOOTH_H_ */232233234