From 779e62ab89e8da1ad814d413b64d1ae3aa3a8d38 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 16 Jul 2015 11:42:12 +0200 Subject: [PATCH 1/3] fix param order for pan.h --- src/pan.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pan.h b/src/pan.h index ea0e5e982..b72d8f1bc 100644 --- a/src/pan.h +++ b/src/pan.h @@ -91,9 +91,9 @@ typedef enum { * @note Make sure the buffer is big enough. * * @param service is an empty buffer to store service record - * @param security_desc * @param name if NULL, the default service name will be assigned * @param description if NULL, the default service description will be assigned + * @param security_desc */ void pan_create_panu_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc); @@ -102,9 +102,9 @@ void pan_create_panu_service(uint8_t *service, const char *name, const char *des * @note Make sure the buffer is big enough. * * @param service is an empty buffer to store service record - * @param security_desc * @param name if NULL, the default service name will be assigned * @param description if NULL, the default service description will be assigned + * @param security_desc * @param IPv4Subnet is optional subnet definition, e.g. "10.0.0.0/8" * @param IPv6Subnet is optional subnet definition given in the standard IETF format with the absolute attribute IDs */ @@ -117,8 +117,8 @@ void pan_create_gn_service(uint8_t *service, const char *name, const char *descr * * @param service is an empty buffer to store service record * @param name if NULL, the default service name will be assigned - * @param security_desc * @param description if NULL, the default service description will be assigned + * @param security_desc * @param net_access_type type of available network access * @param max_net_access_rate based on net_access_type measured in byte/s * @param IPv4Subnet is optional subnet definition, e.g. "10.0.0.0/8" From 342bf200f4a0961e409b60bfa9edc07cd5c8c3a2 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 16 Jul 2015 12:24:46 +0200 Subject: [PATCH 2/3] allow to pass list of network packet types to PAN SDP record create helpers --- src/pan.c | 21 ++++++++++++--------- src/pan.h | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/pan.c b/src/pan.c index ee852b0af..6833b7251 100644 --- a/src/pan.c +++ b/src/pan.c @@ -58,7 +58,7 @@ static const char default_nap_service_desc[] = "Personal Ad-hoc Network Service static const char default_gn_service_name[] = "Group Ad-hoc Network Service"; static const char default_gn_service_desc[] = "Personal Group Ad-hoc Network Service"; -void pan_create_service(uint32_t service_uuid, uint8_t *service, const char *name, const char *descriptor, +void pan_create_service(uint8_t *service, uint32_t service_uuid, uint16_t * network_packet_types, const char *name, const char *descriptor, security_description_t security_desc, net_access_type_t net_access_type, uint32_t max_net_access_rate, const char *IPv4Subnet, const char *IPv6Subnet){ @@ -96,8 +96,11 @@ void pan_create_service(uint32_t service_uuid, uint8_t *service, const char *nam uint8_t * net_packet_type_list = de_push_sequence(bnep); { - // add Supported Network Packet Type List - // de_add_number(net_packet_type_list, DE_UINT, DE_SIZE_16, 0x0100); // version + if (network_packet_types){ + while (*network_packet_types){ + de_add_number(net_packet_type_list, DE_UINT, DE_SIZE_16, *network_packet_types++); + } + } } de_pop_sequence(bnep, net_packet_type_list); } @@ -211,17 +214,17 @@ void pan_create_service(uint32_t service_uuid, uint8_t *service, const char *nam } -void pan_create_nap_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc, +void pan_create_nap_service(uint8_t *service, uint16_t * network_packet_types, const char *name, const char *description, security_description_t security_desc, net_access_type_t net_access_type, uint32_t max_net_access_rate, const char *IPv4Subnet, const char *IPv6Subnet){ - pan_create_service(SDP_NAP, service, name, description, security_desc, net_access_type, max_net_access_rate, IPv4Subnet, IPv6Subnet); + pan_create_service(service, SDP_NAP, network_packet_types, name, description, security_desc, net_access_type, max_net_access_rate, IPv4Subnet, IPv6Subnet); } -void pan_create_gn_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc, +void pan_create_gn_service(uint8_t *service, uint16_t * network_packet_types, const char *name, const char *description, security_description_t security_desc, const char *IPv4Subnet, const char *IPv6Subnet){ - pan_create_service(SDP_GN, service, name, description, security_desc, PAN_NET_ACCESS_TYPE_NONE, 0, IPv4Subnet, IPv6Subnet); + pan_create_service(service, SDP_GN, network_packet_types, name, description, security_desc, PAN_NET_ACCESS_TYPE_NONE, 0, IPv4Subnet, IPv6Subnet); } -void pan_create_panu_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc){ - pan_create_service(SDP_PANU, service, name, description, security_desc, PAN_NET_ACCESS_TYPE_NONE, 0, NULL, NULL); +void pan_create_panu_service(uint8_t *service, uint16_t * network_packet_types, const char *name, const char *description, security_description_t security_desc){ + pan_create_service(service, SDP_PANU, network_packet_types, name, description, security_desc, PAN_NET_ACCESS_TYPE_NONE, 0, NULL, NULL); } diff --git a/src/pan.h b/src/pan.h index b72d8f1bc..c1c22e3a6 100644 --- a/src/pan.h +++ b/src/pan.h @@ -91,25 +91,29 @@ typedef enum { * @note Make sure the buffer is big enough. * * @param service is an empty buffer to store service record + * @param network_packet_types array of types terminated by a 0x0000 entry * @param name if NULL, the default service name will be assigned * @param description if NULL, the default service description will be assigned * @param security_desc */ -void pan_create_panu_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc); +void pan_create_panu_service(uint8_t *service, uint16_t * network_packet_types, const char *name, + const char *description, security_description_t security_desc); /** * @brief Creates SDP record for GN BNEP service in provided empty buffer. * @note Make sure the buffer is big enough. * * @param service is an empty buffer to store service record + * @param network_packet_types array of types terminated by a 0x0000 entry * @param name if NULL, the default service name will be assigned * @param description if NULL, the default service description will be assigned * @param security_desc * @param IPv4Subnet is optional subnet definition, e.g. "10.0.0.0/8" * @param IPv6Subnet is optional subnet definition given in the standard IETF format with the absolute attribute IDs */ -void pan_create_gn_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc, - const char *IPv4Subnet, const char *IPv6Subnet); +void pan_create_gn_service(uint8_t *service, uint16_t * network_packet_types, const char *name, + const char *description, security_description_t security_desc, const char *IPv4Subnet, + const char *IPv6Subnet); /** * @brief Creates SDP record for NAP BNEP service in provided empty buffer. @@ -117,6 +121,7 @@ void pan_create_gn_service(uint8_t *service, const char *name, const char *descr * * @param service is an empty buffer to store service record * @param name if NULL, the default service name will be assigned + * @param network_packet_types array of types terminated by a 0x0000 entry * @param description if NULL, the default service description will be assigned * @param security_desc * @param net_access_type type of available network access @@ -124,8 +129,10 @@ void pan_create_gn_service(uint8_t *service, const char *name, const char *descr * @param IPv4Subnet is optional subnet definition, e.g. "10.0.0.0/8" * @param IPv6Subnet is optional subnet definition given in the standard IETF format with the absolute attribute IDs */ -void pan_create_nap_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc, - net_access_type_t net_access_type, uint32_t max_net_access_rate, const char *IPv4Subnet, const char *IPv6Subnet); +void pan_create_nap_service(uint8_t *service, uint16_t * network_packet_types, const char *name, + const char *description, security_description_t security_desc, net_access_type_t net_access_type, + uint32_t max_net_access_rate, const char *IPv4Subnet, const char *IPv6Subnet); + /* API_END */ #if defined __cplusplus From 117bd1d8e9c292d87ffe1b6a53961978cc5235cd Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 16 Jul 2015 12:25:28 +0200 Subject: [PATCH 3/3] provide PANU SDP record --- test/pts/bnep_test.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/pts/bnep_test.c b/test/pts/bnep_test.c index 05f9828a2..eda97b3cd 100644 --- a/test/pts/bnep_test.c +++ b/test/pts/bnep_test.c @@ -63,10 +63,12 @@ #include "btstack_memory.h" #include "hci_dump.h" #include "l2cap.h" +#include "sdp.h" #include "pan.h" #include "stdin_support.h" -#define NETWORK_TYPE_IPv4 0x800 +#define NETWORK_TYPE_IPv4 0x0800 +#define NETWORK_TYPE_ARP 0x0806 #define NETWORK_TYPE_IPv6 0x86DD #define ICMP_TYPE_PING_REQUEST 0x08 #define ICMP_TYPE_PING_RESPONSE 0x00 @@ -112,6 +114,8 @@ static uint16_t bnep_cid = 0; static uint8_t network_buffer[BNEP_MTU_MIN]; static size_t network_buffer_len = 0; +static uint8_t panu_sdp_record[200]; + static uint16_t setup_ethernet_header(int src_compressed, int dst_compressed, int broadcast, uint16_t network_protocol_type){ // setup packet int pos = 0; @@ -619,6 +623,7 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ + /* Initialize L2CAP */ l2cap_init(); l2cap_register_packet_handler(packet_handler); @@ -628,8 +633,24 @@ int btstack_main(int argc, const char * argv[]){ bnep_register_packet_handler(packet_handler); bnep_register_service(NULL, bnep_local_service_uuid, 1691); /* Minimum L2CAP MTU for bnep is 1691 bytes */ + /* Initialize SDP and add PANU record */ + sdp_init(); + + uint16_t network_packet_types[] = { NETWORK_TYPE_IPv4, NETWORK_TYPE_ARP, 0}; // 0 as end of list +#ifdef EMBEDDED + service_record_item_t * service_record_item = (service_record_item_t *) panu_sdp_record; + pan_create_panu_service((uint8_t*) &service_record_item->service_record, network_packet_types, NULL, NULL, BNEP_SECURITY_NONE); + printf("SDP service buffer size: %u\n", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); + sdp_register_service_internal(NULL, service_record_item); +#else + pan_create_panu_service(panu_sdp_record, network_packet_types, NULL, NULL, BNEP_SECURITY_NONE); + printf("SDP service record size: %u\n", de_get_len((uint8_t*) panu_sdp_record)); + sdp_register_service_internal(NULL, (uint8_t*)panu_sdp_record); +#endif + /* Turn on the device */ hci_power_control(HCI_POWER_ON); + hci_discoverable_control(1); btstack_stdin_setup(stdin_process);