2015-02-06 10:45:10 +00:00
/*
* Copyright ( C ) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
*
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission .
* 4. Any redistribution , use , or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain .
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ` ` AS IS ' ' AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING ,
* BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS
* OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY ,
* OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE .
*
* Please inquire about commercial licensing options at
* contact @ bluekitchen - gmbh . com
*
*/
2019-05-11 19:31:55 +02:00
# define BTSTACK_FILE__ "panu_demo.c"
2017-03-24 23:39:20 +01:00
2014-10-20 10:06:23 +00:00
/*
* panu_demo . c
2015-02-06 10:45:10 +00:00
* Author : Ole Reinhardt < ole . reinhardt @ kernelconcepts . de >
2014-10-20 10:06:23 +00:00
*/
2020-10-23 09:54:54 +02:00
/* EXAMPLE_START(panu_demo): BNEP/PANU (Linux only)
2015-04-24 23:08:52 +02:00
*
2015-04-25 23:45:55 +02:00
* @ text This example implements both a PANU client and a server . In server mode , it
2015-04-26 12:59:22 +02:00
* sets up a BNEP server and registers a PANU SDP record and waits for incoming connections .
2015-04-25 23:45:55 +02:00
* In client mode , it connects to a remote device , does an SDP Query to identify the PANU
2015-04-26 12:59:22 +02:00
* service and initiates a BNEP connection .
2017-11-01 15:35:16 +01:00
*
2020-10-23 09:54:54 +02:00
* Note : currently supported only on Linux and provides a TAP network interface which you
* can configure yourself .
2019-04-05 22:22:50 +02:00
*
2020-10-23 09:54:54 +02:00
* To enable client mode , uncomment ENABLE_PANU_CLIENT below .
2015-04-24 23:08:52 +02:00
*/
2014-10-20 10:06:23 +00:00
# include <stdio.h>
2014-12-18 13:22:03 +00:00
2017-11-07 16:42:06 +01:00
# include "btstack_config.h"
2017-05-22 11:34:34 +02:00
# include "btstack.h"
2014-10-20 10:06:23 +00:00
2019-04-05 22:22:50 +02:00
// #define ENABLE_PANU_CLIENT
2019-02-27 10:42:20 +01:00
// network types
# define NETWORK_TYPE_IPv4 0x0800
# define NETWORK_TYPE_ARP 0x0806
# define NETWORK_TYPE_IPv6 0x86DD
2020-10-27 18:16:56 +01:00
static uint16_t bnep_cid = 0 ;
# ifdef ENABLE_PANU_CLIENT
2014-10-27 11:50:12 +00:00
static int record_id = - 1 ;
2020-10-27 18:16:56 +01:00
2014-10-27 11:50:12 +00:00
static uint16_t bnep_version = 0 ;
2020-10-27 18:16:56 +01:00
static uint32_t bnep_remote_uuid = 0 ;
static uint16_t bnep_l2cap_psm = 0 ;
2014-10-20 10:06:23 +00:00
2017-09-06 15:19:44 +02:00
static uint16_t sdp_bnep_l2cap_psm = 0 ;
static uint16_t sdp_bnep_version = 0 ;
static uint32_t sdp_bnep_remote_uuid = 0 ;
2014-10-20 10:06:23 +00:00
static uint8_t attribute_value [ 1000 ] ;
2014-11-18 21:37:23 +00:00
static const unsigned int attribute_value_buffer_size = sizeof ( attribute_value ) ;
2020-10-27 18:16:56 +01:00
# endif
2014-10-20 10:06:23 +00:00
2017-11-07 16:42:06 +01:00
// MBP 2016
2019-02-27 10:42:20 +01:00
static const char * remote_addr_string = " 78:4F:43:8C:B2:5D " ;
2017-11-07 16:42:06 +01:00
// Wiko Sunny static const char * remote_addr_string = "A0:4C:5B:0F:B2:42";
2014-12-21 21:59:27 +00:00
2017-11-07 16:42:06 +01:00
static bd_addr_t remote_addr ;
2014-12-21 21:59:27 +00:00
2016-02-03 21:55:36 +01:00
static btstack_packet_callback_registration_t hci_event_callback_registration ;
2014-12-18 13:22:03 +00:00
2017-11-07 16:42:06 +01:00
// outgoing network packet
static const uint8_t * network_buffer ;
static uint16_t network_buffer_len ;
2019-04-05 22:22:50 +02:00
static uint8_t panu_sdp_record [ 220 ] ;
2019-02-27 10:42:20 +01:00
2015-04-27 00:02:07 +02:00
/* @section Main application configuration
*
* @ text In the application configuration , L2CAP and BNEP are initialized and a BNEP service , for server mode ,
* is registered , before the Bluetooth stack gets started , as shown in Listing PanuSetup .
*/
/* LISTING_START(PanuSetup): Panu setup */
2015-11-13 21:57:19 +01:00
static void packet_handler ( uint8_t packet_type , uint16_t channel , uint8_t * packet , uint16_t size ) ;
2016-04-01 11:41:58 +02:00
static void handle_sdp_client_query_result ( uint8_t packet_type , uint16_t channel , uint8_t * packet , uint16_t size ) ;
2017-11-07 16:42:06 +01:00
static void network_send_packet_callback ( const uint8_t * packet , uint16_t size ) ;
2015-04-27 00:02:07 +02:00
2015-05-13 10:30:46 +02:00
static void panu_setup ( void ) {
2016-02-03 21:55:36 +01:00
2015-04-27 00:02:07 +02:00
// Initialize L2CAP
l2cap_init ( ) ;
2015-04-24 23:08:52 +02:00
2019-02-27 10:42:20 +01:00
// init SDP, create record for PANU and register with SDP
sdp_init ( ) ;
2019-04-05 22:22:50 +02:00
memset ( panu_sdp_record , 0 , sizeof ( panu_sdp_record ) ) ;
2019-02-27 10:42:20 +01:00
uint16_t network_packet_types [ ] = { NETWORK_TYPE_IPv4 , NETWORK_TYPE_ARP , 0 } ; // 0 as end of list
2019-04-05 22:47:12 +02:00
// Initialise BNEP
bnep_init ( ) ;
// Minimum L2CAP MTU for bnep is 1691 bytes
2019-04-05 22:22:50 +02:00
# ifdef ENABLE_PANU_CLIENT
2019-04-05 22:47:12 +02:00
bnep_register_service ( packet_handler , BLUETOOTH_SERVICE_CLASS_PANU , 1691 ) ;
// PANU
2019-04-05 22:22:50 +02:00
pan_create_panu_sdp_record ( panu_sdp_record , sdp_create_service_record_handle ( ) , network_packet_types , NULL , NULL , BNEP_SECURITY_NONE ) ;
# else
2019-04-05 22:47:12 +02:00
bnep_register_service ( packet_handler , BLUETOOTH_SERVICE_CLASS_NAP , 1691 ) ;
// NAP Network Access Type: Other, 1 MB/s
pan_create_nap_sdp_record ( panu_sdp_record , sdp_create_service_record_handle ( ) , network_packet_types , NULL , NULL , BNEP_SECURITY_NONE , PAN_NET_ACCESS_TYPE_OTHER , 1000000 , NULL , NULL ) ;
2019-04-05 22:22:50 +02:00
# endif
sdp_register_service ( panu_sdp_record ) ;
printf ( " SDP service record size: %u \n " , de_get_len ( ( uint8_t * ) panu_sdp_record ) ) ;
2019-02-27 10:42:20 +01:00
2017-11-07 16:42:06 +01:00
// Initialize network interface
btstack_network_init ( & network_send_packet_callback ) ;
2018-08-24 10:03:14 +02:00
// register for HCI events
hci_event_callback_registration . callback = & packet_handler ;
hci_add_event_handler ( & hci_event_callback_registration ) ;
2014-10-27 11:50:12 +00:00
}
2015-04-25 23:45:55 +02:00
/* LISTING_END */
2014-10-27 11:50:12 +00:00
2019-04-05 22:22:50 +02:00
# ifdef ENABLE_PANU_CLIENT
2015-04-24 23:08:52 +02:00
// PANU client routines
2018-11-28 11:06:11 +01:00
static void get_string_from_data_element ( uint8_t * element , uint16_t buffer_size , char * buffer_data ) {
2014-10-20 10:06:23 +00:00
de_size_t de_size = de_get_size_type ( element ) ;
int pos = de_get_header_size ( element ) ;
int len = 0 ;
switch ( de_size ) {
case DE_SIZE_VAR_8 :
len = element [ 1 ] ;
break ;
case DE_SIZE_VAR_16 :
2016-01-31 00:07:32 +01:00
len = big_endian_read_16 ( element , 1 ) ;
2014-10-20 10:06:23 +00:00
break ;
default :
break ;
}
2018-11-28 11:06:11 +01:00
uint16_t bytes_to_copy = btstack_min ( buffer_size - 1 , len ) ;
memcpy ( buffer_data , & element [ pos ] , bytes_to_copy ) ;
buffer_data [ bytes_to_copy ] = ' \0 ' ;
2014-10-20 10:06:23 +00:00
}
2015-04-24 23:16:02 +02:00
/* @section SDP parser callback
2015-04-25 23:45:55 +02:00
*
2015-06-24 16:47:05 +02:00
* @ text The SDP parsers retrieves the BNEP PAN UUID as explained in
2015-06-24 17:21:05 +02:00
* Section [ on SDP BNEP Query example ] ( # sec : sdpbnepqueryExample } .
2015-04-24 23:16:02 +02:00
*/
2017-09-06 15:19:44 +02:00
static void handle_sdp_client_record_complete ( void ) {
printf ( " SDP BNEP Record complete \n " ) ;
// accept first entry or if we foudn a NAP and only have a PANU yet
if ( ( bnep_remote_uuid = = 0 ) | | ( sdp_bnep_remote_uuid = = BLUETOOTH_SERVICE_CLASS_NAP & & bnep_remote_uuid = = BLUETOOTH_SERVICE_CLASS_PANU ) ) {
bnep_l2cap_psm = sdp_bnep_l2cap_psm ;
bnep_remote_uuid = sdp_bnep_remote_uuid ;
bnep_version = sdp_bnep_version ;
}
}
2016-04-01 11:41:58 +02:00
static void handle_sdp_client_query_result ( uint8_t packet_type , uint16_t channel , uint8_t * packet , uint16_t size ) {
2016-01-29 21:31:07 +01:00
2017-01-07 22:11:48 +01:00
UNUSED ( packet_type ) ;
UNUSED ( channel ) ;
UNUSED ( size ) ;
2014-10-27 11:50:12 +00:00
des_iterator_t des_list_it ;
des_iterator_t prot_it ;
2018-11-28 11:06:11 +01:00
char str [ 20 ] ;
2014-10-20 10:06:23 +00:00
2016-02-19 14:52:36 +01:00
switch ( hci_event_packet_get_type ( packet ) ) {
2016-01-30 23:58:36 +01:00
case SDP_EVENT_QUERY_ATTRIBUTE_VALUE :
2015-04-24 23:08:52 +02:00
// Handle new SDP record
2016-02-03 16:10:30 +01:00
if ( sdp_event_query_attribute_byte_get_record_id ( packet ) ! = record_id ) {
2017-09-06 15:19:44 +02:00
handle_sdp_client_record_complete ( ) ;
// next record started
2016-02-03 16:10:30 +01:00
record_id = sdp_event_query_attribute_byte_get_record_id ( packet ) ;
2014-10-20 10:06:23 +00:00
printf ( " SDP Record: Nr: %d \n " , record_id ) ;
}
2016-02-03 16:10:30 +01:00
if ( sdp_event_query_attribute_byte_get_attribute_length ( packet ) < = attribute_value_buffer_size ) {
attribute_value [ sdp_event_query_attribute_byte_get_data_offset ( packet ) ] = sdp_event_query_attribute_byte_get_data ( packet ) ;
2014-10-20 10:06:23 +00:00
2016-02-03 16:10:30 +01:00
if ( ( uint16_t ) ( sdp_event_query_attribute_byte_get_data_offset ( packet ) + 1 ) = = sdp_event_query_attribute_byte_get_attribute_length ( packet ) ) {
2014-10-20 10:06:23 +00:00
2016-02-03 16:10:30 +01:00
switch ( sdp_event_query_attribute_byte_get_attribute_id ( packet ) ) {
2017-03-26 22:19:18 +02:00
case BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST :
2014-10-27 11:50:12 +00:00
if ( de_get_element_type ( attribute_value ) ! = DE_DES ) break ;
for ( des_iterator_init ( & des_list_it , attribute_value ) ; des_iterator_has_more ( & des_list_it ) ; des_iterator_next ( & des_list_it ) ) {
uint8_t * element = des_iterator_get_element ( & des_list_it ) ;
if ( de_get_element_type ( element ) ! = DE_UUID ) continue ;
2014-12-04 09:40:43 +00:00
uint32_t uuid = de_get_uuid32 ( element ) ;
2014-10-27 11:50:12 +00:00
switch ( uuid ) {
2017-03-26 22:19:18 +02:00
case BLUETOOTH_SERVICE_CLASS_PANU :
case BLUETOOTH_SERVICE_CLASS_NAP :
case BLUETOOTH_SERVICE_CLASS_GN :
2016-02-03 16:10:30 +01:00
printf ( " SDP Attribute 0x%04x: BNEP PAN protocol UUID: %04x \n " , sdp_event_query_attribute_byte_get_attribute_id ( packet ) , uuid ) ;
2017-09-06 15:19:44 +02:00
sdp_bnep_remote_uuid = uuid ;
2014-10-27 11:50:12 +00:00
break ;
default :
break ;
}
}
break ;
2014-10-20 10:06:23 +00:00
case 0x0100 :
case 0x0101 :
2018-11-28 11:06:11 +01:00
get_string_from_data_element ( attribute_value , sizeof ( str ) , str ) ;
2016-02-03 16:10:30 +01:00
printf ( " SDP Attribute: 0x%04x: %s \n " , sdp_event_query_attribute_byte_get_attribute_id ( packet ) , str ) ;
2014-10-20 10:06:23 +00:00
break ;
2017-03-26 22:19:18 +02:00
case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST : {
2016-02-03 16:10:30 +01:00
printf ( " SDP Attribute: 0x%04x \n " , sdp_event_query_attribute_byte_get_attribute_id ( packet ) ) ;
2014-10-20 10:06:23 +00:00
for ( des_iterator_init ( & des_list_it , attribute_value ) ; des_iterator_has_more ( & des_list_it ) ; des_iterator_next ( & des_list_it ) ) {
uint8_t * des_element ;
uint8_t * element ;
2014-12-04 09:40:43 +00:00
uint32_t uuid ;
2014-10-20 10:06:23 +00:00
if ( des_iterator_get_type ( & des_list_it ) ! = DE_DES ) continue ;
des_element = des_iterator_get_element ( & des_list_it ) ;
des_iterator_init ( & prot_it , des_element ) ;
element = des_iterator_get_element ( & prot_it ) ;
2018-10-01 17:50:00 +02:00
if ( ! element ) continue ;
2014-10-20 10:06:23 +00:00
if ( de_get_element_type ( element ) ! = DE_UUID ) continue ;
2014-12-04 09:40:43 +00:00
uuid = de_get_uuid32 ( element ) ;
2018-10-01 17:50:00 +02:00
des_iterator_next ( & prot_it ) ;
2014-10-20 10:06:23 +00:00
switch ( uuid ) {
2017-03-26 22:19:18 +02:00
case BLUETOOTH_PROTOCOL_L2CAP :
2014-10-20 10:06:23 +00:00
if ( ! des_iterator_has_more ( & prot_it ) ) continue ;
2017-09-06 15:19:44 +02:00
de_element_get_uint16 ( des_iterator_get_element ( & prot_it ) , & sdp_bnep_l2cap_psm ) ;
2014-10-20 10:06:23 +00:00
break ;
2017-03-26 22:19:18 +02:00
case BLUETOOTH_PROTOCOL_BNEP :
2014-10-20 10:06:23 +00:00
if ( ! des_iterator_has_more ( & prot_it ) ) continue ;
2017-09-06 15:19:44 +02:00
de_element_get_uint16 ( des_iterator_get_element ( & prot_it ) , & sdp_bnep_version ) ;
2014-10-20 10:06:23 +00:00
break ;
default :
break ;
}
}
2017-10-26 15:42:09 +02:00
printf ( " Summary: uuid 0x%04x, l2cap_psm 0x%04x, bnep_version 0x%04x \n " , sdp_bnep_remote_uuid , sdp_bnep_l2cap_psm , sdp_bnep_version ) ;
2014-10-28 01:16:57 +00:00
2014-10-20 10:06:23 +00:00
}
break ;
default :
break ;
}
}
} else {
2016-02-03 16:10:30 +01:00
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 ) ) ;
2014-10-20 10:06:23 +00:00
}
break ;
2016-01-30 23:58:36 +01:00
case SDP_EVENT_QUERY_COMPLETE :
2017-09-06 15:19:44 +02:00
handle_sdp_client_record_complete ( ) ;
2017-09-04 13:05:09 +02:00
fprintf ( stderr , " General query done with status %d, bnep psm %04x. \n " , sdp_event_query_complete_get_status ( packet ) , bnep_l2cap_psm ) ;
if ( bnep_l2cap_psm ) {
/* Create BNEP connection */
bnep_connect ( packet_handler , remote_addr , bnep_l2cap_psm , BLUETOOTH_SERVICE_CLASS_PANU , bnep_remote_uuid ) ;
} else {
fprintf ( stderr , " No BNEP service found \n " ) ;
}
2014-10-20 10:06:23 +00:00
break ;
}
}
2019-04-05 22:22:50 +02:00
# endif
2014-10-20 10:06:23 +00:00
2015-04-25 23:45:55 +02:00
/*
* @ section Packet Handler
*
* @ text The packet handler responds to various HCI Events .
*/
2015-04-26 11:25:41 +02:00
/* LISTING_START(packetHandler): Packet Handler */
2015-11-13 21:57:19 +01:00
static void packet_handler ( uint8_t packet_type , uint16_t channel , uint8_t * packet , uint16_t size )
2014-10-20 10:06:23 +00:00
{
2015-04-25 23:45:55 +02:00
/* LISTING_PAUSE */
2017-01-07 22:11:48 +01:00
UNUSED ( channel ) ;
2014-10-27 11:50:12 +00:00
uint8_t event ;
2014-10-20 10:06:23 +00:00
bd_addr_t event_addr ;
2015-03-24 08:44:48 +00:00
bd_addr_t local_addr ;
2014-10-20 10:06:23 +00:00
uint16_t uuid_source ;
uint16_t uuid_dest ;
uint16_t mtu ;
2014-10-27 11:50:12 +00:00
2015-04-25 23:45:55 +02:00
/* LISTING_RESUME */
2014-10-20 10:06:23 +00:00
switch ( packet_type ) {
case HCI_EVENT_PACKET :
2016-02-19 14:52:36 +01:00
event = hci_event_packet_get_type ( packet ) ;
2014-10-27 11:50:12 +00:00
switch ( event ) {
2019-04-05 22:22:50 +02:00
# ifdef ENABLE_PANU_CLIENT
2015-04-26 12:59:22 +02:00
/* @text When BTSTACK_EVENT_STATE with state HCI_STATE_WORKING
2015-04-25 23:45:55 +02:00
* is received and the example is started in client mode , the remote SDP BNEP query is started .
*/
2014-10-20 10:06:23 +00:00
case BTSTACK_EVENT_STATE :
2016-04-01 12:27:13 +02:00
if ( btstack_event_state_get_state ( packet ) = = HCI_STATE_WORKING ) {
2017-10-26 15:42:09 +02:00
printf ( " Start SDP BNEP query for remote PAN Network Access Point (NAP). \n " ) ;
sdp_client_query_uuid16 ( & handle_sdp_client_query_result , remote_addr , BLUETOOTH_SERVICE_CLASS_NAP ) ;
2014-10-20 10:06:23 +00:00
}
break ;
2019-04-05 22:22:50 +02:00
# endif
2015-04-25 23:45:55 +02:00
/* LISTING_PAUSE */
2014-10-20 10:06:23 +00:00
case HCI_EVENT_PIN_CODE_REQUEST :
// inform about pin code request
printf ( " Pin code request - using '0000' \n " ) ;
2016-04-01 14:04:14 +02:00
hci_event_pin_code_request_get_bd_addr ( packet , event_addr ) ;
2017-05-22 11:34:34 +02:00
gap_pin_code_response ( event_addr , " 0000 " ) ;
2014-10-20 10:06:23 +00:00
break ;
case HCI_EVENT_USER_CONFIRMATION_REQUEST :
// inform about user confirmation request
2016-01-31 00:07:32 +01:00
printf ( " SSP User Confirmation Request with numeric value '%06u' \n " , little_endian_read_32 ( packet , 8 ) ) ;
2014-10-20 10:06:23 +00:00
printf ( " SSP User Confirmation Auto accept \n " ) ;
break ;
2015-04-25 23:45:55 +02:00
/* LISTING_RESUME */
2015-04-26 11:25:41 +02:00
2016-04-01 11:41:58 +02:00
/* @text BNEP_EVENT_CHANNEL_OPENED is received after a BNEP connection was established or
2015-12-16 14:29:23 +01:00
* or when the connection fails . The status field returns the error code .
*
2015-04-27 00:02:07 +02:00
* The TAP network interface is then configured . A data source is set up and registered with the
2015-04-25 23:45:55 +02:00
* run loop to receive Ethernet packets from the TAP interface .
*
* The event contains both the source and destination UUIDs , as well as the MTU for this connection and
2015-04-27 00:02:07 +02:00
* the BNEP Channel ID , which is used for sending Ethernet packets over BNEP .
2015-12-16 14:29:23 +01:00
*/
2016-04-01 11:41:58 +02:00
case BNEP_EVENT_CHANNEL_OPENED :
2016-04-01 14:49:31 +02:00
if ( bnep_event_channel_opened_get_status ( packet ) ) {
printf ( " BNEP channel open failed, status %02x \n " , bnep_event_channel_opened_get_status ( packet ) ) ;
2014-10-20 10:06:23 +00:00
} else {
2016-04-01 14:49:31 +02:00
bnep_cid = bnep_event_channel_opened_get_bnep_cid ( packet ) ;
uuid_source = bnep_event_channel_opened_get_source_uuid ( packet ) ;
uuid_dest = bnep_event_channel_opened_get_destination_uuid ( packet ) ;
mtu = bnep_event_channel_opened_get_mtu ( packet ) ;
2019-06-05 17:22:17 +02:00
bnep_event_channel_opened_get_remote_address ( packet , event_addr ) ;
2014-10-27 11:50:12 +00:00
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 ) ;
2019-06-05 17:22:17 +02:00
2017-11-07 16:42:06 +01:00
/* Setup network interface */
2016-02-18 17:12:57 +01:00
gap_local_bd_addr ( local_addr ) ;
2017-11-07 16:42:06 +01:00
btstack_network_up ( local_addr ) ;
2017-11-07 22:10:15 +01:00
printf ( " Network Interface %s activated \n " , btstack_network_get_name ( ) ) ;
2014-10-20 10:06:23 +00:00
}
break ;
2015-04-25 23:45:55 +02:00
2015-04-26 12:59:22 +02:00
/* @text If there is a timeout during the connection setup, BNEP_EVENT_CHANNEL_TIMEOUT will be received
2015-04-27 00:02:07 +02:00
* and the BNEP connection will be closed
2015-04-25 23:45:55 +02:00
*/
2014-11-13 00:28:01 +00:00
case BNEP_EVENT_CHANNEL_TIMEOUT :
printf ( " BNEP channel timeout! Channel will be closed \n " ) ;
break ;
2015-04-25 23:45:55 +02:00
2015-04-27 00:02:07 +02:00
/* @text BNEP_EVENT_CHANNEL_CLOSED is received when the connection gets closed.
2015-04-25 23:45:55 +02:00
*/
2014-10-20 10:06:23 +00:00
case BNEP_EVENT_CHANNEL_CLOSED :
printf ( " BNEP channel closed \n " ) ;
2017-11-07 16:42:06 +01:00
btstack_network_down ( ) ;
2014-10-20 10:06:23 +00:00
break ;
2017-09-08 15:56:24 +02:00
/* @text BNEP_EVENT_CAN_SEND_NOW indicates that a new packet can be send. This triggers the send of a
* stored network packet . The tap datas source can be enabled again
2015-04-25 23:45:55 +02:00
*/
2016-03-31 15:18:39 +02:00
case BNEP_EVENT_CAN_SEND_NOW :
2014-10-28 01:16:57 +00:00
if ( network_buffer_len > 0 ) {
2017-11-07 16:42:06 +01:00
bnep_send ( bnep_cid , ( uint8_t * ) network_buffer , network_buffer_len ) ;
2014-10-28 01:16:57 +00:00
network_buffer_len = 0 ;
2017-11-07 16:42:06 +01:00
btstack_network_packet_sent ( ) ;
2014-10-28 01:16:57 +00:00
}
break ;
2014-10-20 10:06:23 +00:00
default :
break ;
}
2014-10-27 11:50:12 +00:00
break ;
2015-04-25 23:45:55 +02:00
2015-04-26 12:59:22 +02:00
/* @text Ethernet packets from the remote device are received in the packet handler with type BNEP_DATA_PACKET.
2015-04-25 23:45:55 +02:00
* It is forwarded to the TAP interface .
*/
2014-10-27 11:50:12 +00:00
case BNEP_DATA_PACKET :
2017-11-07 16:42:06 +01:00
// Write out the ethernet frame to the network interface
btstack_network_process_packet ( packet , size ) ;
2014-10-27 11:50:12 +00:00
break ;
2014-10-20 10:06:23 +00:00
default :
break ;
}
}
2015-04-26 11:25:41 +02:00
/* LISTING_END */
2014-10-20 10:06:23 +00:00
2017-11-07 16:42:06 +01:00
/*
* @ section Network packet handler
*
* @ text A pointer to the network packet is stored and a BNEP_EVENT_CAN_SEND_NOW requested
*/
/* LISTING_START(networkPacketHandler): Network Packet Handler */
static void network_send_packet_callback ( const uint8_t * packet , uint16_t size ) {
network_buffer = packet ;
network_buffer_len = size ;
bnep_request_can_send_now_event ( bnep_cid ) ;
}
/* LISTING_END */
2015-04-27 00:02:07 +02:00
2014-11-14 20:42:29 +00:00
int btstack_main ( int argc , const char * argv [ ] ) ;
int btstack_main ( int argc , const char * argv [ ] ) {
2014-10-20 10:06:23 +00:00
2017-05-22 22:04:20 +02:00
( void ) argc ;
( void ) argv ;
2017-01-07 22:11:48 +01:00
2015-04-27 00:02:07 +02:00
panu_setup ( ) ;
2017-09-04 13:05:09 +02:00
// parse human readable Bluetooth address
sscanf_bd_addr ( remote_addr_string , remote_addr ) ;
2019-04-05 22:22:50 +02:00
gap_discoverable_control ( 1 ) ;
gap_ssp_set_io_capability ( SSP_IO_CAPABILITY_DISPLAY_YES_NO ) ;
# ifdef ENABLE_PANU_CLIENT
gap_set_local_name ( " PANU Client 00:00:00:00:00:00 " ) ;
# else
gap_set_local_name ( " NAP Server 00:00:00:00:00:00 " ) ;
# endif
gap_set_class_of_device ( 0x020300 ) ; // Service Class "Networking", Major Device Class "LAN / NAT"
// Turn on the device
2014-10-20 10:06:23 +00:00
hci_power_control ( HCI_POWER_ON ) ;
return 0 ;
}
2015-02-06 10:45:10 +00:00
2015-04-24 23:08:52 +02:00
/* EXAMPLE_END */
2015-02-06 10:45:10 +00:00
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */