xref: /btstack/example/panu_demo.c (revision 36b4a12c09067d74330201a6a5d396534f610e11)
1bcf00d8fSMatthias Ringwald /*
2bcf00d8fSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3bcf00d8fSMatthias Ringwald  *
4bcf00d8fSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5bcf00d8fSMatthias Ringwald  * modification, are permitted provided that the following conditions
6bcf00d8fSMatthias Ringwald  * are met:
7bcf00d8fSMatthias Ringwald  *
8bcf00d8fSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9bcf00d8fSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10bcf00d8fSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11bcf00d8fSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12bcf00d8fSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13bcf00d8fSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14bcf00d8fSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15bcf00d8fSMatthias Ringwald  *    from this software without specific prior written permission.
16bcf00d8fSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17bcf00d8fSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18bcf00d8fSMatthias Ringwald  *    monetary gain.
19bcf00d8fSMatthias Ringwald  *
20bcf00d8fSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21bcf00d8fSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22bcf00d8fSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23bcf00d8fSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24bcf00d8fSMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25bcf00d8fSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26bcf00d8fSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27bcf00d8fSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28bcf00d8fSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29bcf00d8fSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30bcf00d8fSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31bcf00d8fSMatthias Ringwald  * SUCH DAMAGE.
32bcf00d8fSMatthias Ringwald  *
33bcf00d8fSMatthias Ringwald  * Please inquire about commercial licensing options at
34bcf00d8fSMatthias Ringwald  * [email protected]
35bcf00d8fSMatthias Ringwald  *
36bcf00d8fSMatthias Ringwald  */
37bcf00d8fSMatthias Ringwald 
38ab2c6ae4SMatthias Ringwald #define __BTSTACK_FILE__ "panu_demo.c"
39ab2c6ae4SMatthias Ringwald 
40bcf00d8fSMatthias Ringwald /*
41bcf00d8fSMatthias Ringwald  * panu_demo.c
42bcf00d8fSMatthias Ringwald  * Author: Ole Reinhardt <[email protected]>
43bcf00d8fSMatthias Ringwald  */
44bcf00d8fSMatthias Ringwald 
45bcf00d8fSMatthias Ringwald /* EXAMPLE_START(panu_demo): PANU Demo
46bcf00d8fSMatthias Ringwald  *
47bcf00d8fSMatthias Ringwald  * @text This example implements both a PANU client and a server. In server mode, it
48bcf00d8fSMatthias Ringwald  * sets up a BNEP server and registers a PANU SDP record and waits for incoming connections.
49bcf00d8fSMatthias Ringwald  * In client mode, it connects to a remote device, does an SDP Query to identify the PANU
50bcf00d8fSMatthias Ringwald  * service and initiates a BNEP connection.
51bcf00d8fSMatthias Ringwald  */
52bcf00d8fSMatthias Ringwald 
53bcf00d8fSMatthias Ringwald #include "btstack_config.h"
54bcf00d8fSMatthias Ringwald 
55bcf00d8fSMatthias Ringwald #include <arpa/inet.h>
56bcf00d8fSMatthias Ringwald #include <errno.h>
57bcf00d8fSMatthias Ringwald #include <fcntl.h>
58bcf00d8fSMatthias Ringwald #include <ifaddrs.h>
59bcf00d8fSMatthias Ringwald #include <stdint.h>
60bcf00d8fSMatthias Ringwald #include <stdio.h>
61bcf00d8fSMatthias Ringwald #include <stdlib.h>
62bcf00d8fSMatthias Ringwald #include <string.h>
637693aad0SMatthias Ringwald #include <unistd.h>
64bcf00d8fSMatthias Ringwald 
65bcf00d8fSMatthias Ringwald #include <net/if_arp.h>
66bcf00d8fSMatthias Ringwald 
67bcf00d8fSMatthias Ringwald #ifdef __APPLE__
68bcf00d8fSMatthias Ringwald #include <net/if.h>
69bcf00d8fSMatthias Ringwald #include <net/if_types.h>
70bcf00d8fSMatthias Ringwald 
71bcf00d8fSMatthias Ringwald #include <netinet/if_ether.h>
72bcf00d8fSMatthias Ringwald #include <netinet/in.h>
73bcf00d8fSMatthias Ringwald #endif
74bcf00d8fSMatthias Ringwald 
75bcf00d8fSMatthias Ringwald #include <sys/ioctl.h>
76bcf00d8fSMatthias Ringwald #include <sys/param.h>
77bcf00d8fSMatthias Ringwald #include <sys/socket.h>
78bcf00d8fSMatthias Ringwald #include <sys/stat.h>
79bcf00d8fSMatthias Ringwald #include <sys/types.h>
80bcf00d8fSMatthias Ringwald 
81bcf00d8fSMatthias Ringwald #ifdef __linux
82bcf00d8fSMatthias Ringwald #include <linux/if.h>
83bcf00d8fSMatthias Ringwald #include <linux/if_tun.h>
84bcf00d8fSMatthias Ringwald #endif
85bcf00d8fSMatthias Ringwald 
864d2bcd2aSMatthias Ringwald #include "btstack.h"
87bcf00d8fSMatthias Ringwald 
88bcf00d8fSMatthias Ringwald static int record_id = -1;
89bcf00d8fSMatthias Ringwald static uint16_t bnep_l2cap_psm      = 0;
90bcf00d8fSMatthias Ringwald static uint32_t bnep_remote_uuid    = 0;
91bcf00d8fSMatthias Ringwald static uint16_t bnep_version        = 0;
92bcf00d8fSMatthias Ringwald static uint16_t bnep_cid            = 0;
93bcf00d8fSMatthias Ringwald 
94b5a442a7SMatthias Ringwald static uint16_t sdp_bnep_l2cap_psm      = 0;
95b5a442a7SMatthias Ringwald static uint16_t sdp_bnep_version        = 0;
96b5a442a7SMatthias Ringwald static uint32_t sdp_bnep_remote_uuid    = 0;
97b5a442a7SMatthias Ringwald 
98bcf00d8fSMatthias Ringwald static uint8_t   attribute_value[1000];
99bcf00d8fSMatthias Ringwald static const unsigned int attribute_value_buffer_size = sizeof(attribute_value);
100bcf00d8fSMatthias Ringwald 
101b5a442a7SMatthias Ringwald // MBP 2016 static const char * remote_addr_string = "F4-0F-24-3B-1B-E1";
102b5a442a7SMatthias Ringwald // Wiko Sunny
103b5a442a7SMatthias Ringwald static const char * remote_addr_string = "A0:4C:5B:0F:B2:42";
1047693aad0SMatthias Ringwald static bd_addr_t remote_addr;
105bcf00d8fSMatthias Ringwald 
106bcf00d8fSMatthias Ringwald static int  tap_fd = -1;
107bcf00d8fSMatthias Ringwald static uint8_t network_buffer[BNEP_MTU_MIN];
108bcf00d8fSMatthias Ringwald static size_t  network_buffer_len = 0;
109bcf00d8fSMatthias Ringwald 
110bcf00d8fSMatthias Ringwald #ifdef __APPLE__
111bcf00d8fSMatthias Ringwald // tuntaposx provides fixed set of tapX devices
112bcf00d8fSMatthias Ringwald static const char * tap_dev = "/dev/tap0";
113bcf00d8fSMatthias Ringwald static char tap_dev_name[16] = "tap0";
114bcf00d8fSMatthias Ringwald #endif
115bcf00d8fSMatthias Ringwald 
116bcf00d8fSMatthias Ringwald #ifdef __linux
117bcf00d8fSMatthias Ringwald // Linux uses single control device to bring up tunX or tapX interface
118bcf00d8fSMatthias Ringwald static const char * tap_dev = "/dev/net/tun";
119bcf00d8fSMatthias Ringwald static char tap_dev_name[16] = "bnep%d";
120bcf00d8fSMatthias Ringwald #endif
121bcf00d8fSMatthias Ringwald 
122bcf00d8fSMatthias Ringwald 
123bcf00d8fSMatthias Ringwald static btstack_data_source_t tap_dev_ds;
124bcf00d8fSMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration;
125bcf00d8fSMatthias Ringwald 
126bcf00d8fSMatthias Ringwald /* @section Main application configuration
127bcf00d8fSMatthias Ringwald  *
128bcf00d8fSMatthias Ringwald  * @text In the application configuration, L2CAP and BNEP are initialized and a BNEP service, for server mode,
129bcf00d8fSMatthias Ringwald  * is registered, before the Bluetooth stack gets started, as shown in Listing PanuSetup.
130bcf00d8fSMatthias Ringwald  */
131bcf00d8fSMatthias Ringwald 
132bcf00d8fSMatthias Ringwald /* LISTING_START(PanuSetup): Panu setup */
133bcf00d8fSMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
134423c667cSMatthias Ringwald static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
135bcf00d8fSMatthias Ringwald 
136bcf00d8fSMatthias Ringwald static void panu_setup(void){
137bcf00d8fSMatthias Ringwald 
138bcf00d8fSMatthias Ringwald     // register for HCI events
139bcf00d8fSMatthias Ringwald     hci_event_callback_registration.callback = &packet_handler;
140bcf00d8fSMatthias Ringwald     hci_add_event_handler(&hci_event_callback_registration);
141bcf00d8fSMatthias Ringwald 
142bcf00d8fSMatthias Ringwald     // Initialize L2CAP
143bcf00d8fSMatthias Ringwald     l2cap_init();
144bcf00d8fSMatthias Ringwald 
145bcf00d8fSMatthias Ringwald     // Initialise BNEP
146bcf00d8fSMatthias Ringwald     bnep_init();
147bcf00d8fSMatthias Ringwald     // Minimum L2CAP MTU for bnep is 1691 bytes
148235946f1SMatthias Ringwald     bnep_register_service(packet_handler, BLUETOOTH_SERVICE_CLASS_PANU, 1691);
149bcf00d8fSMatthias Ringwald }
150bcf00d8fSMatthias Ringwald /* LISTING_END */
151bcf00d8fSMatthias Ringwald 
152bcf00d8fSMatthias Ringwald /* @section TUN / TAP interface routines
153bcf00d8fSMatthias Ringwald  *
154bcf00d8fSMatthias Ringwald  * @text This example requires a TUN/TAP interface to connect the Bluetooth network interface
155bcf00d8fSMatthias Ringwald  * with the native system. It has been tested on Linux and OS X, but should work on any
156bcf00d8fSMatthias Ringwald  * system that provides TUN/TAP with minor modifications.
157bcf00d8fSMatthias Ringwald  *
158bcf00d8fSMatthias Ringwald  * On Linux, TUN/TAP is available by default. On OS X, tuntaposx from
159bcf00d8fSMatthias Ringwald  * http://tuntaposx.sourceforge.net needs to be installed.
160bcf00d8fSMatthias Ringwald  *
161bcf00d8fSMatthias Ringwald  * The *tap_alloc* function sets up a virtual network interface with the given Bluetooth Address.
162bcf00d8fSMatthias Ringwald  * It is rather low-level as it sets up and configures a network interface.
163bcf00d8fSMatthias Ringwald  */
164bcf00d8fSMatthias Ringwald 
165bcf00d8fSMatthias Ringwald static int tap_alloc(char *dev, bd_addr_t bd_addr)
166bcf00d8fSMatthias Ringwald {
167bcf00d8fSMatthias Ringwald     struct ifreq ifr;
168bcf00d8fSMatthias Ringwald     int fd_dev;
169bcf00d8fSMatthias Ringwald     int fd_socket;
170bcf00d8fSMatthias Ringwald 
171bcf00d8fSMatthias Ringwald     if( (fd_dev = open(tap_dev, O_RDWR)) < 0 ) {
172bcf00d8fSMatthias Ringwald         fprintf(stderr, "TAP: Error opening %s: %s\n", tap_dev, strerror(errno));
173bcf00d8fSMatthias Ringwald         return -1;
174bcf00d8fSMatthias Ringwald     }
175bcf00d8fSMatthias Ringwald 
176bcf00d8fSMatthias Ringwald #ifdef __linux
177bcf00d8fSMatthias Ringwald     memset(&ifr, 0, sizeof(ifr));
178bcf00d8fSMatthias Ringwald 
179bcf00d8fSMatthias Ringwald     ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
180bcf00d8fSMatthias Ringwald     if( *dev ) {
181bcf00d8fSMatthias Ringwald         strncpy(ifr.ifr_name, dev, IFNAMSIZ);
182bcf00d8fSMatthias Ringwald     }
183bcf00d8fSMatthias Ringwald 
184bcf00d8fSMatthias Ringwald     int err;
185bcf00d8fSMatthias Ringwald     if( (err = ioctl(fd_dev, TUNSETIFF, (void *) &ifr)) < 0 ) {
186bcf00d8fSMatthias Ringwald         fprintf(stderr, "TAP: Error setting device name: %s\n", strerror(errno));
187bcf00d8fSMatthias Ringwald         close(fd_dev);
188bcf00d8fSMatthias Ringwald         return -1;
189bcf00d8fSMatthias Ringwald     }
190bcf00d8fSMatthias Ringwald     strcpy(dev, ifr.ifr_name);
191bcf00d8fSMatthias Ringwald #endif
192bcf00d8fSMatthias Ringwald #ifdef __APPLE__
193bcf00d8fSMatthias Ringwald     dev = tap_dev_name;
194bcf00d8fSMatthias Ringwald #endif
195bcf00d8fSMatthias Ringwald 
196bcf00d8fSMatthias Ringwald     fd_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
197bcf00d8fSMatthias Ringwald 	if (fd_socket < 0) {
198bcf00d8fSMatthias Ringwald         close(fd_dev);
199bcf00d8fSMatthias Ringwald 		fprintf(stderr, "TAP: Error opening netlink socket: %s\n", strerror(errno));
200bcf00d8fSMatthias Ringwald 		return -1;
201bcf00d8fSMatthias Ringwald 	}
202bcf00d8fSMatthias Ringwald 
203bcf00d8fSMatthias Ringwald     // Configure the MAC address of the newly created bnep(x)
204bcf00d8fSMatthias Ringwald     // device to the local bd_address
205bcf00d8fSMatthias Ringwald     memset (&ifr, 0, sizeof(struct ifreq));
206bcf00d8fSMatthias Ringwald     strcpy(ifr.ifr_name, dev);
207bcf00d8fSMatthias Ringwald #ifdef __linux
208bcf00d8fSMatthias Ringwald     ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
209bcf00d8fSMatthias Ringwald     memcpy(ifr.ifr_hwaddr.sa_data, bd_addr, sizeof(bd_addr_t));
210bcf00d8fSMatthias Ringwald 	if (ioctl(fd_socket, SIOCSIFHWADDR, &ifr) == -1) {
211bcf00d8fSMatthias Ringwald         close(fd_dev);
212bcf00d8fSMatthias Ringwald         close(fd_socket);
213bcf00d8fSMatthias Ringwald         fprintf(stderr, "TAP: Error setting hw addr: %s\n", strerror(errno));
214bcf00d8fSMatthias Ringwald         exit(1);
215bcf00d8fSMatthias Ringwald 		return -1;
216bcf00d8fSMatthias Ringwald 	}
217bcf00d8fSMatthias Ringwald #endif
218bcf00d8fSMatthias Ringwald #ifdef __APPLE__
219bcf00d8fSMatthias Ringwald     ifr.ifr_addr.sa_len = ETHER_ADDR_LEN;
220bcf00d8fSMatthias Ringwald     ifr.ifr_addr.sa_family = AF_LINK;
221bcf00d8fSMatthias Ringwald     (void)memcpy(ifr.ifr_addr.sa_data, bd_addr, ETHER_ADDR_LEN);
222bcf00d8fSMatthias Ringwald     if (ioctl(fd_socket, SIOCSIFLLADDR, &ifr) == -1) {
223bcf00d8fSMatthias Ringwald         close(fd_dev);
224bcf00d8fSMatthias Ringwald         close(fd_socket);
225bcf00d8fSMatthias Ringwald         fprintf(stderr, "TAP: Error setting hw addr: %s\n", strerror(errno));
226bcf00d8fSMatthias Ringwald         exit(1);
227bcf00d8fSMatthias Ringwald         return -1;
228bcf00d8fSMatthias Ringwald }
229bcf00d8fSMatthias Ringwald #endif
230bcf00d8fSMatthias Ringwald 
231bcf00d8fSMatthias Ringwald     // Bring the interface up
232bcf00d8fSMatthias Ringwald 	if (ioctl(fd_socket, SIOCGIFFLAGS, &ifr) == -1) {
233bcf00d8fSMatthias Ringwald         close(fd_dev);
234bcf00d8fSMatthias Ringwald         close(fd_socket);
235bcf00d8fSMatthias Ringwald 		fprintf(stderr, "TAP: Error reading interface flags: %s\n", strerror(errno));
236bcf00d8fSMatthias Ringwald 		return -1;
237bcf00d8fSMatthias Ringwald 	}
238bcf00d8fSMatthias Ringwald 
239bcf00d8fSMatthias Ringwald 	if ((ifr.ifr_flags & IFF_UP) == 0) {
240bcf00d8fSMatthias Ringwald 		ifr.ifr_flags |= IFF_UP;
241bcf00d8fSMatthias Ringwald 
242bcf00d8fSMatthias Ringwald 		if (ioctl(fd_socket, SIOCSIFFLAGS, &ifr) == -1) {
243bcf00d8fSMatthias Ringwald             close(fd_dev);
244bcf00d8fSMatthias Ringwald             close(fd_socket);
245bcf00d8fSMatthias Ringwald             fprintf(stderr, "TAP: Error set IFF_UP: %s\n", strerror(errno));
246bcf00d8fSMatthias Ringwald             return -1;
247bcf00d8fSMatthias Ringwald 		}
248bcf00d8fSMatthias Ringwald 	}
249bcf00d8fSMatthias Ringwald 
250bcf00d8fSMatthias Ringwald 	close(fd_socket);
251bcf00d8fSMatthias Ringwald 
252bcf00d8fSMatthias Ringwald     return fd_dev;
253bcf00d8fSMatthias Ringwald }
254bcf00d8fSMatthias Ringwald 
255bcf00d8fSMatthias Ringwald /*
256bcf00d8fSMatthias Ringwald  * @text Listing processTapData shows how a packet is received from the TAP network interface
257bcf00d8fSMatthias Ringwald  * and forwarded over the BNEP connection.
258bcf00d8fSMatthias Ringwald  *
259bcf00d8fSMatthias Ringwald  * After successfully reading a network packet, the call to
260bcf00d8fSMatthias Ringwald  * the *bnep_can_send_packet_now* function checks, if BTstack can forward
261bcf00d8fSMatthias Ringwald  * a network packet now. If that's not possible, the received data stays
262bcf00d8fSMatthias Ringwald  * in the network buffer and the data source elements is removed from the
263bcf00d8fSMatthias Ringwald  * run loop. The *process_tap_dev_data* function will not be called until
264bcf00d8fSMatthias Ringwald  * the data source is registered again. This provides a basic flow control.
265bcf00d8fSMatthias Ringwald  */
266bcf00d8fSMatthias Ringwald 
267bcf00d8fSMatthias Ringwald /* LISTING_START(processTapData): Process incoming network packets */
268423c667cSMatthias Ringwald static void process_tap_dev_data(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type)
269bcf00d8fSMatthias Ringwald {
270c83b0215SMatthias Ringwald     UNUSED(ds);
271c83b0215SMatthias Ringwald     UNUSED(callback_type);
272c83b0215SMatthias Ringwald 
273bcf00d8fSMatthias Ringwald     ssize_t len;
274bcf00d8fSMatthias Ringwald     len = read(ds->fd, network_buffer, sizeof(network_buffer));
275bcf00d8fSMatthias Ringwald     if (len <= 0){
276bcf00d8fSMatthias Ringwald         fprintf(stderr, "TAP: Error while reading: %s\n", strerror(errno));
277423c667cSMatthias Ringwald         return;
278bcf00d8fSMatthias Ringwald     }
279bcf00d8fSMatthias Ringwald 
280bcf00d8fSMatthias Ringwald     network_buffer_len = len;
281*36b4a12cSMatthias Ringwald 
282*36b4a12cSMatthias Ringwald     // disable reading from netif
283*36b4a12cSMatthias Ringwald     btstack_run_loop_disable_data_source_callbacks(&tap_dev_ds, DATA_SOURCE_CALLBACK_READ);
284*36b4a12cSMatthias Ringwald 
285*36b4a12cSMatthias Ringwald     // request permission to send
28660f21f52SMatthias Ringwald     bnep_request_can_send_now_event(bnep_cid);
287bcf00d8fSMatthias Ringwald }
288bcf00d8fSMatthias Ringwald /* LISTING_END */
289bcf00d8fSMatthias Ringwald 
290bcf00d8fSMatthias Ringwald // PANU client routines
291bcf00d8fSMatthias Ringwald static char * get_string_from_data_element(uint8_t * element){
292bcf00d8fSMatthias Ringwald     de_size_t de_size = de_get_size_type(element);
293bcf00d8fSMatthias Ringwald     int pos     = de_get_header_size(element);
294bcf00d8fSMatthias Ringwald     int len = 0;
295bcf00d8fSMatthias Ringwald     switch (de_size){
296bcf00d8fSMatthias Ringwald         case DE_SIZE_VAR_8:
297bcf00d8fSMatthias Ringwald             len = element[1];
298bcf00d8fSMatthias Ringwald             break;
299bcf00d8fSMatthias Ringwald         case DE_SIZE_VAR_16:
300bcf00d8fSMatthias Ringwald             len = big_endian_read_16(element, 1);
301bcf00d8fSMatthias Ringwald             break;
302bcf00d8fSMatthias Ringwald         default:
303bcf00d8fSMatthias Ringwald             break;
304bcf00d8fSMatthias Ringwald     }
305bcf00d8fSMatthias Ringwald     char * str = (char*)malloc(len+1);
306bcf00d8fSMatthias Ringwald     memcpy(str, &element[pos], len);
307bcf00d8fSMatthias Ringwald     str[len] ='\0';
308bcf00d8fSMatthias Ringwald     return str;
309bcf00d8fSMatthias Ringwald }
310bcf00d8fSMatthias Ringwald 
311bcf00d8fSMatthias Ringwald 
312bcf00d8fSMatthias Ringwald /* @section SDP parser callback
313bcf00d8fSMatthias Ringwald  *
314bcf00d8fSMatthias Ringwald  * @text The SDP parsers retrieves the BNEP PAN UUID as explained in
315bcf00d8fSMatthias Ringwald  * Section [on SDP BNEP Query example](#sec:sdpbnepqueryExample}.
316bcf00d8fSMatthias Ringwald  */
317b5a442a7SMatthias Ringwald static void handle_sdp_client_record_complete(void){
318b5a442a7SMatthias Ringwald 
319b5a442a7SMatthias Ringwald     printf("SDP BNEP Record complete\n");
320b5a442a7SMatthias Ringwald 
321b5a442a7SMatthias Ringwald     // accept first entry or if we foudn a NAP and only have a PANU yet
322b5a442a7SMatthias Ringwald     if ((bnep_remote_uuid == 0) || (sdp_bnep_remote_uuid == BLUETOOTH_SERVICE_CLASS_NAP && bnep_remote_uuid == BLUETOOTH_SERVICE_CLASS_PANU)){
323b5a442a7SMatthias Ringwald         bnep_l2cap_psm   = sdp_bnep_l2cap_psm;
324b5a442a7SMatthias Ringwald         bnep_remote_uuid = sdp_bnep_remote_uuid;
325b5a442a7SMatthias Ringwald         bnep_version     = sdp_bnep_version;
326b5a442a7SMatthias Ringwald     }
327b5a442a7SMatthias Ringwald }
328b5a442a7SMatthias Ringwald 
329423c667cSMatthias Ringwald static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
330bcf00d8fSMatthias Ringwald 
331c83b0215SMatthias Ringwald     UNUSED(packet_type);
332c83b0215SMatthias Ringwald     UNUSED(channel);
333c83b0215SMatthias Ringwald     UNUSED(size);
334c83b0215SMatthias Ringwald 
335bcf00d8fSMatthias Ringwald     des_iterator_t des_list_it;
336bcf00d8fSMatthias Ringwald     des_iterator_t prot_it;
337bcf00d8fSMatthias Ringwald     char *str;
338bcf00d8fSMatthias Ringwald 
3390e2df43fSMatthias Ringwald     switch (hci_event_packet_get_type(packet)){
340bcf00d8fSMatthias Ringwald         case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
341bcf00d8fSMatthias Ringwald             // Handle new SDP record
342bcf00d8fSMatthias Ringwald             if (sdp_event_query_attribute_byte_get_record_id(packet) != record_id) {
343b5a442a7SMatthias Ringwald                 handle_sdp_client_record_complete();
344b5a442a7SMatthias Ringwald                 // next record started
345bcf00d8fSMatthias Ringwald                 record_id = sdp_event_query_attribute_byte_get_record_id(packet);
346bcf00d8fSMatthias Ringwald                 printf("SDP Record: Nr: %d\n", record_id);
347bcf00d8fSMatthias Ringwald             }
348bcf00d8fSMatthias Ringwald 
349bcf00d8fSMatthias Ringwald             if (sdp_event_query_attribute_byte_get_attribute_length(packet) <= attribute_value_buffer_size) {
350bcf00d8fSMatthias Ringwald                 attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet);
351bcf00d8fSMatthias Ringwald 
352bcf00d8fSMatthias Ringwald                 if ((uint16_t)(sdp_event_query_attribute_byte_get_data_offset(packet)+1) == sdp_event_query_attribute_byte_get_attribute_length(packet)) {
353bcf00d8fSMatthias Ringwald 
354bcf00d8fSMatthias Ringwald                     switch(sdp_event_query_attribute_byte_get_attribute_id(packet)) {
355235946f1SMatthias Ringwald                         case BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST:
356bcf00d8fSMatthias Ringwald                             if (de_get_element_type(attribute_value) != DE_DES) break;
357bcf00d8fSMatthias Ringwald                             for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
358bcf00d8fSMatthias Ringwald                                 uint8_t * element = des_iterator_get_element(&des_list_it);
359bcf00d8fSMatthias Ringwald                                 if (de_get_element_type(element) != DE_UUID) continue;
360bcf00d8fSMatthias Ringwald                                 uint32_t uuid = de_get_uuid32(element);
361bcf00d8fSMatthias Ringwald                                 switch (uuid){
362235946f1SMatthias Ringwald                                     case BLUETOOTH_SERVICE_CLASS_PANU:
363235946f1SMatthias Ringwald                                     case BLUETOOTH_SERVICE_CLASS_NAP:
364235946f1SMatthias Ringwald                                     case BLUETOOTH_SERVICE_CLASS_GN:
365bcf00d8fSMatthias Ringwald                                         printf("SDP Attribute 0x%04x: BNEP PAN protocol UUID: %04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet), uuid);
366b5a442a7SMatthias Ringwald                                         sdp_bnep_remote_uuid = uuid;
367bcf00d8fSMatthias Ringwald                                         break;
368bcf00d8fSMatthias Ringwald                                     default:
369bcf00d8fSMatthias Ringwald                                         break;
370bcf00d8fSMatthias Ringwald                                 }
371bcf00d8fSMatthias Ringwald                             }
372bcf00d8fSMatthias Ringwald                             break;
373bcf00d8fSMatthias Ringwald                         case 0x0100:
374bcf00d8fSMatthias Ringwald                         case 0x0101:
375bcf00d8fSMatthias Ringwald                             str = get_string_from_data_element(attribute_value);
376bcf00d8fSMatthias Ringwald                             printf("SDP Attribute: 0x%04x: %s\n", sdp_event_query_attribute_byte_get_attribute_id(packet), str);
377bcf00d8fSMatthias Ringwald                             free(str);
378bcf00d8fSMatthias Ringwald                             break;
379235946f1SMatthias Ringwald                         case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: {
380bcf00d8fSMatthias Ringwald                                 printf("SDP Attribute: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet));
381bcf00d8fSMatthias Ringwald 
382bcf00d8fSMatthias Ringwald                                 for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
383bcf00d8fSMatthias Ringwald                                     uint8_t       *des_element;
384bcf00d8fSMatthias Ringwald                                     uint8_t       *element;
385bcf00d8fSMatthias Ringwald                                     uint32_t       uuid;
386bcf00d8fSMatthias Ringwald 
387bcf00d8fSMatthias Ringwald                                     if (des_iterator_get_type(&des_list_it) != DE_DES) continue;
388bcf00d8fSMatthias Ringwald 
389bcf00d8fSMatthias Ringwald                                     des_element = des_iterator_get_element(&des_list_it);
390bcf00d8fSMatthias Ringwald                                     des_iterator_init(&prot_it, des_element);
391bcf00d8fSMatthias Ringwald                                     element = des_iterator_get_element(&prot_it);
392bcf00d8fSMatthias Ringwald 
393bcf00d8fSMatthias Ringwald                                     if (de_get_element_type(element) != DE_UUID) continue;
394bcf00d8fSMatthias Ringwald 
395bcf00d8fSMatthias Ringwald                                     uuid = de_get_uuid32(element);
396bcf00d8fSMatthias Ringwald                                     switch (uuid){
397235946f1SMatthias Ringwald                                         case BLUETOOTH_PROTOCOL_L2CAP:
398bcf00d8fSMatthias Ringwald                                             if (!des_iterator_has_more(&prot_it)) continue;
399bcf00d8fSMatthias Ringwald                                             des_iterator_next(&prot_it);
400b5a442a7SMatthias Ringwald                                             de_element_get_uint16(des_iterator_get_element(&prot_it), &sdp_bnep_l2cap_psm);
401bcf00d8fSMatthias Ringwald                                             break;
402235946f1SMatthias Ringwald                                         case BLUETOOTH_PROTOCOL_BNEP:
403bcf00d8fSMatthias Ringwald                                             if (!des_iterator_has_more(&prot_it)) continue;
404bcf00d8fSMatthias Ringwald                                             des_iterator_next(&prot_it);
405b5a442a7SMatthias Ringwald                                             de_element_get_uint16(des_iterator_get_element(&prot_it), &sdp_bnep_version);
406bcf00d8fSMatthias Ringwald                                             break;
407bcf00d8fSMatthias Ringwald                                         default:
408bcf00d8fSMatthias Ringwald                                             break;
409bcf00d8fSMatthias Ringwald                                     }
410bcf00d8fSMatthias Ringwald                                 }
411bcf00d8fSMatthias Ringwald                                 printf("l2cap_psm 0x%04x, bnep_version 0x%04x\n", bnep_l2cap_psm, bnep_version);
412bcf00d8fSMatthias Ringwald 
413bcf00d8fSMatthias Ringwald                             }
414bcf00d8fSMatthias Ringwald                             break;
415bcf00d8fSMatthias Ringwald                         default:
416bcf00d8fSMatthias Ringwald                             break;
417bcf00d8fSMatthias Ringwald                     }
418bcf00d8fSMatthias Ringwald                 }
419bcf00d8fSMatthias Ringwald             } else {
420bcf00d8fSMatthias Ringwald                 fprintf(stderr, "SDP attribute value buffer size exceeded: available %d, required %d\n", attribute_value_buffer_size, sdp_event_query_attribute_byte_get_attribute_length(packet));
421bcf00d8fSMatthias Ringwald             }
422bcf00d8fSMatthias Ringwald             break;
423bcf00d8fSMatthias Ringwald 
424bcf00d8fSMatthias Ringwald         case SDP_EVENT_QUERY_COMPLETE:
425b5a442a7SMatthias Ringwald             handle_sdp_client_record_complete();
4267693aad0SMatthias Ringwald             fprintf(stderr, "General query done with status %d, bnep psm %04x.\n", sdp_event_query_complete_get_status(packet), bnep_l2cap_psm);
4277693aad0SMatthias Ringwald             if (bnep_l2cap_psm){
4287693aad0SMatthias Ringwald                 /* Create BNEP connection */
4297693aad0SMatthias Ringwald                 bnep_connect(packet_handler, remote_addr, bnep_l2cap_psm, BLUETOOTH_SERVICE_CLASS_PANU, bnep_remote_uuid);
4307693aad0SMatthias Ringwald             } else {
4317693aad0SMatthias Ringwald                 fprintf(stderr, "No BNEP service found\n");
4327693aad0SMatthias Ringwald             }
433bcf00d8fSMatthias Ringwald 
434bcf00d8fSMatthias Ringwald             break;
435bcf00d8fSMatthias Ringwald     }
436bcf00d8fSMatthias Ringwald }
437bcf00d8fSMatthias Ringwald 
438bcf00d8fSMatthias Ringwald /*
439bcf00d8fSMatthias Ringwald  * @section Packet Handler
440bcf00d8fSMatthias Ringwald  *
441bcf00d8fSMatthias Ringwald  * @text The packet handler responds to various HCI Events.
442bcf00d8fSMatthias Ringwald  */
443bcf00d8fSMatthias Ringwald 
444bcf00d8fSMatthias Ringwald 
445bcf00d8fSMatthias Ringwald /* LISTING_START(packetHandler): Packet Handler */
446bcf00d8fSMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
447bcf00d8fSMatthias Ringwald {
448bcf00d8fSMatthias Ringwald /* LISTING_PAUSE */
449c83b0215SMatthias Ringwald     UNUSED(channel);
450c83b0215SMatthias Ringwald 
451bcf00d8fSMatthias Ringwald     int       rc;
452bcf00d8fSMatthias Ringwald     uint8_t   event;
453bcf00d8fSMatthias Ringwald     bd_addr_t event_addr;
454bcf00d8fSMatthias Ringwald     bd_addr_t local_addr;
455bcf00d8fSMatthias Ringwald     uint16_t  uuid_source;
456bcf00d8fSMatthias Ringwald     uint16_t  uuid_dest;
457bcf00d8fSMatthias Ringwald     uint16_t  mtu;
458bcf00d8fSMatthias Ringwald 
459bcf00d8fSMatthias Ringwald     /* LISTING_RESUME */
460bcf00d8fSMatthias Ringwald     switch (packet_type) {
461bcf00d8fSMatthias Ringwald 		case HCI_EVENT_PACKET:
4620e2df43fSMatthias Ringwald             event = hci_event_packet_get_type(packet);
463bcf00d8fSMatthias Ringwald             switch (event) {
464bcf00d8fSMatthias Ringwald                 /* @text When BTSTACK_EVENT_STATE with state HCI_STATE_WORKING
465bcf00d8fSMatthias Ringwald                  * is received and the example is started in client mode, the remote SDP BNEP query is started.
466bcf00d8fSMatthias Ringwald                  */
467bcf00d8fSMatthias Ringwald                 case BTSTACK_EVENT_STATE:
468be7cc9a0SMilanka Ringwald                     if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING){
469bcf00d8fSMatthias Ringwald                         printf("Start SDP BNEP query.\n");
4707693aad0SMatthias Ringwald                         sdp_client_query_uuid16(&handle_sdp_client_query_result, remote_addr, BLUETOOTH_PROTOCOL_BNEP);
471bcf00d8fSMatthias Ringwald                     }
472bcf00d8fSMatthias Ringwald                     break;
473bcf00d8fSMatthias Ringwald 
474bcf00d8fSMatthias Ringwald                 /* LISTING_PAUSE */
475bcf00d8fSMatthias Ringwald                 case HCI_EVENT_PIN_CODE_REQUEST:
476bcf00d8fSMatthias Ringwald 					// inform about pin code request
477bcf00d8fSMatthias Ringwald                     printf("Pin code request - using '0000'\n");
478a6ef64baSMilanka Ringwald                     hci_event_pin_code_request_get_bd_addr(packet, event_addr);
4794d2bcd2aSMatthias Ringwald                     gap_pin_code_response(event_addr, "0000");
480bcf00d8fSMatthias Ringwald 					break;
481bcf00d8fSMatthias Ringwald 
482bcf00d8fSMatthias Ringwald                 case HCI_EVENT_USER_CONFIRMATION_REQUEST:
483bcf00d8fSMatthias Ringwald                     // inform about user confirmation request
484bcf00d8fSMatthias Ringwald                     printf("SSP User Confirmation Request with numeric value '%06u'\n", little_endian_read_32(packet, 8));
485bcf00d8fSMatthias Ringwald                     printf("SSP User Confirmation Auto accept\n");
486bcf00d8fSMatthias Ringwald                     break;
487bcf00d8fSMatthias Ringwald 
488bcf00d8fSMatthias Ringwald                 /* LISTING_RESUME */
489bcf00d8fSMatthias Ringwald 
490423c667cSMatthias Ringwald                 /* @text BNEP_EVENT_CHANNEL_OPENED is received after a BNEP connection was established or
491bcf00d8fSMatthias Ringwald                  * or when the connection fails. The status field returns the error code.
492bcf00d8fSMatthias Ringwald                  *
493bcf00d8fSMatthias Ringwald                  * The TAP network interface is then configured. A data source is set up and registered with the
494bcf00d8fSMatthias Ringwald                  * run loop to receive Ethernet packets from the TAP interface.
495bcf00d8fSMatthias Ringwald                  *
496bcf00d8fSMatthias Ringwald                  * The event contains both the source and destination UUIDs, as well as the MTU for this connection and
497bcf00d8fSMatthias Ringwald                  * the BNEP Channel ID, which is used for sending Ethernet packets over BNEP.
498bcf00d8fSMatthias Ringwald                  */
499423c667cSMatthias Ringwald 				case BNEP_EVENT_CHANNEL_OPENED:
500508c11d6SMilanka Ringwald                     if (bnep_event_channel_opened_get_status(packet)) {
501508c11d6SMilanka Ringwald                         printf("BNEP channel open failed, status %02x\n", bnep_event_channel_opened_get_status(packet));
502bcf00d8fSMatthias Ringwald                     } else {
503508c11d6SMilanka Ringwald                         bnep_cid    = bnep_event_channel_opened_get_bnep_cid(packet);
504508c11d6SMilanka Ringwald                         uuid_source = bnep_event_channel_opened_get_source_uuid(packet);
505508c11d6SMilanka Ringwald                         uuid_dest   = bnep_event_channel_opened_get_destination_uuid(packet);
506508c11d6SMilanka Ringwald                         mtu         = bnep_event_channel_opened_get_mtu(packet);
507bcf00d8fSMatthias Ringwald                         //bt_flip_addr(event_addr, &packet[9]);
508423c667cSMatthias Ringwald                         memcpy(&event_addr, &packet[11], sizeof(bd_addr_t));
509bcf00d8fSMatthias Ringwald                         printf("BNEP connection open succeeded to %s source UUID 0x%04x dest UUID: 0x%04x, max frame size %u\n", bd_addr_to_str(event_addr), uuid_source, uuid_dest, mtu);
510bcf00d8fSMatthias Ringwald                         /* Create the tap interface */
511bcf00d8fSMatthias Ringwald                         gap_local_bd_addr(local_addr);
512bcf00d8fSMatthias Ringwald                         tap_fd = tap_alloc(tap_dev_name, local_addr);
513bcf00d8fSMatthias Ringwald                         if (tap_fd < 0) {
514bcf00d8fSMatthias Ringwald                             printf("Creating BNEP tap device failed: %s\n", strerror(errno));
515bcf00d8fSMatthias Ringwald                         } else {
516bcf00d8fSMatthias Ringwald                             printf("BNEP device \"%s\" allocated.\n", tap_dev_name);
517bcf00d8fSMatthias Ringwald                             /* Create and register a new runloop data source */
51880edae71SMatthias Ringwald                             btstack_run_loop_set_data_source_fd(&tap_dev_ds, tap_fd);
519423c667cSMatthias Ringwald                             btstack_run_loop_set_data_source_handler(&tap_dev_ds, &process_tap_dev_data);
520bcf00d8fSMatthias Ringwald                             btstack_run_loop_add_data_source(&tap_dev_ds);
521*36b4a12cSMatthias Ringwald                             btstack_run_loop_enable_data_source_callbacks(&tap_dev_ds, DATA_SOURCE_CALLBACK_READ);
522bcf00d8fSMatthias Ringwald                         }
523bcf00d8fSMatthias Ringwald                     }
524bcf00d8fSMatthias Ringwald 					break;
525bcf00d8fSMatthias Ringwald 
526bcf00d8fSMatthias Ringwald                 /* @text If there is a timeout during the connection setup, BNEP_EVENT_CHANNEL_TIMEOUT will be received
527bcf00d8fSMatthias Ringwald                  * and the BNEP connection  will be closed
528bcf00d8fSMatthias Ringwald                  */
529bcf00d8fSMatthias Ringwald                 case BNEP_EVENT_CHANNEL_TIMEOUT:
530bcf00d8fSMatthias Ringwald                     printf("BNEP channel timeout! Channel will be closed\n");
531bcf00d8fSMatthias Ringwald                     break;
532bcf00d8fSMatthias Ringwald 
533bcf00d8fSMatthias Ringwald                 /* @text BNEP_EVENT_CHANNEL_CLOSED is received when the connection gets closed.
534bcf00d8fSMatthias Ringwald                  */
535bcf00d8fSMatthias Ringwald                 case BNEP_EVENT_CHANNEL_CLOSED:
536bcf00d8fSMatthias Ringwald                     printf("BNEP channel closed\n");
537bcf00d8fSMatthias Ringwald                     btstack_run_loop_remove_data_source(&tap_dev_ds);
538bcf00d8fSMatthias Ringwald                     if (tap_fd > 0) {
539bcf00d8fSMatthias Ringwald                         close(tap_fd);
540bcf00d8fSMatthias Ringwald                         tap_fd = -1;
541bcf00d8fSMatthias Ringwald                     }
542bcf00d8fSMatthias Ringwald                     break;
543bcf00d8fSMatthias Ringwald 
544*36b4a12cSMatthias Ringwald                 /* @text BNEP_EVENT_CAN_SEND_NOW indicates that a new packet can be send. This triggers the send of a
545*36b4a12cSMatthias Ringwald                  * stored network packet. The tap datas source can be enabled again
546bcf00d8fSMatthias Ringwald                  */
5472d4c8c04SMatthias Ringwald                 case BNEP_EVENT_CAN_SEND_NOW:
548bcf00d8fSMatthias Ringwald                     if (network_buffer_len > 0) {
549bcf00d8fSMatthias Ringwald                         bnep_send(bnep_cid, network_buffer, network_buffer_len);
550bcf00d8fSMatthias Ringwald                         network_buffer_len = 0;
551*36b4a12cSMatthias Ringwald                         // Re-enable the tap device data source
552*36b4a12cSMatthias Ringwald                         btstack_run_loop_enable_data_source_callbacks(&tap_dev_ds, DATA_SOURCE_CALLBACK_READ);
553bcf00d8fSMatthias Ringwald                     }
554bcf00d8fSMatthias Ringwald                     break;
555bcf00d8fSMatthias Ringwald 
556bcf00d8fSMatthias Ringwald                 default:
557bcf00d8fSMatthias Ringwald                     break;
558bcf00d8fSMatthias Ringwald             }
559bcf00d8fSMatthias Ringwald             break;
560bcf00d8fSMatthias Ringwald 
561bcf00d8fSMatthias Ringwald         /* @text Ethernet packets from the remote device are received in the packet handler with type BNEP_DATA_PACKET.
562bcf00d8fSMatthias Ringwald          * It is forwarded to the TAP interface.
563bcf00d8fSMatthias Ringwald          */
564bcf00d8fSMatthias Ringwald         case BNEP_DATA_PACKET:
565bcf00d8fSMatthias Ringwald             // Write out the ethernet frame to the tap device
566bcf00d8fSMatthias Ringwald             if (tap_fd > 0) {
567bcf00d8fSMatthias Ringwald                 rc = write(tap_fd, packet, size);
568bcf00d8fSMatthias Ringwald                 if (rc < 0) {
569bcf00d8fSMatthias Ringwald                     fprintf(stderr, "TAP: Could not write to TAP device: %s\n", strerror(errno));
570bcf00d8fSMatthias Ringwald                 } else
571bcf00d8fSMatthias Ringwald                 if (rc != size) {
572bcf00d8fSMatthias Ringwald                     fprintf(stderr, "TAP: Package written only partially %d of %d bytes\n", rc, size);
573bcf00d8fSMatthias Ringwald                 }
574bcf00d8fSMatthias Ringwald             }
575bcf00d8fSMatthias Ringwald             break;
576bcf00d8fSMatthias Ringwald 
577bcf00d8fSMatthias Ringwald         default:
578bcf00d8fSMatthias Ringwald             break;
579bcf00d8fSMatthias Ringwald     }
580bcf00d8fSMatthias Ringwald }
581bcf00d8fSMatthias Ringwald /* LISTING_END */
582bcf00d8fSMatthias Ringwald 
583bcf00d8fSMatthias Ringwald 
584bcf00d8fSMatthias Ringwald int btstack_main(int argc, const char * argv[]);
585bcf00d8fSMatthias Ringwald int btstack_main(int argc, const char * argv[]){
586bcf00d8fSMatthias Ringwald 
5876316c8edSMatthias Ringwald     (void)argc;
5886316c8edSMatthias Ringwald     (void)argv;
589c83b0215SMatthias Ringwald 
590bcf00d8fSMatthias Ringwald     panu_setup();
5917693aad0SMatthias Ringwald 
5927693aad0SMatthias Ringwald     // parse human readable Bluetooth address
5937693aad0SMatthias Ringwald     sscanf_bd_addr(remote_addr_string, remote_addr);
5947693aad0SMatthias Ringwald 
595bcf00d8fSMatthias Ringwald     // Turn on the device
596bcf00d8fSMatthias Ringwald     hci_power_control(HCI_POWER_ON);
597bcf00d8fSMatthias Ringwald     return 0;
598bcf00d8fSMatthias Ringwald }
599bcf00d8fSMatthias Ringwald 
600bcf00d8fSMatthias Ringwald /* EXAMPLE_END */
601bcf00d8fSMatthias Ringwald /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-  */
602bcf00d8fSMatthias Ringwald 
603