1 /* $NetBSD: btpand.h,v 1.1 2008/08/17 13:20:57 plunky Exp $ */
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2008 Iain Hibbert
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/types.h>
32 #include <sys/queue.h>
33 #include <sys/socket.h>
36 #include <net/ethernet.h>
39 #include <bluetooth.h>
48 #define __arraycount(__x) (int)(sizeof((__x)) / sizeof((__x)[0]))
51 #ifndef L2CAP_PSM_INVALID
52 #define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001)
55 #ifndef L2CAP_PSM_BNEP
56 #define L2CAP_PSM_BNEP 15
59 typedef struct channel channel_t;
60 typedef struct pfilter pfilter_t;
61 typedef struct mfilter mfilter_t;
62 typedef struct packet packet_t;
63 typedef struct pkthdr pkthdr_t;
64 typedef struct pktlist pktlist_t;
65 typedef struct exthdr exthdr_t;
66 typedef struct extlist extlist_t;
68 LIST_HEAD(chlist, channel);
69 STAILQ_HEAD(extlist, exthdr);
70 STAILQ_HEAD(pktlist, pkthdr);
74 CHANNEL_WAIT_CONNECT_REQ,
75 CHANNEL_WAIT_CONNECT_RSP,
79 #define CHANNEL_MAXQLEN 128
81 /* BNEP or tap channel */
83 enum channel_state state;
86 uint8_t laddr[ETHER_ADDR_LEN];
87 uint8_t raddr[ETHER_ADDR_LEN];
105 bool (*send)(channel_t *, packet_t *);
106 bool (*recv)(packet_t *);
113 LIST_ENTRY(channel) next;
116 /* network protocol type filter */
122 /* multicast address filter */
124 uint8_t start[ETHER_ADDR_LEN];
125 uint8_t end[ETHER_ADDR_LEN];
128 /* packet data buffer */
130 channel_t * chan; /* source channel */
131 uint8_t * dst; /* dest address */
132 uint8_t * src; /* source address */
133 uint8_t * type; /* protocol type */
134 uint8_t * ptr; /* data pointer */
135 size_t len; /* data length */
136 int refcnt; /* reference count */
137 extlist_t extlist;/* extension headers */
138 uint8_t buf[0]; /* data starts here */
141 /* extension header */
143 STAILQ_ENTRY(exthdr) next;
150 STAILQ_ENTRY(pkthdr) next;
154 /* global variables */
155 extern const char * control_path;
156 extern const char * service_name;
157 extern const char * interface_name;
158 extern bdaddr_t local_bdaddr;
159 extern bdaddr_t remote_bdaddr;
160 extern uint16_t l2cap_psm;
161 extern int l2cap_mode;
162 extern uint16_t service_class;
163 extern int server_limit;
166 * Bluetooth addresses are stored the other way around than
167 * Ethernet addresses even though they are of the same family
170 b2eaddr(void *dst, bdaddr_t *src)
175 for (i = 0; i < ETHER_ADDR_LEN; i++)
176 d[i] = src->b[ETHER_ADDR_LEN - i - 1];
179 #define log_err(fmt, args...) syslog(LOG_ERR, fmt , ##args)
180 #define log_info(fmt, args...) syslog(LOG_INFO, fmt , ##args)
181 #define log_notice(fmt, args...) syslog(LOG_NOTICE, fmt , ##args)
182 #define log_debug(fmt, args...) syslog(LOG_DEBUG, "%s: " fmt, __func__ , ##args)
185 bool bnep_send(channel_t *, packet_t *);
186 bool bnep_recv(packet_t *);
187 void bnep_send_control(channel_t *, unsigned, ...);
190 void channel_init(void);
191 channel_t * channel_alloc(void);
192 bool channel_open(channel_t *, int);
193 void channel_close(channel_t *);
194 void channel_free(channel_t *);
195 void channel_timeout(channel_t *, int);
196 void channel_put(channel_t *, packet_t *);
199 void client_init(void);
202 packet_t * packet_alloc(channel_t *);
203 void packet_free(packet_t *);
204 void packet_adj(packet_t *, size_t);
205 pkthdr_t * pkthdr_alloc(packet_t *);
206 void pkthdr_free(pkthdr_t *);
209 void server_init(void);
210 void server_update(int);