GNU Radio's BLUETOOTH Package
packet_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2013 Christopher D. Kilgour
4 * Copyright 2008, 2009 Dominic Spill, Michael Ossmann
5 * Copyright 2007 Dominic Spill
6 * Copyright 2005, 2006 Free Software Foundation, Inc.
7 *
8 * This file is part of gr-bluetooth
9 *
10 * This is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this software; see the file COPYING. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street,
23 * Boston, MA 02110-1301, USA.
24 */
25
26#ifndef INCLUDED_BLUETOOTH_GR_BLUETOOTH_PACKET_IMPL_H
27#define INCLUDED_BLUETOOTH_GR_BLUETOOTH_PACKET_IMPL_H
28
29#include "bluetooth/packet.h"
30#include <string>
31
32namespace gr {
33 namespace bluetooth {
34
35 class classic_packet_impl : virtual public classic_packet
36 {
37 private:
38 /* lower address part found in access code */
39 uint32_t d_LAP;
40
41 /* upper address part */
42 uint8_t d_UAP;
43
44 /* non-significant address part */
45 uint8_t d_NAP;
46
47 /* packet header, one bit per char */
48 char d_packet_header[18];
49
50 /* payload header, one bit per char */
51 /* the packet may have a payload header of 0, 1, or 2 bytes, reserving 2 */
52 char d_payload_header[16];
53
54 /* number of payload header bytes */
55 /* set to 0, 1, 2, or -1 for unknown */
56 int d_payload_header_length;
57
58 /* LLID field of payload header (2 bits) */
59 uint8_t d_payload_llid;
60
61 /* flow field of payload header (1 bit) */
62 uint8_t d_payload_flow;
63
64 /* do we know the UAP/NAP? */
65 bool d_have_UAP;
66 bool d_have_NAP;
67
68 /* do we know the master clock? */
69 bool d_have_clk6;
70 bool d_have_clk27;
71
72 /* CLK1-27 of master */
73 uint32_t d_clock;
74
75 /* type-specific CRC checks and decoding */
76 int fhs(int clock);
77 int DM(int clock);
78 int DH(int clock);
79 int EV3(int clock);
80 int EV4(int clock);
81 int EV5(int clock);
82 int HV(int clock);
83
84 /* decode payload header, return value indicates success */
85 bool decode_payload_header(char *stream, int clock, int header_bytes, int size, bool fec);
86
87 /* Remove the whitening from an air order array */
88 void unwhiten(char* input, char* output, int clock, int length, int skip);
89
90 /* verify the payload CRC */
91 bool payload_crc();
92
93 public:
94 classic_packet_impl(char *stream, int length);
96
97 /* return the classic_packet's LAP */
98 uint32_t get_LAP();
99
100 /* return the classic_packet's UAP */
101 uint8_t get_UAP();
102
103 /* set the classic_packet's UAP */
104 void set_UAP(uint8_t UAP);
105
106 /* set the classic_packet's NAP */
107 void set_NAP(uint16_t NAP);
108
109 /* set the classic_packet's clock */
110 void set_clock(uint32_t clk6, bool have27);
111
112 /* return the classic_packet's clock (CLK1-27) */
113 uint32_t get_clock();
114
115 /* check if the classic_packet's CRC is correct for a given clock (CLK1-6) */
116 int crc_check(int clock);
117
118 /* try a clock value (CLK1-6) to unwhiten classic_packet header,
119 * sets resultant d_packet_type and d_UAP, returns UAP.
120 */
121 uint8_t try_clock(int clock);
122
123 /* decode the classic_packet header */
125
126 /* decode the classic_packet header */
128
129 /* print classic_packet information */
130 void print();
131
132 /* format payload for tun interface */
133 char *tun_format();
134
135 /* check to see if the classic_packet has a header */
137
138 /* extract LAP from FHS payload */
139 uint32_t lap_from_fhs();
140
141 /* extract UAP from FHS payload */
142 uint8_t uap_from_fhs();
143
144 /* extract NAP from FHS payload */
145 uint16_t nap_from_fhs();
146
147 /* extract clock from FHS payload */
148 uint32_t clock_from_fhs();
149 };
150
151 class le_packet_impl : virtual public le_packet
152 {
153 private:
154 int d_channel;
155
156 int d_index;
157 uint32_t d_AA;
158
159 uint8_t d_PDU_Type;
160 uint8_t d_TxAdd;
161 uint8_t d_RxAdd;
162 uint8_t d_LLID;
163 uint8_t d_NESN;
164 uint8_t d_SN;
165 uint8_t d_MD;
166 unsigned d_PDU_Length;
167
168 char d_link_symbols[LE_MAX_SYMBOLS];
169 uint8_t d_pdu[LE_MAX_PDU_OCTETS];
170
171 public:
172 le_packet_impl(char *stream, int length, double freq=0.0);
174
175 /* decode the packet header */
177
178 /* decode the packet header */
180
181 /* print packet information */
182 void print();
183
184 /* format payload for tun interface */
185 char *tun_format();
186
187 /* check to see if the packet has a header */
189
190 /* return the low-energy packet's AA */
191 uint32_t get_AA() { return d_AA; }
192
193 int get_channel( ) { return d_channel; }
194 };
195
196 } // namespace bluetooth
197} // namespace gr
198
199#endif /* INCLUDED_BLUETOOTH_GR_BLUETOOTH_PACKET_IMPL_H */
200
classic_packet_impl(char *stream, int length)
void set_clock(uint32_t clk6, bool have27)
<+description of block+>
Definition packet.h:164
uint32_t get_AA()
Definition packet_impl.h:191
int get_channel()
Definition packet_impl.h:193
le_packet_impl(char *stream, int length, double freq=0.0)
Definition packet.h:292
Definition multi_block.h:34
Definition multi_block.h:33
#define LE_MAX_PDU_OCTETS
Definition packet.h:287
#define LE_MAX_SYMBOLS
Definition packet.h:289