xref: /freebsd/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h (revision 0fac350c54d0a72f5341e15021efcde63eb58a4b)
1878ed226SJulian Elischer /*
2878ed226SJulian Elischer  * ng_btsocket_l2cap.h
3c398230bSWarner Losh  */
4c398230bSWarner Losh 
5c398230bSWarner Losh /*-
64d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
7fe267a55SPedro F. Giffuni  *
8878ed226SJulian Elischer  * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9878ed226SJulian Elischer  * All rights reserved.
10878ed226SJulian Elischer  *
11878ed226SJulian Elischer  * Redistribution and use in source and binary forms, with or without
12878ed226SJulian Elischer  * modification, are permitted provided that the following conditions
13878ed226SJulian Elischer  * are met:
14878ed226SJulian Elischer  * 1. Redistributions of source code must retain the above copyright
15878ed226SJulian Elischer  *    notice, this list of conditions and the following disclaimer.
16878ed226SJulian Elischer  * 2. Redistributions in binary form must reproduce the above copyright
17878ed226SJulian Elischer  *    notice, this list of conditions and the following disclaimer in the
18878ed226SJulian Elischer  *    documentation and/or other materials provided with the distribution.
19878ed226SJulian Elischer  *
20878ed226SJulian Elischer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21878ed226SJulian Elischer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22878ed226SJulian Elischer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23878ed226SJulian Elischer  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24878ed226SJulian Elischer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25878ed226SJulian Elischer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26878ed226SJulian Elischer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27878ed226SJulian Elischer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28878ed226SJulian Elischer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29878ed226SJulian Elischer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30878ed226SJulian Elischer  * SUCH DAMAGE.
31878ed226SJulian Elischer  *
32f2bb1caeSJulian Elischer  * $Id: ng_btsocket_l2cap.h,v 1.4 2003/03/25 23:53:33 max Exp $
33878ed226SJulian Elischer  */
34878ed226SJulian Elischer 
35878ed226SJulian Elischer #ifndef _NETGRAPH_BTSOCKET_L2CAP_H_
36f21fff6cSMaksim Yevmenkin #define _NETGRAPH_BTSOCKET_L2CAP_H_
37878ed226SJulian Elischer 
38878ed226SJulian Elischer /*
39878ed226SJulian Elischer  * L2CAP routing entry
40878ed226SJulian Elischer  */
41878ed226SJulian Elischer 
42878ed226SJulian Elischer struct ng_hook;
43878ed226SJulian Elischer struct ng_message;
44878ed226SJulian Elischer 
45878ed226SJulian Elischer struct ng_btsocket_l2cap_rtentry {
46878ed226SJulian Elischer 	bdaddr_t				 src;  /* source BD_ADDR */
47878ed226SJulian Elischer 	struct ng_hook				*hook; /* downstream hook */
48f2bb1caeSJulian Elischer 	LIST_ENTRY(ng_btsocket_l2cap_rtentry)	 next; /* link to next */
49878ed226SJulian Elischer };
50878ed226SJulian Elischer typedef struct ng_btsocket_l2cap_rtentry	ng_btsocket_l2cap_rtentry_t;
51878ed226SJulian Elischer typedef struct ng_btsocket_l2cap_rtentry *	ng_btsocket_l2cap_rtentry_p;
52878ed226SJulian Elischer 
53878ed226SJulian Elischer /*****************************************************************************
54878ed226SJulian Elischer  *****************************************************************************
55878ed226SJulian Elischer  **                          SOCK_RAW L2CAP sockets                         **
56878ed226SJulian Elischer  *****************************************************************************
57878ed226SJulian Elischer  *****************************************************************************/
58878ed226SJulian Elischer 
59878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_RAW_SENDSPACE	NG_L2CAP_MTU_DEFAULT
60878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_RAW_RECVSPACE	NG_L2CAP_MTU_DEFAULT
61878ed226SJulian Elischer 
62878ed226SJulian Elischer /*
63878ed226SJulian Elischer  * Bluetooth raw L2CAP socket PCB
64878ed226SJulian Elischer  */
65878ed226SJulian Elischer 
66878ed226SJulian Elischer struct ng_btsocket_l2cap_raw_pcb {
67878ed226SJulian Elischer 	struct socket				*so;	/* socket */
68878ed226SJulian Elischer 
69f2bb1caeSJulian Elischer 	u_int32_t				 flags; /* flags */
70f2bb1caeSJulian Elischer #define NG_BTSOCKET_L2CAP_RAW_PRIVILEGED	(1 << 0)
71f2bb1caeSJulian Elischer 
72878ed226SJulian Elischer 	bdaddr_t				 src;	/* source address */
73f2bb1caeSJulian Elischer 	bdaddr_t				 dst;	/* dest address */
74fbc48c2bSTakanori Watanabe 	uint8_t			 	 	 srctype;/*source addr type*/
75fbc48c2bSTakanori Watanabe 	uint8_t			 	 	 dsttype;/*source addr type*/
76878ed226SJulian Elischer 	ng_btsocket_l2cap_rtentry_p		 rt;    /* routing info */
77878ed226SJulian Elischer 
78878ed226SJulian Elischer 	u_int32_t				 token;	/* message token */
79878ed226SJulian Elischer 	struct ng_mesg				*msg;   /* message */
80878ed226SJulian Elischer 
81f2bb1caeSJulian Elischer 	struct mtx				 pcb_mtx; /* pcb mutex */
82f2bb1caeSJulian Elischer 
83878ed226SJulian Elischer 	LIST_ENTRY(ng_btsocket_l2cap_raw_pcb)	 next;  /* link to next PCB */
84878ed226SJulian Elischer };
85878ed226SJulian Elischer typedef struct ng_btsocket_l2cap_raw_pcb	ng_btsocket_l2cap_raw_pcb_t;
86878ed226SJulian Elischer typedef struct ng_btsocket_l2cap_raw_pcb *	ng_btsocket_l2cap_raw_pcb_p;
87878ed226SJulian Elischer 
88878ed226SJulian Elischer #define	so2l2cap_raw_pcb(so) \
89878ed226SJulian Elischer 	((struct ng_btsocket_l2cap_raw_pcb *)((so)->so_pcb))
90878ed226SJulian Elischer 
91878ed226SJulian Elischer /*
92878ed226SJulian Elischer  * Bluetooth raw L2CAP socket methods
93878ed226SJulian Elischer  */
94878ed226SJulian Elischer 
95878ed226SJulian Elischer #ifdef _KERNEL
96878ed226SJulian Elischer 
97ac45e92fSRobert Watson void ng_btsocket_l2cap_raw_abort      (struct socket *);
98a152f8a3SRobert Watson void ng_btsocket_l2cap_raw_close      (struct socket *);
99878ed226SJulian Elischer int  ng_btsocket_l2cap_raw_attach     (struct socket *, int, struct thread *);
100878ed226SJulian Elischer int  ng_btsocket_l2cap_raw_bind       (struct socket *, struct sockaddr *,
101878ed226SJulian Elischer                                        struct thread *);
102878ed226SJulian Elischer int  ng_btsocket_l2cap_raw_connect    (struct socket *, struct sockaddr *,
103878ed226SJulian Elischer                                        struct thread *);
104f277746eSGleb Smirnoff int  ng_btsocket_l2cap_raw_control    (struct socket *, u_long, void *,
105878ed226SJulian Elischer                                        struct ifnet *, struct thread *);
106bc725eafSRobert Watson void ng_btsocket_l2cap_raw_detach     (struct socket *);
107878ed226SJulian Elischer int  ng_btsocket_l2cap_raw_disconnect (struct socket *);
108*0fac350cSGleb Smirnoff int  ng_btsocket_l2cap_raw_peeraddr   (struct socket *, struct sockaddr *);
109878ed226SJulian Elischer int  ng_btsocket_l2cap_raw_send       (struct socket *, int, struct mbuf *,
110878ed226SJulian Elischer                                        struct sockaddr *, struct mbuf *,
111878ed226SJulian Elischer                                        struct thread *);
112*0fac350cSGleb Smirnoff int  ng_btsocket_l2cap_raw_sockaddr   (struct socket *, struct sockaddr *);
113878ed226SJulian Elischer 
114878ed226SJulian Elischer #endif /* _KERNEL */
115878ed226SJulian Elischer 
116878ed226SJulian Elischer /*****************************************************************************
117878ed226SJulian Elischer  *****************************************************************************
118878ed226SJulian Elischer  **                    SOCK_SEQPACKET L2CAP sockets                         **
119878ed226SJulian Elischer  *****************************************************************************
120878ed226SJulian Elischer  *****************************************************************************/
121878ed226SJulian Elischer 
122878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_SENDSPACE	NG_L2CAP_MTU_DEFAULT /* (64 * 1024) */
123878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_RECVSPACE	(64 * 1024)
124878ed226SJulian Elischer 
125878ed226SJulian Elischer /*
126878ed226SJulian Elischer  * Bluetooth L2CAP socket PCB
127878ed226SJulian Elischer  */
128878ed226SJulian Elischer 
129878ed226SJulian Elischer struct ng_btsocket_l2cap_pcb {
130878ed226SJulian Elischer 	struct socket			*so;	     /* Pointer to socket */
131878ed226SJulian Elischer 
132878ed226SJulian Elischer 	bdaddr_t			 src;	     /* Source address */
133878ed226SJulian Elischer 	bdaddr_t			 dst;	     /* Destination address */
134fbc48c2bSTakanori Watanabe 	uint8_t			 	 srctype;	/*source addr type*/
135fbc48c2bSTakanori Watanabe 	uint8_t			 	 dsttype;	/*source addr type*/
136878ed226SJulian Elischer 
137878ed226SJulian Elischer 	u_int16_t			 psm;	     /* PSM */
138878ed226SJulian Elischer 	u_int16_t			 cid;	     /* Local channel ID */
1393a601a23STakanori Watanabe 	uint8_t				 idtype;
140878ed226SJulian Elischer 	u_int16_t			 flags;      /* socket flags */
141878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_CLIENT	(1 << 0)     /* socket is client */
142878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_TIMO		(1 << 1)     /* timeout pending */
143878ed226SJulian Elischer 
144878ed226SJulian Elischer 	u_int8_t			 state;      /* socket state */
145878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_CLOSED	0            /* socket closed */
146878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_CONNECTING	1            /* wait for connect */
147878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_CONFIGURING	2            /* wait for config */
148878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_OPEN		3            /* socket open */
149878ed226SJulian Elischer #define NG_BTSOCKET_L2CAP_DISCONNECTING	4            /* wait for disconnect */
1503a601a23STakanori Watanabe #define NG_BTSOCKET_L2CAP_W4_ENC_CHANGE 5
151878ed226SJulian Elischer 
152878ed226SJulian Elischer 	u_int8_t			 cfg_state;  /* config state */
153878ed226SJulian Elischer #define	NG_BTSOCKET_L2CAP_CFG_IN	(1 << 0)     /* incoming path done */
154878ed226SJulian Elischer #define	NG_BTSOCKET_L2CAP_CFG_OUT	(1 << 1)     /* outgoing path done */
155878ed226SJulian Elischer #define	NG_BTSOCKET_L2CAP_CFG_BOTH \
156878ed226SJulian Elischer 	(NG_BTSOCKET_L2CAP_CFG_IN | NG_BTSOCKET_L2CAP_CFG_OUT)
157878ed226SJulian Elischer 
158878ed226SJulian Elischer #define	NG_BTSOCKET_L2CAP_CFG_IN_SENT	(1 << 2)     /* L2CAP ConfigReq sent */
159878ed226SJulian Elischer #define	NG_BTSOCKET_L2CAP_CFG_OUT_SENT	(1 << 3)     /* ---/--- */
1603a601a23STakanori Watanabe 	uint8_t 			 encryption;
161878ed226SJulian Elischer 	u_int16_t			 imtu;       /* Incoming MTU */
162878ed226SJulian Elischer 	ng_l2cap_flow_t			 iflow;      /* Input flow spec */
163878ed226SJulian Elischer 
164878ed226SJulian Elischer 	u_int16_t			 omtu;       /* Outgoing MTU */
165878ed226SJulian Elischer 	ng_l2cap_flow_t			 oflow;      /* Outgoing flow spec */
166878ed226SJulian Elischer 
167878ed226SJulian Elischer 	u_int16_t			 flush_timo; /* flush timeout */
168878ed226SJulian Elischer 	u_int16_t			 link_timo;  /* link timeout */
169878ed226SJulian Elischer 
1703d1592efSJohn Baldwin 	struct callout			 timo;       /* timeout */
171878ed226SJulian Elischer 
172878ed226SJulian Elischer 	u_int32_t			 token;	     /* message token */
173878ed226SJulian Elischer 	ng_btsocket_l2cap_rtentry_p	 rt;         /* routing info */
174878ed226SJulian Elischer 
175878ed226SJulian Elischer 	struct mtx			 pcb_mtx;    /* pcb mutex */
1763a601a23STakanori Watanabe 	uint16_t			 need_encrypt; /*encryption needed*/
177878ed226SJulian Elischer 
178878ed226SJulian Elischer 	LIST_ENTRY(ng_btsocket_l2cap_pcb) next;      /* link to next PCB */
179878ed226SJulian Elischer };
180878ed226SJulian Elischer typedef struct ng_btsocket_l2cap_pcb	ng_btsocket_l2cap_pcb_t;
181878ed226SJulian Elischer typedef struct ng_btsocket_l2cap_pcb *	ng_btsocket_l2cap_pcb_p;
182878ed226SJulian Elischer 
183878ed226SJulian Elischer #define	so2l2cap_pcb(so) \
184878ed226SJulian Elischer 	((struct ng_btsocket_l2cap_pcb *)((so)->so_pcb))
185878ed226SJulian Elischer 
186878ed226SJulian Elischer /*
187878ed226SJulian Elischer  * Bluetooth L2CAP socket methods
188878ed226SJulian Elischer  */
189878ed226SJulian Elischer 
190878ed226SJulian Elischer #ifdef _KERNEL
191878ed226SJulian Elischer 
192ac45e92fSRobert Watson void ng_btsocket_l2cap_abort      (struct socket *);
193a152f8a3SRobert Watson void ng_btsocket_l2cap_close      (struct socket *);
194878ed226SJulian Elischer int  ng_btsocket_l2cap_attach     (struct socket *, int, struct thread *);
195878ed226SJulian Elischer int  ng_btsocket_l2cap_bind       (struct socket *, struct sockaddr *,
196878ed226SJulian Elischer                                    struct thread *);
197878ed226SJulian Elischer int  ng_btsocket_l2cap_connect    (struct socket *, struct sockaddr *,
198878ed226SJulian Elischer                                    struct thread *);
199f277746eSGleb Smirnoff int  ng_btsocket_l2cap_control    (struct socket *, u_long, void *,
200878ed226SJulian Elischer                                    struct ifnet *, struct thread *);
201878ed226SJulian Elischer int  ng_btsocket_l2cap_ctloutput  (struct socket *, struct sockopt *);
202bc725eafSRobert Watson void ng_btsocket_l2cap_detach     (struct socket *);
203878ed226SJulian Elischer int  ng_btsocket_l2cap_disconnect (struct socket *);
204d374e81eSRobert Watson int  ng_btsocket_l2cap_listen     (struct socket *, int, struct thread *);
205*0fac350cSGleb Smirnoff int  ng_btsocket_l2cap_peeraddr   (struct socket *, struct sockaddr *);
206878ed226SJulian Elischer int  ng_btsocket_l2cap_send       (struct socket *, int, struct mbuf *,
207878ed226SJulian Elischer                                    struct sockaddr *, struct mbuf *,
208878ed226SJulian Elischer                                    struct thread *);
209*0fac350cSGleb Smirnoff int  ng_btsocket_l2cap_sockaddr   (struct socket *, struct sockaddr *);
210878ed226SJulian Elischer 
211878ed226SJulian Elischer #endif /* _KERNEL */
212878ed226SJulian Elischer 
213878ed226SJulian Elischer #endif /* _NETGRAPH_BTSOCKET_L2CAP_H_ */
214