1 /* 2 * ng_btsocket_l2cap.h 3 * 4 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: ng_btsocket_l2cap.h,v 1.3 2002/09/22 18:23:31 max Exp $ 29 * $FreeBSD$ 30 */ 31 32 #ifndef _NETGRAPH_BTSOCKET_L2CAP_H_ 33 #define _NETGRAPH_BTSOCKET_L2CAP_H_ 1 34 35 /* 36 * L2CAP routing entry 37 */ 38 39 struct ng_hook; 40 struct ng_message; 41 42 struct ng_btsocket_l2cap_rtentry { 43 bdaddr_t src; /* source BD_ADDR */ 44 struct ng_hook *hook; /* downstream hook */ 45 LIST_ENTRY(ng_btsocket_l2cap_rtentry) next; /* linkt to next */ 46 }; 47 typedef struct ng_btsocket_l2cap_rtentry ng_btsocket_l2cap_rtentry_t; 48 typedef struct ng_btsocket_l2cap_rtentry * ng_btsocket_l2cap_rtentry_p; 49 50 /***************************************************************************** 51 ***************************************************************************** 52 ** SOCK_RAW L2CAP sockets ** 53 ***************************************************************************** 54 *****************************************************************************/ 55 56 #define NG_BTSOCKET_L2CAP_RAW_SENDSPACE NG_L2CAP_MTU_DEFAULT 57 #define NG_BTSOCKET_L2CAP_RAW_RECVSPACE NG_L2CAP_MTU_DEFAULT 58 59 /* 60 * Bluetooth raw L2CAP socket PCB 61 */ 62 63 struct ng_btsocket_l2cap_raw_pcb { 64 struct socket *so; /* socket */ 65 66 bdaddr_t src; /* source address */ 67 ng_btsocket_l2cap_rtentry_p rt; /* routing info */ 68 69 u_int32_t token; /* message token */ 70 struct ng_mesg *msg; /* message */ 71 72 LIST_ENTRY(ng_btsocket_l2cap_raw_pcb) next; /* link to next PCB */ 73 }; 74 typedef struct ng_btsocket_l2cap_raw_pcb ng_btsocket_l2cap_raw_pcb_t; 75 typedef struct ng_btsocket_l2cap_raw_pcb * ng_btsocket_l2cap_raw_pcb_p; 76 77 #define so2l2cap_raw_pcb(so) \ 78 ((struct ng_btsocket_l2cap_raw_pcb *)((so)->so_pcb)) 79 80 /* 81 * Bluetooth raw L2CAP socket methods 82 */ 83 84 #ifdef _KERNEL 85 86 void ng_btsocket_l2cap_raw_init (void); 87 int ng_btsocket_l2cap_raw_abort (struct socket *); 88 int ng_btsocket_l2cap_raw_attach (struct socket *, int, struct thread *); 89 int ng_btsocket_l2cap_raw_bind (struct socket *, struct sockaddr *, 90 struct thread *); 91 int ng_btsocket_l2cap_raw_connect (struct socket *, struct sockaddr *, 92 struct thread *); 93 int ng_btsocket_l2cap_raw_control (struct socket *, u_long, caddr_t, 94 struct ifnet *, struct thread *); 95 int ng_btsocket_l2cap_raw_detach (struct socket *); 96 int ng_btsocket_l2cap_raw_disconnect (struct socket *); 97 int ng_btsocket_l2cap_raw_peeraddr (struct socket *, struct sockaddr **); 98 int ng_btsocket_l2cap_raw_send (struct socket *, int, struct mbuf *, 99 struct sockaddr *, struct mbuf *, 100 struct thread *); 101 int ng_btsocket_l2cap_raw_sockaddr (struct socket *, struct sockaddr **); 102 103 #endif /* _KERNEL */ 104 105 /***************************************************************************** 106 ***************************************************************************** 107 ** SOCK_SEQPACKET L2CAP sockets ** 108 ***************************************************************************** 109 *****************************************************************************/ 110 111 #define NG_BTSOCKET_L2CAP_SENDSPACE NG_L2CAP_MTU_DEFAULT /* (64 * 1024) */ 112 #define NG_BTSOCKET_L2CAP_RECVSPACE (64 * 1024) 113 114 /* 115 * Bluetooth L2CAP socket PCB 116 */ 117 118 struct ng_btsocket_l2cap_pcb { 119 struct socket *so; /* Pointer to socket */ 120 121 bdaddr_t src; /* Source address */ 122 bdaddr_t dst; /* Destination address */ 123 124 u_int16_t psm; /* PSM */ 125 u_int16_t cid; /* Local channel ID */ 126 127 u_int16_t flags; /* socket flags */ 128 #define NG_BTSOCKET_L2CAP_CLIENT (1 << 0) /* socket is client */ 129 #define NG_BTSOCKET_L2CAP_TIMO (1 << 1) /* timeout pending */ 130 131 u_int8_t state; /* socket state */ 132 #define NG_BTSOCKET_L2CAP_CLOSED 0 /* socket closed */ 133 #define NG_BTSOCKET_L2CAP_CONNECTING 1 /* wait for connect */ 134 #define NG_BTSOCKET_L2CAP_CONFIGURING 2 /* wait for config */ 135 #define NG_BTSOCKET_L2CAP_OPEN 3 /* socket open */ 136 #define NG_BTSOCKET_L2CAP_DISCONNECTING 4 /* wait for disconnect */ 137 138 u_int8_t cfg_state; /* config state */ 139 #define NG_BTSOCKET_L2CAP_CFG_IN (1 << 0) /* incoming path done */ 140 #define NG_BTSOCKET_L2CAP_CFG_OUT (1 << 1) /* outgoing path done */ 141 #define NG_BTSOCKET_L2CAP_CFG_BOTH \ 142 (NG_BTSOCKET_L2CAP_CFG_IN | NG_BTSOCKET_L2CAP_CFG_OUT) 143 144 #define NG_BTSOCKET_L2CAP_CFG_IN_SENT (1 << 2) /* L2CAP ConfigReq sent */ 145 #define NG_BTSOCKET_L2CAP_CFG_OUT_SENT (1 << 3) /* ---/--- */ 146 147 u_int16_t imtu; /* Incoming MTU */ 148 ng_l2cap_flow_t iflow; /* Input flow spec */ 149 150 u_int16_t omtu; /* Outgoing MTU */ 151 ng_l2cap_flow_t oflow; /* Outgoing flow spec */ 152 153 u_int16_t flush_timo; /* flush timeout */ 154 u_int16_t link_timo; /* link timeout */ 155 156 struct callout_handle timo; /* timeout */ 157 158 u_int32_t token; /* message token */ 159 ng_btsocket_l2cap_rtentry_p rt; /* routing info */ 160 161 struct mtx pcb_mtx; /* pcb mutex */ 162 163 LIST_ENTRY(ng_btsocket_l2cap_pcb) next; /* link to next PCB */ 164 }; 165 typedef struct ng_btsocket_l2cap_pcb ng_btsocket_l2cap_pcb_t; 166 typedef struct ng_btsocket_l2cap_pcb * ng_btsocket_l2cap_pcb_p; 167 168 #define so2l2cap_pcb(so) \ 169 ((struct ng_btsocket_l2cap_pcb *)((so)->so_pcb)) 170 171 /* 172 * Bluetooth L2CAP socket methods 173 */ 174 175 #ifdef _KERNEL 176 177 void ng_btsocket_l2cap_init (void); 178 int ng_btsocket_l2cap_abort (struct socket *); 179 int ng_btsocket_l2cap_accept (struct socket *, struct sockaddr **); 180 int ng_btsocket_l2cap_attach (struct socket *, int, struct thread *); 181 int ng_btsocket_l2cap_bind (struct socket *, struct sockaddr *, 182 struct thread *); 183 int ng_btsocket_l2cap_connect (struct socket *, struct sockaddr *, 184 struct thread *); 185 int ng_btsocket_l2cap_control (struct socket *, u_long, caddr_t, 186 struct ifnet *, struct thread *); 187 int ng_btsocket_l2cap_ctloutput (struct socket *, struct sockopt *); 188 int ng_btsocket_l2cap_detach (struct socket *); 189 int ng_btsocket_l2cap_disconnect (struct socket *); 190 int ng_btsocket_l2cap_listen (struct socket *, struct thread *); 191 int ng_btsocket_l2cap_peeraddr (struct socket *, struct sockaddr **); 192 int ng_btsocket_l2cap_send (struct socket *, int, struct mbuf *, 193 struct sockaddr *, struct mbuf *, 194 struct thread *); 195 int ng_btsocket_l2cap_sockaddr (struct socket *, struct sockaddr **); 196 197 #endif /* _KERNEL */ 198 199 #endif /* _NETGRAPH_BTSOCKET_L2CAP_H_ */ 200 201