Path: blob/main/sys/netgraph/bluetooth/hci/ng_hci_var.h
34814 views
/*1* ng_hci_var.h2*/34/*-5* SPDX-License-Identifier: BSD-2-Clause6*7* Copyright (c) 2001 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_hci_var.h,v 1.3 2003/04/26 22:35:21 max Exp $32*/3334#ifndef _NETGRAPH_HCI_VAR_H_35#define _NETGRAPH_HCI_VAR_H_3637/* MALLOC decalation */38#ifdef NG_SEPARATE_MALLOC39MALLOC_DECLARE(M_NETGRAPH_HCI);40#else41#define M_NETGRAPH_HCI M_NETGRAPH42#endif /* NG_SEPARATE_MALLOC */4344/* Debug */45#define NG_HCI_ALERT if (unit->debug >= NG_HCI_ALERT_LEVEL) printf46#define NG_HCI_ERR if (unit->debug >= NG_HCI_ERR_LEVEL) printf47#define NG_HCI_WARN if (unit->debug >= NG_HCI_WARN_LEVEL) printf48#define NG_HCI_INFO if (unit->debug >= NG_HCI_INFO_LEVEL) printf4950/* Wrapper around m_pullup */51#define NG_HCI_M_PULLUP(m, s) \52do { \53if ((m)->m_len < (s)) \54(m) = m_pullup((m), (s)); \55if ((m) == NULL) \56NG_HCI_ALERT("%s: %s - m_pullup(%zd) failed\n", \57__func__, NG_NODE_NAME(unit->node), (s)); \58} while (0)5960/*61* Unit hardware buffer descriptor62*/6364typedef struct ng_hci_unit_buff {65u_int8_t cmd_free; /* space available (cmds) */6667u_int8_t sco_size; /* max. size of one packet */68u_int16_t sco_pkts; /* size of buffer (packets) */69u_int16_t sco_free; /* space available (packets)*/7071u_int16_t acl_size; /* max. size of one packet */72u_int16_t acl_pkts; /* size of buffer (packets) */73u_int16_t acl_free; /* space available (packets)*/74} ng_hci_unit_buff_t;7576/*77* These macro's must be used everywhere in the code. So if extra locking78* is required later, it can be added without much troubles.79*/8081#define NG_HCI_BUFF_CMD_SET(b, v) (b).cmd_free = (v)82#define NG_HCI_BUFF_CMD_GET(b, v) (v) = (b).cmd_free83#define NG_HCI_BUFF_CMD_USE(b, v) (b).cmd_free -= (v)8485#define NG_HCI_BUFF_ACL_USE(b, v) (b).acl_free -= (v)86#define NG_HCI_BUFF_ACL_FREE(b, v) \87do { \88(b).acl_free += (v); \89if ((b).acl_free > (b).acl_pkts) \90(b).acl_free = (b).acl_pkts; \91} while (0)92#define NG_HCI_BUFF_ACL_AVAIL(b, v) (v) = (b).acl_free93#define NG_HCI_BUFF_ACL_TOTAL(b, v) (v) = (b).acl_pkts94#define NG_HCI_BUFF_ACL_SIZE(b, v) (v) = (b).acl_size95#define NG_HCI_BUFF_ACL_SET(b, n, s, f) \96do { \97(b).acl_free = (f); \98(b).acl_size = (s); \99(b).acl_pkts = (n); \100} while (0)101102#define NG_HCI_BUFF_SCO_USE(b, v) (b).sco_free -= (v)103#define NG_HCI_BUFF_SCO_FREE(b, v) \104do { \105(b).sco_free += (v); \106if ((b).sco_free > (b).sco_pkts) \107(b).sco_free = (b).sco_pkts; \108} while (0)109#define NG_HCI_BUFF_SCO_AVAIL(b, v) (v) = (b).sco_free110#define NG_HCI_BUFF_SCO_TOTAL(b, v) (v) = (b).sco_pkts111#define NG_HCI_BUFF_SCO_SIZE(b, v) (v) = (b).sco_size112#define NG_HCI_BUFF_SCO_SET(b, n, s, f) \113do { \114(b).sco_free = (f); \115(b).sco_size = (s); \116(b).sco_pkts = (n); \117} while (0)118119/*120* Unit (Node private)121*/122123struct ng_hci_unit_con;124struct ng_hci_neighbor;125126typedef struct ng_hci_unit {127node_p node; /* node ptr */128129ng_hci_node_debug_ep debug; /* debug level */130ng_hci_node_state_ep state; /* unit state */131132bdaddr_t bdaddr; /* unit address */133u_int8_t features[NG_HCI_FEATURES_SIZE];134/* LMP features */135136ng_hci_node_link_policy_mask_ep link_policy_mask; /* link policy mask */137ng_hci_node_packet_mask_ep packet_mask; /* packet mask */138ng_hci_node_role_switch_ep role_switch; /* role switch */139140ng_hci_node_stat_ep stat; /* statistic */141#define NG_HCI_STAT_CMD_SENT(s) (s).cmd_sent ++142#define NG_HCI_STAT_EVNT_RECV(s) (s).evnt_recv ++143#define NG_HCI_STAT_ACL_SENT(s, n) (s).acl_sent += (n)144#define NG_HCI_STAT_ACL_RECV(s) (s).acl_recv ++145#define NG_HCI_STAT_SCO_SENT(s, n) (s).sco_sent += (n)146#define NG_HCI_STAT_SCO_RECV(s) (s).sco_recv ++147#define NG_HCI_STAT_BYTES_SENT(s, b) (s).bytes_sent += (b)148#define NG_HCI_STAT_BYTES_RECV(s, b) (s).bytes_recv += (b)149#define NG_HCI_STAT_RESET(s) bzero(&(s), sizeof((s)))150151ng_hci_unit_buff_t buffer; /* buffer info */152153struct callout cmd_timo; /* command timeout */154ng_bt_mbufq_t cmdq; /* command queue */155#define NG_HCI_CMD_QUEUE_LEN 12 /* max. size of cmd q */156157hook_p drv; /* driver hook */158hook_p acl; /* upstream hook */159hook_p sco; /* upstream hook */160hook_p raw; /* upstream hook */161162LIST_HEAD(, ng_hci_unit_con) con_list; /* connections */163LIST_HEAD(, ng_hci_neighbor) neighbors; /* unit neighbors */164} ng_hci_unit_t;165typedef ng_hci_unit_t * ng_hci_unit_p;166167/*168* Unit connection descriptor169*/170171typedef struct ng_hci_unit_con {172ng_hci_unit_p unit; /* pointer back */173174u_int16_t state; /* con. state */175u_int16_t flags; /* con. flags */176#define NG_HCI_CON_TIMEOUT_PENDING (1 << 0)177#define NG_HCI_CON_NOTIFY_ACL (1 << 1)178#define NG_HCI_CON_NOTIFY_SCO (1 << 2)179180bdaddr_t bdaddr; /* remote address */181u_int16_t con_handle; /* con. handle */182183u_int8_t link_type; /* ACL or SCO */184u_int8_t encryption_mode; /* none, p2p, ... */185u_int8_t mode; /* ACTIVE, HOLD ... */186u_int8_t role; /* MASTER/SLAVE */187188struct callout con_timo; /* con. timeout */189190int pending; /* # of data pkts */191ng_bt_itemq_t conq; /* con. queue */192193LIST_ENTRY(ng_hci_unit_con) next; /* next */194} ng_hci_unit_con_t;195typedef ng_hci_unit_con_t * ng_hci_unit_con_p;196197/*198* Unit's neighbor descriptor.199* Neighbor is a remote unit that responded to our inquiry.200*/201202typedef struct ng_hci_neighbor {203struct timeval updated; /* entry was updated */204205bdaddr_t bdaddr; /* address */206u_int8_t features[NG_HCI_FEATURES_SIZE];207/* LMP features */208u_int8_t addrtype; /*Address Type*/209210u_int8_t page_scan_rep_mode; /* PS rep. mode */211u_int8_t page_scan_mode; /* page scan mode */212u_int16_t clock_offset; /* clock offset */213uint8_t extinq_size;214uint8_t extinq_data[NG_HCI_EXTINQ_MAX];215LIST_ENTRY(ng_hci_neighbor) next;216} ng_hci_neighbor_t;217typedef ng_hci_neighbor_t * ng_hci_neighbor_p;218219#endif /* ndef _NETGRAPH_HCI_VAR_H_ */220221222