ng_hci_var.h revision 137163
1107120Sjulian/* 2107120Sjulian * ng_hci_var.h 3107120Sjulian * 4107120Sjulian * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5107120Sjulian * All rights reserved. 6107120Sjulian * 7107120Sjulian * Redistribution and use in source and binary forms, with or without 8107120Sjulian * modification, are permitted provided that the following conditions 9107120Sjulian * are met: 10107120Sjulian * 1. Redistributions of source code must retain the above copyright 11107120Sjulian * notice, this list of conditions and the following disclaimer. 12107120Sjulian * 2. Redistributions in binary form must reproduce the above copyright 13107120Sjulian * notice, this list of conditions and the following disclaimer in the 14107120Sjulian * documentation and/or other materials provided with the distribution. 15107120Sjulian * 16107120Sjulian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17107120Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18107120Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19107120Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20107120Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21107120Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22107120Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23107120Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24107120Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25107120Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26107120Sjulian * SUCH DAMAGE. 27107120Sjulian * 28114878Sjulian * $Id: ng_hci_var.h,v 1.3 2003/04/26 22:35:21 max Exp $ 29107120Sjulian * $FreeBSD: head/sys/netgraph/bluetooth/hci/ng_hci_var.h 137163 2004-11-03 18:00:49Z emax $ 30107120Sjulian */ 31107120Sjulian 32107120Sjulian#ifndef _NETGRAPH_HCI_VAR_H_ 33122634Semax#define _NETGRAPH_HCI_VAR_H_ 34107120Sjulian 35107120Sjulian/* MALLOC decalation */ 36107120Sjulian#ifdef NG_SEPARATE_MALLOC 37107120SjulianMALLOC_DECLARE(M_NETGRAPH_HCI); 38107120Sjulian#else 39107120Sjulian#define M_NETGRAPH_HCI M_NETGRAPH 40107120Sjulian#endif /* NG_SEPARATE_MALLOC */ 41107120Sjulian 42107120Sjulian/* Debug */ 43107120Sjulian#define NG_HCI_ALERT if (unit->debug >= NG_HCI_ALERT_LEVEL) printf 44107120Sjulian#define NG_HCI_ERR if (unit->debug >= NG_HCI_ERR_LEVEL) printf 45107120Sjulian#define NG_HCI_WARN if (unit->debug >= NG_HCI_WARN_LEVEL) printf 46107120Sjulian#define NG_HCI_INFO if (unit->debug >= NG_HCI_INFO_LEVEL) printf 47107120Sjulian 48107120Sjulian/* Wrapper around m_pullup */ 49107120Sjulian#define NG_HCI_M_PULLUP(m, s) \ 50107120Sjulian do { \ 51107120Sjulian if ((m)->m_len < (s)) \ 52107120Sjulian (m) = m_pullup((m), (s)); \ 53107120Sjulian if ((m) == NULL) \ 54128076Semax NG_HCI_ALERT("%s: %s - m_pullup(%zd) failed\n", \ 55107120Sjulian __func__, NG_NODE_NAME(unit->node), (s)); \ 56107120Sjulian } while (0) 57107120Sjulian 58107120Sjulian/* 59107120Sjulian * Unit hardware buffer descriptor 60107120Sjulian */ 61107120Sjulian 62107120Sjuliantypedef struct ng_hci_unit_buff { 63107120Sjulian u_int8_t cmd_free; /* space available (cmds) */ 64107120Sjulian 65107120Sjulian u_int8_t sco_size; /* max. size of one packet */ 66107120Sjulian u_int16_t sco_pkts; /* size of buffer (packets) */ 67107120Sjulian u_int16_t sco_free; /* space available (packets)*/ 68107120Sjulian 69107120Sjulian u_int16_t acl_size; /* max. size of one packet */ 70107120Sjulian u_int16_t acl_pkts; /* size of buffer (packets) */ 71107120Sjulian u_int16_t acl_free; /* space available (packets)*/ 72107120Sjulian} ng_hci_unit_buff_t; 73107120Sjulian 74107120Sjulian/* 75107120Sjulian * These macro's must be used everywhere in the code. So if extra locking 76107120Sjulian * is required later, it can be added without much troubles. 77107120Sjulian */ 78107120Sjulian 79107120Sjulian#define NG_HCI_BUFF_CMD_SET(b, v) (b).cmd_free = (v) 80107120Sjulian#define NG_HCI_BUFF_CMD_GET(b, v) (v) = (b).cmd_free 81107120Sjulian#define NG_HCI_BUFF_CMD_USE(b, v) (b).cmd_free -= (v) 82107120Sjulian 83107120Sjulian#define NG_HCI_BUFF_ACL_USE(b, v) (b).acl_free -= (v) 84107120Sjulian#define NG_HCI_BUFF_ACL_FREE(b, v) \ 85107120Sjulian do { \ 86107120Sjulian (b).acl_free += (v); \ 87107120Sjulian if ((b).acl_free > (b).acl_pkts) \ 88107120Sjulian (b).acl_free = (b).acl_pkts; \ 89107120Sjulian } while (0) 90107120Sjulian#define NG_HCI_BUFF_ACL_AVAIL(b, v) (v) = (b).acl_free 91107120Sjulian#define NG_HCI_BUFF_ACL_TOTAL(b, v) (v) = (b).acl_pkts 92107120Sjulian#define NG_HCI_BUFF_ACL_SIZE(b, v) (v) = (b).acl_size 93107120Sjulian#define NG_HCI_BUFF_ACL_SET(b, n, s, f) \ 94107120Sjulian do { \ 95107120Sjulian (b).acl_free = (f); \ 96107120Sjulian (b).acl_size = (s); \ 97107120Sjulian (b).acl_pkts = (n); \ 98107120Sjulian } while (0) 99107120Sjulian 100107120Sjulian#define NG_HCI_BUFF_SCO_USE(b, v) (b).sco_free -= (v) 101107120Sjulian#define NG_HCI_BUFF_SCO_FREE(b, v) \ 102107120Sjulian do { \ 103107120Sjulian (b).sco_free += (v); \ 104107120Sjulian if ((b).sco_free > (b).sco_pkts) \ 105107120Sjulian (b).sco_free = (b).sco_pkts; \ 106107120Sjulian } while (0) 107107120Sjulian#define NG_HCI_BUFF_SCO_AVAIL(b, v) (v) = (b).sco_free 108107120Sjulian#define NG_HCI_BUFF_SCO_TOTAL(b, v) (v) = (b).sco_pkts 109107120Sjulian#define NG_HCI_BUFF_SCO_SIZE(b, v) (v) = (b).sco_size 110107120Sjulian#define NG_HCI_BUFF_SCO_SET(b, n, s, f) \ 111107120Sjulian do { \ 112107120Sjulian (b).sco_free = (f); \ 113107120Sjulian (b).sco_size = (s); \ 114107120Sjulian (b).sco_pkts = (n); \ 115107120Sjulian } while (0) 116107120Sjulian 117107120Sjulian/* 118107120Sjulian * Unit (Node private) 119107120Sjulian */ 120107120Sjulian 121107120Sjulianstruct ng_hci_unit_con; 122107120Sjulianstruct ng_hci_neighbor; 123107120Sjulian 124107120Sjuliantypedef struct ng_hci_unit { 125107120Sjulian node_p node; /* node ptr */ 126107120Sjulian 127107120Sjulian ng_hci_node_debug_ep debug; /* debug level */ 128107120Sjulian ng_hci_node_state_ep state; /* unit state */ 129107120Sjulian 130107120Sjulian bdaddr_t bdaddr; /* unit address */ 131107120Sjulian u_int8_t features[NG_HCI_FEATURES_SIZE]; 132107120Sjulian /* LMP features */ 133107120Sjulian 134107120Sjulian ng_hci_node_link_policy_mask_ep link_policy_mask; /* link policy mask */ 135107120Sjulian ng_hci_node_packet_mask_ep packet_mask; /* packet mask */ 136114878Sjulian ng_hci_node_role_switch_ep role_switch; /* role switch */ 137107120Sjulian 138107120Sjulian ng_hci_node_stat_ep stat; /* statistic */ 139107120Sjulian#define NG_HCI_STAT_CMD_SENT(s) (s).cmd_sent ++ 140107120Sjulian#define NG_HCI_STAT_EVNT_RECV(s) (s).evnt_recv ++ 141107120Sjulian#define NG_HCI_STAT_ACL_SENT(s, n) (s).acl_sent += (n) 142107120Sjulian#define NG_HCI_STAT_ACL_RECV(s) (s).acl_recv ++ 143107120Sjulian#define NG_HCI_STAT_SCO_SENT(s, n) (s).sco_sent += (n) 144107120Sjulian#define NG_HCI_STAT_SCO_RECV(s) (s).sco_recv ++ 145107120Sjulian#define NG_HCI_STAT_BYTES_SENT(s, b) (s).bytes_sent += (b) 146107120Sjulian#define NG_HCI_STAT_BYTES_RECV(s, b) (s).bytes_recv += (b) 147107120Sjulian#define NG_HCI_STAT_RESET(s) bzero(&(s), sizeof((s))) 148107120Sjulian 149107120Sjulian ng_hci_unit_buff_t buffer; /* buffer info */ 150107120Sjulian 151137163Semax struct callout cmd_timo; /* command timeout */ 152107120Sjulian ng_bt_mbufq_t cmdq; /* command queue */ 153107120Sjulian#define NG_HCI_CMD_QUEUE_LEN 12 /* max. size of cmd q */ 154107120Sjulian 155107120Sjulian hook_p drv; /* driver hook */ 156107120Sjulian hook_p acl; /* upstream hook */ 157107120Sjulian hook_p sco; /* upstream hook */ 158107120Sjulian hook_p raw; /* upstream hook */ 159107120Sjulian 160107120Sjulian LIST_HEAD(, ng_hci_unit_con) con_list; /* connections */ 161107120Sjulian LIST_HEAD(, ng_hci_neighbor) neighbors; /* unit neighbors */ 162107120Sjulian} ng_hci_unit_t; 163107120Sjuliantypedef ng_hci_unit_t * ng_hci_unit_p; 164107120Sjulian 165107120Sjulian/* 166107120Sjulian * Unit connection descriptor 167107120Sjulian */ 168107120Sjulian 169107120Sjuliantypedef struct ng_hci_unit_con { 170107120Sjulian ng_hci_unit_p unit; /* pointer back */ 171107120Sjulian 172107120Sjulian u_int16_t state; /* con. state */ 173107120Sjulian u_int16_t flags; /* con. flags */ 174107120Sjulian#define NG_HCI_CON_TIMEOUT_PENDING (1 << 0) 175114878Sjulian#define NG_HCI_CON_NOTIFY_ACL (1 << 1) 176114878Sjulian#define NG_HCI_CON_NOTIFY_SCO (1 << 2) 177107120Sjulian 178107120Sjulian bdaddr_t bdaddr; /* remote address */ 179107120Sjulian u_int16_t con_handle; /* con. handle */ 180107120Sjulian 181107120Sjulian u_int8_t link_type; /* ACL or SCO */ 182107120Sjulian u_int8_t encryption_mode; /* none, p2p, ... */ 183107120Sjulian u_int8_t mode; /* ACTIVE, HOLD ... */ 184107120Sjulian u_int8_t role; /* MASTER/SLAVE */ 185107120Sjulian 186137163Semax struct callout con_timo; /* con. timeout */ 187107120Sjulian 188107120Sjulian int pending; /* # of data pkts */ 189107120Sjulian ng_bt_itemq_t conq; /* con. queue */ 190107120Sjulian 191107120Sjulian LIST_ENTRY(ng_hci_unit_con) next; /* next */ 192107120Sjulian} ng_hci_unit_con_t; 193107120Sjuliantypedef ng_hci_unit_con_t * ng_hci_unit_con_p; 194107120Sjulian 195107120Sjulian/* 196107120Sjulian * Unit's neighbor descriptor. 197107120Sjulian * Neighbor is a remote unit that responded to our inquiry. 198107120Sjulian */ 199107120Sjulian 200107120Sjuliantypedef struct ng_hci_neighbor { 201107120Sjulian struct timeval updated; /* entry was updated */ 202107120Sjulian 203107120Sjulian bdaddr_t bdaddr; /* address */ 204107120Sjulian u_int8_t features[NG_HCI_FEATURES_SIZE]; 205107120Sjulian /* LMP features */ 206107120Sjulian 207107120Sjulian u_int8_t page_scan_rep_mode; /* PS rep. mode */ 208107120Sjulian u_int8_t page_scan_mode; /* page scan mode */ 209107120Sjulian u_int16_t clock_offset; /* clock offset */ 210107120Sjulian 211107120Sjulian LIST_ENTRY(ng_hci_neighbor) next; 212107120Sjulian} ng_hci_neighbor_t; 213107120Sjuliantypedef ng_hci_neighbor_t * ng_hci_neighbor_p; 214107120Sjulian 215107120Sjulian#endif /* ndef _NETGRAPH_HCI_VAR_H_ */ 216107120Sjulian 217