1 /* $NetBSD: btpand.h,v 1.1 2008/08/17 13:20:57 plunky Exp $ */
4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
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.
32 #include <sys/types.h>
33 #include <sys/queue.h>
34 #include <sys/socket.h>
37 #include <net/ethernet.h>
40 #include <bluetooth.h>
49 #define __arraycount(__x) (int)(sizeof((__x)) / sizeof((__x)[0]))
52 #ifndef L2CAP_PSM_INVALID
53 #define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001)
56 #ifndef L2CAP_PSM_BNEP
57 #define L2CAP_PSM_BNEP 15
60 typedef struct channel channel_t;
61 typedef struct pfilter pfilter_t;
62 typedef struct mfilter mfilter_t;
63 typedef struct packet packet_t;
64 typedef struct pkthdr pkthdr_t;
65 typedef struct pktlist pktlist_t;
66 typedef struct exthdr exthdr_t;
67 typedef struct extlist extlist_t;
69 LIST_HEAD(chlist, channel);
70 STAILQ_HEAD(extlist, exthdr);
71 STAILQ_HEAD(pktlist, pkthdr);
75 CHANNEL_WAIT_CONNECT_REQ,
76 CHANNEL_WAIT_CONNECT_RSP,
80 #define CHANNEL_MAXQLEN 128
82 /* BNEP or tap channel */
84 enum channel_state state;
87 uint8_t laddr[ETHER_ADDR_LEN];
88 uint8_t raddr[ETHER_ADDR_LEN];
106 bool (*send)(channel_t *, packet_t *);
107 bool (*recv)(packet_t *);
114 LIST_ENTRY(channel) next;
117 /* network protocol type filter */
123 /* multicast address filter */
125 uint8_t start[ETHER_ADDR_LEN];
126 uint8_t end[ETHER_ADDR_LEN];
129 /* packet data buffer */
131 channel_t * chan; /* source channel */
132 uint8_t * dst; /* dest address */
133 uint8_t * src; /* source address */
134 uint8_t * type; /* protocol type */
135 uint8_t * ptr; /* data pointer */
136 size_t len; /* data length */
137 int refcnt; /* reference count */
138 extlist_t extlist;/* extension headers */
139 uint8_t buf[0]; /* data starts here */
142 /* extension header */
144 STAILQ_ENTRY(exthdr) next;
151 STAILQ_ENTRY(pkthdr) next;
155 /* global variables */
156 extern const char * control_path;
157 extern const char * service_name;
158 extern const char * interface_name;
159 extern bdaddr_t local_bdaddr;
160 extern bdaddr_t remote_bdaddr;
161 extern uint16_t l2cap_psm;
162 extern int l2cap_mode;
163 extern uint16_t service_class;
164 extern int server_limit;
167 * Bluetooth addresses are stored the other way around than
168 * Ethernet addresses even though they are of the same family
171 b2eaddr(void *dst, bdaddr_t *src)
176 for (i = 0; i < ETHER_ADDR_LEN; i++)
177 d[i] = src->b[ETHER_ADDR_LEN - i - 1];
180 #define log_err(fmt, args...) syslog(LOG_ERR, fmt , ##args)
181 #define log_info(fmt, args...) syslog(LOG_INFO, fmt , ##args)
182 #define log_notice(fmt, args...) syslog(LOG_NOTICE, fmt , ##args)
183 #define log_debug(fmt, args...) syslog(LOG_DEBUG, "%s: " fmt, __func__ , ##args)
186 bool bnep_send(channel_t *, packet_t *);
187 bool bnep_recv(packet_t *);
188 void bnep_send_control(channel_t *, unsigned, ...);
191 void channel_init(void);
192 channel_t * channel_alloc(void);
193 bool channel_open(channel_t *, int);
194 void channel_close(channel_t *);
195 void channel_free(channel_t *);
196 void channel_timeout(channel_t *, int);
197 void channel_put(channel_t *, packet_t *);
200 void client_init(void);
203 packet_t * packet_alloc(channel_t *);
204 void packet_free(packet_t *);
205 void packet_adj(packet_t *, size_t);
206 pkthdr_t * pkthdr_alloc(packet_t *);
207 void pkthdr_free(pkthdr_t *);
210 void server_init(void);
211 void server_update(int);