xref: /freebsd/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h (revision 7660b554bc59a07be0431c17e0e33815818baa69)
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.4 2003/03/25 23:53:33 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; /* link 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 	u_int32_t				 flags; /* flags */
67 #define NG_BTSOCKET_L2CAP_RAW_PRIVILEGED	(1 << 0)
68 
69 	bdaddr_t				 src;	/* source address */
70 	bdaddr_t				 dst;	/* dest address */
71 	ng_btsocket_l2cap_rtentry_p		 rt;    /* routing info */
72 
73 	u_int32_t				 token;	/* message token */
74 	struct ng_mesg				*msg;   /* message */
75 
76 	struct mtx				 pcb_mtx; /* pcb mutex */
77 
78 	LIST_ENTRY(ng_btsocket_l2cap_raw_pcb)	 next;  /* link to next PCB */
79 };
80 typedef struct ng_btsocket_l2cap_raw_pcb	ng_btsocket_l2cap_raw_pcb_t;
81 typedef struct ng_btsocket_l2cap_raw_pcb *	ng_btsocket_l2cap_raw_pcb_p;
82 
83 #define	so2l2cap_raw_pcb(so) \
84 	((struct ng_btsocket_l2cap_raw_pcb *)((so)->so_pcb))
85 
86 /*
87  * Bluetooth raw L2CAP socket methods
88  */
89 
90 #ifdef _KERNEL
91 
92 void ng_btsocket_l2cap_raw_init       (void);
93 int  ng_btsocket_l2cap_raw_abort      (struct socket *);
94 int  ng_btsocket_l2cap_raw_attach     (struct socket *, int, struct thread *);
95 int  ng_btsocket_l2cap_raw_bind       (struct socket *, struct sockaddr *,
96                                        struct thread *);
97 int  ng_btsocket_l2cap_raw_connect    (struct socket *, struct sockaddr *,
98                                        struct thread *);
99 int  ng_btsocket_l2cap_raw_control    (struct socket *, u_long, caddr_t,
100                                        struct ifnet *, struct thread *);
101 int  ng_btsocket_l2cap_raw_detach     (struct socket *);
102 int  ng_btsocket_l2cap_raw_disconnect (struct socket *);
103 int  ng_btsocket_l2cap_raw_peeraddr   (struct socket *, struct sockaddr **);
104 int  ng_btsocket_l2cap_raw_send       (struct socket *, int, struct mbuf *,
105                                        struct sockaddr *, struct mbuf *,
106                                        struct thread *);
107 int  ng_btsocket_l2cap_raw_sockaddr   (struct socket *, struct sockaddr **);
108 
109 #endif /* _KERNEL */
110 
111 /*****************************************************************************
112  *****************************************************************************
113  **                    SOCK_SEQPACKET L2CAP sockets                         **
114  *****************************************************************************
115  *****************************************************************************/
116 
117 #define NG_BTSOCKET_L2CAP_SENDSPACE	NG_L2CAP_MTU_DEFAULT /* (64 * 1024) */
118 #define NG_BTSOCKET_L2CAP_RECVSPACE	(64 * 1024)
119 
120 /*
121  * Bluetooth L2CAP socket PCB
122  */
123 
124 struct ng_btsocket_l2cap_pcb {
125 	struct socket			*so;	     /* Pointer to socket */
126 
127 	bdaddr_t			 src;	     /* Source address */
128 	bdaddr_t			 dst;	     /* Destination address */
129 
130 	u_int16_t			 psm;	     /* PSM */
131 	u_int16_t			 cid;	     /* Local channel ID */
132 
133 	u_int16_t			 flags;      /* socket flags */
134 #define NG_BTSOCKET_L2CAP_CLIENT	(1 << 0)     /* socket is client */
135 #define NG_BTSOCKET_L2CAP_TIMO		(1 << 1)     /* timeout pending */
136 
137 	u_int8_t			 state;      /* socket state */
138 #define NG_BTSOCKET_L2CAP_CLOSED	0            /* socket closed */
139 #define NG_BTSOCKET_L2CAP_CONNECTING	1            /* wait for connect */
140 #define NG_BTSOCKET_L2CAP_CONFIGURING	2            /* wait for config */
141 #define NG_BTSOCKET_L2CAP_OPEN		3            /* socket open */
142 #define NG_BTSOCKET_L2CAP_DISCONNECTING	4            /* wait for disconnect */
143 
144 	u_int8_t			 cfg_state;  /* config state */
145 #define	NG_BTSOCKET_L2CAP_CFG_IN	(1 << 0)     /* incoming path done */
146 #define	NG_BTSOCKET_L2CAP_CFG_OUT	(1 << 1)     /* outgoing path done */
147 #define	NG_BTSOCKET_L2CAP_CFG_BOTH \
148 	(NG_BTSOCKET_L2CAP_CFG_IN | NG_BTSOCKET_L2CAP_CFG_OUT)
149 
150 #define	NG_BTSOCKET_L2CAP_CFG_IN_SENT	(1 << 2)     /* L2CAP ConfigReq sent */
151 #define	NG_BTSOCKET_L2CAP_CFG_OUT_SENT	(1 << 3)     /* ---/--- */
152 
153 	u_int16_t			 imtu;       /* Incoming MTU */
154 	ng_l2cap_flow_t			 iflow;      /* Input flow spec */
155 
156 	u_int16_t			 omtu;       /* Outgoing MTU */
157 	ng_l2cap_flow_t			 oflow;      /* Outgoing flow spec */
158 
159 	u_int16_t			 flush_timo; /* flush timeout */
160 	u_int16_t			 link_timo;  /* link timeout */
161 
162 	struct callout_handle		 timo;       /* timeout */
163 
164 	u_int32_t			 token;	     /* message token */
165 	ng_btsocket_l2cap_rtentry_p	 rt;         /* routing info */
166 
167 	struct mtx			 pcb_mtx;    /* pcb mutex */
168 
169 	LIST_ENTRY(ng_btsocket_l2cap_pcb) next;      /* link to next PCB */
170 };
171 typedef struct ng_btsocket_l2cap_pcb	ng_btsocket_l2cap_pcb_t;
172 typedef struct ng_btsocket_l2cap_pcb *	ng_btsocket_l2cap_pcb_p;
173 
174 #define	so2l2cap_pcb(so) \
175 	((struct ng_btsocket_l2cap_pcb *)((so)->so_pcb))
176 
177 /*
178  * Bluetooth L2CAP socket methods
179  */
180 
181 #ifdef _KERNEL
182 
183 void ng_btsocket_l2cap_init       (void);
184 int  ng_btsocket_l2cap_abort      (struct socket *);
185 int  ng_btsocket_l2cap_accept     (struct socket *, struct sockaddr **);
186 int  ng_btsocket_l2cap_attach     (struct socket *, int, struct thread *);
187 int  ng_btsocket_l2cap_bind       (struct socket *, struct sockaddr *,
188                                    struct thread *);
189 int  ng_btsocket_l2cap_connect    (struct socket *, struct sockaddr *,
190                                    struct thread *);
191 int  ng_btsocket_l2cap_control    (struct socket *, u_long, caddr_t,
192                                    struct ifnet *, struct thread *);
193 int  ng_btsocket_l2cap_ctloutput  (struct socket *, struct sockopt *);
194 int  ng_btsocket_l2cap_detach     (struct socket *);
195 int  ng_btsocket_l2cap_disconnect (struct socket *);
196 int  ng_btsocket_l2cap_listen     (struct socket *, struct thread *);
197 int  ng_btsocket_l2cap_peeraddr   (struct socket *, struct sockaddr **);
198 int  ng_btsocket_l2cap_send       (struct socket *, int, struct mbuf *,
199                                    struct sockaddr *, struct mbuf *,
200                                    struct thread *);
201 int  ng_btsocket_l2cap_sockaddr   (struct socket *, struct sockaddr **);
202 
203 #endif /* _KERNEL */
204 
205 #endif /* _NETGRAPH_BTSOCKET_L2CAP_H_ */
206 
207