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