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