| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: bnep.c,v 1.4 2009/05/02 20:07:51 plunky Exp $ */ | | 1 | /* $NetBSD: bnep.c,v 1.5 2009/05/02 20:13:44 plunky Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 Iain Hibbert | | 4 | * Copyright (c) 2008 Iain Hibbert |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -16,27 +16,27 @@ | | | @@ -16,27 +16,27 @@ |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __RCSID("$NetBSD: bnep.c,v 1.4 2009/05/02 20:07:51 plunky Exp $"); | | 29 | __RCSID("$NetBSD: bnep.c,v 1.5 2009/05/02 20:13:44 plunky Exp $"); |
30 | | | 30 | |
31 | #include <bluetooth.h> | | 31 | #include <bluetooth.h> |
32 | #include <sdp.h> | | 32 | #include <sdp.h> |
33 | #include <stdarg.h> | | 33 | #include <stdarg.h> |
34 | #include <string.h> | | 34 | #include <string.h> |
35 | | | 35 | |
36 | #include "btpand.h" | | 36 | #include "btpand.h" |
37 | #include "bnep.h" | | 37 | #include "bnep.h" |
38 | | | 38 | |
39 | static bool bnep_recv_extension(packet_t *); | | 39 | static bool bnep_recv_extension(packet_t *); |
40 | static size_t bnep_recv_control(channel_t *, uint8_t *, size_t, bool); | | 40 | static size_t bnep_recv_control(channel_t *, uint8_t *, size_t, bool); |
41 | static size_t bnep_recv_control_command_not_understood(channel_t *, uint8_t *, size_t); | | 41 | static size_t bnep_recv_control_command_not_understood(channel_t *, uint8_t *, size_t); |
42 | static size_t bnep_recv_setup_connection_req(channel_t *, uint8_t *, size_t); | | 42 | static size_t bnep_recv_setup_connection_req(channel_t *, uint8_t *, size_t); |
| @@ -158,26 +158,31 @@ bnep_recv(packet_t *pkt) | | | @@ -158,26 +158,31 @@ bnep_recv(packet_t *pkt) |
158 | | | 158 | |
159 | log_debug("dropped packet with reserved type 0x%2.2x", type); | | 159 | log_debug("dropped packet with reserved type 0x%2.2x", type); |
160 | return false; | | 160 | return false; |
161 | } | | 161 | } |
162 | | | 162 | |
163 | if (BNEP_TYPE_EXT(type) | | 163 | if (BNEP_TYPE_EXT(type) |
164 | && !bnep_recv_extension(pkt)) | | 164 | && !bnep_recv_extension(pkt)) |
165 | return false; /* invalid extensions */ | | 165 | return false; /* invalid extensions */ |
166 | | | 166 | |
167 | if (BNEP_TYPE(type) == BNEP_CONTROL | | 167 | if (BNEP_TYPE(type) == BNEP_CONTROL |
168 | || pkt->chan->state != CHANNEL_OPEN) | | 168 | || pkt->chan->state != CHANNEL_OPEN) |
169 | return false; /* no forwarding */ | | 169 | return false; /* no forwarding */ |
170 | | | 170 | |
| | | 171 | if (pkt->len > ETHER_MAX_LEN) |
| | | 172 | log_debug("received long packet " |
| | | 173 | "(type=0x%2.2x, proto=0x%4.4x, len=%d)", |
| | | 174 | type, be16dec(pkt->type), pkt->len); |
| | | 175 | |
171 | return true; | | 176 | return true; |
172 | } | | 177 | } |
173 | | | 178 | |
174 | static bool | | 179 | static bool |
175 | bnep_recv_extension(packet_t *pkt) | | 180 | bnep_recv_extension(packet_t *pkt) |
176 | { | | 181 | { |
177 | exthdr_t *eh; | | 182 | exthdr_t *eh; |
178 | size_t len, size; | | 183 | size_t len, size; |
179 | uint8_t type; | | 184 | uint8_t type; |
180 | | | 185 | |
181 | do { | | 186 | do { |
182 | if (pkt->len < 2) | | 187 | if (pkt->len < 2) |
183 | return false; | | 188 | return false; |