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